ENH: allow direct writing of polyhedra from foamToVTK

This commit is contained in:
Mark Olesen
2010-05-07 09:06:48 +02:00
parent 5b588af7ab
commit 64ac5cbc78
8 changed files with 76 additions and 57 deletions

View File

@ -40,7 +40,6 @@ Usage
- foamToVTK [OPTION] - foamToVTK [OPTION]
@param -ascii \n @param -ascii \n
Write VTK data in ASCII format instead of binary. Write VTK data in ASCII format instead of binary.
@ -78,6 +77,9 @@ Usage
@param -noLinks \n @param -noLinks \n
(in parallel) do not link processor files to master (in parallel) do not link processor files to master
@param poly \n
write polyhedral cells without tet/pyramid decomposition
@param -allPatches \n @param -allPatches \n
Combine all patches into a single file Combine all patches into a single file
@ -95,7 +97,7 @@ Usage
Note Note
mesh subset is handled by vtkMesh. Slight inconsistency in mesh subset is handled by vtkMesh. Slight inconsistency in
interpolation: on the internal field it interpolates the whole volfield interpolation: on the internal field it interpolates the whole volField
to the whole-mesh pointField and then selects only those values it to the whole-mesh pointField and then selects only those values it
needs for the subMesh (using the fvMeshSubset cellMap(), pointMap() needs for the subMesh (using the fvMeshSubset cellMap(), pointMap()
functions). For the patches however it uses the functions). For the patches however it uses the
@ -262,14 +264,11 @@ int main(int argc, char *argv[])
"ascii", "ascii",
"write in ASCII format instead of binary" "write in ASCII format instead of binary"
); );
/*
argList::addBoolOption argList::addBoolOption
( (
"noDecompose", "poly",
"do not decompose polyhedral cells into tets/prism cells" "write polyhedral cells without tet/pyramid decomposition"
"- NOT YET IMPLEMENTED"
); );
*/
argList::addBoolOption argList::addBoolOption
( (
"surfaceFields", "surfaceFields",
@ -326,9 +325,8 @@ int main(int argc, char *argv[])
const bool binary = !args.optionFound("ascii"); const bool binary = !args.optionFound("ascii");
const bool useTimeName = args.optionFound("useTimeName"); const bool useTimeName = args.optionFound("useTimeName");
// decomposition of polyhedral cells into tets/prism cells // decomposition of polyhedral cells into tets/pyramids cells
// vtkTopo::decomposePoly = !args.optionFound("noDecompose"); vtkTopo::decomposePoly = !args.optionFound("poly");
if (binary && (sizeof(floatScalar) != 4 || sizeof(label) != 4)) if (binary && (sizeof(floatScalar) != 4 || sizeof(label) != 4))
{ {

View File

@ -28,7 +28,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::internalWriter::internalWriter Foam::internalWriter::internalWriter
( (
const vtkMesh& vMesh, const vtkMesh& vMesh,
@ -58,8 +57,7 @@ Foam::internalWriter::internalWriter
const labelList& addPointCellLabels = topo.addPointCellLabels(); const labelList& addPointCellLabels = topo.addPointCellLabels();
const label nTotPoints = mesh.nPoints() + addPointCellLabels.size(); const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
os_ << "POINTS " << nTotPoints os_ << "POINTS " << nTotPoints << " float" << std::endl;
<< " float" << std::endl;
DynamicList<floatScalar> ptField(3*nTotPoints); DynamicList<floatScalar> ptField(3*nTotPoints);
@ -87,9 +85,7 @@ Foam::internalWriter::internalWriter
nFaceVerts += vtkVertLabels[cellI].size() + 1; nFaceVerts += vtkVertLabels[cellI].size() + 1;
} }
os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts << std::endl;
<< std::endl;
DynamicList<label> vertLabels(nFaceVerts); DynamicList<label> vertLabels(nFaceVerts);
@ -104,7 +100,6 @@ Foam::internalWriter::internalWriter
writeFuns::write(os_, binary_, vertLabels); writeFuns::write(os_, binary_, vertLabels);
const labelList& vtkCellTypes = topo.cellTypes(); const labelList& vtkCellTypes = topo.cellTypes();
os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl; os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
@ -128,8 +123,7 @@ void Foam::internalWriter::writeCellIDs()
const labelList& superCells = topo.superCells(); const labelList& superCells = topo.superCells();
// Cell ids first // Cell ids first
os_ << "cellID 1 " << vtkCellTypes.size() << " int" os_ << "cellID 1 " << vtkCellTypes.size() << " int" << std::endl;
<< std::endl;
labelList cellId(vtkCellTypes.size()); labelList cellId(vtkCellTypes.size());
label labelI = 0; label labelI = 0;

View File

@ -30,7 +30,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::lagrangianWriter::lagrangianWriter Foam::lagrangianWriter::lagrangianWriter
( (
const vtkMesh& vMesh, const vtkMesh& vMesh,

View File

@ -26,11 +26,8 @@ License
#include "patchWriter.H" #include "patchWriter.H"
#include "writeFuns.H" #include "writeFuns.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::patchWriter::patchWriter Foam::patchWriter::patchWriter
( (
const vtkMesh& vMesh, const vtkMesh& vMesh,
@ -91,8 +88,7 @@ Foam::patchWriter::patchWriter
} }
writeFuns::write(os_, binary_, ptField); writeFuns::write(os_, binary_, ptField);
os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts << std::endl;
<< std::endl;
DynamicList<label> vertLabels(nFaceVerts); DynamicList<label> vertLabels(nFaceVerts);
DynamicList<label> faceTypes(nFaceVerts); DynamicList<label> faceTypes(nFaceVerts);
@ -130,7 +126,6 @@ Foam::patchWriter::patchWriter
writeFuns::write(os_, binary_, vertLabels); writeFuns::write(os_, binary_, vertLabels);
os_ << "CELL_TYPES " << nFaces_ << std::endl; os_ << "CELL_TYPES " << nFaces_ << std::endl;
writeFuns::write(os_, binary_, faceTypes); writeFuns::write(os_, binary_, faceTypes);
} }

View File

@ -28,12 +28,8 @@ License
#include "Time.H" #include "Time.H"
#include "cellSet.H" #include "cellSet.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::vtkMesh::vtkMesh Foam::vtkMesh::vtkMesh
( (
fvMesh& baseMesh, fvMesh& baseMesh,
@ -63,8 +59,8 @@ Foam::polyMesh::readUpdateState Foam::vtkMesh::readUpdate()
if (meshState != polyMesh::UNCHANGED) if (meshState != polyMesh::UNCHANGED)
{ {
// Note: since fvMeshSubset has no movePoints() functionality reconstruct // Note: since fvMeshSubset has no movePoints() functionality,
// the subset even if only movement. // reconstruct the subset even if only movement.
topoPtr_.clear(); topoPtr_.clear();

View File

@ -102,10 +102,6 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
} }
} }
} }
else
{
notImplemented("vtkTopo: non-decomposed polyhedron");
}
// Set size of additional point addressing array // Set size of additional point addressing array
@ -191,7 +187,7 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
} }
else if (decomposePoly) else if (decomposePoly)
{ {
// Polyhedral cell. Decompose into tets + prisms. // Polyhedral cell. Decompose into tets + pyramids.
// Mapping from additional point to cell // Mapping from additional point to cell
addPointCellLabels_[addPointI] = cellI; addPointCellLabels_[addPointI] = cellI;
@ -314,6 +310,50 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
{ {
// Polyhedral cell - not decomposed // Polyhedral cell - not decomposed
cellTypes_[cellI] = VTK_POLYHEDRON; cellTypes_[cellI] = VTK_POLYHEDRON;
const labelList& cFaces = mesh_.cells()[cellI];
// space for the number of faces and size of each face
label nData = 1 + cFaces.size();
// count total number of face points
forAll(cFaces, cFaceI)
{
const face& f = mesh.faces()[cFaces[cFaceI]];
nData += f.size(); // space for the face labels
}
vtkVerts.setSize(nData);
nData = 0;
vtkVerts[nData++] = cFaces.size();
// build face stream
forAll(cFaces, cFaceI)
{
const face& f = mesh.faces()[cFaces[cFaceI]];
const bool isOwner = (owner[cFaces[cFaceI]] == cellI);
// number of labels for this face
vtkVerts[nData++] = f.size();
if (isOwner)
{
forAll(f, fp)
{
vtkVerts[nData++] = f[fp];
}
}
else
{
// fairly immaterial if we reverse the list
// or use face::reverseFace()
forAllReverse(f, fp)
{
vtkVerts[nData++] = f[fp];
}
}
}
} }
} }

View File

@ -227,62 +227,59 @@ void Foam::writeFuns::writePointDataHeader
} }
void Foam::writeFuns::insert(const scalar pt, DynamicList<floatScalar>& dest) void Foam::writeFuns::insert(const scalar src, DynamicList<floatScalar>& dest)
{ {
dest.append(float(pt)); dest.append(float(src));
} }
void Foam::writeFuns::insert(const vector& pt, DynamicList<floatScalar>& dest) void Foam::writeFuns::insert(const vector& src, DynamicList<floatScalar>& dest)
{ {
for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++) for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
{ {
dest.append(float(pt[cmpt])); dest.append(float(src[cmpt]));
} }
} }
void Foam::writeFuns::insert void Foam::writeFuns::insert
( (
const sphericalTensor& pt, const sphericalTensor& src,
DynamicList<floatScalar>& dest DynamicList<floatScalar>& dest
) )
{ {
for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; cmpt++) for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; ++cmpt)
{ {
dest.append(float(pt[cmpt])); dest.append(float(src[cmpt]));
} }
} }
void Foam::writeFuns::insert void Foam::writeFuns::insert
( (
const symmTensor& pt, const symmTensor& src,
DynamicList<floatScalar>& dest DynamicList<floatScalar>& dest
) )
{ {
for (direction cmpt = 0; cmpt < symmTensor::nComponents; cmpt++) for (direction cmpt = 0; cmpt < symmTensor::nComponents; ++cmpt)
{ {
dest.append(float(pt[cmpt])); dest.append(float(src[cmpt]));
} }
} }
void Foam::writeFuns::insert(const tensor& pt, DynamicList<floatScalar>& dest) void Foam::writeFuns::insert(const tensor& src, DynamicList<floatScalar>& dest)
{ {
for (direction cmpt = 0; cmpt < tensor::nComponents; cmpt++) for (direction cmpt = 0; cmpt < tensor::nComponents; ++cmpt)
{ {
dest.append(float(pt[cmpt])); dest.append(float(src[cmpt]));
} }
} }
void Foam::writeFuns::insert(const labelList& source, DynamicList<label>& dest) void Foam::writeFuns::insert(const labelList& src, DynamicList<label>& dest)
{ {
forAll(source, i) dest.append(src);
{
dest.append(source[i]);
}
} }

View File

@ -44,7 +44,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Write lagrangian fields. // Write surface vector fields
void writeSurfFields void writeSurfFields
( (
const bool binary, const bool binary,