Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
writemblock.cpp
Go to the documentation of this file.
1 /* *******************************************************************
2  * Illinois Open Source License *
3  * *
4  * University of Illinois/NCSA *
5  * Open Source License *
6  * *
7  * Copyright@2008, University of Illinois. All rights reserved. *
8  * *
9  * Developed by: *
10  * *
11  * Center for Simulation of Advanced Rockets *
12  * *
13  * University of Illinois *
14  * *
15  * www.csar.uiuc.edu *
16  * *
17  * Permission is hereby granted, free of charge, to any person *
18  * obtaining a copy of this software and associated documentation *
19  * files (the "Software"), to deal with the Software without *
20  * restriction, including without limitation the rights to use, *
21  * copy, modify, merge, publish, distribute, sublicense, and/or *
22  * sell copies of the Software, and to permit persons to whom the *
23  * Software is furnished to do so, subject to the following *
24  * conditions: *
25  * *
26  * *
27  * @ Redistributions of source code must retain the above copyright *
28  * notice, this list of conditions and the following disclaimers. *
29  * *
30  * @ Redistributions in binary form must reproduce the above *
31  * copyright notice, this list of conditions and the following *
32  * disclaimers in the documentation and/or other materials *
33  * provided with the distribution. *
34  * *
35  * @ Neither the names of the Center for Simulation of Advanced *
36  * Rockets, the University of Illinois, nor the names of its *
37  * contributors may be used to endorse or promote products derived *
38  * from this Software without specific prior written permission. *
39  * *
40  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
41  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
42  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
43  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
44  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
45  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
46  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
47  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
48  *********************************************************************
49  * Please acknowledge The University of Illinois Center for *
50  * Simulation of Advanced Rockets in works and publications *
51  * resulting from this software or its derivatives. *
52  *********************************************************************/
53 /*
54 Routines to write a .mblock mesh description file,
55 given a set of intersecting blocks.
56 
57 Orion Sky Lawlor, olawlor@acm.org, 7/17/2001
58 */
59 #include <stdio.h>
60 #include "makeflo.h"
61 #include "face.h"
62 
63 class mblockData {
64  int nBlock;
65  vector<block *> &blocks;
66  //This class stores the patches for each face of a block
67  class blockPatches {
68  public:
69  vector<patch *> patches[block::nFaces];
70  void init(block *b) {
71  for (int f=0;f<block::nFaces;f++)
72  patches[f]=b->getFace(f).getPatches();
73  }
74  void write(FILE *out,mblockData &d,block *b);
75  void swap(int &a,int &b) {int tmp=a;a=b;b=tmp;}
76  int getPatchNumber(patch *forPatch,int *retFace=NULL)
77  {
78  //Find that patch in our list
79  int patchNo=0;
80  for (int f=0;f<block::nFaces;f++)
81  for (unsigned int p=0;p<patches[f].size();p++)
82  if (patches[f][p]==forPatch) {
83  if (retFace!=NULL) *retFace=f;
84  return patchNo;
85  }
86  else
87  patchNo++;
88  fprintf(stderr,"Can't match patch in %s!\n",__FILE__);
89  abort();
90  return 0;
91  }
92  int totalPatches(void) const {
93  int ret=0;
94  for (int f=0;f<block::nFaces;f++)
95  ret+=patches[f].size();
96  return ret;
97  }
98  };
100 public:
101  mblockData(vector<block *> &blocks_)
102  :blocks(blocks_)
103  {
104  int b;
105  nBlock=blocks.size();
107  for (b=0;b<nBlock;b++)
108  block2patches[b].init(blocks[b]);
109  }
111  delete[] block2patches;
112  }
113 
114  void write(block *b,FILE *out) {
115  block2patches[b->getBlockNumber()].write(out,*this,b);
116  }
117 
118  //Get this patch's number in this block's communication list
119  int getPatchNumber(block *dest,patch *partner)
120  {
121  return block2patches[dest->getBlockNumber()].
122  getPatchNumber(partner);
123  }
124  vector<patch *> &getPatchListWith(block *dest,patch *partner,int *hisFace=NULL)
125  {
127  int face;
128  b.getPatchNumber(partner,&face);
129  if (hisFace!=NULL) *hisFace=face;
130  return b.patches[face];
131  }
132 };
133 
134 const char * writeMblock(vector<block *> &blocks,
135  const char *outMblock)
136 {
137  mblockData d(blocks);
138  for (unsigned int b=0;b<blocks.size();b++) {
139  char fName[1024];
140 
141  //Write the boundary descriptions
142  sprintf(fName,"%s%05d.bblk",outMblock,b);
143  FILE *fb=fopen(fName,"w");
144  if (fb==NULL) return "Couldn't create .bblk file";
145  d.write(blocks[b],fb);
146  fclose(fb);
147 
148  //Write the mesh locations themselves
149  if (!parameters.topologyOnly) {
150  sprintf(fName,"%s%05d.mblk",outMblock,b);
151  FILE *fm=fopen(fName,"wb");
152  if (fm==NULL) return "Couldn't create .bblk file";
153  fwrite(&blocks[b]->getLoc(blockLoc(0,0,0)),sizeof(vector3d),
154  blocks[b]->getDim().getSize(),fm);
155  fclose(fm);
156  }
157  }
158  return NULL;
159 }
160 
162 {
163  internalBCpatch *send=new internalBCpatch(NULL,recv->src,recv->dest,
164  recv->srcSpan,recv->destSpan,recv->orient);
165  return send;
166 }
167 
169 {
170  //Write the block header:
171  fprintf(out,"# Charm++ Mblock framework block boundary condition file\n");
172  fprintf(out,"1.0 # Version number\n");
173  fprintf(out,"%d %d %d %d # Block number and size\n",b->getBlockNumber(),
174  b->getDim()[0],b->getDim()[1],b->getDim()[2]);
175  fprintf(out,"%d %d # Number of faces, patches\n",block::nFaces,totalPatches());
176  for (int f=0;f<block::nFaces;f++)
177  {
178  fprintf(out,"\n%d # Number of patches on this face\n",
179  (int)patches[f].size());
180  for (unsigned int p=0;p<patches[f].size();p++)
181  patches[f][p]->writeMblock(out,d);
182  }
183 }
184 
185 //Print a range of grid indices
186 static void printSpan(FILE *out,const blockSpan &sp)
187 {
188  const blockLoc &s(sp.start), &e(sp.end);
189  fprintf(out," %d %d %d %d %d %d \n",
190  s[0],e[0],s[1],e[1],s[2],e[2]);
191 }
192 
193 
195 {
196  fprintf(out,"%d ",bcNo);
197  printSpan(out,srcSpan);
198 }
199 
201 {
202  fprintf(out,"-1 ");
203  printSpan(out,srcSpan);
204  fprintf(out," %d %d ",dest->getBlockNumber(),
205  d.getPatchNumber(dest,partner));
206  //Figure out the orientation of each axis
207  for (int srcAxis=0;srcAxis<3;srcAxis++) {
208  int destAxis=orient[srcAxis];
209  int isFlipped=0; //Is this axis orientation-reversed?
210  if (destSpan.end[destAxis]<destSpan.start[destAxis])
211  isFlipped=1;
212  fprintf(out,"%c%d ",isFlipped?'-':'+',destAxis+1);
213  }
214  fprintf(out,"\n");
215 }
216 
217 
void write(FILE *out, mblockData &d, block *b)
const char * writeMblock(vector< block * > &blocks, const char *outMblock)
vector< block * > & blocks
Definition: writemblock.cpp:65
const vector< patch * > & getPatches(void) const
Definition: face.h:145
const NT & d
virtual void writeMblock(FILE *out, mblockData &d)
double s
Definition: blastest.C:80
int topologyOnly
Definition: makeflo.h:93
void write(block *b, FILE *out)
blockSpan srcSpan
Definition: patch.h:79
block * src
Definition: patch.h:78
int fclose(std::FILE *file)
Close a file, and check for possible errors.
Definition: CImg.h:5507
void int int int REAL REAL REAL const char * fName
Definition: write.cpp:76
int fwrite(const T *ptr, const unsigned int nmemb, std::FILE *stream)
Write data to a file, and check for possible errors.
Definition: CImg.h:5587
orient_t orient
Definition: patch.h:128
Definition: adj.h:203
Definition: patch.h:74
static void printSpan(FILE *out, const blockSpan &sp)
block * dest
Definition: patch.h:122
blockLoc start
Definition: gridutil.h:155
const blockDim & getDim(void) const
Definition: adj.h:222
blockLoc end
Definition: gridutil.h:156
int totalPatches(void) const
Definition: writemblock.cpp:92
int getPatchNumber(patch *forPatch, int *retFace=NULL)
Definition: writemblock.cpp:76
bool blocks
Input data is block-structured grid.
Definition: hdf2pltV2.C:51
vector< patch * > & getPatchListWith(block *dest, patch *partner, int *hisFace=NULL)
vector< patch * > patches[block::nFaces]
Definition: writemblock.cpp:69
static T_VertexSet * face
Definition: vinci_lass.c:79
blockSpan destSpan
Definition: patch.h:123
makefloParam parameters
Definition: makeflo.cpp:101
blockPatches * block2patches
Definition: writemblock.cpp:99
virtual void writeMblock(FILE *out, mblockData &d)
mblockData(vector< block * > &blocks_)
int getBlockNumber(void) const
Definition: adj.h:219
internalBCpatch * createSendPatch(internalBCpatch *recv, int faceNo)
std::FILE * fopen(const char *const path, const char *const mode)
Open a file, and check for possible errors.
Definition: CImg.h:5494
face & getFace(int faceNo)
Definition: adj.h:248
void swap(int &a, int &b)
Definition: writemblock.cpp:75
int getPatchNumber(block *dest, patch *partner)