foamToVTK: Rationalised the low-level write function to avoid 3x duplication

Moved the writeFuns into the vtkWriteOps namespace which is extensible, see the
the write functions in setSet as an example of this.
This commit is contained in:
Henry Weller
2020-01-28 16:12:57 +00:00
parent a296733a76
commit 9ff1e2e168
30 changed files with 334 additions and 525 deletions

View File

@ -3,10 +3,12 @@ EXE_INC = \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude
EXE_LIBS = \
-lfoamToVTK \
-ldynamicMesh \
-llagrangian \
-lgenericPatchFields
-lgenericPatchFields \
-lfileFormats

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -150,7 +150,7 @@ Note
#include "vtkMesh.H"
#include "readFields.H"
#include "writeFuns.H"
#include "vtkWriteOps.H"
#include "internalWriter.H"
#include "patchWriter.H"
@ -746,7 +746,7 @@ int main(int argc, char *argv[])
internalWriter writer(vMesh, binary, vtkFileName);
// cellID + volFields::Internal + VolFields
writeFuns::writeCellDataHeader
vtkWriteOps::writeCellDataHeader
(
writer.os(),
vMesh.nFieldCells(),
@ -772,7 +772,7 @@ int main(int argc, char *argv[])
if (!noPointValues)
{
writeFuns::writePointDataHeader
vtkWriteOps::writePointDataHeader
(
writer.os(),
vMesh.nFieldPoints(),
@ -909,7 +909,7 @@ int main(int argc, char *argv[])
);
// VolFields + patchID
writeFuns::writeCellDataHeader
vtkWriteOps::writeCellDataHeader
(
writer.os(),
writer.nFaces(),
@ -928,7 +928,7 @@ int main(int argc, char *argv[])
if (!noPointValues)
{
writeFuns::writePointDataHeader
vtkWriteOps::writePointDataHeader
(
writer.os(),
writer.nPoints(),
@ -986,7 +986,7 @@ int main(int argc, char *argv[])
if (!isA<emptyPolyPatch>(pp))
{
// VolFields + patchID
writeFuns::writeCellDataHeader
vtkWriteOps::writeCellDataHeader
(
writer.os(),
writer.nFaces(),
@ -1005,7 +1005,7 @@ int main(int argc, char *argv[])
if (!noPointValues)
{
writeFuns::writePointDataHeader
vtkWriteOps::writePointDataHeader
(
writer.os(),
writer.nPoints(),
@ -1111,7 +1111,7 @@ int main(int argc, char *argv[])
);
// Number of fields
writeFuns::writeCellDataHeader
vtkWriteOps::writeCellDataHeader
(
writer.os(),
pp.size(),

View File

@ -2,7 +2,6 @@ surfaceMeshWriter.C
internalWriter.C
lagrangianWriter.C
patchWriter.C
writeFuns.C
writeFaceSet.C
writePointSet.C
writeSurfFields.C

View File

@ -2,9 +2,11 @@ EXE_INC = \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude
LIB_LIBS = \
-ldynamicMesh \
-llagrangian \
-lgenericPatchFields
-lgenericPatchFields \
-lfileFormats

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "internalWriter.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -44,7 +44,7 @@ Foam::internalWriter::internalWriter
const vtkTopo& topo = vMesh_.topo();
// Write header
writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
vtkWriteOps::writeHeader(os_, binary_, mesh.time().caseName());
os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
@ -61,14 +61,14 @@ Foam::internalWriter::internalWriter
DynamicList<floatScalar> ptField(3*nTotPoints);
writeFuns::insert(mesh.points(), ptField);
vtkWriteOps::insert(mesh.points(), ptField);
const pointField& ctrs = mesh.cellCentres();
forAll(addPointCellLabels, api)
{
writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
vtkWriteOps::insert(ctrs[addPointCellLabels[api]], ptField);
}
writeFuns::write(os_, binary_, ptField);
vtkWriteOps::write(os_, binary_, ptField);
//
@ -95,9 +95,9 @@ Foam::internalWriter::internalWriter
vertLabels.append(vtkVerts.size());
writeFuns::insert(vtkVerts, vertLabels);
vtkWriteOps::insert(vtkVerts, vertLabels);
}
writeFuns::write(os_, binary_, vertLabels);
vtkWriteOps::write(os_, binary_, vertLabels);
const labelList& vtkCellTypes = topo.cellTypes();
@ -107,9 +107,9 @@ Foam::internalWriter::internalWriter
// Make copy since writing might swap stuff.
DynamicList<label> cellTypes(vtkCellTypes.size());
writeFuns::insert(vtkCellTypes, cellTypes);
vtkWriteOps::insert(vtkCellTypes, cellTypes);
writeFuns::write(os_, binary_, cellTypes);
vtkWriteOps::write(os_, binary_, cellTypes);
}
@ -158,7 +158,7 @@ void Foam::internalWriter::writeCellIDs()
}
}
writeFuns::write(os_, binary_, cellId);
vtkWriteOps::write(os_, binary_, cellId);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "internalWriter.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -36,7 +36,7 @@ void Foam::internalWriter::write
{
forAll(flds, i)
{
writeFuns::write(os_, binary_, flds[i], vMesh_);
vtkWriteOps::write(os_, binary_, flds[i], vMesh_);
}
}
@ -49,7 +49,7 @@ void Foam::internalWriter::write
{
forAll(flds, i)
{
writeFuns::write(os_, binary_, flds[i], vMesh_);
vtkWriteOps::write(os_, binary_, flds[i], vMesh_);
}
}
@ -63,7 +63,7 @@ void Foam::internalWriter::write
{
forAll(flds, i)
{
writeFuns::write
vtkWriteOps::write
(
os_,
binary_,

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "lagrangianWriter.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
#include "Cloud.H"
#include "passiveParticle.H"
@ -48,7 +48,7 @@ Foam::lagrangianWriter::lagrangianWriter
const fvMesh& mesh = vMesh_.mesh();
// Write header
writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
vtkWriteOps::writeHeader(os_, binary_, mesh.time().caseName());
os_ << "DATASET POLYDATA" << std::endl;
if (dummyCloud)
@ -69,9 +69,9 @@ Foam::lagrangianWriter::lagrangianWriter
forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
{
writeFuns::insert(elmnt().position(), partField);
vtkWriteOps::insert(elmnt().position(), partField);
}
writeFuns::write(os_, binary_, partField);
vtkWriteOps::write(os_, binary_, partField);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "lagrangianWriter.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
#include "IOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,9 +54,9 @@ void Foam::lagrangianWriter::writeIOField(const wordList& objects)
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*fld.size());
writeFuns::insert(fld, fField);
vtkWriteOps::insert(fld, fField);
writeFuns::write(os_, binary_, fField);
vtkWriteOps::write(os_, binary_, fField);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "patchWriter.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -50,11 +50,11 @@ Foam::patchWriter::patchWriter
// Write header
if (patchIDs_.size() == 1)
{
writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
vtkWriteOps::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
}
else
{
writeFuns::writeHeader(os_, binary_, "patches");
vtkWriteOps::writeHeader(os_, binary_, "patches");
}
os_ << "DATASET POLYDATA" << std::endl;
@ -84,9 +84,9 @@ Foam::patchWriter::patchWriter
{
const polyPatch& pp = patches[patchIDs_[i]];
writeFuns::insert(pp.localPoints(), ptField);
vtkWriteOps::insert(pp.localPoints(), ptField);
}
writeFuns::write(os_, binary_, ptField);
vtkWriteOps::write(os_, binary_, ptField);
os_ << "POLYGONS " << nFaces_ << ' ' << nFaceVerts << std::endl;
@ -103,11 +103,11 @@ Foam::patchWriter::patchWriter
const face& f = pp.localFaces()[facei];
vertLabels.append(f.size());
writeFuns::insert(f + offset, vertLabels);
vtkWriteOps::insert(f + offset, vertLabels);
}
offset += pp.nPoints();
}
writeFuns::write(os_, binary_, vertLabels);
vtkWriteOps::write(os_, binary_, vertLabels);
}
@ -129,10 +129,10 @@ void Foam::patchWriter::writePatchIDs()
if (!isA<emptyPolyPatch>(pp))
{
writeFuns::insert(scalarField(pp.size(), patchi), fField);
vtkWriteOps::insert(scalarField(pp.size(), patchi), fField);
}
}
writeFuns::write(os_, binary_, fField);
vtkWriteOps::write(os_, binary_, fField);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "patchWriter.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -51,14 +51,14 @@ void Foam::patchWriter::write
if (nearCellValue_)
{
writeFuns::insert(pfld.patchInternalField()(), fField);
vtkWriteOps::insert(pfld.patchInternalField()(), fField);
}
else
{
writeFuns::insert(pfld, fField);
vtkWriteOps::insert(pfld, fField);
}
}
writeFuns::write(os_, binary_, fField);
vtkWriteOps::write(os_, binary_, fField);
}
}
@ -85,9 +85,9 @@ void Foam::patchWriter::write
const pointPatchField<Type>& pfld = fld.boundaryField()[patchi];
writeFuns::insert(pfld.patchInternalField()(), fField);
vtkWriteOps::insert(pfld.patchInternalField()(), fField);
}
writeFuns::write(os_, binary_, fField);
vtkWriteOps::write(os_, binary_, fField);
}
}
@ -116,7 +116,7 @@ void Foam::patchWriter::write
if (nearCellValue_)
{
writeFuns::insert
vtkWriteOps::insert
(
pInter.faceToPointInterpolate
(
@ -127,14 +127,14 @@ void Foam::patchWriter::write
}
else
{
writeFuns::insert
vtkWriteOps::insert
(
pInter.faceToPointInterpolate(pfld)(),
fField
);
}
}
writeFuns::write(os_, binary_, fField);
vtkWriteOps::write(os_, binary_, fField);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "surfaceMeshWriter.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -42,7 +42,7 @@ Foam::surfaceMeshWriter::surfaceMeshWriter
os_(fName.c_str())
{
// Write header
writeFuns::writeHeader(os_, binary_, name);
vtkWriteOps::writeHeader(os_, binary_, name);
os_ << "DATASET POLYDATA" << std::endl;
@ -57,8 +57,8 @@ Foam::surfaceMeshWriter::surfaceMeshWriter
os_ << "POINTS " << pp.nPoints() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*pp.nPoints());
writeFuns::insert(pp.localPoints(), ptField);
writeFuns::write(os_, binary, ptField);
vtkWriteOps::insert(pp.localPoints(), ptField);
vtkWriteOps::write(os_, binary, ptField);
os_ << "POLYGONS " << pp.size() << ' ' << nFaceVerts << std::endl;
@ -70,9 +70,9 @@ Foam::surfaceMeshWriter::surfaceMeshWriter
const face& f = pp.localFaces()[facei];
vertLabels.append(f.size());
writeFuns::insert(f, vertLabels);
vtkWriteOps::insert(f, vertLabels);
}
writeFuns::write(os_, binary_, vertLabels);
vtkWriteOps::write(os_, binary_, vertLabels);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "surfaceMeshWriter.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -78,8 +78,8 @@ void Foam::surfaceMeshWriter::write
<< pp_.size() << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*pp_.size());
writeFuns::insert(getFaceField(fld)(), fField);
writeFuns::write(os_, binary_, fField);
vtkWriteOps::insert(getFaceField(fld)(), fField);
vtkWriteOps::write(os_, binary_, fField);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -22,22 +22,20 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::writeFuns
Foam::vtkWriteFieldOps
Description
Various functions for collecting and writing binary data.
VTK ASCII and binary write functions
SourceFiles
writeFuns.C
vtkWriteFieldOps.C
\*---------------------------------------------------------------------------*/
#ifndef writeFuns_H
#define writeFuns_H
#ifndef vtkWriteFieldOps_H
#define vtkWriteFieldOps_H
#include "floatScalar.H"
#include "DynamicList.H"
#include "volFieldsFwd.H"
#include "vtkWriteOps.H"
#include "pointFieldsFwd.H"
#include "vtkMesh.H"
#include "volPointInterpolation.H"
@ -48,68 +46,14 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class writeFuns Declaration
Namespace vtkWriteOps Declaration
\*---------------------------------------------------------------------------*/
class writeFuns
namespace vtkWriteOps
{
// Private Member Functions
// Swap halves of word.
static void swapWord(label& word32);
static void swapWords(const label nWords, label* words32);
public:
// Write ascii or binary. If binary optionally in-place swaps argument
static void write(std::ostream&, const bool, List<floatScalar>&);
static void write(std::ostream&, const bool, DynamicList<floatScalar>&);
static void write(std::ostream&, const bool, labelList&);
static void write(std::ostream&, const bool, DynamicList<label>&);
// Write header
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 nPoints,
const label nFields
);
// Convert to VTK and store
static void insert(const scalar, DynamicList<floatScalar>&);
static void insert(const point&, DynamicList<floatScalar>&);
static void insert(const sphericalTensor&, DynamicList<floatScalar>&);
static void insert(const symmTensor&, DynamicList<floatScalar>&);
static void insert(const tensor&, DynamicList<floatScalar>&);
//- Append elements to DynamicList
static void insert(const labelList&, DynamicList<label>&);
template<class Type>
static void insert(const List<Type>&, DynamicList<floatScalar>&);
//- Write volField with cell values (including decomposed cells)
template<class Type>
static void write
void write
(
std::ostream&,
const bool binary,
@ -120,7 +64,7 @@ public:
//- Write pointField on all mesh points. Interpolate to cell centre
// for decomposed cell centres.
template<class Type>
static void write
void write
(
std::ostream&,
const bool binary,
@ -131,7 +75,7 @@ public:
//- Write interpolated field on points and original cell values on
// decomposed cell centres.
template<class Type>
static void write
void write
(
std::ostream&,
const bool binary,
@ -142,7 +86,7 @@ public:
//- Write generic GeometricFields
template<class Type, template<class> class PatchField, class GeoMesh>
static void write
void write
(
std::ostream&,
const bool binary,
@ -152,7 +96,7 @@ public:
//- Interpolate and write volFields
template<class Type>
static void write
void write
(
std::ostream&,
const bool binary,
@ -160,7 +104,8 @@ public:
const PtrList<GeometricField<Type, fvPatchField, volMesh>>&,
const vtkMesh&
);
};
} // End namespace vtkWriteOps
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -170,7 +115,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "writeFunsTemplates.C"
#include "vtkWriteFieldOpsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,27 +23,13 @@ License
\*---------------------------------------------------------------------------*/
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
#include "interpolatePointToCell.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::writeFuns::insert
(
const List<Type>& source,
DynamicList<floatScalar>& dest
)
{
forAll(source, i)
{
insert(source[i], dest);
}
}
template<class Type>
void Foam::writeFuns::write
void Foam::vtkWriteOps::write
(
std::ostream& os,
const bool binary,
@ -75,7 +61,7 @@ void Foam::writeFuns::write
template<class Type>
void Foam::writeFuns::write
void Foam::vtkWriteOps::write
(
std::ostream& os,
const bool binary,
@ -107,7 +93,7 @@ void Foam::writeFuns::write
template<class Type>
void Foam::writeFuns::write
void Foam::vtkWriteOps::write
(
std::ostream& os,
const bool binary,
@ -140,7 +126,7 @@ void Foam::writeFuns::write
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::writeFuns::write
void Foam::vtkWriteOps::write
(
std::ostream& os,
const bool binary,
@ -156,7 +142,7 @@ void Foam::writeFuns::write
template<class Type>
void Foam::writeFuns::write
void Foam::vtkWriteOps::write
(
std::ostream& os,
const bool binary,

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,7 +25,7 @@ License
#include "writeFaceSet.H"
#include "OFstream.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
@ -41,7 +41,7 @@ void Foam::writeFaceSet
std::ofstream ostr(fileName.c_str());
writeFuns::writeHeader
vtkWriteOps::writeHeader
(
ostr,
binary,
@ -78,9 +78,9 @@ void Foam::writeFaceSet
DynamicList<floatScalar> ptField(3*fp.nPoints());
writeFuns::insert(fp.localPoints(), ptField);
vtkWriteOps::insert(fp.localPoints(), ptField);
writeFuns::write(ostr, binary, ptField);
vtkWriteOps::write(ostr, binary, ptField);
label nFaceVerts = 0;
@ -100,9 +100,9 @@ void Foam::writeFaceSet
vertLabels.append(f.size());
writeFuns::insert(f, vertLabels);
vtkWriteOps::insert(f, vertLabels);
}
writeFuns::write(ostr, binary, vertLabels);
vtkWriteOps::write(ostr, binary, vertLabels);
//-----------------------------------------------------------------
@ -120,7 +120,7 @@ void Foam::writeFaceSet
// Cell ids first
ostr<< "faceID 1 " << fp.size() << " int" << std::endl;
writeFuns::write(ostr, binary, setFaceLabels);
vtkWriteOps::write(ostr, binary, setFaceLabels);
}

View File

@ -1,288 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "writeFuns.H"
#include "vtkTopo.H"
#if defined(__mips)
#include <standards.h>
#include <sys/endian.h>
#endif
// MacOSX
#ifdef __DARWIN_BYTE_ORDER
#if __DARWIN_BYTE_ORDER==__DARWIN_BIG_ENDIAN
#undef LITTLE_ENDIAN
#else
#undef BIG_ENDIAN
#endif
#endif
#if defined(LITTLE_ENDIAN) \
|| defined(_LITTLE_ENDIAN) \
|| defined(__LITTLE_ENDIAN)
#define LITTLEENDIAN 1
#elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN)
#undef LITTLEENDIAN
#else
#error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
#error "Please add to compilation options"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::writeFuns::swapWord(label& word32)
{
char* mem = reinterpret_cast<char*>(&word32);
char a = mem[0];
mem[0] = mem[3];
mem[3] = a;
a = mem[1];
mem[1] = mem[2];
mem[2] = a;
}
void Foam::writeFuns::swapWords(const label nWords, label* words32)
{
for (label i = 0; i < nWords; i++)
{
swapWord(words32[i]);
}
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
List<floatScalar>& fField
)
{
if (binary)
{
#ifdef LITTLEENDIAN
swapWords(fField.size(), reinterpret_cast<label*>(fField.begin()));
#endif
os.write
(
reinterpret_cast<char*>(fField.begin()),
fField.size()*sizeof(float)
);
os << std::endl;
}
else
{
forAll(fField, i)
{
os << fField[i];
if (i > 0 && (i % 10) == 0)
{
os << std::endl;
}
else
{
os << ' ';
}
}
os << std::endl;
}
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
DynamicList<floatScalar>& fField
)
{
List<floatScalar>& fld = fField.shrink();
write(os, binary, fld);
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
labelList& elems
)
{
if (binary)
{
#ifdef LITTLEENDIAN
swapWords(elems.size(), reinterpret_cast<label*>(elems.begin()));
#endif
os.write
(
reinterpret_cast<char*>(elems.begin()),
elems.size()*sizeof(label)
);
os << std::endl;
}
else
{
forAll(elems, i)
{
os << elems[i];
if (i > 0 && (i % 10) == 0)
{
os << std::endl;
}
else
{
os << ' ';
}
}
os << std::endl;
}
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
DynamicList<label>& elems
)
{
labelList& fld = elems.shrink();
write(os, binary, fld);
}
void Foam::writeFuns::writeHeader
(
std::ostream& os,
const bool binary,
const std::string& title
)
{
os << "# vtk DataFile Version 2.0" << std::endl
<< title << std::endl;
if (binary)
{
os << "BINARY" << std::endl;
}
else
{
os << "ASCII" << std::endl;
}
}
void Foam::writeFuns::writeCellDataHeader
(
std::ostream& os,
const label nCells,
const label nFields
)
{
os << "CELL_DATA " << nCells << std::endl
<< "FIELD attributes " << nFields << std::endl;
}
void Foam::writeFuns::writePointDataHeader
(
std::ostream& os,
const label nPoints,
const label nFields
)
{
os << "POINT_DATA " << nPoints << std::endl
<< "FIELD attributes " << nFields << std::endl;
}
void Foam::writeFuns::insert(const scalar src, DynamicList<floatScalar>& dest)
{
dest.append(float(src));
}
void Foam::writeFuns::insert(const vector& src, DynamicList<floatScalar>& dest)
{
for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
{
dest.append(float(src[cmpt]));
}
}
void Foam::writeFuns::insert
(
const sphericalTensor& src,
DynamicList<floatScalar>& dest
)
{
for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; ++cmpt)
{
dest.append(float(src[cmpt]));
}
}
void Foam::writeFuns::insert
(
const symmTensor& src,
DynamicList<floatScalar>& dest
)
{
dest.append(float(src.xx()));
dest.append(float(src.yy()));
dest.append(float(src.zz()));
dest.append(float(src.xy()));
dest.append(float(src.yz()));
dest.append(float(src.xz()));
}
void Foam::writeFuns::insert(const tensor& src, DynamicList<floatScalar>& dest)
{
for (direction cmpt = 0; cmpt < tensor::nComponents; ++cmpt)
{
dest.append(float(src[cmpt]));
}
}
void Foam::writeFuns::insert(const labelList& src, DynamicList<label>& dest)
{
dest.append(src);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,7 +25,7 @@ License
#include "writePointSet.H"
#include "OFstream.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -44,7 +44,7 @@ void writePointSet
{
std::ofstream ostr(fileName.c_str());
writeFuns::writeHeader
vtkWriteOps::writeHeader
(
ostr,
binary,
@ -66,13 +66,13 @@ void writePointSet
DynamicList<floatScalar> ptField(3*set.size());
writeFuns::insert
vtkWriteOps::insert
(
UIndirectList<point>(vMesh.mesh().points(), set.toc())(),
ptField
);
writeFuns::write(ostr, binary, ptField);
vtkWriteOps::write(ostr, binary, ptField);
//-----------------------------------------------------------------
@ -92,7 +92,7 @@ void writePointSet
labelList pointIDs(set.toc());
writeFuns::write(ostr, binary, pointIDs);
vtkWriteOps::write(ostr, binary, pointIDs);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -26,7 +26,7 @@ License
#include "writeSurfFields.H"
#include "OFstream.H"
#include "floatScalar.H"
#include "writeFuns.H"
#include "vtkWriteFieldOps.H"
#include "emptyFvsPatchFields.H"
#include "fvsPatchFields.H"
@ -44,7 +44,7 @@ void Foam::writeSurfFields
std::ofstream str(fileName.c_str());
writeFuns::writeHeader
vtkWriteOps::writeHeader
(
str,
binary,
@ -61,10 +61,10 @@ void Foam::writeSurfFields
for (label facei = 0; facei < mesh.nFaces(); facei++)
{
writeFuns::insert(fc[facei], pField);
vtkWriteOps::insert(fc[facei], pField);
}
writeFuns::write(str, binary, pField);
vtkWriteOps::write(str, binary, pField);
str << "POINT_DATA " << mesh.nFaces() << std::endl
<< "FIELD attributes " << surfVectorFields.size() << std::endl;
@ -81,7 +81,7 @@ void Foam::writeSurfFields
for (label facei = 0; facei < mesh.nInternalFaces(); facei++)
{
writeFuns::insert(svf[facei], fField);
vtkWriteOps::insert(svf[facei], fField);
}
forAll(svf.boundaryField(), patchi)
@ -95,19 +95,19 @@ void Foam::writeSurfFields
// Note: loop over polypatch size, not fvpatch size.
forAll(pp.patch(), i)
{
writeFuns::insert(vector::zero, fField);
vtkWriteOps::insert(vector::zero, fField);
}
}
else
{
forAll(pf, i)
{
writeFuns::insert(pf[i], fField);
vtkWriteOps::insert(pf[i], fField);
}
}
}
writeFuns::write(str, binary, fField);
vtkWriteOps::write(str, binary, fField);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -132,7 +132,7 @@ bool Foam::functionObjects::writeVTK::write()
UPtrList<const volTensorField> vtf(lookupFields<volTensorField>());
// Write header for cellID and volFields
writeFuns::writeCellDataHeader
vtkWriteOps::writeCellDataHeader
(
writer.os(),
vMesh.nFieldCells(),