Commit 0722c274 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: respect face orientation when decomposing polyhedra.

ENH: use face::trianglesQuads() method for PV3FoamReader as well.
- this avoids missing faces (and weird cells) in the decomposed polyhedra.
parent 87ae7d97
...@@ -91,7 +91,8 @@ ...@@ -91,7 +91,8 @@
animateable="0"> animateable="0">
<BooleanDomain name="bool"/> <BooleanDomain name="bool"/>
<Documentation> <Documentation>
Use vtkPolyhedron instead of decomposing polyhedra Use vtkPolyhedron instead of decomposing polyhedra.
!!Actually uses vtkConvexPointSet until this is properly supported in VTK!!
</Documentation> </Documentation>
</IntVectorProperty> </IntVectorProperty>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2010-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2010-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
......
...@@ -31,6 +31,7 @@ License ...@@ -31,6 +31,7 @@ License
#include "fvMesh.H" #include "fvMesh.H"
#include "cellModeller.H" #include "cellModeller.H"
#include "vtkOpenFOAMPoints.H" #include "vtkOpenFOAMPoints.H"
#include "Swap.H"
// VTK includes // VTK includes
#include "vtkCellArray.h" #include "vtkCellArray.h"
...@@ -45,6 +46,13 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -45,6 +46,13 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
polyDecomp& decompInfo polyDecomp& decompInfo
) )
{ {
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& wedge = *(cellModeller::lookup("wedge"));
const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
const cellModel& hex = *(cellModeller::lookup("hex"));
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New(); vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
if (debug) if (debug)
...@@ -53,36 +61,27 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -53,36 +61,27 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
printMemory(); printMemory();
} }
const cellShapeList& cellShapes = mesh.cellShapes();
// Number of additional points needed by the decomposition of polyhedra // Number of additional points needed by the decomposition of polyhedra
label nAddPoints = 0; label nAddPoints = 0;
// Number of additional cells generated by the decomposition of polyhedra // Number of additional cells generated by the decomposition of polyhedra
label nAddCells = 0; label nAddCells = 0;
// face owner is needed to determine the face orientation
const labelList& owner = mesh.faceOwner();
labelList& superCells = decompInfo.superCells(); labelList& superCells = decompInfo.superCells();
labelList& addPointCellLabels = decompInfo.addPointCellLabels(); labelList& addPointCellLabels = decompInfo.addPointCellLabels();
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& wedge = *(cellModeller::lookup("wedge"));
const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
const cellModel& hex = *(cellModeller::lookup("hex"));
// Scan for cells which need to be decomposed and count additional points
// and cells
if (debug)
{
Info<< "... building cell-shapes" << endl;
}
const cellShapeList& cellShapes = mesh.cellShapes();
if (debug) if (debug)
{ {
Info<< "... scanning" << endl; Info<< "... scanning" << endl;
} }
// count number of cells to decompose // Scan for cells which need to be decomposed and count additional points
// and cells
if (!reader_->GetUseVTKPolyhedron()) if (!reader_->GetUseVTKPolyhedron())
{ {
forAll(cellShapes, cellI) forAll(cellShapes, cellI)
...@@ -105,10 +104,10 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -105,10 +104,10 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
{ {
const face& f = mesh.faces()[cFaces[cFaceI]]; const face& f = mesh.faces()[cFaces[cFaceI]];
label nFacePoints = f.size(); label nQuads = 0;
label nTris = 0;
f.nTrianglesQuads(mesh.points(), nTris, nQuads);
label nQuads = (nFacePoints - 2)/2;
label nTris = (nFacePoints - 2)%2;
nAddCells += nQuads + nTris; nAddCells += nQuads + nTris;
} }
...@@ -201,8 +200,8 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -201,8 +200,8 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
} }
else if (cellModel == prism) else if (cellModel == prism)
{ {
// VTK has a different node order - their triangles point outwards! // VTK has a different node order for VTK_WEDGE
// their triangles point outwards!
nodeIds[0] = cellShape[0]; nodeIds[0] = cellShape[0];
nodeIds[1] = cellShape[2]; nodeIds[1] = cellShape[2];
nodeIds[2] = cellShape[1]; nodeIds[2] = cellShape[1];
...@@ -349,29 +348,34 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -349,29 +348,34 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
// Mapping from additional point to cell // Mapping from additional point to cell
addPointCellLabels[addPointI] = cellI; addPointCellLabels[addPointI] = cellI;
// Insert the new vertex from the cell-centre // The new vertex from the cell-centre
label newVertexLabel = mesh.nPoints() + addPointI; const label newVertexLabel = mesh.nPoints() + addPointI;
vtkInsertNextOpenFOAMPoint(vtkpoints, mesh.C()[cellI]); vtkInsertNextOpenFOAMPoint(vtkpoints, mesh.C()[cellI]);
// Whether to insert cell in place of original or not. // Whether to insert cell in place of original or not.
bool substituteCell = true; bool substituteCell = true;
const labelList& cFaces = mesh.cells()[cellI]; const labelList& cFaces = mesh.cells()[cellI];
forAll(cFaces, cFaceI) forAll(cFaces, cFaceI)
{ {
const face& f = mesh.faces()[cFaces[cFaceI]]; const face& f = mesh.faces()[cFaces[cFaceI]];
const bool isOwner = (owner[cFaces[cFaceI]] == cellI);
label nFacePoints = f.size(); // Number of triangles and quads in decomposition
label nTris = 0;
label nQuads = 0;
f.nTrianglesQuads(mesh.points(), nTris, nQuads);
label nQuads = (nFacePoints - 2)/2; // Do actual decomposition into triFcs and quadFcs.
label nTris = (nFacePoints - 2)%2; faceList triFcs(nTris);
faceList quadFcs(nQuads);
label trii = 0;
label quadi = 0;
f.trianglesQuads(mesh.points(), trii, quadi, triFcs, quadFcs);
label qpi = 0; forAll(quadFcs, quadI)
for (label quadi=0; quadi<nQuads; quadi++)
{ {
label thisCellI = -1; label thisCellI;
if (substituteCell) if (substituteCell)
{ {
...@@ -384,10 +388,29 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -384,10 +388,29 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
superCells[addCellI++] = cellI; superCells[addCellI++] = cellI;
} }
nodeIds[0] = f[0]; const face& quad = quadFcs[quadI];
nodeIds[1] = f[qpi + 1];
nodeIds[2] = f[qpi + 2]; // Ensure we have the correct orientation for the
nodeIds[3] = f[qpi + 3]; // base of the primitive cell shape.
// If the cell is face owner, the orientation needs to be
// flipped.
// At the moment, VTK doesn't actually seem to care if
// negative cells are defined, but we'll do it anyhow
// (for safety).
if (isOwner)
{
nodeIds[0] = quad[3];
nodeIds[1] = quad[2];
nodeIds[2] = quad[1];
nodeIds[3] = quad[0];
}
else
{
nodeIds[0] = quad[0];
nodeIds[1] = quad[1];
nodeIds[2] = quad[2];
nodeIds[3] = quad[3];
}
nodeIds[4] = newVertexLabel; nodeIds[4] = newVertexLabel;
vtkmesh->InsertNextCell vtkmesh->InsertNextCell
( (
...@@ -395,13 +418,11 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -395,13 +418,11 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
5, 5,
nodeIds nodeIds
); );
qpi += 2;
} }
if (nTris) forAll(triFcs, triI)
{ {
label thisCellI = -1; label thisCellI;
if (substituteCell) if (substituteCell)
{ {
...@@ -414,10 +435,23 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh ...@@ -414,10 +435,23 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
superCells[addCellI++] = cellI; superCells[addCellI++] = cellI;
} }
nodeIds[0] = f[0]; const face& tri = triFcs[triI];
nodeIds[1] = f[qpi + 1];
nodeIds[2] = f[qpi + 2]; // See note above about the orientation.
if (isOwner)
{
nodeIds[0] = tri[2];
nodeIds[1] = tri[1];
nodeIds[2] = tri[0];
}
else
{
nodeIds[0] = tri[0];
nodeIds[1] = tri[1];
nodeIds[2] = tri[2];
}
nodeIds[3] = newVertexLabel; nodeIds[3] = newVertexLabel;
vtkmesh->InsertNextCell vtkmesh->InsertNextCell
( (
VTK_TETRA, VTK_TETRA,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment