intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / applications / utilities / postProcessing / dataConversion / foamToFieldview9 / fieldviewTopology.C
blobd97c5706f0242f41e46f4542e4c93c914cc74fee
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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
27 \*---------------------------------------------------------------------------*/
29 #include "fieldviewTopology.H"
30 #include "polyMesh.H"
31 #include "cellShape.H"
32 #include "cellModeller.H"
33 #include "wallPolyPatch.H"
34 #include "symmetryPolyPatch.H"
37 #include "fv_reader_tags.h"
39 extern "C"
41     unsigned int fv_encode_elem_header(int elem_type, int wall_info[]);
45 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
47 Foam::labelList Foam::fieldviewTopology::calcFaceAddressing
49     const faceList& allFaces,   // faces given faceLabels
50     const cellShape& shape,
51     const labelList& faces,     // faceLabels for given cell
52     const label cellI
55     // return value. 
56     labelList shapeToMesh(shape.nFaces(), -1);
58     const faceList modelFaces(shape.faces());
60     // Loop over all faces of cellShape
61     forAll(modelFaces, cellFaceI)
62     {
63         // face (vertex list)
64         const face& modelFace = modelFaces[cellFaceI];
66         // Loop over all face labels
67         forAll(faces, faceI)
68         {
69             const face& vertLabels = allFaces[faces[faceI]];
71             if (vertLabels == modelFace)
72             {
73                 shapeToMesh[cellFaceI] = faces[faceI];
74                 break;
75             }
76         }
78         if (shapeToMesh[cellFaceI] == -1)
79         {
80             FatalErrorIn("foamToFieldview : calcFaceAddressing")
81                 << "calcFaceAddressing : can't match face to shape.\n"
82                 << "    shape face:" << modelFace << endl
83                 << "    face labels:" << faces << endl
84                 << "    cellI:" << cellI << endl;
86             FatalError << "Faces consist of vertices:" << endl;
87             forAll(faces, faceI)
88             {
89                 FatalError
90                     << "    face:" << faces[faceI]
91                     << allFaces[faces[faceI]] << endl;
92             }
93             FatalError << exit(FatalError);
94         }
95     }
96     return shapeToMesh;
100 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
102 // Construct from components
103 Foam::fieldviewTopology::fieldviewTopology
105     const polyMesh& mesh,
106     const bool setWallInfo
109     hexLabels_((1+8)*mesh.nCells()),
110     prismLabels_((1+6)*mesh.nCells()),
111     pyrLabels_((1+5)*mesh.nCells()),
112     tetLabels_((1+4)*mesh.nCells()),
113     nPoly_(0),
114     quadFaceLabels_(mesh.boundaryMesh().size()),
115     nPolyFaces_(mesh.boundaryMesh().size())
117     // Mark all faces that are to be seen as wall for particle
118     // tracking and all cells that use one or more of these walls
120     labelList wallFace(mesh.nFaces(), NOT_A_WALL);
121     boolList wallCell(mesh.nCells(), false);
123     if (setWallInfo)
124     {
125         forAll (mesh.boundaryMesh(), patchI)
126         {
127             const polyPatch& currPatch = mesh.boundaryMesh()[patchI];
128             if 
129             (
130                 isType<wallPolyPatch>(currPatch)
131              || isType<symmetryPolyPatch>(currPatch)
132             )
133             {
134                 forAll(currPatch, patchFaceI)
135                 {
136                     label meshFaceI = currPatch.start() + patchFaceI;
138                     wallFace[meshFaceI] = A_WALL;
139                     wallCell[mesh.faceOwner()[meshFaceI]] = true;
140                 }
141             }
142         }
143     }
147     const cellModel& tet = *(cellModeller::lookup("tet"));
148     const cellModel& pyr = *(cellModeller::lookup("pyr"));
149     const cellModel& prism = *(cellModeller::lookup("prism"));
150     const cellModel& wedge = *(cellModeller::lookup("wedge"));
151     const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
152     const cellModel& hex = *(cellModeller::lookup("hex"));
154     // Pre calculate headers for cells not on walls
155     labelList notWallFlags(6, NOT_A_WALL);
156     label tetNotWall = fv_encode_elem_header
157     (
158         FV_TET_ELEM_ID, notWallFlags.begin()
159     );
160     label pyrNotWall = fv_encode_elem_header
161     (
162         FV_PYRA_ELEM_ID, notWallFlags.begin()
163     );
164     label prismNotWall = fv_encode_elem_header
165     (
166         FV_PRISM_ELEM_ID, notWallFlags.begin()
167     );
168     label hexNotWall = fv_encode_elem_header
169     (
170         FV_HEX_ELEM_ID, notWallFlags.begin()
171     );
173     // Some aliases
174     const cellList& cellFaces = mesh.cells();
175     const cellShapeList& cellShapes = mesh.cellShapes();
178     label hexi = 0;
179     label prismi = 0;
180     label pyri = 0;
181     label teti = 0;
183     const faceList& allFaces = mesh.faces();
185     labelList wallFlags(6);
186     forAll(cellShapes, celli)
187     {
188         const cellShape& cellShape = cellShapes[celli];
189         const cellModel& cellModel = cellShape.model();
191         if (cellModel == tet)
192         {
193             if (!wallCell[celli])
194             {
195                 tetLabels_[teti++] = tetNotWall;
196             }
197             else
198             {
199                 labelList modelToMesh = calcFaceAddressing
200                 (
201                     allFaces, cellShape, cellFaces[celli], celli
202                 );
204                 wallFlags[0] = wallFace[modelToMesh[0]];
205                 wallFlags[1] = wallFace[modelToMesh[1]];
206                 wallFlags[2] = wallFace[modelToMesh[2]];
207                 wallFlags[3] = wallFace[modelToMesh[3]];
209                 tetLabels_[teti++] = fv_encode_elem_header
210                 (
211                     FV_TET_ELEM_ID, wallFlags.begin()
212                 );
213             }
215             tetLabels_[teti++] = cellShape[0] + 1;
216             tetLabels_[teti++] = cellShape[1] + 1;
217             tetLabels_[teti++] = cellShape[2] + 1;
218             tetLabels_[teti++] = cellShape[3] + 1;
219         }
220         else if (cellModel == pyr)
221         {
222             if (!wallCell[celli])
223             {
224                 pyrLabels_[pyri++] = pyrNotWall;
225             }
226             else
227             {
228                 labelList modelToMesh = calcFaceAddressing
229                 (
230                     allFaces, cellShape, cellFaces[celli], celli
231                 );
233                 wallFlags[0] = wallFace[modelToMesh[0]];
234                 wallFlags[1] = wallFace[modelToMesh[3]];
235                 wallFlags[2] = wallFace[modelToMesh[2]];
236                 wallFlags[3] = wallFace[modelToMesh[1]];
237                 wallFlags[4] = wallFace[modelToMesh[4]];
239                 pyrLabels_[pyri++] = fv_encode_elem_header
240                 (
241                     FV_PYRA_ELEM_ID, wallFlags.begin()
242                 );
243             }
245             pyrLabels_[pyri++] = cellShape[0] + 1;
246             pyrLabels_[pyri++] = cellShape[1] + 1;
247             pyrLabels_[pyri++] = cellShape[2] + 1;
248             pyrLabels_[pyri++] = cellShape[3] + 1;
249             pyrLabels_[pyri++] = cellShape[4] + 1;
250         }
251         else if (cellModel == prism)
252         {
253             if (!wallCell[celli])
254             {
255                 prismLabels_[prismi++] = prismNotWall;
256             }
257             else
258             {
259                 labelList modelToMesh = calcFaceAddressing
260                 (
261                     allFaces, cellShape, cellFaces[celli], celli
262                 );
264                 wallFlags[0] = wallFace[modelToMesh[4]];
265                 wallFlags[1] = wallFace[modelToMesh[2]];
266                 wallFlags[2] = wallFace[modelToMesh[3]];
267                 wallFlags[3] = wallFace[modelToMesh[0]];
268                 wallFlags[4] = wallFace[modelToMesh[1]];
270                 prismLabels_[prismi++] = fv_encode_elem_header
271                 (
272                     FV_PRISM_ELEM_ID, wallFlags.begin()
273                 );
274             }
276             prismLabels_[prismi++] = cellShape[0] + 1;
277             prismLabels_[prismi++] = cellShape[3] + 1;
278             prismLabels_[prismi++] = cellShape[4] + 1;
279             prismLabels_[prismi++] = cellShape[1] + 1;
280             prismLabels_[prismi++] = cellShape[5] + 1;
281             prismLabels_[prismi++] = cellShape[2] + 1;
282         }
283         else if (cellModel == tetWedge)
284         {
285             // Treat as prism with collapsed edge
286             if (!wallCell[celli])
287             {
288                 prismLabels_[prismi++] = prismNotWall;
289             }
290             else
291             {
292                 labelList modelToMesh = calcFaceAddressing
293                 (
294                     allFaces, cellShape, cellFaces[celli], celli
295                 );
297                 wallFlags[0] = wallFace[modelToMesh[1]];
298                 wallFlags[1] = wallFace[modelToMesh[2]];
299                 wallFlags[2] = wallFace[modelToMesh[3]];
300                 wallFlags[3] = wallFace[modelToMesh[0]];
301                 wallFlags[4] = wallFace[modelToMesh[3]];
303                 prismLabels_[prismi++] = fv_encode_elem_header
304                 (
305                     FV_PRISM_ELEM_ID, wallFlags.begin()
306                 );
307             }
309             prismLabels_[prismi++] = cellShape[0] + 1;
310             prismLabels_[prismi++] = cellShape[3] + 1;
311             prismLabels_[prismi++] = cellShape[4] + 1;
312             prismLabels_[prismi++] = cellShape[1] + 1;
313             prismLabels_[prismi++] = cellShape[4] + 1;
314             prismLabels_[prismi++] = cellShape[2] + 1;
315         }
316         else if (cellModel == wedge)
317         {
318             if (!wallCell[celli])
319             {
320                 hexLabels_[hexi++] = hexNotWall;
321             }
322             else
323             {
324                 labelList modelToMesh = calcFaceAddressing
325                 (
326                     allFaces, cellShape, cellFaces[celli], celli
327                 );
329                 wallFlags[0] = wallFace[modelToMesh[2]];
330                 wallFlags[1] = wallFace[modelToMesh[3]];
331                 wallFlags[2] = wallFace[modelToMesh[0]];
332                 wallFlags[3] = wallFace[modelToMesh[1]];
333                 wallFlags[4] = wallFace[modelToMesh[4]];
334                 wallFlags[5] = wallFace[modelToMesh[5]];
336                 hexLabels_[hexi++] = fv_encode_elem_header
337                 (
338                     FV_HEX_ELEM_ID, wallFlags.begin()
339                 );
340             }
341             hexLabels_[hexi++] = cellShape[0] + 1;
342             hexLabels_[hexi++] = cellShape[1] + 1;
343             hexLabels_[hexi++] = cellShape[0] + 1;
344             hexLabels_[hexi++] = cellShape[2] + 1;
345             hexLabels_[hexi++] = cellShape[3] + 1;
346             hexLabels_[hexi++] = cellShape[4] + 1;
347             hexLabels_[hexi++] = cellShape[6] + 1;
348             hexLabels_[hexi++] = cellShape[5] + 1;
349         }
350         else if (cellModel == hex)
351         {
352             if (!wallCell[celli])
353             {
354                 hexLabels_[hexi++] = hexNotWall;
355             }
356             else
357             {
358                 labelList modelToMesh = calcFaceAddressing
359                 (
360                     allFaces, cellShape, cellFaces[celli], celli
361                 );
363                 wallFlags[0] = wallFace[modelToMesh[0]];
364                 wallFlags[1] = wallFace[modelToMesh[1]];
365                 wallFlags[2] = wallFace[modelToMesh[4]];
366                 wallFlags[3] = wallFace[modelToMesh[5]];
367                 wallFlags[4] = wallFace[modelToMesh[2]];
368                 wallFlags[5] = wallFace[modelToMesh[3]];
370                 hexLabels_[hexi++] = fv_encode_elem_header
371                 (
372                     FV_HEX_ELEM_ID, wallFlags.begin()
373                 );
374             }
375             hexLabels_[hexi++] = cellShape[0] + 1;
376             hexLabels_[hexi++] = cellShape[1] + 1;
377             hexLabels_[hexi++] = cellShape[3] + 1;
378             hexLabels_[hexi++] = cellShape[2] + 1;
379             hexLabels_[hexi++] = cellShape[4] + 1;
380             hexLabels_[hexi++] = cellShape[5] + 1;
381             hexLabels_[hexi++] = cellShape[7] + 1;
382             hexLabels_[hexi++] = cellShape[6] + 1;
383         }
384         else
385         {
386             nPoly_++;
387         }
388     }
390     hexLabels_.setSize(hexi);
391     prismLabels_.setSize(prismi);
392     pyrLabels_.setSize(pyri);
393     tetLabels_.setSize(teti);
396     //
397     // Patches
398     //
399     forAll(mesh.boundaryMesh(), patchI)
400     {
401         const polyPatch& patchFaces = mesh.boundaryMesh()[patchI];
403         labelList& faceLabels = quadFaceLabels_[patchI];
405         // Faces, each 4 labels. Size big enough
406         faceLabels.setSize(patchFaces.size()*4);
408         label labelI = 0;
410         forAll(patchFaces, faceI)
411         {
412             const face& patchFace = patchFaces[faceI];
414             if (patchFace.size() == 3)
415             {
416                 faceLabels[labelI++] = patchFace[0] + 1;
417                 faceLabels[labelI++] = patchFace[1] + 1;
418                 faceLabels[labelI++] = patchFace[2] + 1;
419                 faceLabels[labelI++] = 0;   // Fieldview:triangle definition
420             }
421             else if (patchFace.size() == 4)
422             {
423                 faceLabels[labelI++] = patchFace[0] + 1;
424                 faceLabels[labelI++] = patchFace[1] + 1;
425                 faceLabels[labelI++] = patchFace[2] + 1;
426                 faceLabels[labelI++] = patchFace[3] + 1;
427             } 
428         }
430         faceLabels.setSize(labelI);
432         label nFaces = labelI/4;
434         nPolyFaces_[patchI] = patchFaces.size() - nFaces;
435     }
439 // ************************************************************************* //