ENH: allow direct writing of polyhedra from foamToVTK
This commit is contained in:
parent
5b588af7ab
commit
64ac5cbc78
@ -40,7 +40,6 @@ Usage
|
||||
|
||||
- foamToVTK [OPTION]
|
||||
|
||||
|
||||
@param -ascii \n
|
||||
Write VTK data in ASCII format instead of binary.
|
||||
|
||||
@ -78,6 +77,9 @@ Usage
|
||||
@param -noLinks \n
|
||||
(in parallel) do not link processor files to master
|
||||
|
||||
@param poly \n
|
||||
write polyhedral cells without tet/pyramid decomposition
|
||||
|
||||
@param -allPatches \n
|
||||
Combine all patches into a single file
|
||||
|
||||
@ -95,7 +97,7 @@ Usage
|
||||
|
||||
Note
|
||||
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
|
||||
needs for the subMesh (using the fvMeshSubset cellMap(), pointMap()
|
||||
functions). For the patches however it uses the
|
||||
@ -262,14 +264,11 @@ int main(int argc, char *argv[])
|
||||
"ascii",
|
||||
"write in ASCII format instead of binary"
|
||||
);
|
||||
/*
|
||||
argList::addBoolOption
|
||||
(
|
||||
"noDecompose",
|
||||
"do not decompose polyhedral cells into tets/prism cells"
|
||||
"- NOT YET IMPLEMENTED"
|
||||
"poly",
|
||||
"write polyhedral cells without tet/pyramid decomposition"
|
||||
);
|
||||
*/
|
||||
argList::addBoolOption
|
||||
(
|
||||
"surfaceFields",
|
||||
@ -326,9 +325,8 @@ int main(int argc, char *argv[])
|
||||
const bool binary = !args.optionFound("ascii");
|
||||
const bool useTimeName = args.optionFound("useTimeName");
|
||||
|
||||
// decomposition of polyhedral cells into tets/prism cells
|
||||
// vtkTopo::decomposePoly = !args.optionFound("noDecompose");
|
||||
|
||||
// decomposition of polyhedral cells into tets/pyramids cells
|
||||
vtkTopo::decomposePoly = !args.optionFound("poly");
|
||||
|
||||
if (binary && (sizeof(floatScalar) != 4 || sizeof(label) != 4))
|
||||
{
|
||||
|
@ -28,7 +28,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// Construct from components
|
||||
Foam::internalWriter::internalWriter
|
||||
(
|
||||
const vtkMesh& vMesh,
|
||||
@ -58,8 +57,7 @@ Foam::internalWriter::internalWriter
|
||||
const labelList& addPointCellLabels = topo.addPointCellLabels();
|
||||
const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
|
||||
|
||||
os_ << "POINTS " << nTotPoints
|
||||
<< " float" << std::endl;
|
||||
os_ << "POINTS " << nTotPoints << " float" << std::endl;
|
||||
|
||||
DynamicList<floatScalar> ptField(3*nTotPoints);
|
||||
|
||||
@ -87,9 +85,7 @@ Foam::internalWriter::internalWriter
|
||||
nFaceVerts += vtkVertLabels[cellI].size() + 1;
|
||||
}
|
||||
|
||||
os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts
|
||||
<< std::endl;
|
||||
|
||||
os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts << std::endl;
|
||||
|
||||
DynamicList<label> vertLabels(nFaceVerts);
|
||||
|
||||
@ -104,7 +100,6 @@ Foam::internalWriter::internalWriter
|
||||
writeFuns::write(os_, binary_, vertLabels);
|
||||
|
||||
|
||||
|
||||
const labelList& vtkCellTypes = topo.cellTypes();
|
||||
|
||||
os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
|
||||
@ -128,8 +123,7 @@ void Foam::internalWriter::writeCellIDs()
|
||||
const labelList& superCells = topo.superCells();
|
||||
|
||||
// Cell ids first
|
||||
os_ << "cellID 1 " << vtkCellTypes.size() << " int"
|
||||
<< std::endl;
|
||||
os_ << "cellID 1 " << vtkCellTypes.size() << " int" << std::endl;
|
||||
|
||||
labelList cellId(vtkCellTypes.size());
|
||||
label labelI = 0;
|
||||
|
@ -30,7 +30,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// Construct from components
|
||||
Foam::lagrangianWriter::lagrangianWriter
|
||||
(
|
||||
const vtkMesh& vMesh,
|
||||
|
@ -26,11 +26,8 @@ License
|
||||
#include "patchWriter.H"
|
||||
#include "writeFuns.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// Construct from components
|
||||
Foam::patchWriter::patchWriter
|
||||
(
|
||||
const vtkMesh& vMesh,
|
||||
@ -91,8 +88,7 @@ Foam::patchWriter::patchWriter
|
||||
}
|
||||
writeFuns::write(os_, binary_, ptField);
|
||||
|
||||
os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts
|
||||
<< std::endl;
|
||||
os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts << std::endl;
|
||||
|
||||
DynamicList<label> vertLabels(nFaceVerts);
|
||||
DynamicList<label> faceTypes(nFaceVerts);
|
||||
@ -130,7 +126,6 @@ Foam::patchWriter::patchWriter
|
||||
writeFuns::write(os_, binary_, vertLabels);
|
||||
|
||||
os_ << "CELL_TYPES " << nFaces_ << std::endl;
|
||||
|
||||
writeFuns::write(os_, binary_, faceTypes);
|
||||
}
|
||||
|
||||
|
@ -28,12 +28,8 @@ License
|
||||
#include "Time.H"
|
||||
#include "cellSet.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// Construct from components
|
||||
Foam::vtkMesh::vtkMesh
|
||||
(
|
||||
fvMesh& baseMesh,
|
||||
@ -63,8 +59,8 @@ Foam::polyMesh::readUpdateState Foam::vtkMesh::readUpdate()
|
||||
|
||||
if (meshState != polyMesh::UNCHANGED)
|
||||
{
|
||||
// Note: since fvMeshSubset has no movePoints() functionality reconstruct
|
||||
// the subset even if only movement.
|
||||
// Note: since fvMeshSubset has no movePoints() functionality,
|
||||
// reconstruct the subset even if only movement.
|
||||
|
||||
topoPtr_.clear();
|
||||
|
||||
|
@ -102,10 +102,6 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
notImplemented("vtkTopo: non-decomposed polyhedron");
|
||||
}
|
||||
|
||||
|
||||
// Set size of additional point addressing array
|
||||
@ -191,7 +187,7 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
|
||||
}
|
||||
else if (decomposePoly)
|
||||
{
|
||||
// Polyhedral cell. Decompose into tets + prisms.
|
||||
// Polyhedral cell. Decompose into tets + pyramids.
|
||||
|
||||
// Mapping from additional point to cell
|
||||
addPointCellLabels_[addPointI] = cellI;
|
||||
@ -314,6 +310,50 @@ Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
|
||||
{
|
||||
// Polyhedral cell - not decomposed
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
(
|
||||
const sphericalTensor& pt,
|
||||
const sphericalTensor& src,
|
||||
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
|
||||
(
|
||||
const symmTensor& pt,
|
||||
const symmTensor& src,
|
||||
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(source[i]);
|
||||
}
|
||||
dest.append(src);
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Write lagrangian fields.
|
||||
// Write surface vector fields
|
||||
void writeSurfFields
|
||||
(
|
||||
const bool binary,
|
||||
|
Loading…
Reference in New Issue
Block a user