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 "vtkPV3Foam.H"
32 #include "cellModeller.H"
33 #include "vtkPV3FoamPoints.H"
36 #include "vtkCellArray.h"
37 #include "vtkUnstructuredGrid.h"
39 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
44 polyDecomp& decompInfo
47 vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
51 Info<< "<beg> Foam::vtkPV3Foam::volumeVTKMesh" << endl;
55 // Number of additional points needed by the decomposition of polyhedra
58 // Number of additional cells generated by the decomposition of polyhedra
61 labelList& superCells = decompInfo.superCells();
62 labelList& addPointCellLabels = decompInfo.addPointCellLabels();
64 const cellModel& tet = *(cellModeller::lookup("tet"));
65 const cellModel& pyr = *(cellModeller::lookup("pyr"));
66 const cellModel& prism = *(cellModeller::lookup("prism"));
67 const cellModel& wedge = *(cellModeller::lookup("wedge"));
68 const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
69 const cellModel& hex = *(cellModeller::lookup("hex"));
71 // Scan for cells which need to be decomposed and count additional points
75 Info<< "... building cell-shapes" << endl;
77 const cellShapeList& cellShapes = mesh.cellShapes();
81 Info<< "... scanning" << endl;
83 forAll(cellShapes, cellI)
85 const cellModel& model = cellShapes[cellI].model();
97 const cell& cFaces = mesh.cells()[cellI];
99 forAll(cFaces, cFaceI)
101 const face& f = mesh.faces()[cFaces[cFaceI]];
103 label nFacePoints = f.size();
105 label nQuads = (nFacePoints - 2)/2;
106 label nTris = (nFacePoints - 2)%2;
107 nAddCells += nQuads + nTris;
115 // Set size of additional point addressing array
116 // (from added point to original cell)
117 addPointCellLabels.setSize(nAddPoints);
119 // Set size of additional cells mapping array
120 // (from added cell to original cell)
124 Info<<" mesh nCells = " << mesh.nCells() << nl
125 <<" nPoints = " << mesh.nPoints() << nl
126 <<" nAddCells = " << nAddCells << nl
127 <<" nAddPoints = " << nAddPoints << endl;
130 superCells.setSize(mesh.nCells() + nAddCells);
134 Info<< "... converting points" << endl;
137 // Convert Foam mesh vertices to VTK
138 vtkPoints *vtkpoints = vtkPoints::New();
139 vtkpoints->Allocate( mesh.nPoints() + nAddPoints );
141 const Foam::pointField& points = mesh.points();
145 vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
151 Info<< "... converting cells" << endl;
154 vtkmesh->Allocate( mesh.nCells() + nAddCells );
156 // Set counters for additional points and additional cells
157 label addPointI = 0, addCellI = 0;
159 // Create storage for points - needed for mapping from Foam to VTK
160 // data types - max 'order' = hex = 8 points
161 vtkIdType nodeIds[8];
163 forAll(cellShapes, cellI)
165 const cellShape& cellShape = cellShapes[cellI];
166 const cellModel& cellModel = cellShape.model();
168 superCells[addCellI++] = cellI;
170 if (cellModel == tet)
172 for (int j = 0; j < 4; j++)
174 nodeIds[j] = cellShape[j];
176 vtkmesh->InsertNextCell
183 else if (cellModel == pyr)
185 for (int j = 0; j < 5; j++)
187 nodeIds[j] = cellShape[j];
189 vtkmesh->InsertNextCell
196 else if (cellModel == prism)
198 for (int j = 0; j < 6; j++)
200 nodeIds[j] = cellShape[j];
202 vtkmesh->InsertNextCell
209 else if (cellModel == tetWedge)
211 // Treat as squeezed prism
213 nodeIds[0] = cellShape[0];
214 nodeIds[1] = cellShape[2];
215 nodeIds[2] = cellShape[1];
216 nodeIds[3] = cellShape[3];
217 nodeIds[4] = cellShape[4];
218 nodeIds[5] = cellShape[4];
220 vtkmesh->InsertNextCell
227 else if (cellModel == wedge)
229 // Treat as squeezed hex
231 nodeIds[0] = cellShape[0];
232 nodeIds[1] = cellShape[1];
233 nodeIds[2] = cellShape[2];
234 nodeIds[3] = cellShape[2];
235 nodeIds[4] = cellShape[3];
236 nodeIds[5] = cellShape[4];
237 nodeIds[6] = cellShape[5];
238 nodeIds[7] = cellShape[6];
240 vtkmesh->InsertNextCell
247 else if (cellModel == hex)
249 for (int j = 0; j < 8; j++)
251 nodeIds[j] = cellShape[j];
253 vtkmesh->InsertNextCell
262 // Polyhedral cell. Decompose into tets + prisms.
264 // Mapping from additional point to cell
265 addPointCellLabels[addPointI] = cellI;
267 // Insert the new vertex from the cell-centre
268 label newVertexLabel = mesh.nPoints() + addPointI;
269 vtkPV3FoamInsertNextPoint(vtkpoints, mesh.C()[cellI]);
271 // Whether to insert cell in place of original or not.
272 bool substituteCell = true;
274 const labelList& cFaces = mesh.cells()[cellI];
276 forAll(cFaces, cFaceI)
278 const face& f = mesh.faces()[cFaces[cFaceI]];
280 label nFacePoints = f.size();
282 label nQuads = (nFacePoints - 2)/2;
283 label nTris = (nFacePoints - 2)%2;
287 for (label quadi=0; quadi<nQuads; quadi++)
291 substituteCell = false;
295 superCells[addCellI++] = cellI;
299 nodeIds[1] = f[qpi + 1];
300 nodeIds[2] = f[qpi + 2];
301 nodeIds[3] = f[qpi + 3];
302 nodeIds[4] = newVertexLabel;
303 vtkmesh->InsertNextCell
317 substituteCell = false;
321 superCells[addCellI++] = cellI;
325 nodeIds[1] = f[qpi + 1];
326 nodeIds[2] = f[qpi + 2];
327 nodeIds[3] = newVertexLabel;
328 vtkmesh->InsertNextCell
341 vtkmesh->SetPoints(vtkpoints);
346 Info<< "<end> Foam::vtkPV3Foam::volumeVTKMesh" << endl;
354 // ************************************************************************* //