1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 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
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
27 \*---------------------------------------------------------------------------*/
29 #include "vtkPV3Foam.H"
33 #include "cellModeller.H"
34 #include "vtkPV3FoamPoints.H"
37 #include "vtkCellArray.h"
38 #include "vtkUnstructuredGrid.h"
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
42 vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
45 polyDecomp& decompInfo
48 vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
52 Info<< "<beg> Foam::vtkPV3Foam::volumeVTKMesh" << endl;
56 // Number of additional points needed by the decomposition of polyhedra
59 // Number of additional cells generated by the decomposition of polyhedra
62 labelList& superCells = decompInfo.superCells();
63 labelList& addPointCellLabels = decompInfo.addPointCellLabels();
65 const cellModel& tet = *(cellModeller::lookup("tet"));
66 const cellModel& pyr = *(cellModeller::lookup("pyr"));
67 const cellModel& prism = *(cellModeller::lookup("prism"));
68 const cellModel& wedge = *(cellModeller::lookup("wedge"));
69 const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
70 const cellModel& hex = *(cellModeller::lookup("hex"));
72 // Scan for cells which need to be decomposed and count additional points
76 Info<< "... building cell-shapes" << endl;
78 const cellShapeList& cellShapes = mesh.cellShapes();
82 Info<< "... scanning" << endl;
84 forAll(cellShapes, cellI)
86 const cellModel& model = cellShapes[cellI].model();
98 const cell& cFaces = mesh.cells()[cellI];
100 forAll(cFaces, cFaceI)
102 const face& f = mesh.faces()[cFaces[cFaceI]];
104 label nFacePoints = f.size();
106 label nQuads = (nFacePoints - 2)/2;
107 label nTris = (nFacePoints - 2)%2;
108 nAddCells += nQuads + nTris;
116 // Set size of additional point addressing array
117 // (from added point to original cell)
118 addPointCellLabels.setSize(nAddPoints);
120 // Set size of additional cells mapping array
121 // (from added cell to original cell)
125 Info<<" mesh nCells = " << mesh.nCells() << nl
126 <<" nPoints = " << mesh.nPoints() << nl
127 <<" nAddCells = " << nAddCells << nl
128 <<" nAddPoints = " << nAddPoints << endl;
131 superCells.setSize(mesh.nCells() + nAddCells);
135 Info<< "... converting points" << endl;
138 // Convert Foam mesh vertices to VTK
139 vtkPoints *vtkpoints = vtkPoints::New();
140 vtkpoints->Allocate( mesh.nPoints() + nAddPoints );
142 const Foam::pointField& points = mesh.points();
146 vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
152 Info<< "... converting cells" << endl;
155 vtkmesh->Allocate( mesh.nCells() + nAddCells );
157 // Set counters for additional points and additional cells
158 label addPointI = 0, addCellI = 0;
160 // Create storage for points - needed for mapping from Foam to VTK
161 // data types - max 'order' = hex = 8 points
162 vtkIdType nodeIds[8];
164 forAll(cellShapes, cellI)
166 const cellShape& cellShape = cellShapes[cellI];
167 const cellModel& cellModel = cellShape.model();
169 superCells[addCellI++] = cellI;
171 if (cellModel == tet)
173 for (int j = 0; j < 4; j++)
175 nodeIds[j] = cellShape[j];
177 vtkmesh->InsertNextCell
184 else if (cellModel == pyr)
186 for (int j = 0; j < 5; j++)
188 nodeIds[j] = cellShape[j];
190 vtkmesh->InsertNextCell
197 else if (cellModel == prism)
199 for (int j = 0; j < 6; j++)
201 nodeIds[j] = cellShape[j];
203 vtkmesh->InsertNextCell
210 else if (cellModel == tetWedge)
212 // Treat as squeezed prism
214 nodeIds[0] = cellShape[0];
215 nodeIds[1] = cellShape[2];
216 nodeIds[2] = cellShape[1];
217 nodeIds[3] = cellShape[3];
218 nodeIds[4] = cellShape[4];
219 nodeIds[5] = cellShape[4];
221 vtkmesh->InsertNextCell
228 else if (cellModel == wedge)
230 // Treat as squeezed hex
232 nodeIds[0] = cellShape[0];
233 nodeIds[1] = cellShape[1];
234 nodeIds[2] = cellShape[2];
235 nodeIds[3] = cellShape[2];
236 nodeIds[4] = cellShape[3];
237 nodeIds[5] = cellShape[4];
238 nodeIds[6] = cellShape[5];
239 nodeIds[7] = cellShape[6];
241 vtkmesh->InsertNextCell
248 else if (cellModel == hex)
250 for (int j = 0; j < 8; j++)
252 nodeIds[j] = cellShape[j];
254 vtkmesh->InsertNextCell
263 // Polyhedral cell. Decompose into tets + prisms.
265 // Mapping from additional point to cell
266 addPointCellLabels[addPointI] = cellI;
268 // Insert the new vertex from the cell-centre
269 label newVertexLabel = mesh.nPoints() + addPointI;
270 vtkPV3FoamInsertNextPoint(vtkpoints, mesh.C()[cellI]);
272 // Whether to insert cell in place of original or not.
273 bool substituteCell = true;
275 const labelList& cFaces = mesh.cells()[cellI];
277 forAll(cFaces, cFaceI)
279 const face& f = mesh.faces()[cFaces[cFaceI]];
281 label nFacePoints = f.size();
283 label nQuads = (nFacePoints - 2)/2;
284 label nTris = (nFacePoints - 2)%2;
288 for (label quadi=0; quadi<nQuads; quadi++)
290 label thisCellI = -1;
295 substituteCell = false;
299 thisCellI = mesh.nCells() + addCellI;
300 superCells[addCellI++] = cellI;
304 nodeIds[1] = f[qpi + 1];
305 nodeIds[2] = f[qpi + 2];
306 nodeIds[3] = f[qpi + 3];
307 nodeIds[4] = newVertexLabel;
308 vtkmesh->InsertNextCell
320 label thisCellI = -1;
325 substituteCell = false;
329 thisCellI = mesh.nCells() + addCellI;
330 superCells[addCellI++] = cellI;
334 nodeIds[1] = f[qpi + 1];
335 nodeIds[2] = f[qpi + 2];
336 nodeIds[3] = newVertexLabel;
337 vtkmesh->InsertNextCell
350 vtkmesh->SetPoints(vtkpoints);
355 Info<< "<end> Foam::vtkPV3Foam::volumeVTKMesh" << endl;
363 // ************************************************************************* //