Commit 992833d9 authored by Andrew Heather's avatar Andrew Heather
Browse files

Merge branch 'olesenm'

parents 7ad0be02 1668cb76
......@@ -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))
{
......@@ -991,17 +989,17 @@ int main(int argc, char *argv[])
Info<< " FaceZone : " << patchFileName << endl;
std::ofstream str(patchFileName.c_str());
std::ofstream ostr(patchFileName.c_str());
writeFuns::writeHeader(str, binary, pp.name());
str << "DATASET POLYDATA" << std::endl;
writeFuns::writeHeader(ostr, binary, pp.name());
ostr<< "DATASET POLYDATA" << std::endl;
writePatchGeom
(
binary,
pp().localFaces(),
pp().localPoints(),
str
ostr
);
}
}
......
......@@ -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,
......@@ -59,7 +56,7 @@ Foam::patchWriter::patchWriter
{
writeFuns::writeHeader(os_, binary_, "patches");
}
os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
os_ << "DATASET POLYDATA" << std::endl;
// Write topology
nPoints_ = 0;
......@@ -91,11 +88,9 @@ Foam::patchWriter::patchWriter
}
writeFuns::write(os_, binary_, ptField);
os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts
<< std::endl;
os_ << "POLYGONS " << nFaces_ << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
DynamicList<label> faceTypes(nFaceVerts);
label offset = 0;
......@@ -107,31 +102,12 @@ Foam::patchWriter::patchWriter
{
const face& f = pp.localFaces()[faceI];
const label fSize = f.size();
vertLabels.append(fSize);
vertLabels.append(f.size());
writeFuns::insert(f + offset, vertLabels);
if (fSize == 3)
{
faceTypes.append(vtkTopo::VTK_TRIANGLE);
}
else if (fSize == 4)
{
faceTypes.append(vtkTopo::VTK_QUAD);
}
else
{
faceTypes.append(vtkTopo::VTK_POLYGON);
}
}
offset += pp.nPoints();
}
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];
}
}
}
}
}
......
......@@ -39,21 +39,16 @@ void Foam::writeFaceSet
{
const faceList& faces = vMesh.mesh().faces();
std::ofstream pStream(fileName.c_str());
std::ofstream ostr(fileName.c_str());
pStream
<< "# vtk DataFile Version 2.0" << std::endl
<< set.name() << std::endl;
if (binary)
{
pStream << "BINARY" << std::endl;
}
else
{
pStream << "ASCII" << std::endl;
}
pStream << "DATASET POLYDATA" << std::endl;
writeFuns::writeHeader
(
ostr,
binary,
set.name()
);
ostr<< "DATASET POLYDATA" << std::endl;
//------------------------------------------------------------------
//
......@@ -79,13 +74,13 @@ void Foam::writeFaceSet
// Write points and faces as polygons
pStream << "POINTS " << fp.nPoints() << " float" << std::endl;
ostr<< "POINTS " << fp.nPoints() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*fp.nPoints());
writeFuns::insert(fp.localPoints(), ptField);
writeFuns::write(pStream, binary, ptField);
writeFuns::write(ostr, binary, ptField);
label nFaceVerts = 0;
......@@ -94,8 +89,7 @@ void Foam::writeFaceSet
{
nFaceVerts += fp.localFaces()[faceI].size() + 1;
}
pStream << "POLYGONS " << fp.size() << ' ' << nFaceVerts
<< std::endl;
ostr<< "POLYGONS " << fp.size() << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
......@@ -108,7 +102,7 @@ void Foam::writeFaceSet
writeFuns::insert(f, vertLabels);
}
writeFuns::write(pStream, binary, vertLabels);
writeFuns::write(ostr, binary, vertLabels);
//-----------------------------------------------------------------
......@@ -119,14 +113,14 @@ void Foam::writeFaceSet
// Write faceID
pStream
ostr
<< "CELL_DATA " << fp.size() << std::endl
<< "FIELD attributes 1" << std::endl;
// Cell ids first
pStream << "faceID 1 " << fp.size() << " int" << std::endl;
ostr<< "faceID 1 " << fp.size() << " int" << std::endl;
writeFuns::write(pStream, binary, setFaceLabels);
writeFuns::write(ostr, binary, setFaceLabels);
}
......
......@@ -100,14 +100,18 @@ void Foam::writeFuns::write
{
forAll(fField, i)
{
os << fField[i] << ' ';
os << fField[i];
if (i > 0 && (i % 10) == 0)
{
os << std::endl;
}
else
{
os << ' ';
}
}
os << std::endl;
os << std::endl;
}
}
......@@ -149,12 +153,16 @@ void Foam::writeFuns::write
{
forAll(elems, i)
{
os << elems[i] << ' ';
os << elems[i];
if (i > 0 && (i % 10) == 0)
{
os << std::endl;
}
else
{
os << ' ';
}
}
os << std::endl;
}
......@@ -178,11 +186,11 @@ void Foam::writeFuns::writeHeader
(
std::ostream& os,
const bool binary,
const string& name
const std::string& title
)
{
os << "# vtk DataFile Version 2.0" << std::endl
<< name << std::endl;
<< title << std::endl;
if (binary)
{
......@@ -219,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);
}
......
......@@ -73,13 +73,23 @@ public:
// Write header
static void writeHeader(std::ostream&, const bool, const string&);
static void writeCellDataHeader(std::ostream&, const label, const label);
static void writeHeader
(
std::ostream&,
const bool isBinary,
const std::string& title
);
static void writeCellDataHeader
(
std::ostream&,
const label nCells,
const label nFields
);
static void writePointDataHeader
(
std::ostream&,
const label,
const label
const label nPoints,
const label nFields
);
......
......@@ -40,16 +40,16 @@ void writePatchGeom
const bool binary,
const faceList& faces,
const pointField& points,
std::ofstream& pStream
std::ofstream& ostr
)
{
pStream << "POINTS " << points.size() << " float" << std::endl;
ostr<< "POINTS " << points.size() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*points.size());
writeFuns::insert(points, ptField);
writeFuns::write(pStream, binary, ptField);
writeFuns::write(ostr, binary, ptField);
label nFaceVerts = 0;
......@@ -58,8 +58,7 @@ void writePatchGeom
{
nFaceVerts += faces[faceI].size() + 1;
}
pStream << "POLYGONS " << faces.size() << ' ' << nFaceVerts
<< std::endl;
ostr<< "POLYGONS " << faces.size() << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
......@@ -72,7 +71,7 @@ void writePatchGeom
writeFuns::insert(f, vertLabels);
}
writeFuns::write(pStream, binary, vertLabels);
writeFuns::write(ostr, binary, vertLabels);
}
......
......@@ -43,13 +43,13 @@ SourceFiles
namespace Foam
{
// Write lagrangian fields.
// Write patch geometry
void writePatchGeom
(
const bool binary,
const faceList& faces,
const pointField& points,
std::ofstream& pStream
std::ofstream&
);
} // End namespace Foam
......