Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adj.h
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 Determine which blocks are adjacent, at which
55 faces. To do this, we keep a node->face list.
56 
57 Orion Sky Lawlor, olawlor@acm.org, 5/30/2001
58 */
59 #ifndef __CSAR_ADJ_H
60 #define __CSAR_ADJ_H
61 #include <cstdlib>
62 #include <cstring>
63 #include <cstdio>
64 #include <vector>
65 using std::vector;
66 #include "hash_table.h"
67 #include "gridutil.h"
68 #include "patch.h"
69 
70 //A trivial grouped allocator
71 template <class T>
72 class allocPool {
73  enum {nAlloc=256}; //Number to allocate at once
74  T *buf;
75  int cur;
76  void fillBuffer(void) {
77  bufferCount++;
78  buf=(T*)malloc(sizeof(T)*nAlloc);
79  cur=0;
80  }
81 public:
84  cur=nAlloc;
86  }
87  void *alloc(void) {
88  allocCount++;
89  if (cur>=nAlloc) fillBuffer();
90  return &buf[cur++];
91  }
92  void free(void *) {
93  freeCount++;
94  /*otherwise ignored*/
95  }
96 };
97 
98 class face;
99 class block;
100 
101 //Records that the pointing node
102 // has the given location in the given face
103 class adjRec {
104  face *b;
107 public:
109  void *operator new(size_t s) { return pool.alloc(); }
110  void operator delete(void *ptr) { pool.free(ptr); }
111 
112  adjRec(face *b_,const blockLoc &l_,adjRec *next_=NULL)
113  :b(b_), l(l_), next(next_) { }
114  face *getFace(void) {return b;}
115  const face *getFace(void) const {return b;}
116  const blockLoc &getLoc(void) const {return l;}
117  adjRec *getNext(void) {return next;}
118  void print(void);
119  bool isExternal(void) const;
120 };
121 
122 //Maintains a (possibly zero-length) list of adjacent blocks
123 class adjList {
124  protected:
125  adjRec *next;//Blocks we're adjacent to
126 public:
128  next=NULL;
129  }
130  ~adjList();
131 
132  int getLength(void) const;
133 
134  bool hasFace(const face *test) const;
135  bool hasLoc(const face *test,const blockLoc &l) const;
136 
137  //Add this block & loc to the list (if they're not already there)
138  void addFace(face *b,const blockLoc &l);
139 
140  //Find our (first) location in this face
141  const blockLoc &getLoc(const face *b) const;
142 
143  //Return true if any block lists us with an external BC
144  bool isExternal(void) const;
145 
146  void print(void) const;
147 };
148 
149 //A location in space, owned by (possibly several) faces
150 class node : public adjList {
151  const vector3d &loc; //Coordinates of this node
152 public:
154  void *operator new(size_t s) { return pool.alloc(); }
155  void operator delete(void *ptr) { pool.free(ptr); }
156 
157  node(const vector3d &l) :loc(l) { }
158 
159  //Get location in 3D space
160  const vector3d &getLoc(void) const { return loc; }
161 
162  //Find our index in this face
163  const blockLoc &getLoc(const face *b) const { return adjList::getLoc(b); }
164 
165  //Return some face present in all 4 nodes,
166  // but different from notHim. Optionally return the
167  // destination location and orientations
168  static face *intersect(const node** nodes,
169  const face *notHim=NULL,
170  blockLoc *loc=NULL,
171  blockLoc *oX=NULL, blockLoc *oY=NULL);
172 
173 };
174 
175 /*A vector3D, quantized to integers
176 so roundoff will not affect node matching.
177 */
179  int x,y,z;
180  public:
181  static double scale,offset; //Converts doubles to integers
182  static void checkVector(const vector3d &v);
183 
184  hashableVector3d(const vector3d &v);
185 };
186 
187 /*This class accepts node locations read from
188 the input file and either returns a previously
189 created node, or creates a new node for the location.
190 This maps (non-unique) locations onto (unique)
191 node objects.
192 */
193 class nodeMatcher {
194  //This table maps node location to node records
195  CkHashtableTslow<hashableVector3d,node *> map;
196 public:
197  //Map this location to a node.
198  // Creates a new node there if none exists
199  node *loc2node(const vector3d &loc);
200 };
201 
202 //A rectangular 3D grid of nodes
203 class block {
204  blockDim dim;//This block's size
205  int originalNo; //The source block's (0-based) serial number
206  int blockNo;//This block's (0-based) serial number
207  vector3d *nodeLocs;//The locations of all nodes (dim.getSize() vectors)
208 
209  //Force this location in-bounds
210  blockLoc pin(const blockLoc &l) const;
211 
212  //Create a new block as a subregion of this one
213  block *subBlock(const blockSpan &span) const;
214 public:
215  block(const blockDim &dim_,int originalNo_,int blockNo_,vector3d *nodeLocs_);
216  ~block();
217 
218  //Return our 0-based block number
219  int getBlockNumber(void) const { return blockNo; }
220  int getOriginalNumber(void) const { return originalNo; }
221 
222  const blockDim &getDim(void) const {return dim;}
223  const vector3d &getLoc(const blockLoc &l) const
224  {return nodeLocs[dim[l]];}
225 
226  //Split this block into n pieces, which go into dest
227  void split(int nPieces,vector<block *> &dest);
228 
229  //Describes the 6 faces of the block
230  enum {
231  iMin=0,jMin=1,kMin=2,
232  iMax=3,jMax=4,kMax=5,
234  };
235  //Maps face number to a human-readable name
236  static const char *face2name[nFaces];
237 
238 private:
239  //External boundary conditions per face
240  vector<externalBCpatch> BCs[nFaces];
242 public:
243  //Set an external boundary condition
244  void addBC(const blockSpan &span,int bcNo);
245 
246  //Build/access our face structures
247  void buildFaces(nodeMatcher &map);
248  face &getFace(int faceNo) {return *faces[faceNo];}
249  const face &getFace(int faceNo) const {return *faces[faceNo];}
250  int getFaceNo(const face *f) {
251  for (int i=0;i<nFaces;i++)
252  if (faces[i]==f) return i;
253  return nFaces;
254  }
255 };
256 
257 /************** BlockReader **********/
258 class blockReader : public blockConsumer {
259  int curBlock;//Index of current block
260  vector<block *> &blocks;
261 public:
262  blockReader(vector<block *> &dest) :blocks(dest) {curBlock=0;}
263 
264  virtual const char *consume(
265  const blockDim &dim,//Dimentions of incoming block
266  vector3d *locs); //X,Y,Z coordinates (ni x nj x nk)
267 
268  virtual void freeBlock(vector3d *locs);
269 };
270 
271 
272 
273 #endif
274 
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
const blockLoc & getLoc(const face *b) const
Definition: adj.h:163
int cur
Definition: adj.h:75
int getOriginalNumber(void) const
Definition: adj.h:220
const vector3d & getLoc(void) const
Definition: adj.h:160
void addBC(const blockSpan &span, int bcNo)
Definition: adj.cpp:262
int blockNo
Definition: adj.h:206
Definition: face.h:90
vector< externalBCpatch > BCs[nFaces]
Definition: adj.h:240
void addFace(face *b, const blockLoc &l)
Definition: adj.cpp:105
static allocPool< adjRec > pool
Definition: adj.h:108
const vector3d & loc
Definition: adj.h:151
face * faces[nFaces]
Definition: adj.h:241
double s
Definition: blastest.C:80
allocPool()
Definition: adj.h:83
void free(void *)
Definition: adj.h:92
bool isExternal(void) const
block * subBlock(const blockSpan &span) const
Definition: split.cpp:88
node * loc2node(const vector3d &loc)
Definition: adj.cpp:230
const face & getFace(int faceNo) const
Definition: adj.h:249
void print(void) const
Definition: adj.cpp:120
static double offset
Definition: adj.h:181
int getFaceNo(const face *f)
Definition: adj.h:250
blockLoc l
Definition: adj.h:105
Definition: adj.h:150
T * buf
Definition: adj.h:74
void fillBuffer(void)
Definition: adj.h:76
Definition: adj.h:123
const face * getFace(void) const
Definition: adj.h:115
const blockLoc & getLoc(void) const
Definition: adj.h:116
~block()
Definition: adj.cpp:254
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
face * getFace(void)
Definition: adj.h:114
int bufferCount
Definition: adj.h:82
CkHashtableTslow< hashableVector3d, node * > map
Definition: adj.h:195
bool hasFace(const face *test) const
Definition: adj.cpp:93
static allocPool< node > pool
Definition: adj.h:153
Definition: adj.h:203
vector< block * > & blocks
Definition: adj.h:260
const blockLoc & getLoc(const face *b) const
Definition: adj.cpp:111
static const char * face2name[nFaces]
Definition: adj.h:236
static void checkVector(const vector3d &v)
Definition: adj.cpp:209
void * alloc(void)
Definition: adj.h:87
Definition: adj.h:72
const blockDim & getDim(void) const
Definition: adj.h:222
adjRec * getNext(void)
Definition: adj.h:117
int allocCount
Definition: adj.h:82
blockLoc i
Definition: read.cpp:79
void test(void)
Definition: flotsam.C:99
static double scale
Definition: adj.h:181
blockLoc pin(const blockLoc &l) const
Definition: split.cpp:77
bool hasLoc(const face *test, const blockLoc &l) const
Definition: adj.cpp:99
int originalNo
Definition: adj.h:205
node(const vector3d &l)
Definition: adj.h:157
virtual void freeBlock(vector3d *locs)
Definition: adj.cpp:316
face * b
Definition: adj.h:104
Definition: adj.h:103
int getLength(void) const
Definition: adj.cpp:87
adjRec * next
Definition: adj.h:125
const vector3d & getLoc(const blockLoc &l) const
Definition: adj.h:223
static face * intersect(const node **nodes, const face *notHim=NULL, blockLoc *loc=NULL, blockLoc *oX=NULL, blockLoc *oY=NULL)
Definition: adj.cpp:136
int curBlock
Definition: adj.h:259
adjRec * next
Definition: adj.h:106
virtual const char * consume(const blockDim &dim, vector3d *locs)
Definition: adj.cpp:299
vector3d * nodeLocs
Definition: adj.h:207
int freeCount
Definition: adj.h:82
~adjList()
Definition: adj.cpp:79
hashableVector3d(const vector3d &v)
Definition: adj.cpp:220
bool isExternal(void) const
Definition: buildface.cpp:76
void buildFaces(nodeMatcher &map)
Definition: adj.cpp:273
block(const blockDim &dim_, int originalNo_, int blockNo_, vector3d *nodeLocs_)
Definition: adj.cpp:244
adjRec(face *b_, const blockLoc &l_, adjRec *next_=NULL)
Definition: adj.h:112
int getBlockNumber(void) const
Definition: adj.h:219
void print(void)
Definition: adj.cpp:68
blockDim dim
Definition: adj.h:204
face & getFace(int faceNo)
Definition: adj.h:248
void split(int nPieces, vector< block * > &dest)
Definition: split.cpp:113
blockReader(vector< block * > &dest)
Definition: adj.h:262
adjList()
Definition: adj.h:127