Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
buildface.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 Match up nodelists into actual patches, and
55 construct all type 2 boundary conditions
56 
57 Orion Sky Lawlor, olawlor@acm.org, 6/8/2001
58 */
59 #include <stdio.h>
60 #include "face.h"
61 
62 
63 bool patch::isExternal(void) const {return false;}
64 bool externalBCpatch::isExternal(void) const {return true;}
65 
67 {
68  blockLoc ret(0,0,0);
69  for (int i=0;i<3;i++)
70  if (dir[i])
71  ret[i] = b->getDim()[i]-1;
72  return ret;
73 }
74 
75 //Return true if any block lists us with an external BC
76 bool adjList::isExternal(void) const
77 {
78  adjRec *cur=next;
79  while (cur!=NULL) {
80  patch *p=cur->getFace()->patchForCoord(cur->getLoc());
81  if (p->isExternal())
82  return true;
83  cur=cur->getNext();
84  }
85  return false;
86 }
87 
88 inline void swap(int &a,int &b) {int tmp=a;a=b;b=tmp;}
89 
90 patch *findPatch(const blockSpan &at,const vector<patch *> &from)
91 {
92  int p,len=from.size();
93  for (p=0;p<len;p++)
94  if (from[p]->srcSpan==at)
95  return from[p];
96  return NULL;
97 }
98 
99 //Find the corresponding patch on the destination block
101 {
102  //First orient the start and end locations:
103  blockSpan d=p->destSpan;
104  d.orient();
105  patch *partner=NULL;
106  for (int f=0;partner==NULL && f<block::nFaces;f++)
107  partner=findPatch(d,p->dest->getFace(f).getPatches());
108  if (partner==NULL) {
109  fprintf(stderr,"Couldn't find match for internal patch on block %d!\n",
110  p->dest->getBlockNumber()+1);
111  abort();
112  }
113  p->setPartner((internalBCpatch *)partner);
114 }
115 
116 //Return true if a's face is "smaller" than b's
117 bool isSmaller(face *a,face *b) {
118  int a_area=a->getDim().getSize();
119  int b_area=b->getDim().getSize();
120  return a_area<=b_area;
121 }
122 
123 void buildFaces(vector<block *> &blocks,bool buildTypeTwo)
124 {
125  int f; unsigned int bNo;
126  /* Build each block's faces, which matches up the nodes*/
127  nodeMatcher map;
128  for (bNo=0;bNo<blocks.size();bNo++)
129  blocks[bNo]->buildFaces(map);
130 
131  /* Build each face's patches, which aggregates matched nodes
132  into rectangular patches.*/
133  for (bNo=0;bNo<blocks.size();bNo++)
134  for (f=0;f<block::nFaces;f++)
135  blocks[bNo]->getFace(f).buildPatches();
136 
137  /*Match up facing internal patches*/
138  for (bNo=0;bNo<blocks.size();bNo++)
139  for (f=0;f<block::nFaces;f++) {
140  const vector<patch *> &patches=
141  blocks[bNo]->getFace(f).getPatches();
142  for (unsigned int pNo=0;pNo<patches.size();pNo++) {
143  patch *p=patches[pNo];
144  if (p->isExternal()) continue;
146  }
147  }
148 
149  if (!buildTypeTwo) return;
150  /*
151  Determine which patches should be "type two"--
152  patches whose neighbors get pulled around by
153  mesh motion, but don't move themselves.
154  Such patches touch a corner node that faces the
155  exterior; but none of them are exterior themselves.
156  */
157  const int nCorners=8;
158  blockLoc cornDirs[nCorners]={
159  blockLoc(0,0,0),
160  blockLoc(0,0,1),
161  blockLoc(0,1,0),
162  blockLoc(0,1,1),
163  blockLoc(1,0,0),
164  blockLoc(1,0,1),
165  blockLoc(1,1,0),
166  blockLoc(1,1,1)
167  };
168  /*Loop over blocks*/
169  for (bNo=0;bNo<blocks.size();bNo++) {
170  block *b=blocks[bNo];
171  /*Loop over corners*/
172  for (int cNo=0;cNo<nCorners;cNo++) {
173  blockLoc c=dirToCorner(b,cornDirs[cNo]);
174  /*Determine if this corner faces external world*/
175  node *n=map.loc2node(b->getLoc(c));
176  if (!n->isExternal())
177  continue; /*Nothing to do*/
178  /*Corner faces outside-- check if any of our patches do:*/
179  bool hasExternalFace=false;
180  for (f=0;f<block::nFaces;f++) {
181  patch *p=b->getFace(f).patchForCoord(c);
182  if (p!=NULL && p->isExternal())
183  hasExternalFace=true;
184  }
185  if (hasExternalFace)
186  continue; /*Nothing to do*/
187  /*Corner is outside, but none of our faces are:
188  mark all patches as type 2.
189  */
190  printf("Corner %d of block %d is external> patches on ",
191  cNo,b->getBlockNumber()+1);
192  for (f=0;f<block::nFaces;f++) {
193  patch *p=b->getFace(f).patchForCoord(c);
194  if (p!=NULL) {
195  printf("%s ",block::face2name[f]);
196  ((internalBCpatch *)p)->setType(2);
197  }
198  }
199  printf("are all type 2\n");
200  }
201  }
202  /*Loop over patches, eliminating facing pairs of type 2 boundaries*/
203  for (bNo=0;bNo<blocks.size();bNo++) {
204  block *b=blocks[bNo];
205  for (f=0;f<block::nFaces;f++) {
206  const vector<patch *> &patches=b->getFace(f).getPatches();
207  for (unsigned int pNo=0;pNo<patches.size();pNo++) {
208  patch *p=patches[pNo];
209  if (!p->isExternal()) {
211  if (i->type==2 && i->partner->type==2)
212  /*A facing pair of type 2's!*/
213  i->type=i->partner->type=1;
214  }
215  }
216  }
217  }
218 
219  /*Loop over patches one final time, adding type 2's to the
220  smaller face of each pair.*/
221  for (bNo=0;bNo<blocks.size();bNo++) {
222  block *b=blocks[bNo];
223  for (f=0;f<block::nFaces;f++) {
224  const vector<patch *> &patches=b->getFace(f).getPatches();
225  for (unsigned int pNo=0;pNo<patches.size();pNo++) {
226  patch *p=patches[pNo];
227  if (!p->isExternal()) {
229  if (i->type==1 && i->partner->type==1
230  && isSmaller(i->getFace(),i->partner->getFace()))
231  i->type=2;
232  }
233  }
234  }
235  }
236 
237 }
238 
239 
void swap(int &a, int &b)
Definition: buildface.cpp:88
blockLoc dirToCorner(block *b, const blockLoc &dir)
Definition: buildface.cpp:66
internalBCpatch * partner
Definition: patch.h:124
const vector< patch * > & getPatches(void) const
Definition: face.h:145
Definition: face.h:90
const NT & d
void orient(void)
Definition: gridutil.h:165
node * loc2node(const vector3d &loc)
Definition: adj.cpp:230
face * getFace(void) const
Definition: patch.h:82
Definition: adj.h:150
const blockLoc & getLoc(void) const
Definition: adj.h:116
face * getFace(void)
Definition: adj.h:114
bool isSmaller(face *a, face *b)
Definition: buildface.cpp:117
patch * patchForCoord(const blockLoc &at)
Definition: face.cpp:120
Definition: adj.h:203
Definition: patch.h:74
static const char * face2name[nFaces]
Definition: adj.h:236
block * dest
Definition: patch.h:122
const blockDim & getDim(void) const
Definition: adj.h:222
adjRec * getNext(void)
Definition: adj.h:117
blockLoc i
Definition: read.cpp:79
virtual bool isExternal(void) const
Definition: buildface.cpp:64
const NT & n
void findPartner(internalBCpatch *p)
Definition: buildface.cpp:100
blockDim getDim(void) const
Definition: face.h:141
void setPartner(internalBCpatch *p)
Definition: patch.h:125
bool blocks
Input data is block-structured grid.
Definition: hdf2pltV2.C:51
Definition: adj.h:103
adjRec * next
Definition: adj.h:125
virtual bool isExternal(void) const
Definition: buildface.cpp:63
const vector3d & getLoc(const blockLoc &l) const
Definition: adj.h:223
blockSpan destSpan
Definition: patch.h:123
patch * findPatch(const blockSpan &at, const vector< patch * > &from)
Definition: buildface.cpp:90
bool isExternal(void) const
Definition: buildface.cpp:76
int getSize(void) const
Definition: gridutil.h:126
int getBlockNumber(void) const
Definition: adj.h:219
face & getFace(int faceNo)
Definition: adj.h:248
void buildFaces(vector< block * > &blocks, bool buildTypeTwo)
Definition: buildface.cpp:123