FreeFOAM The Cross-Platform CFD Toolkit
createPolyBoundary.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Create intermediate mesh files from PROSTAR files
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "starMesh.H"
30 #include <OpenFOAM/polyPatch.H>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 void starMesh::createPolyBoundary()
35 {
36  label nBoundaryFacesFound = 0;
37 
38  polyBoundaryPatchStartIndices_.setSize(boundary_.size());
39 
40  label nCreatedFaces = nInternalFaces_;
41 
42  const labelListList& PointCells = pointCells();
43 
44  forAll (boundary_, patchI)
45  {
46  const faceList& curShapePatch = boundary_[patchI];
47 
48  polyBoundaryPatchStartIndices_[patchI] = nCreatedFaces;
49 
50  forAll (curShapePatch, faceI)
51  {
52  bool found = false;
53 
54  const face& curFace = curShapePatch[faceI];
55 
56  meshFaces_[nCreatedFaces] = curFace;
57 
58  // Must find which cell this face belongs to in order to
59  // mark it in the cellPolys_
60  const labelList& facePoints = curFace;
61 
62  forAll(facePoints, pointI)
63  {
64  const labelList& facePointCells =
65  PointCells[facePoints[pointI]];
66 
67  forAll(facePointCells, cellI)
68  {
69  const faceList& curCellFaces =
70  cellFaces_[facePointCells[cellI]];
71 
72  forAll(curCellFaces, cellFaceI)
73  {
74  if (curCellFaces[cellFaceI] == curFace)
75  {
76  // Found the cell face corresponding to this face
77  found = true;
78 
79  // Debugging
80  if
81  (
82  cellPolys_[facePointCells[cellI]][cellFaceI]
83  != -1
84  )
85  {
86  if
87  (
88  cellPolys_[facePointCells[cellI]][cellFaceI]
89  > nInternalFaces_
90  )
91  {
92  Info
93  << "void starMesh::createPolyBoundary()"
94  << ": Problem with face: " << curFace
95  << "\nProbably multiple definitions "
96  << "of a single boundary face. " << endl
97  << "Other boundary face: "
98  << curCellFaces[cellFaceI]
99  << endl;
100 
101  Info << "PROSTAR Command: vset,news,vlis";
102  forAll (curCellFaces[cellFaceI], spI)
103  {
104  // check if the point is given by STAR
105  // or created locally
106  if
107  (
108  curCellFaces[cellFaceI][spI] > -1
109  && curCellFaces[cellFaceI][spI]
110  < starPointID_.size()
111  )
112  {
113  Info
114  << ","
115  << starPointID_
116  [curCellFaces[cellFaceI][spI]];
117  }
118  else
119  {
120  Info << ",???";
121  }
122  }
123  Info << " $ bset,add,vset,all" << endl;
124  }
125  else
126  {
127  Info
128  << "void starMesh::createPolyBoundary()"
129  << ": Problem with face: " << curFace
130  << "\nProbably trying to define a "
131  << "boundary face on a previously "
132  << "matched internal face. " << endl
133  << "Internal face: "
134  << curCellFaces[cellFaceI]
135  << endl;
136 
137  Info << "PROSTAR Command: vset,news,vlis";
138  forAll (curCellFaces[cellFaceI], spI)
139  {
140  // check if the point is given by STAR
141  // or created locally
142  if
143  (
144  curCellFaces[cellFaceI][spI] > -1
145  && curCellFaces[cellFaceI][spI]
146  < starPointID_.size()
147  )
148  {
149  Info
150  << ","
151  << starPointID_
152  [curCellFaces[cellFaceI][spI]];
153  }
154  else
155  {
156  Info << ",???";
157  }
158  }
159  Info << " $ bset,add,vset,all" << endl;
160 
161  }
162  }
163 
164  cellPolys_[facePointCells[cellI]][cellFaceI] =
165  nCreatedFaces;
166 
167  nBoundaryFacesFound++;
168  }
169  if (found) break;
170  }
171  if (found) break;
172  }
173  if (found) break;
174  }
175 
176  nCreatedFaces++;
177  }
178  }
179 
180  // check all cellPolys_ to see if there are any missing faces
181  label nMissingFaceFound = 0;
182 
183  forAll (cellPolys_, cellI)
184  {
185  const labelList& curFaces = cellPolys_[cellI];
186 
187  forAll (curFaces, faceI)
188  {
189  if (curFaces[faceI] < 0)
190  {
191  const face& missingFace = cellFaces_[cellI][faceI];
192 
193  Info << "starMesh::createPolyBoundary() : "
194  << "missing face found in cell " << cellI
195  << ".\nType: " << cellShapes_[cellI].model().name()
196  << ". STAR cell number: " << starCellID_[cellI]
197  << ". Face: " << missingFace << endl;
198 
199  nMissingFaceFound++;
200 
201  Info << "PROSTAR Command: vset,news,vlis";
202  forAll (missingFace, spI)
203  {
204  // check if the point is given by STAR or created locally
205  if
206  (
207  missingFace[spI] > -1
208  && missingFace[spI] < starPointID_.size()
209  )
210  {
211  Info << "," << starPointID_[missingFace[spI]];
212  }
213  else
214  {
215  Info << ",???";
216  }
217  }
218  Info << " $ bset,add,vset,all" << endl;
219  }
220  }
221  }
222 
223  if (nMissingFaceFound > 0)
224  {
225  Info << "Number of unmatched faces: " << nMissingFaceFound << endl;
226  }
227 
228  // reset the size of the face list
229  meshFaces_.setSize(nCreatedFaces);
230 
231  // check the mesh for face mismatch
232  // (faces addressed once or more than twice)
233  labelList markupFaces(meshFaces_.size(), 0);
234 
235  forAll (cellPolys_, cellI)
236  {
237  const labelList& curFaces = cellPolys_[cellI];
238 
239  forAll (curFaces, faceI)
240  {
241  markupFaces[curFaces[faceI]]++;
242  }
243  }
244 
245  for (label i = nInternalFaces_; i < markupFaces.size(); i++)
246  {
247  markupFaces[i]++;
248  }
249 
250  label nProblemFacesFound = 0;
251 
252  forAll (markupFaces, faceI)
253  {
254  if (markupFaces[faceI] != 2)
255  {
256  const face& problemFace = meshFaces_[faceI];
257 
258  Info << "starMesh::createPolyBoundary() : "
259  << "problem with face " << faceI << ": addressed "
260  << markupFaces[faceI] << " times (should be 2!). Face: "
261  << problemFace << endl;
262 
263  nProblemFacesFound++;
264 
265  Info << "PROSTAR Command: vset,news,vlis";
266  forAll (problemFace, spI)
267  {
268  // check if the point is given by STAR or created locally
269  if
270  (
271  problemFace[spI] > -1
272  && problemFace[spI] < starPointID_.size()
273  )
274  {
275  Info << "," << starPointID_[problemFace[spI]];
276  }
277  else
278  {
279  Info << ",???";
280  }
281  }
282  Info << " $ bset,add,vset,all" << endl;
283  }
284  }
285 
286  if (nProblemFacesFound > 0)
287  {
288  Info << "Number of incorrectly matched faces: "
289  << nProblemFacesFound << endl;
290  }
291 
292  Info << "Number of boundary faces: " << nBoundaryFacesFound << endl;
293  Info << "Total number of faces: " << nCreatedFaces << endl;
294 }
295 
296 
297 List<polyPatch*> starMesh::polyBoundaryPatches(const polyMesh& pMesh)
298 {
299  List<polyPatch*> p(boundary_.size());
300 
301  forAll (boundary_, patchI)
302  {
303  p[patchI] = polyPatch::New
304  (
305  patchTypes_[patchI],
306  patchNames_[patchI],
307  boundary_[patchI].size(),
308  polyBoundaryPatchStartIndices_[patchI],
309  patchI,
310  pMesh.boundaryMesh()
311  ).ptr();
312  }
313 
314  return p;
315 }
316 
317 
318 // ************************ vim: set sw=4 sts=4 et: ************************ //