initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / conversion / starToFoam / createPolyBoundary.C
blob5f1e4b726045d4c96433d30af01a186a87edd631
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Create intermediate mesh files from PROSTAR files
28 \*---------------------------------------------------------------------------*/
30 #include "starMesh.H"
31 #include "polyPatch.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 void starMesh::createPolyBoundary()
37     label nBoundaryFacesFound = 0;
39     polyBoundaryPatchStartIndices_.setSize(boundary_.size());
41     label nCreatedFaces = nInternalFaces_;
43     const labelListList& PointCells = pointCells();
45     forAll (boundary_, patchI)
46     {
47         const faceList& curShapePatch = boundary_[patchI];
49         polyBoundaryPatchStartIndices_[patchI] = nCreatedFaces;
51         forAll (curShapePatch, faceI)
52         {
53             bool found = false;
55             const face& curFace = curShapePatch[faceI];
57             meshFaces_[nCreatedFaces] = curFace;
59             // Must find which cell this face belongs to in order to
60             // mark it in the cellPolys_
61             const labelList& facePoints = curFace;
63             forAll(facePoints, pointI)
64             {
65                 const labelList& facePointCells =
66                     PointCells[facePoints[pointI]];
68                 forAll(facePointCells, cellI)
69                 {
70                     const faceList& curCellFaces =
71                         cellFaces_[facePointCells[cellI]];
73                     forAll(curCellFaces, cellFaceI)
74                     {
75                         if (curCellFaces[cellFaceI] == curFace)
76                         {
77                             // Found the cell face corresponding to this face
78                             found = true;
80                             // Debugging
81                             if
82                             (
83                                 cellPolys_[facePointCells[cellI]][cellFaceI]
84                              != -1
85                             )
86                             {
87                                 if
88                                 (
89                                     cellPolys_[facePointCells[cellI]][cellFaceI]
90                                   > nInternalFaces_
91                                 )
92                                 {
93                                     Info
94                                         << "void starMesh::createPolyBoundary()"
95                                         << ": Problem with face: " << curFace
96                                         << "\nProbably multiple definitions "
97                                         << "of a single boundary face. " << endl
98                                         << "Other boundary face: "
99                                         << curCellFaces[cellFaceI]
100                                         << endl;
102                                     Info << "PROSTAR Command: vset,news,vlis";
103                                     forAll (curCellFaces[cellFaceI], spI)
104                                     {
105                                         // check if the point is given by STAR
106                                         // or created locally
107                                         if
108                                         (
109                                             curCellFaces[cellFaceI][spI] > -1
110                                          && curCellFaces[cellFaceI][spI]
111                                                 < starPointID_.size()
112                                         )
113                                         {
114                                             Info
115                                                 << ","
116                                                 << starPointID_
117                                                  [curCellFaces[cellFaceI][spI]];
118                                         }
119                                         else
120                                         {
121                                             Info << ",???";
122                                         }
123                                     }
124                                     Info << " $ bset,add,vset,all" << endl;
125                                 }
126                                 else
127                                 {
128                                     Info
129                                         << "void starMesh::createPolyBoundary()"
130                                         << ": Problem with face: " << curFace
131                                         << "\nProbably trying to define a "
132                                         << "boundary face on a previously "
133                                         << "matched internal face. " << endl
134                                         << "Internal face: "
135                                         << curCellFaces[cellFaceI]
136                                         << endl;
138                                     Info << "PROSTAR Command: vset,news,vlis";
139                                     forAll (curCellFaces[cellFaceI], spI)
140                                     {
141                                         // check if the point is given by STAR
142                                         // or created locally
143                                         if
144                                         (
145                                             curCellFaces[cellFaceI][spI] > -1
146                                          && curCellFaces[cellFaceI][spI]
147                                                 < starPointID_.size()
148                                         )
149                                         {
150                                             Info
151                                                 << ","
152                                                 << starPointID_
153                                                  [curCellFaces[cellFaceI][spI]];
154                                         }
155                                         else
156                                         {
157                                             Info << ",???";
158                                         }
159                                     }
160                                     Info << " $ bset,add,vset,all" << endl;
162                                 }
163                             }
165                             cellPolys_[facePointCells[cellI]][cellFaceI] =
166                                 nCreatedFaces;
168                             nBoundaryFacesFound++;
169                         }
170                         if (found) break;
171                     }
172                     if (found) break;
173                 }
174                 if (found) break;
175             }
177             nCreatedFaces++;
178         }
179     }
181     // check all cellPolys_ to see if there are any missing faces
182     label nMissingFaceFound = 0;
184     forAll (cellPolys_, cellI)
185     {
186         const labelList& curFaces = cellPolys_[cellI];
188         forAll (curFaces, faceI)
189         {
190             if (curFaces[faceI] < 0)
191             {
192                 const face& missingFace = cellFaces_[cellI][faceI];
194                 Info << "starMesh::createPolyBoundary() : "
195                     << "missing face found in cell " << cellI
196                     << ".\nType: " << cellShapes_[cellI].model().name()
197                     << ". STAR cell number: " << starCellID_[cellI]
198                     << ". Face: " << missingFace << endl;
200                 nMissingFaceFound++;
202                 Info << "PROSTAR Command: vset,news,vlis";
203                 forAll (missingFace, spI)
204                 {
205                     // check if the point is given by STAR or created locally
206                     if
207                     (
208                         missingFace[spI] > -1
209                      && missingFace[spI] < starPointID_.size()
210                     )
211                     {
212                         Info << "," << starPointID_[missingFace[spI]];
213                     }
214                     else
215                     {
216                         Info << ",???";
217                     }
218                 }
219                 Info << " $ bset,add,vset,all" << endl;
220             }
221         }
222     }
224     if (nMissingFaceFound > 0)
225     {
226         Info << "Number of unmatched faces: " << nMissingFaceFound << endl;
227     }
229     // reset the size of the face list
230     meshFaces_.setSize(nCreatedFaces);
232     // check the mesh for face mismatch
233     // (faces addressed once or more than twice)
234     labelList markupFaces(meshFaces_.size(), 0);
236     forAll (cellPolys_, cellI)
237     {
238         const labelList& curFaces = cellPolys_[cellI];
240         forAll (curFaces, faceI)
241         {
242             markupFaces[curFaces[faceI]]++;
243         }
244     }
246     for (label i = nInternalFaces_; i < markupFaces.size(); i++)
247     {
248         markupFaces[i]++;
249     }
251     label nProblemFacesFound = 0;
253     forAll (markupFaces, faceI)
254     {
255         if (markupFaces[faceI] != 2)
256         {
257             const face& problemFace = meshFaces_[faceI];
259             Info << "starMesh::createPolyBoundary() : "
260                 << "problem with face " << faceI << ": addressed "
261                 << markupFaces[faceI] << " times (should be 2!). Face: "
262                 << problemFace << endl;
264             nProblemFacesFound++;
266             Info << "PROSTAR Command: vset,news,vlis";
267             forAll (problemFace, spI)
268             {
269                 // check if the point is given by STAR or created locally
270                 if
271                 (
272                     problemFace[spI] > -1
273                  && problemFace[spI] < starPointID_.size()
274                 )
275                 {
276                     Info << "," << starPointID_[problemFace[spI]];
277                 }
278                 else
279                 {
280                     Info << ",???";
281                 }
282             }
283             Info << " $ bset,add,vset,all" << endl;
284         }
285     }
287     if (nProblemFacesFound > 0)
288     {
289         Info << "Number of incorrectly matched faces: "
290             << nProblemFacesFound << endl;
291     }
293     Info << "Number of boundary faces: " << nBoundaryFacesFound << endl;
294     Info << "Total number of faces: " << nCreatedFaces << endl;
298 List<polyPatch*> starMesh::polyBoundaryPatches(const polyMesh& pMesh)
300     List<polyPatch*> p(boundary_.size());
302     forAll (boundary_, patchI)
303     {
304         p[patchI] = polyPatch::New
305         (
306             patchTypes_[patchI],
307             patchNames_[patchI],
308             boundary_[patchI].size(),
309             polyBoundaryPatchStartIndices_[patchI],
310             patchI,
311             pMesh.boundaryMesh()
312         ).ptr();
313     }
315     return p;
319 // ************************************************************************* //