1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
28 #include "fieldviewTopology.H"
30 #include "cellShape.H"
31 #include "cellModeller.H"
32 #include "wallPolyPatch.H"
33 #include "symmetryPolyPatch.H"
36 #include "fv_reader_tags.h"
40 unsigned int fv_encode_elem_header(int elem_type, int wall_info[]);
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 Foam::labelList Foam::fieldviewTopology::calcFaceAddressing
48 const faceList& allFaces, // faces given faceLabels
49 const cellShape& shape,
50 const labelList& faces, // faceLabels for given cell
55 labelList shapeToMesh(shape.nFaces(), -1);
57 const faceList modelFaces(shape.faces());
59 // Loop over all faces of cellShape
60 forAll(modelFaces, cellFaceI)
63 const face& modelFace = modelFaces[cellFaceI];
65 // Loop over all face labels
68 const face& vertLabels = allFaces[faces[faceI]];
70 if (vertLabels == modelFace)
72 shapeToMesh[cellFaceI] = faces[faceI];
77 if (shapeToMesh[cellFaceI] == -1)
79 FatalErrorIn("foamToFieldview : calcFaceAddressing")
80 << "calcFaceAddressing : can't match face to shape.\n"
81 << " shape face:" << modelFace << endl
82 << " face labels:" << faces << endl
83 << " cellI:" << cellI << endl;
85 FatalError << "Faces consist of vertices:" << endl;
89 << " face:" << faces[faceI]
90 << allFaces[faces[faceI]] << endl;
92 FatalError << exit(FatalError);
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 // Construct from components
102 Foam::fieldviewTopology::fieldviewTopology
104 const polyMesh& mesh,
105 const bool setWallInfo
108 hexLabels_((1+8)*mesh.nCells()),
109 prismLabels_((1+6)*mesh.nCells()),
110 pyrLabels_((1+5)*mesh.nCells()),
111 tetLabels_((1+4)*mesh.nCells()),
113 quadFaceLabels_(mesh.boundaryMesh().size()),
114 nPolyFaces_(mesh.boundaryMesh().size())
116 // Mark all faces that are to be seen as wall for particle
117 // tracking and all cells that use one or more of these walls
119 labelList wallFace(mesh.nFaces(), NOT_A_WALL);
120 boolList wallCell(mesh.nCells(), false);
124 forAll (mesh.boundaryMesh(), patchI)
126 const polyPatch& currPatch = mesh.boundaryMesh()[patchI];
129 isA<wallPolyPatch>(currPatch)
130 || isA<symmetryPolyPatch>(currPatch)
133 forAll(currPatch, patchFaceI)
135 label meshFaceI = currPatch.start() + patchFaceI;
137 wallFace[meshFaceI] = A_WALL;
138 wallCell[mesh.faceOwner()[meshFaceI]] = true;
146 const cellModel& tet = *(cellModeller::lookup("tet"));
147 const cellModel& pyr = *(cellModeller::lookup("pyr"));
148 const cellModel& prism = *(cellModeller::lookup("prism"));
149 const cellModel& wedge = *(cellModeller::lookup("wedge"));
150 const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
151 const cellModel& hex = *(cellModeller::lookup("hex"));
153 // Pre calculate headers for cells not on walls
154 labelList notWallFlags(6, NOT_A_WALL);
155 label tetNotWall = fv_encode_elem_header
157 FV_TET_ELEM_ID, notWallFlags.begin()
159 label pyrNotWall = fv_encode_elem_header
161 FV_PYRA_ELEM_ID, notWallFlags.begin()
163 label prismNotWall = fv_encode_elem_header
165 FV_PRISM_ELEM_ID, notWallFlags.begin()
167 label hexNotWall = fv_encode_elem_header
169 FV_HEX_ELEM_ID, notWallFlags.begin()
173 const cellList& cellFaces = mesh.cells();
174 const cellShapeList& cellShapes = mesh.cellShapes();
182 const faceList& allFaces = mesh.faces();
184 labelList wallFlags(6);
185 forAll(cellShapes, celli)
187 const cellShape& cellShape = cellShapes[celli];
188 const cellModel& cellModel = cellShape.model();
190 if (cellModel == tet)
192 if (!wallCell[celli])
194 tetLabels_[teti++] = tetNotWall;
198 labelList modelToMesh = calcFaceAddressing
200 allFaces, cellShape, cellFaces[celli], celli
203 wallFlags[0] = wallFace[modelToMesh[0]];
204 wallFlags[1] = wallFace[modelToMesh[1]];
205 wallFlags[2] = wallFace[modelToMesh[2]];
206 wallFlags[3] = wallFace[modelToMesh[3]];
208 tetLabels_[teti++] = fv_encode_elem_header
210 FV_TET_ELEM_ID, wallFlags.begin()
214 tetLabels_[teti++] = cellShape[0] + 1;
215 tetLabels_[teti++] = cellShape[1] + 1;
216 tetLabels_[teti++] = cellShape[2] + 1;
217 tetLabels_[teti++] = cellShape[3] + 1;
219 else if (cellModel == pyr)
221 if (!wallCell[celli])
223 pyrLabels_[pyri++] = pyrNotWall;
227 labelList modelToMesh = calcFaceAddressing
229 allFaces, cellShape, cellFaces[celli], celli
232 wallFlags[0] = wallFace[modelToMesh[0]];
233 wallFlags[1] = wallFace[modelToMesh[3]];
234 wallFlags[2] = wallFace[modelToMesh[2]];
235 wallFlags[3] = wallFace[modelToMesh[1]];
236 wallFlags[4] = wallFace[modelToMesh[4]];
238 pyrLabels_[pyri++] = fv_encode_elem_header
240 FV_PYRA_ELEM_ID, wallFlags.begin()
244 pyrLabels_[pyri++] = cellShape[0] + 1;
245 pyrLabels_[pyri++] = cellShape[1] + 1;
246 pyrLabels_[pyri++] = cellShape[2] + 1;
247 pyrLabels_[pyri++] = cellShape[3] + 1;
248 pyrLabels_[pyri++] = cellShape[4] + 1;
250 else if (cellModel == prism)
252 if (!wallCell[celli])
254 prismLabels_[prismi++] = prismNotWall;
258 labelList modelToMesh = calcFaceAddressing
260 allFaces, cellShape, cellFaces[celli], celli
263 wallFlags[0] = wallFace[modelToMesh[4]];
264 wallFlags[1] = wallFace[modelToMesh[2]];
265 wallFlags[2] = wallFace[modelToMesh[3]];
266 wallFlags[3] = wallFace[modelToMesh[0]];
267 wallFlags[4] = wallFace[modelToMesh[1]];
269 prismLabels_[prismi++] = fv_encode_elem_header
271 FV_PRISM_ELEM_ID, wallFlags.begin()
275 prismLabels_[prismi++] = cellShape[0] + 1;
276 prismLabels_[prismi++] = cellShape[3] + 1;
277 prismLabels_[prismi++] = cellShape[4] + 1;
278 prismLabels_[prismi++] = cellShape[1] + 1;
279 prismLabels_[prismi++] = cellShape[5] + 1;
280 prismLabels_[prismi++] = cellShape[2] + 1;
282 else if (cellModel == tetWedge)
284 // Treat as prism with collapsed edge
285 if (!wallCell[celli])
287 prismLabels_[prismi++] = prismNotWall;
291 labelList modelToMesh = calcFaceAddressing
293 allFaces, cellShape, cellFaces[celli], celli
296 wallFlags[0] = wallFace[modelToMesh[1]];
297 wallFlags[1] = wallFace[modelToMesh[2]];
298 wallFlags[2] = wallFace[modelToMesh[3]];
299 wallFlags[3] = wallFace[modelToMesh[0]];
300 wallFlags[4] = wallFace[modelToMesh[3]];
302 prismLabels_[prismi++] = fv_encode_elem_header
304 FV_PRISM_ELEM_ID, wallFlags.begin()
308 prismLabels_[prismi++] = cellShape[0] + 1;
309 prismLabels_[prismi++] = cellShape[3] + 1;
310 prismLabels_[prismi++] = cellShape[4] + 1;
311 prismLabels_[prismi++] = cellShape[1] + 1;
312 prismLabels_[prismi++] = cellShape[4] + 1;
313 prismLabels_[prismi++] = cellShape[2] + 1;
315 else if (cellModel == wedge)
317 if (!wallCell[celli])
319 hexLabels_[hexi++] = hexNotWall;
323 labelList modelToMesh = calcFaceAddressing
325 allFaces, cellShape, cellFaces[celli], celli
328 wallFlags[0] = wallFace[modelToMesh[2]];
329 wallFlags[1] = wallFace[modelToMesh[3]];
330 wallFlags[2] = wallFace[modelToMesh[0]];
331 wallFlags[3] = wallFace[modelToMesh[1]];
332 wallFlags[4] = wallFace[modelToMesh[4]];
333 wallFlags[5] = wallFace[modelToMesh[5]];
335 hexLabels_[hexi++] = fv_encode_elem_header
337 FV_HEX_ELEM_ID, wallFlags.begin()
340 hexLabels_[hexi++] = cellShape[0] + 1;
341 hexLabels_[hexi++] = cellShape[1] + 1;
342 hexLabels_[hexi++] = cellShape[0] + 1;
343 hexLabels_[hexi++] = cellShape[2] + 1;
344 hexLabels_[hexi++] = cellShape[3] + 1;
345 hexLabels_[hexi++] = cellShape[4] + 1;
346 hexLabels_[hexi++] = cellShape[6] + 1;
347 hexLabels_[hexi++] = cellShape[5] + 1;
349 else if (cellModel == hex)
351 if (!wallCell[celli])
353 hexLabels_[hexi++] = hexNotWall;
357 labelList modelToMesh = calcFaceAddressing
359 allFaces, cellShape, cellFaces[celli], celli
362 wallFlags[0] = wallFace[modelToMesh[0]];
363 wallFlags[1] = wallFace[modelToMesh[1]];
364 wallFlags[2] = wallFace[modelToMesh[4]];
365 wallFlags[3] = wallFace[modelToMesh[5]];
366 wallFlags[4] = wallFace[modelToMesh[2]];
367 wallFlags[5] = wallFace[modelToMesh[3]];
369 hexLabels_[hexi++] = fv_encode_elem_header
371 FV_HEX_ELEM_ID, wallFlags.begin()
374 hexLabels_[hexi++] = cellShape[0] + 1;
375 hexLabels_[hexi++] = cellShape[1] + 1;
376 hexLabels_[hexi++] = cellShape[3] + 1;
377 hexLabels_[hexi++] = cellShape[2] + 1;
378 hexLabels_[hexi++] = cellShape[4] + 1;
379 hexLabels_[hexi++] = cellShape[5] + 1;
380 hexLabels_[hexi++] = cellShape[7] + 1;
381 hexLabels_[hexi++] = cellShape[6] + 1;
389 hexLabels_.setSize(hexi);
390 prismLabels_.setSize(prismi);
391 pyrLabels_.setSize(pyri);
392 tetLabels_.setSize(teti);
398 forAll(mesh.boundaryMesh(), patchI)
400 const polyPatch& patchFaces = mesh.boundaryMesh()[patchI];
402 labelList& faceLabels = quadFaceLabels_[patchI];
404 // Faces, each 4 labels. Size big enough
405 faceLabels.setSize(patchFaces.size()*4);
409 forAll(patchFaces, faceI)
411 const face& patchFace = patchFaces[faceI];
413 if (patchFace.size() == 3)
415 faceLabels[labelI++] = patchFace[0] + 1;
416 faceLabels[labelI++] = patchFace[1] + 1;
417 faceLabels[labelI++] = patchFace[2] + 1;
418 faceLabels[labelI++] = 0; // Fieldview:triangle definition
420 else if (patchFace.size() == 4)
422 faceLabels[labelI++] = patchFace[0] + 1;
423 faceLabels[labelI++] = patchFace[1] + 1;
424 faceLabels[labelI++] = patchFace[2] + 1;
425 faceLabels[labelI++] = patchFace[3] + 1;
429 faceLabels.setSize(labelI);
431 label nFaces = labelI/4;
433 nPolyFaces_[patchI] = patchFaces.size() - nFaces;
438 // ************************************************************************* //