FreeFOAM The Cross-Platform CFD Toolkit
starMesh.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 \*---------------------------------------------------------------------------*/
25 
26 #include "starMesh.H"
29 #include <OpenFOAM/cellModeller.H>
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 // Merge tolerances
34 // Moni, tolerances:
35 const scalar starMesh::smallMergeTol_ = 1e-3;
36 const scalar starMesh::cpMergePointTol_ = 1e-4;
37 
38 // const scalar starMesh::smallMergeTol_ = 4e-4;
39 // const scalar starMesh::cpMergePointTol_ = 1e-3;
40 
41 // Cell shape models
42 const cellModel* starMesh::unknownPtr_ = cellModeller::lookup("unknown");
43 const cellModel* starMesh::tetPtr_ = cellModeller::lookup("tet");
44 const cellModel* starMesh::pyrPtr_ = cellModeller::lookup("pyr");
45 const cellModel* starMesh::tetWedgePtr_ = cellModeller::lookup("tetWedge");
46 const cellModel* starMesh::prismPtr_ = cellModeller::lookup("prism");
47 const cellModel* starMesh::wedgePtr_ = cellModeller::lookup("wedge");
48 const cellModel* starMesh::hexPtr_ = cellModeller::lookup("hex");
49 
50 const cellModel* starMesh::sammTrim1Ptr_ = cellModeller::lookup("sammTrim1");
51 const cellModel* starMesh::sammTrim2Ptr_ = cellModeller::lookup("sammTrim2");
52 const cellModel* starMesh::sammTrim3Ptr_ = cellModeller::lookup("sammTrim3");
53 const cellModel* starMesh::sammTrim4Ptr_ = cellModeller::lookup("sammTrim4");
54 const cellModel* starMesh::sammTrim5Ptr_ = cellModeller::lookup("sammTrim5");
55 const cellModel* starMesh::sammTrim8Ptr_ = cellModeller::lookup("hexagonalPrism");
56 
57 // Regular cell point addressing
58 // SAMM point addressing
59 const label starMesh::regularAddressingTable[6][8] =
60 {
61  { 0, 1, 2, 4, -1, -1, -1, -1}, // tet
62  { 0, 1, 2, 3, 4, -1, -1, -1}, // pyramid
63  { 0, 1, 2, 4, 6, -1, -1, -1}, // tet wedge
64  { 0, 1, 2, 4, 5, 6, -1, -1}, // prism
65  { 7, 6, 5, 3, 2, 1, 0, -1}, // wedge
66  { 0, 1, 2, 3, 4, 5, 6, 7} // hex
67 };
68 
69 
70 // SAMM point addressing
71 const label starMesh::sammAddressingTable[9][12] =
72 {
73  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // samm0 - empty
74  { 3, 2, 6, 7, 11, 9, 1, 5, 4, 12, -1, -1}, // samm1+
75  {13, 5, 6, 2, 10, 12, 4, 7, 3, 11, -1, -1}, // samm2+
76  { 2, 3, 0, 1, 10, 11, 12, 4, 8, 9, -1, -1}, // samm3+
77  { 0, 1, 3, 4, 13, 8, 9, 10, 11, 12, -1, -1}, // samm4+
78  {12, 7, 6, 5, 8, 11, 10, 9, -1, -1, -1, -1}, // samm5+
79  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // samm6 - empty
80  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // samm7 - empty
81  {11, 3, 15, 12, 4, 8, 10, 2, 14, 13, 5, 9} // samm8+
82 };
83 
84 
85 // lookup table giving FOAM face number when looked up with shape index
86 // (first index) and STAR face number
87 // - first column is always -1
88 // - last column is -1 for all but hexagonal prism
89 // WARNING: Possible bug for sammTrim2
90 // The lookup table for SAMM shapes is based on the rotation of the
91 // shape. This would imply that the table below needs to be split between
92 // the regular shapes (3-9), which are OK, and the SAMM shapes, for which
93 // the face lookup needs to be done based on the rotation. Thus, for a samm
94 // cell, firts find out the face index in the normal rotation using the cell
95 // face permutation table and then use the index from the shape face lookup.
96 // Additionally, have in mind that this silliness does not allow matches
97 // on face 7 and 8 of the samm cell.
98 
99 const label starMesh::sammFacePermutationTable[24][8] =
100 {
101  {-1, 1, 2, 3, 4, 5, 6, 7}, // permutation 0
102  {-1, 3, 4, 5, 6, 1, 2, 7}, // permutation 1
103  {-1, 5, 6, 1, 2, 3, 4, 7}, // permutation 2
104  {-1, 1, 2, 5, 6, 4, 3, 7}, // permutation 3
105  {-1, 3, 4, 1, 2, 6, 5, 7}, // permutation 4
106  {-1, 5, 6, 3, 4, 2, 1, 7}, // permutation 5
107  {-1, 1, 2, 4, 3, 6, 5, 7}, // permutation 6
108  {-1, 3, 4, 6, 5, 2, 1, 7}, // permutation 7
109  {-1, 5, 6, 2, 1, 4, 3, 7}, // permutation 8
110  {-1, 1, 2, 6, 5, 3, 4, 7}, // permutation 9
111  {-1, 3, 4, 2, 1, 5, 6, 7}, // permutation 10
112  {-1, 5, 6, 4, 3, 1, 2, 7}, // permutation 11
113  {-1, 2, 1, 5, 6, 3, 4, 7}, // permutation 12
114  {-1, 4, 3, 1, 2, 5, 6, 7}, // permutation 13
115  {-1, 6, 5, 3, 4, 1, 2, 7}, // permutation 14
116  {-1, 2, 1, 3, 4, 6, 5, 7}, // permutation 15
117  {-1, 4, 3, 5, 6, 2, 1, 7}, // permutation 16
118  {-1, 6, 5, 1, 2, 4, 3, 7}, // permutation 17
119  {-1, 2, 1, 6, 5, 4, 3, 7}, // permutation 18
120  {-1, 4, 3, 2, 1, 6, 5, 7}, // permutation 19
121  {-1, 6, 5, 4, 3, 2, 1, 7}, // permutation 20
122  {-1, 2, 1, 4, 3, 5, 6, 7}, // permutation 21
123  {-1, 4, 3, 6, 5, 1, 2, 7}, // permutation 22
124  {-1, 6, 5, 2, 1, 3, 4, 7} // permutation 23
125 };
126 
127 const label starMesh::shapeFaceLookup[19][9] =
128 {
129  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 0 - empty+
130  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 1 - empty+
131  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 2 - empty+
132  {-1, 4, 5, 2, 3, 0, 1, -1, -1}, // shape 3 - hex+
133  {-1, 1, 0, 5, 4, 2, 3, -1, -1}, // shape 4 - wedge+
134  {-1, 0, 1, 4, -1, 2, 3, -1, -1}, // shape 5 - prism+
135  {-1, 0, -1, 4, 2, 1, 3, -1, -1}, // shape 6 - pyr+
136  {-1, 3, -1, 2, -1, 1, 0, -1, -1}, // shape 7 - tet+
137  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 8 - splitHex (empty)
138  {-1, 0, -1, 1, -1, 2, 3, -1, -1}, // shape 9 - tetWedge+
139  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 10 - empty+
140  {-1, 1, 0, 3, 2, 5, 4, 6, -1}, // shape 11 - sammTrim1
141  {-1, 5, 4, 1, 0, 3, 2, 6, -1}, // shape 12 - sammTrim2
142  {-1, 2, 3, 0, 1, 4, 5, 6, -1}, // shape 13 - sammTrim3
143  {-1, 2, 3, 0, 1, 4, 5, 6, -1}, // shape 14 - sammTrim4
144  {-1, 5, 2, 4, 3, 1, 0, -1, -1}, // shape 15 - sammTrim5
145  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 16 - empty
146  {-1, -1, -1, -1, -1, -1, -1, -1, -1}, // shape 17 - empty
147  {-1, 1, 0, 6, 7, 2, 3, 4, 5} // shape 18 - sammTrim8
148 };
149 
150 
151 // The star to foam face order mapping tables are potentially incomplete
152 // Currently available data is listed below.
153 // 1) hex and degenerate hex: OK
154 // samm trim 1:
155 // star number: 1 2 3 4 5 6 7 8 In ROTATION 0
156 // foam number: 5 4 1 0 3 2 6
157 // confirmed: 1 0 3 2 5 4 6
158 
159 // samm trim 2:
160 // star number: 1 2 3 4 5 6 7 8 In ROTATION 0
161 // foam number: 5 4 1 0 3 2 6
162 // confirmed: 4 0 3 2
163 
164 // samm trim 3:
165 // star number: 1 2 3 4 5 6 7 8 In ROTATION 0
166 // foam number: 2 3 0 1 4 5 6
167 // confirmed:
168 
169 // samm trim 4:
170 // star number: 1 2 3 4 5 6 7 8 In ROTATION 0
171 // foam number: 2 3 0 1 4 5 6
172 // confirmed:
173 
174 // samm trim 5:
175 // star number: 1 2 3 4 5 6 7 8 In ROTATION 0
176 // foam number: 2 4 3 1 0 5
177 // confirmed: 5 2 4 3 1 0
178 
179 // samm trim 8:
180 // star number: 1 2 3 4 5 6 7 8 In ROTATION 0
181 // foam number: 2 5 4 7 1 0 3 6
182 // confirmed: 1 0 6
183 
184 
185 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
186 
187 // Make polyhedral mesh data (packing)
188 void starMesh::createPolyMeshData()
189 {
190  Info << "Creating a polyMesh" << endl;
191 
192  createPolyCells();
193 
194  Info<< "\nNumber of internal faces: "
195  << nInternalFaces_ << endl;
196 
197  createPolyBoundary();
198 }
199 
200 
201 // Clear extra storage before creation of the mesh to remove
202 // a memory peak
203 void starMesh::clearExtraStorage()
204 {
205  Info << "Clearing extra storage" << endl;
206 
207  starPointLabelLookup_.setSize(0);
208  starPointID_.setSize(0);
209  starCellID_.setSize(0);
210  starCellLabelLookup_.setSize(0);
211  starCellPermutation_.setSize(0);
212  cellFaces_.setSize(0);
213  boundaryCellIDs_.setSize(0);
214  boundaryCellFaceIDs_.setSize(0);
215  couples_.clear();
216 
217  deleteDemandDrivenData(pointCellsPtr_);
218 }
219 
220 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
221 
222 // Construct from components
223 starMesh::starMesh
224 (
225  const fileName& prefix,
226  const Time& rt,
227  const scalar scaleFactor
228 )
229 :
230  casePrefix_(prefix),
231  runTime_(rt),
232  points_(0),
233  cellShapes_(0),
234  boundary_(0),
235  patchTypes_(0),
236  defaultFacesName_("defaultFaces"),
237  defaultFacesType_(emptyPolyPatch::typeName),
238  patchNames_(0),
239  patchPhysicalTypes_(0),
240  starPointLabelLookup_(0),
241  starPointID_(0),
242  starCellID_(0),
243  starCellLabelLookup_(0),
244  starCellPermutation_(0),
245  cellFaces_(0),
246  boundaryCellIDs_(0),
247  boundaryCellFaceIDs_(0),
248  meshFaces_(0),
249  cellPolys_(0),
250  nInternalFaces_(0),
251  polyBoundaryPatchStartIndices_(0),
252  pointCellsPtr_(NULL),
253  couples_(0),
254  isShapeMesh_(true)
255 {
256  readPoints(scaleFactor);
257 
258  readCells();
259 
260  readBoundary();
261 
262  fixCollapsedEdges();
263 
264  readCouples();
265 
266  if (couples_.size())
267  {
268  createCoupleMatches();
269  }
270 
271  markBoundaryFaces();
272 
273  mergeCoupleFacePoints();
274 
275  purgeCellShapes();
276 
277  collectBoundaryFaces();
278 }
279 
280 
281 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
282 
284 {
285  deleteDemandDrivenData(pointCellsPtr_);
286 }
287 
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 
292 // ************************ vim: set sw=4 sts=4 et: ************************ //