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) 2011-2016 OpenFOAM Foundation
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 "polyPatch.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 void Foam::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  {
93  << "Problem with face: " << curFace
94  << "\nProbably multiple definitions "
95  << "of a single boundary face. " << endl
96  << "Other boundary face: "
97  << curCellFaces[cellFacei]
98  << endl;
99 
100  Info<< "PROSTAR Command: vset,news,vlis";
101  forAll(curCellFaces[cellFacei], spI)
102  {
103  // check if the point is given by STAR
104  // or created locally
105  if
106  (
107  curCellFaces[cellFacei][spI] > -1
108  && curCellFaces[cellFacei][spI]
109  < starPointID_.size()
110  )
111  {
112  Info<< ","
113  << starPointID_
114  [curCellFaces[cellFacei][spI]];
115  }
116  else
117  {
118  Info<< ",???";
119  }
120  }
121  Info<< " $ bset,add,vset,all" << endl;
122  }
123  else
124  {
126  << "Problem with face: " << curFace
127  << "\nProbably trying to define a "
128  << "boundary face on a previously "
129  << "matched internal face. " << endl
130  << "Internal face: "
131  << curCellFaces[cellFacei]
132  << endl;
133 
134  Info<< "PROSTAR Command: vset,news,vlis";
135  forAll(curCellFaces[cellFacei], spI)
136  {
137  // check if the point is given by STAR
138  // or created locally
139  if
140  (
141  curCellFaces[cellFacei][spI] > -1
142  && curCellFaces[cellFacei][spI]
143  < starPointID_.size()
144  )
145  {
146  Info<< ","
147  << starPointID_
148  [curCellFaces[cellFacei][spI]];
149  }
150  else
151  {
152  Info<< ",???";
153  }
154  }
155  Info<< " $ bset,add,vset,all" << endl;
156 
157  }
158  }
159 
160  cellPolys_[facePointCells[celli]][cellFacei] =
161  nCreatedFaces;
162 
163  nBoundaryFacesFound++;
164  }
165  if (found) break;
166  }
167  if (found) break;
168  }
169  if (found) break;
170  }
171 
172  nCreatedFaces++;
173  }
174  }
175 
176  // check all cellPolys_ to see if there are any missing faces
177  label nMissingFaceFound = 0;
178 
179  forAll(cellPolys_, celli)
180  {
181  const labelList& curFaces = cellPolys_[celli];
182 
183  forAll(curFaces, facei)
184  {
185  if (curFaces[facei] < 0)
186  {
187  const face& missingFace = cellFaces_[celli][facei];
188 
190  << "Missing face found in cell " << celli
191  << ".\nType: " << cellShapes_[celli].model().name()
192  << ". STAR cell number: " << starCellID_[celli]
193  << ". Face: " << missingFace << endl;
194 
195  nMissingFaceFound++;
196 
197  Info<< "PROSTAR Command: vset,news,vlis";
198  forAll(missingFace, spI)
199  {
200  // check if the point is given by STAR or created locally
201  if
202  (
203  missingFace[spI] > -1
204  && missingFace[spI] < starPointID_.size()
205  )
206  {
207  Info<< "," << starPointID_[missingFace[spI]];
208  }
209  else
210  {
211  Info<< ",???";
212  }
213  }
214  Info<< " $ bset,add,vset,all" << endl;
215  }
216  }
217  }
218 
219  if (nMissingFaceFound > 0)
220  {
221  Info<< "Number of unmatched faces: " << nMissingFaceFound << endl;
222  }
223 
224  // reset the size of the face list
225  meshFaces_.setSize(nCreatedFaces);
226 
227  // check the mesh for face mismatch
228  // (faces addressed once or more than twice)
229  labelList markupFaces(meshFaces_.size(), 0);
230 
231  forAll(cellPolys_, celli)
232  {
233  const labelList& curFaces = cellPolys_[celli];
234 
235  forAll(curFaces, facei)
236  {
237  markupFaces[curFaces[facei]]++;
238  }
239  }
240 
241  for (label i = nInternalFaces_; i < markupFaces.size(); i++)
242  {
243  markupFaces[i]++;
244  }
245 
246  label nProblemFacesFound = 0;
247 
248  forAll(markupFaces, facei)
249  {
250  if (markupFaces[facei] != 2)
251  {
252  const face& problemFace = meshFaces_[facei];
253 
255  << "Problem with face " << facei << ": addressed "
256  << markupFaces[facei] << " times (should be 2!). Face: "
257  << problemFace << endl;
258 
259  nProblemFacesFound++;
260 
261  Info<< "PROSTAR Command: vset,news,vlis";
262  forAll(problemFace, spI)
263  {
264  // check if the point is given by STAR or created locally
265  if
266  (
267  problemFace[spI] > -1
268  && problemFace[spI] < starPointID_.size()
269  )
270  {
271  Info<< "," << starPointID_[problemFace[spI]];
272  }
273  else
274  {
275  Info<< ",???";
276  }
277  }
278  Info<< " $ bset,add,vset,all" << endl;
279  }
280  }
281 
282  if (nProblemFacesFound > 0)
283  {
284  Info<< "Number of incorrectly matched faces: "
285  << nProblemFacesFound << endl;
286  }
287 
288  Info<< "Number of boundary faces: " << nBoundaryFacesFound << endl;
289  Info<< "Total number of faces: " << nCreatedFaces << endl;
290 }
291 
292 
294 Foam::starMesh::polyBoundaryPatches(const polyMesh& pMesh)
295 {
296  List<polyPatch*> p(boundary_.size());
297 
298  forAll(boundary_, patchi)
299  {
301  (
302  patchTypes_[patchi],
303  patchNames_[patchi],
304  boundary_[patchi].size(),
305  polyBoundaryPatchStartIndices_[patchi],
306  patchi,
307  pMesh.boundaryMesh()
308  ).ptr();
309  }
310 
311  return p;
312 }
313 
314 
315 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
List< label > labelList
A List of labels.
Definition: labelList.H:56
void setSize(const label)
Reset size of List.
Definition: List.C:281
label patchi
messageStream Info
static autoPtr< polyPatch > New(const word &patchType, const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm)
Return a pointer to a new patch created on freestore from.
Definition: polyPatchNew.C:32
volScalarField & p
#define InfoInFunction
Report an information message using Foam::Info.