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.
This commit is contained in:
Mark Olesen
2010-03-04 11:20:20 +01:00
parent 5726d59f63
commit 89615f708e
31 changed files with 188 additions and 157 deletions

View File

@ -159,13 +159,6 @@ Note
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
static const label VTK_TETRA = 10;
static const label VTK_PYRAMID = 14;
static const label VTK_WEDGE = 13;
static const label VTK_HEXAHEDRON = 12;
template<class GeoField> template<class GeoField>
void print(const char* msg, Ostream& os, const PtrList<GeoField>& flds) void print(const char* msg, Ostream& os, const PtrList<GeoField>& flds)
{ {
@ -229,10 +222,7 @@ labelList getSelectedPatches
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -285,11 +275,11 @@ int main(int argc, char *argv[])
# include "setRootCase.H" # include "setRootCase.H"
# include "createTime.H" # include "createTime.H"
bool doWriteInternal = !args.optionFound("noInternal"); const bool doWriteInternal = !args.optionFound("noInternal");
bool doFaceZones = !args.optionFound("noFaceZones"); const bool doFaceZones = !args.optionFound("noFaceZones");
bool doLinks = !args.optionFound("noLinks"); const bool doLinks = !args.optionFound("noLinks");
bool binary = !args.optionFound("ascii"); const bool binary = !args.optionFound("ascii");
bool useTimeName = args.optionFound("useTimeName"); const bool useTimeName = args.optionFound("useTimeName");
if (binary && (sizeof(floatScalar) != 4 || sizeof(label) != 4)) if (binary && (sizeof(floatScalar) != 4 || sizeof(label) != 4))
{ {
@ -299,7 +289,7 @@ int main(int argc, char *argv[])
<< exit(FatalError); << exit(FatalError);
} }
bool nearCellValue = args.optionFound("nearCellValue"); const bool nearCellValue = args.optionFound("nearCellValue");
if (nearCellValue) if (nearCellValue)
{ {
@ -308,7 +298,7 @@ int main(int argc, char *argv[])
<< nl << endl; << nl << endl;
} }
bool noPointValues = args.optionFound("noPointValues"); const bool noPointValues = args.optionFound("noPointValues");
if (noPointValues) if (noPointValues)
{ {
@ -316,7 +306,7 @@ int main(int argc, char *argv[])
<< "Outputting cell values only" << nl << endl; << "Outputting cell values only" << nl << endl;
} }
bool allPatches = args.optionFound("allPatches"); const bool allPatches = args.optionFound("allPatches");
List<wordRe> excludePatches; List<wordRe> excludePatches;
if (args.optionFound("excludePatches")) if (args.optionFound("excludePatches"))
@ -392,15 +382,8 @@ int main(int argc, char *argv[])
Info<< "Time: " << runTime.timeName() << endl; Info<< "Time: " << runTime.timeName() << endl;
word timeDesc = ""; word timeDesc =
if (useTimeName) useTimeName ? runTime.timeName() : Foam::name(runTime.timeIndex());
{
timeDesc = runTime.timeName();
}
else
{
timeDesc = name(runTime.timeIndex());
}
// Check for new polyMesh/ and update mesh, fvMeshSubset and cell // Check for new polyMesh/ and update mesh, fvMeshSubset and cell
// decomposition. // decomposition.
@ -470,10 +453,7 @@ int main(int argc, char *argv[])
IOobjectList objects(mesh, runTime.timeName()); IOobjectList objects(mesh, runTime.timeName());
HashSet<word> selectedFields; HashSet<word> selectedFields;
if (args.optionFound("fields")) args.optionReadIfPresent("fields", selectedFields);
{
args.optionLookup("fields")() >> selectedFields;
}
// Construct the vol fields (on the original mesh if subsetted) // Construct the vol fields (on the original mesh if subsetted)

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -33,10 +33,10 @@ Description
#include "polyMesh.H" #include "polyMesh.H"
#include "cellShape.H" #include "cellShape.H"
#include "cellModeller.H" #include "cellModeller.H"
#include "Swap.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::vtkTopo::vtkTopo(const polyMesh& mesh) Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
: :
mesh_(mesh), mesh_(mesh),
@ -61,6 +61,9 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
// 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();
// Scan for cells which need to be decomposed and count additional points // Scan for cells which need to be decomposed and count additional points
// and cells // and cells
@ -71,7 +74,7 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
if if
( (
model != hex model != hex
// && model != wedge // See above. // && model != wedge // See above.
&& model != prism && model != prism
&& model != pyr && model != pyr
&& model != tet && model != tet
@ -111,7 +114,7 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
cellTypes_.setSize(cellShapes.size() + nAddCells); cellTypes_.setSize(cellShapes.size() + nAddCells);
// Set counters for additional points and additional cells // Set counters for additional points and additional cells
label api = 0, aci = 0; label addPointI = 0, addCellI = 0;
forAll(cellShapes, cellI) forAll(cellShapes, cellI)
{ {
@ -134,15 +137,13 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
} }
else if (cellModel == prism) else if (cellModel == prism)
{ {
vtkVerts.setSize(6); // VTK has a different node order for VTK_WEDGE
vtkVerts[0] = cellShape[0]; // their triangles point outwards!
vtkVerts[1] = cellShape[2]; vtkVerts = cellShape;
vtkVerts[2] = cellShape[1];
vtkVerts[3] = cellShape[3]; Foam::Swap(vtkVerts[1], vtkVerts[2]);
vtkVerts[4] = cellShape[5]; Foam::Swap(vtkVerts[4], vtkVerts[5]);
vtkVerts[5] = cellShape[4];
// VTK calls this a wedge.
cellTypes_[cellI] = VTK_WEDGE; cellTypes_[cellI] = VTK_WEDGE;
} }
else if (cellModel == tetWedge) else if (cellModel == tetWedge)
@ -175,34 +176,28 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
// } // }
else if (cellModel == hex) else if (cellModel == hex)
{ {
vtkVerts.setSize(8); vtkVerts = cellShape;
vtkVerts[0] = cellShape[0];
vtkVerts[1] = cellShape[1];
vtkVerts[2] = cellShape[2];
vtkVerts[3] = cellShape[3];
vtkVerts[4] = cellShape[4];
vtkVerts[5] = cellShape[5];
vtkVerts[6] = cellShape[6];
vtkVerts[7] = cellShape[7];
cellTypes_[cellI] = VTK_HEXAHEDRON; cellTypes_[cellI] = VTK_HEXAHEDRON;
} }
else else
{ {
// Polyhedral cell. Decompose into tets + prisms. // Polyhedral cell. Decompose into tets + prisms.
// (see dxFoamExec/createDxConnections.C)
// Mapping from additional point to cell // Mapping from additional point to cell
addPointCellLabels_[api] = cellI; addPointCellLabels_[addPointI] = cellI;
// The new vertex from the cell-centre
const label newVertexLabel = mesh_.nPoints() + addPointI;
// 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);
// Number of triangles and quads in decomposition // Number of triangles and quads in decomposition
label nTris = 0; label nTris = 0;
@ -216,75 +211,95 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
label quadi = 0; label quadi = 0;
f.trianglesQuads(mesh_.points(), trii, quadi, triFcs, quadFcs); f.trianglesQuads(mesh_.points(), trii, quadi, triFcs, quadFcs);
forAll(quadFcs, quadi) forAll(quadFcs, quadI)
{ {
label thisCellI = -1; label thisCellI;
if (substituteCell) if (substituteCell)
{ {
thisCellI = cellI; thisCellI = cellI;
substituteCell = false; substituteCell = false;
} }
else else
{ {
thisCellI = mesh_.nCells() + aci; thisCellI = mesh_.nCells() + addCellI;
superCells_[addCellI++] = cellI;
superCells_[aci] = cellI;
aci++;
} }
labelList& addVtkVerts = vertLabels_[thisCellI]; labelList& addVtkVerts = vertLabels_[thisCellI];
addVtkVerts.setSize(5); addVtkVerts.setSize(5);
const face& quad = quadFcs[quadi]; const face& quad = quadFcs[quadI];
// Ensure we have the correct orientation for the
// 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)
{
addVtkVerts[0] = quad[3];
addVtkVerts[1] = quad[2];
addVtkVerts[2] = quad[1];
addVtkVerts[3] = quad[0];
}
else
{
addVtkVerts[0] = quad[0]; addVtkVerts[0] = quad[0];
addVtkVerts[1] = quad[1]; addVtkVerts[1] = quad[1];
addVtkVerts[2] = quad[2]; addVtkVerts[2] = quad[2];
addVtkVerts[3] = quad[3]; addVtkVerts[3] = quad[3];
addVtkVerts[4] = mesh_.nPoints() + api; }
addVtkVerts[4] = newVertexLabel;
cellTypes_[thisCellI] = VTK_PYRAMID; cellTypes_[thisCellI] = VTK_PYRAMID;
} }
forAll(triFcs, trii) forAll(triFcs, triI)
{ {
label thisCellI = -1; label thisCellI;
if (substituteCell) if (substituteCell)
{ {
thisCellI = cellI; thisCellI = cellI;
substituteCell = false; substituteCell = false;
} }
else else
{ {
thisCellI = mesh_.nCells() + aci; thisCellI = mesh_.nCells() + addCellI;
superCells_[addCellI++] = cellI;
superCells_[aci] = cellI;
aci++;
} }
labelList& addVtkVerts = vertLabels_[thisCellI]; labelList& addVtkVerts = vertLabels_[thisCellI];
const face& tri = triFcs[trii]; const face& tri = triFcs[triI];
addVtkVerts.setSize(4); addVtkVerts.setSize(4);
// See note above about the orientation.
if (isOwner)
{
addVtkVerts[0] = tri[2];
addVtkVerts[1] = tri[1];
addVtkVerts[2] = tri[0];
}
else
{
addVtkVerts[0] = tri[0]; addVtkVerts[0] = tri[0];
addVtkVerts[1] = tri[1]; addVtkVerts[1] = tri[1];
addVtkVerts[2] = tri[2]; addVtkVerts[2] = tri[2];
addVtkVerts[3] = mesh_.nPoints() + api; }
addVtkVerts[3] = newVertexLabel;
cellTypes_[thisCellI] = VTK_TETRA; cellTypes_[thisCellI] = VTK_TETRA;
} }
} }
api++; addPointI++;
} }
} }

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -80,7 +80,7 @@ public:
// Public static data // Public static data
// this must be consistent with the enumeration in "vtkCell.H" //- equivalent to enumeration in "vtkCellType.h"
enum vtkTypes enum vtkTypes
{ {
VTK_TRIANGLE = 5, VTK_TRIANGLE = 5,
@ -88,9 +88,10 @@ public:
VTK_QUAD = 9, VTK_QUAD = 9,
VTK_TETRA = 10, VTK_TETRA = 10,
VTK_PYRAMID = 14,
VTK_WEDGE = 13,
VTK_HEXAHEDRON = 12, VTK_HEXAHEDRON = 12,
VTK_WEDGE = 13,
VTK_PYRAMID = 14,
VTK_POLYHEDRON = 42
}; };
// Constructors // Constructors

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

@ -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>

View File

@ -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

View File

@ -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

View File

@ -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
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
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
{ {
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
} }
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
// 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
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
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
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,