1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "fieldviewTopology.H"
28 #include "cellShape.H"
29 #include "cellModeller.H"
30 #include "wallPolyPatch.H"
31 #include "symmetryPolyPatch.H"
34 #include "fv_reader_tags.h"
38 unsigned int fv_encode_elem_header(int elem_type, int wall_info[]);
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 Foam::labelList Foam::fieldviewTopology::calcFaceAddressing
46 const faceList& allFaces, // faces given faceLabels
47 const cellShape& shape,
48 const labelList& faces, // faceLabels for given cell
53 labelList shapeToMesh(shape.nFaces(), -1);
55 const faceList modelFaces(shape.faces());
57 // Loop over all faces of cellShape
58 forAll(modelFaces, cellFaceI)
61 const face& modelFace = modelFaces[cellFaceI];
63 // Loop over all face labels
66 const face& vertLabels = allFaces[faces[faceI]];
68 if (vertLabels == modelFace)
70 shapeToMesh[cellFaceI] = faces[faceI];
75 if (shapeToMesh[cellFaceI] == -1)
77 FatalErrorIn("foamToFieldview : calcFaceAddressing")
78 << "calcFaceAddressing : can't match face to shape.\n"
79 << " shape face:" << modelFace << endl
80 << " face labels:" << faces << endl
81 << " cellI:" << cellI << endl;
83 FatalError << "Faces consist of vertices:" << endl;
87 << " face:" << faces[faceI]
88 << allFaces[faces[faceI]] << endl;
90 FatalError << exit(FatalError);
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 // Construct from components
100 Foam::fieldviewTopology::fieldviewTopology
102 const polyMesh& mesh,
103 const bool setWallInfo
106 hexLabels_((1+8)*mesh.nCells()),
107 prismLabels_((1+6)*mesh.nCells()),
108 pyrLabels_((1+5)*mesh.nCells()),
109 tetLabels_((1+4)*mesh.nCells()),
111 quadFaceLabels_(mesh.boundaryMesh().size()),
112 nPolyFaces_(mesh.boundaryMesh().size())
114 // Mark all faces that are to be seen as wall for particle
115 // tracking and all cells that use one or more of these walls
117 labelList wallFace(mesh.nFaces(), NOT_A_WALL);
118 boolList wallCell(mesh.nCells(), false);
122 forAll(mesh.boundaryMesh(), patchI)
124 const polyPatch& currPatch = mesh.boundaryMesh()[patchI];
127 isA<wallPolyPatch>(currPatch)
128 || isA<symmetryPolyPatch>(currPatch)
131 forAll(currPatch, patchFaceI)
133 label meshFaceI = currPatch.start() + patchFaceI;
135 wallFace[meshFaceI] = A_WALL;
136 wallCell[mesh.faceOwner()[meshFaceI]] = true;
144 const cellModel& tet = *(cellModeller::lookup("tet"));
145 const cellModel& pyr = *(cellModeller::lookup("pyr"));
146 const cellModel& prism = *(cellModeller::lookup("prism"));
147 const cellModel& wedge = *(cellModeller::lookup("wedge"));
148 const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
149 const cellModel& hex = *(cellModeller::lookup("hex"));
151 // Pre calculate headers for cells not on walls
152 labelList notWallFlags(6, NOT_A_WALL);
153 label tetNotWall = fv_encode_elem_header
155 FV_TET_ELEM_ID, notWallFlags.begin()
157 label pyrNotWall = fv_encode_elem_header
159 FV_PYRA_ELEM_ID, notWallFlags.begin()
161 label prismNotWall = fv_encode_elem_header
163 FV_PRISM_ELEM_ID, notWallFlags.begin()
165 label hexNotWall = fv_encode_elem_header
167 FV_HEX_ELEM_ID, notWallFlags.begin()
171 const cellList& cellFaces = mesh.cells();
172 const cellShapeList& cellShapes = mesh.cellShapes();
180 const faceList& allFaces = mesh.faces();
182 labelList wallFlags(6);
183 forAll(cellShapes, celli)
185 const cellShape& cellShape = cellShapes[celli];
186 const cellModel& cellModel = cellShape.model();
188 if (cellModel == tet)
190 if (!wallCell[celli])
192 tetLabels_[teti++] = tetNotWall;
196 labelList modelToMesh = calcFaceAddressing
198 allFaces, cellShape, cellFaces[celli], celli
201 wallFlags[0] = wallFace[modelToMesh[0]];
202 wallFlags[1] = wallFace[modelToMesh[1]];
203 wallFlags[2] = wallFace[modelToMesh[2]];
204 wallFlags[3] = wallFace[modelToMesh[3]];
206 tetLabels_[teti++] = fv_encode_elem_header
208 FV_TET_ELEM_ID, wallFlags.begin()
212 tetLabels_[teti++] = cellShape[0] + 1;
213 tetLabels_[teti++] = cellShape[1] + 1;
214 tetLabels_[teti++] = cellShape[2] + 1;
215 tetLabels_[teti++] = cellShape[3] + 1;
217 else if (cellModel == pyr)
219 if (!wallCell[celli])
221 pyrLabels_[pyri++] = pyrNotWall;
225 labelList modelToMesh = calcFaceAddressing
227 allFaces, cellShape, cellFaces[celli], celli
230 wallFlags[0] = wallFace[modelToMesh[0]];
231 wallFlags[1] = wallFace[modelToMesh[3]];
232 wallFlags[2] = wallFace[modelToMesh[2]];
233 wallFlags[3] = wallFace[modelToMesh[1]];
234 wallFlags[4] = wallFace[modelToMesh[4]];
236 pyrLabels_[pyri++] = fv_encode_elem_header
238 FV_PYRA_ELEM_ID, wallFlags.begin()
242 pyrLabels_[pyri++] = cellShape[0] + 1;
243 pyrLabels_[pyri++] = cellShape[1] + 1;
244 pyrLabels_[pyri++] = cellShape[2] + 1;
245 pyrLabels_[pyri++] = cellShape[3] + 1;
246 pyrLabels_[pyri++] = cellShape[4] + 1;
248 else if (cellModel == prism)
250 if (!wallCell[celli])
252 prismLabels_[prismi++] = prismNotWall;
256 labelList modelToMesh = calcFaceAddressing
258 allFaces, cellShape, cellFaces[celli], celli
261 wallFlags[0] = wallFace[modelToMesh[4]];
262 wallFlags[1] = wallFace[modelToMesh[2]];
263 wallFlags[2] = wallFace[modelToMesh[3]];
264 wallFlags[3] = wallFace[modelToMesh[0]];
265 wallFlags[4] = wallFace[modelToMesh[1]];
267 prismLabels_[prismi++] = fv_encode_elem_header
269 FV_PRISM_ELEM_ID, wallFlags.begin()
273 prismLabels_[prismi++] = cellShape[0] + 1;
274 prismLabels_[prismi++] = cellShape[3] + 1;
275 prismLabels_[prismi++] = cellShape[4] + 1;
276 prismLabels_[prismi++] = cellShape[1] + 1;
277 prismLabels_[prismi++] = cellShape[5] + 1;
278 prismLabels_[prismi++] = cellShape[2] + 1;
280 else if (cellModel == tetWedge)
282 // Treat as prism with collapsed edge
283 if (!wallCell[celli])
285 prismLabels_[prismi++] = prismNotWall;
289 labelList modelToMesh = calcFaceAddressing
291 allFaces, cellShape, cellFaces[celli], celli
294 wallFlags[0] = wallFace[modelToMesh[1]];
295 wallFlags[1] = wallFace[modelToMesh[2]];
296 wallFlags[2] = wallFace[modelToMesh[3]];
297 wallFlags[3] = wallFace[modelToMesh[0]];
298 wallFlags[4] = wallFace[modelToMesh[3]];
300 prismLabels_[prismi++] = fv_encode_elem_header
302 FV_PRISM_ELEM_ID, wallFlags.begin()
306 prismLabels_[prismi++] = cellShape[0] + 1;
307 prismLabels_[prismi++] = cellShape[3] + 1;
308 prismLabels_[prismi++] = cellShape[4] + 1;
309 prismLabels_[prismi++] = cellShape[1] + 1;
310 prismLabels_[prismi++] = cellShape[4] + 1;
311 prismLabels_[prismi++] = cellShape[2] + 1;
313 else if (cellModel == wedge)
315 if (!wallCell[celli])
317 hexLabels_[hexi++] = hexNotWall;
321 labelList modelToMesh = calcFaceAddressing
323 allFaces, cellShape, cellFaces[celli], celli
326 wallFlags[0] = wallFace[modelToMesh[2]];
327 wallFlags[1] = wallFace[modelToMesh[3]];
328 wallFlags[2] = wallFace[modelToMesh[0]];
329 wallFlags[3] = wallFace[modelToMesh[1]];
330 wallFlags[4] = wallFace[modelToMesh[4]];
331 wallFlags[5] = wallFace[modelToMesh[5]];
333 hexLabels_[hexi++] = fv_encode_elem_header
335 FV_HEX_ELEM_ID, wallFlags.begin()
338 hexLabels_[hexi++] = cellShape[0] + 1;
339 hexLabels_[hexi++] = cellShape[1] + 1;
340 hexLabels_[hexi++] = cellShape[0] + 1;
341 hexLabels_[hexi++] = cellShape[2] + 1;
342 hexLabels_[hexi++] = cellShape[3] + 1;
343 hexLabels_[hexi++] = cellShape[4] + 1;
344 hexLabels_[hexi++] = cellShape[6] + 1;
345 hexLabels_[hexi++] = cellShape[5] + 1;
347 else if (cellModel == hex)
349 if (!wallCell[celli])
351 hexLabels_[hexi++] = hexNotWall;
355 labelList modelToMesh = calcFaceAddressing
357 allFaces, cellShape, cellFaces[celli], celli
360 wallFlags[0] = wallFace[modelToMesh[0]];
361 wallFlags[1] = wallFace[modelToMesh[1]];
362 wallFlags[2] = wallFace[modelToMesh[4]];
363 wallFlags[3] = wallFace[modelToMesh[5]];
364 wallFlags[4] = wallFace[modelToMesh[2]];
365 wallFlags[5] = wallFace[modelToMesh[3]];
367 hexLabels_[hexi++] = fv_encode_elem_header
369 FV_HEX_ELEM_ID, wallFlags.begin()
372 hexLabels_[hexi++] = cellShape[0] + 1;
373 hexLabels_[hexi++] = cellShape[1] + 1;
374 hexLabels_[hexi++] = cellShape[3] + 1;
375 hexLabels_[hexi++] = cellShape[2] + 1;
376 hexLabels_[hexi++] = cellShape[4] + 1;
377 hexLabels_[hexi++] = cellShape[5] + 1;
378 hexLabels_[hexi++] = cellShape[7] + 1;
379 hexLabels_[hexi++] = cellShape[6] + 1;
387 hexLabels_.setSize(hexi);
388 prismLabels_.setSize(prismi);
389 pyrLabels_.setSize(pyri);
390 tetLabels_.setSize(teti);
396 forAll(mesh.boundaryMesh(), patchI)
398 const polyPatch& patchFaces = mesh.boundaryMesh()[patchI];
400 labelList& faceLabels = quadFaceLabels_[patchI];
402 // Faces, each 4 labels. Size big enough
403 faceLabels.setSize(patchFaces.size()*4);
407 forAll(patchFaces, faceI)
409 const face& patchFace = patchFaces[faceI];
411 if (patchFace.size() == 3)
413 faceLabels[labelI++] = patchFace[0] + 1;
414 faceLabels[labelI++] = patchFace[1] + 1;
415 faceLabels[labelI++] = patchFace[2] + 1;
416 faceLabels[labelI++] = 0; // Fieldview:triangle definition
418 else if (patchFace.size() == 4)
420 faceLabels[labelI++] = patchFace[0] + 1;
421 faceLabels[labelI++] = patchFace[1] + 1;
422 faceLabels[labelI++] = patchFace[2] + 1;
423 faceLabels[labelI++] = patchFace[3] + 1;
427 faceLabels.setSize(labelI);
429 label nFaces = labelI/4;
431 nPolyFaces_[patchI] = patchFaces.size() - nFaces;
436 // ************************************************************************* //