FreeFOAM The Cross-Platform CFD Toolkit
createBoundaryFaces.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 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 // Specialist version of face comparison to deal with
34 // PROSTAR boundary format idiosyncracies
35 bool starMesh::starEqualFace
36 (
37  const face& boundaryFace,
38  const face& cellFace
39 ) const
40 {
41  // A PROSTAR boundary face is defined by 4 vertices irrespective
42  // of its topology.
43  // In order to deal with all possibilities, cell face is
44  // considered equal if three of the vertices are the same.
45  bool cellFaceHappy = false;
46 
47  label nEqual = 0;
48 
49  forAll (cellFace, cellFaceLabelI)
50  {
51  const label curCellFaceLabel = cellFace[cellFaceLabelI];
52 
53  forAll (boundaryFace, bouFaceLabelI)
54  {
55  if (boundaryFace[bouFaceLabelI] == curCellFaceLabel)
56  {
57  nEqual++;
58 
59  break;
60  }
61  }
62  }
63 
64  if (nEqual >= 3)
65  {
66  cellFaceHappy = true;
67  }
68 
69  // Boundary face is happy if all of its vertices are recognised
70  bool boundaryFaceHappy = true;
71 
72  forAll (boundaryFace, bouFaceLabelI)
73  {
74  const label curBouFaceLabel = boundaryFace[bouFaceLabelI];
75 
76  bool found = false;
77 
78  forAll (cellFace, cellFaceLabelI)
79  {
80  if (curBouFaceLabel == cellFace[cellFaceLabelI])
81  {
82  found = true;
83  break;
84  }
85  }
86 
87  boundaryFaceHappy = boundaryFaceHappy && found;
88  }
89 
90  return (cellFaceHappy && boundaryFaceHappy);
91 }
92 
93 
94 void starMesh::markBoundaryFaces()
95 {
96  // set size of mark lists for the boundary
97  boundaryCellIDs_.setSize(boundary_.size());
98  boundaryCellFaceIDs_.setSize(boundary_.size());
99 
100  forAll(boundary_, patchI)
101  {
102  const faceList& patchFaces = boundary_[patchI];
103 
104  // set size of patch lists
105  labelList& curBoundaryCellIDs = boundaryCellIDs_[patchI];
106  labelList& curBoundaryCellFaceIDs = boundaryCellFaceIDs_[patchI];
107 
108  curBoundaryCellIDs.setSize(patchFaces.size());
109  curBoundaryCellFaceIDs.setSize(patchFaces.size());
110 
111  const labelListList& PointCells = pointCells();
112 
113  forAll(patchFaces, faceI)
114  {
115  bool found = false;
116 
117  const face& curFace = patchFaces[faceI];
118  const labelList& facePoints = curFace;
119 
120  forAll(facePoints, pointI)
121  {
122  const labelList& facePointCells =
123  PointCells[facePoints[pointI]];
124 
125  forAll(facePointCells, cellI)
126  {
127  const label curCellIndex = facePointCells[cellI];
128 
129  const faceList& curCellFaces =
130  cellFaces_[curCellIndex];
131 
132  forAll(curCellFaces, cellFaceI)
133  {
134  if (starEqualFace(curFace, curCellFaces[cellFaceI]))
135  {
136  // Found the cell face corresponding to this face
137  found = true;
138 
139  // Set boundary face to the corresponding cell face
140  curBoundaryCellIDs[faceI] = curCellIndex;
141  curBoundaryCellFaceIDs[faceI] = cellFaceI;
142  }
143  if (found) break;
144  }
145  if (found) break;
146  }
147  if (found) break;
148  }
149  if (!found)
150  {
151  FatalErrorIn("starMesh::markBoundaryFaces()")
152  << "Face " << faceI
153  << " does not have neighbour cell."
154  << " Face : " << endl << curFace << endl
155  << "PROSTAR Command: vset,news,vlis";
156 
157  forAll (curFace, spI)
158  {
159  if (curFace[spI] > -1 && curFace[spI] < starPointID_.size())
160  {
161  Info << "," << starPointID_[curFace[spI]];
162  }
163  else
164  {
165  Info << ",???";
166  }
167  }
168 
169  FatalError << " $ bset,add,vset,all" << abort(FatalError);
170  }
171  }
172  }
173 }
174 
175 
176 void starMesh::collectBoundaryFaces()
177 {
178  Info << "Collecting boundary faces" << endl;
179  forAll(boundary_, patchI)
180  {
181  faceList& patchFaces = boundary_[patchI];
182 
183  // set size of patch lists
184  const labelList& curBoundaryCellIDs = boundaryCellIDs_[patchI];
185  const labelList& curBoundaryCellFaceIDs = boundaryCellFaceIDs_[patchI];
186 
187  forAll (curBoundaryCellIDs, faceI)
188  {
189  patchFaces[faceI] =
190  cellFaces_[curBoundaryCellIDs[faceI]]
191  [curBoundaryCellFaceIDs[faceI]];
192  }
193  }
194 
195  Info << "Finished collecting boundary faces" << endl;
196 }
197 
198 
199 // ************************ vim: set sw=4 sts=4 et: ************************ //