ENH: construct VTK writers with the outputOptions and adjust internally

- this shifts responsibility away from caller to the individual writers
  for knowing which file formats are supported and which file ending is
  appropriate. When the writer receives the output format request,
  it can elect to downgrade or otherwise adjust it to what it can
  actually manage (eg, legacy vs xml vs xml-append).

  But currently still just with legacy format backends.
This commit is contained in:
Mark Olesen
2017-05-31 22:08:54 +02:00
parent 03944c2a26
commit c4f1349496
45 changed files with 593 additions and 322 deletions

View File

@ -1,4 +1,5 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
$(COMP_FLAGS) $(COMP_FLAGS)

View File

@ -76,7 +76,7 @@ void writeVTK
( (
const polyMesh& mesh, const polyMesh& mesh,
const topoSet& currentSet, const topoSet& currentSet,
const fileName& vtkName const fileName& vtkBaseName
) )
{ {
if (isA<faceSet>(currentSet)) if (isA<faceSet>(currentSet))
@ -84,10 +84,10 @@ void writeVTK
// Faces of set with OpenFOAM faceID as value // Faces of set with OpenFOAM faceID as value
foamVtkOutput::writeFaceSet foamVtkOutput::writeFaceSet
( (
true,
mesh, mesh,
currentSet, currentSet,
mesh.time().path()/vtkName mesh.time().path()/vtkBaseName,
foamVtkOutput::formatType::LEGACY_BINARY
); );
} }
else if (isA<cellSet>(currentSet)) else if (isA<cellSet>(currentSet))
@ -95,20 +95,20 @@ void writeVTK
// External faces of cellset with OpenFOAM cellID as value // External faces of cellset with OpenFOAM cellID as value
foamVtkOutput::writeCellSetFaces foamVtkOutput::writeCellSetFaces
( (
true,
mesh, mesh,
currentSet, currentSet,
mesh.time().path()/vtkName mesh.time().path()/vtkBaseName,
foamVtkOutput::formatType::LEGACY_BINARY
); );
} }
else if (isA<pointSet>(currentSet)) else if (isA<pointSet>(currentSet))
{ {
foamVtkOutput::writePointSet foamVtkOutput::writePointSet
( (
true,
mesh, mesh,
currentSet, currentSet,
mesh.time().path()/vtkName mesh.time().path()/vtkBaseName,
foamVtkOutput::formatType::LEGACY_BINARY
); );
} }
else else
@ -123,58 +123,58 @@ void writeVTK
void printHelp(Ostream& os) void printHelp(Ostream& os)
{ {
os << "Please type 'help', 'list', 'quit', 'time ddd'" os << "Please type 'help', 'list', 'quit', 'time ddd'"
<< " or a set command after prompt." << endl << " or a set command after prompt." << nl
<< "'list' will show all current cell/face/point sets." << endl << "'list' will show all current cell/face/point sets." << nl
<< "'time ddd' will change the current time." << endl << "'time ddd' will change the current time." << nl
<< endl << nl
<< "A set command should be of the following form" << endl << "A set command should be of the following form" << nl
<< endl << nl
<< " cellSet|faceSet|pointSet <setName> <action> <source>" << " cellSet|faceSet|pointSet <setName> <action> <source>"
<< endl << nl
<< endl << nl
<< "The <action> is one of" << endl << "The <action> is one of" << nl
<< " list - prints the contents of the set" << endl << " list - prints the contents of the set" << nl
<< " clear - clears the set" << endl << " clear - clears the set" << nl
<< " invert - inverts the set" << endl << " invert - inverts the set" << nl
<< " remove - remove the set" << endl << " remove - remove the set" << nl
<< " new <source> - sets to set to the source set" << endl << " new <source> - sets to set to the source set" << nl
<< " add <source> - adds all elements from the source set" << endl << " add <source> - adds all elements from the source set" << nl
<< " delete <source> - deletes ,," << endl << " delete <source> - deletes ,," << nl
<< " subset <source> - combines current set with the source set" << " subset <source> - combines current set with the source set"
<< endl << nl
<< endl << nl
<< "The sources come in various forms. Type a wrong source" << "The sources come in various forms. Type a wrong source"
<< " to see all the types available." << endl << " to see all the types available." << nl
<< endl << nl
<< "Example: pick up all cells connected by point or face to patch" << "Example: pick up all cells connected by point or face to patch"
<< " movingWall" << endl << " movingWall" << nl
<< endl << nl
<< "Pick up all faces of patch:" << endl << "Pick up all faces of patch:" << nl
<< " faceSet f0 new patchToFace movingWall" << endl << " faceSet f0 new patchToFace movingWall" << nl
<< "Add faces 0,1,2:" << endl << "Add faces 0,1,2:" << nl
<< " faceSet f0 add labelToFace (0 1 2)" << endl << " faceSet f0 add labelToFace (0 1 2)" << nl
<< "Pick up all points used by faces in faceSet f0:" << endl << "Pick up all points used by faces in faceSet f0:" << nl
<< " pointSet p0 new faceToPoint f0 all" << endl << " pointSet p0 new faceToPoint f0 all" << nl
<< "Pick up cell which has any face in f0:" << endl << "Pick up cell which has any face in f0:" << nl
<< " cellSet c0 new faceToCell f0 any" << endl << " cellSet c0 new faceToCell f0 any" << nl
<< "Add cells which have any point in p0:" << endl << "Add cells which have any point in p0:" << nl
<< " cellSet c0 add pointToCell p0 any" << endl << " cellSet c0 add pointToCell p0 any" << nl
<< "List set:" << endl << "List set:" << nl
<< " cellSet c0 list" << endl << " cellSet c0 list" << nl
<< endl << nl
<< "Zones can be set using zoneSets from corresponding sets:" << endl << "Zones can be set using zoneSets from corresponding sets:" << nl
<< " cellZoneSet c0Zone new setToCellZone c0" << endl << " cellZoneSet c0Zone new setToCellZone c0" << nl
<< " faceZoneSet f0Zone new setToFaceZone f0" << endl << " faceZoneSet f0Zone new setToFaceZone f0" << nl
<< endl << nl
<< "or if orientation is important:" << endl << "or if orientation is important:" << nl
<< " faceZoneSet f0Zone new setsToFaceZone f0 c0" << endl << " faceZoneSet f0Zone new setsToFaceZone f0 c0" << nl
<< endl << nl
<< "ZoneSets can be manipulated using the general actions:" << endl << "ZoneSets can be manipulated using the general actions:" << nl
<< " list - prints the contents of the set" << endl << " list - prints the contents of the set" << nl
<< " clear - clears the set" << endl << " clear - clears the set" << nl
<< " invert - inverts the set (undefined orientation)" << " invert - inverts the set (undefined orientation)"
<< endl << nl
<< " remove - remove the set" << endl << " remove - remove the set" << nl
<< endl; << endl;
} }
@ -513,7 +513,6 @@ bool doCommand
"VTK"/currentSet.name()/currentSet.name() "VTK"/currentSet.name()/currentSet.name()
+ "_" + "_"
+ name(mesh.time().timeIndex()) + name(mesh.time().timeIndex())
+ ".vtk"
); );
Info<< " Writing " << currentSet.name() Info<< " Writing " << currentSet.name()

View File

@ -239,12 +239,19 @@ labelList getSelectedPatches
// Process args for output options // Process args for output options
// Default from foamVtkOutputOptions is inline ASCII xml // Default from foamVtkOutputOptions is inline ASCII xml
// //
enum foamVtkOutput::formatType getOutputOptions(const argList& args) foamVtkOutput::outputOptions getOutputOptions(const argList& args)
{ {
foamVtkOutput::outputOptions opts;
{
opts.legacy(true);
if (!args.optionFound("ascii")) if (!args.optionFound("ascii"))
{ {
if (sizeof(floatScalar) != 4 || sizeof(label) != 4) if (sizeof(floatScalar) != 4 || sizeof(label) != 4)
{ {
opts.ascii(true);
WarningInFunction WarningInFunction
<< "Using ASCII rather than binary VTK format since " << "Using ASCII rather than binary VTK format since "
<< "floatScalar and/or label are not 4 bytes in size." << "floatScalar and/or label are not 4 bytes in size."
@ -252,11 +259,12 @@ enum foamVtkOutput::formatType getOutputOptions(const argList& args)
} }
else else
{ {
return foamVtkOutput::formatType::LEGACY_BINARY; opts.ascii(false);
}
} }
} }
return foamVtkOutput::formatType::LEGACY_ASCII; return opts;
} }
@ -398,11 +406,10 @@ int main(int argc, char *argv[])
const bool doLinks = !args.optionFound("noLinks"); const bool doLinks = !args.optionFound("noLinks");
const bool useTimeName = args.optionFound("useTimeName"); const bool useTimeName = args.optionFound("useTimeName");
const bool noLagrangian = args.optionFound("noLagrangian"); const bool noLagrangian = args.optionFound("noLagrangian");
const enum foamVtkOutput::formatType fmtType = getOutputOptions(args);
const bool binary = (fmtType == foamVtkOutput::formatType::LEGACY_BINARY);
const bool nearCellValue = args.optionFound("nearCellValue"); const bool nearCellValue = args.optionFound("nearCellValue");
const foamVtkOutput::outputOptions fmtType = getOutputOptions(args);
if (nearCellValue) if (nearCellValue)
{ {
WarningInFunction WarningInFunction
@ -495,11 +502,7 @@ int main(int argc, char *argv[])
meshSubsetHelper meshRef(mesh, meshSubsetHelper::SET, cellSetName); meshSubsetHelper meshRef(mesh, meshSubsetHelper::SET, cellSetName);
// Collect decomposition information etc. // Collect decomposition information etc.
foamVtkCells foamVtkMeshCells foamVtkCells foamVtkMeshCells(fmtType, decomposePoly);
(
foamVtkCells::contentType::LEGACY,
decomposePoly
);
Info<< "VTK mesh topology: " Info<< "VTK mesh topology: "
<< timer.cpuTimeIncrement() << " s, " << timer.cpuTimeIncrement() << " s, "
@ -545,17 +548,16 @@ int main(int argc, char *argv[])
fvPath/set.name()/set.name() fvPath/set.name()/set.name()
+ "_" + "_"
+ timeDesc + timeDesc
+ ".vtk"
); );
Info<< " faceSet : " Info<< " faceSet : "
<< relativeName(runTime, outputName) << nl; << relativeName(runTime, outputName) << nl;
foamVtkOutput::writeFaceSet foamVtkOutput::writeFaceSet
( (
binary,
meshRef.mesh(), meshRef.mesh(),
set, set,
outputName outputName,
fmtType
); );
continue; continue;
} }
@ -574,17 +576,16 @@ int main(int argc, char *argv[])
fvPath/set.name()/set.name() fvPath/set.name()/set.name()
+ "_" + "_"
+ timeDesc + timeDesc
+ ".vtk"
); );
Info<< " pointSet : " Info<< " pointSet : "
<< relativeName(runTime, outputName) << nl; << relativeName(runTime, outputName) << nl;
foamVtkOutput::writePointSet foamVtkOutput::writePointSet
( (
binary,
meshRef.mesh(), meshRef.mesh(),
set, set,
outputName outputName,
fmtType
); );
continue; continue;
} }
@ -594,7 +595,7 @@ int main(int argc, char *argv[])
IOobjectList objects(mesh, runTime.timeName()); IOobjectList objects(mesh, runTime.timeName());
HashSet<word> selectedFields; HashSet<word> selectedFields;
bool specifiedFields = args.optionReadIfPresent const bool specifiedFields = args.optionReadIfPresent
( (
"fields", "fields",
selectedFields selectedFields
@ -836,7 +837,6 @@ int main(int argc, char *argv[])
fvPath/vtkName fvPath/vtkName
+ "_" + "_"
+ timeDesc + timeDesc
+ ".vtk"
); );
Info<< " Internal : " Info<< " Internal : "
<< relativeName(runTime, outputName) << endl; << relativeName(runTime, outputName) << endl;
@ -845,9 +845,9 @@ int main(int argc, char *argv[])
foamVtkOutput::internalWriter writer foamVtkOutput::internalWriter writer
( (
meshRef.baseMesh(), meshRef.baseMesh(),
fmtType,
foamVtkMeshCells, foamVtkMeshCells,
outputName outputName,
fmtType
); );
// CellData // CellData
@ -963,14 +963,13 @@ int main(int argc, char *argv[])
/ "surfaceFields" / "surfaceFields"
+ "_" + "_"
+ timeDesc + timeDesc
+ ".vtk"
); );
foamVtkOutput::writeSurfFields foamVtkOutput::writeSurfFields
( (
binary,
meshRef.mesh(), meshRef.mesh(),
outputName, outputName,
fmtType,
sVectorFld sVectorFld
); );
} }
@ -995,7 +994,6 @@ int main(int argc, char *argv[])
/ (meshRef.useSubMesh() ? cellSetName : "allPatches") / (meshRef.useSubMesh() ? cellSetName : "allPatches")
+ "_" + "_"
+ timeDesc + timeDesc
+ ".vtk"
); );
Info<< " Combined patches : " Info<< " Combined patches : "
<< relativeName(runTime, outputName) << nl; << relativeName(runTime, outputName) << nl;
@ -1003,9 +1001,9 @@ int main(int argc, char *argv[])
foamVtkOutput::patchWriter writer foamVtkOutput::patchWriter writer
( (
meshRef.mesh(), meshRef.mesh(),
binary,
nearCellValue,
outputName, outputName,
fmtType,
nearCellValue,
getSelectedPatches(patches, excludePatches) getSelectedPatches(patches, excludePatches)
); );
@ -1064,7 +1062,6 @@ int main(int argc, char *argv[])
/ (meshRef.useSubMesh() ? cellSetName : pp.name()) / (meshRef.useSubMesh() ? cellSetName : pp.name())
+ "_" + "_"
+ timeDesc + timeDesc
+ ".vtk"
); );
Info<< " Patch : " Info<< " Patch : "
<< relativeName(runTime, outputName) << nl; << relativeName(runTime, outputName) << nl;
@ -1072,9 +1069,9 @@ int main(int argc, char *argv[])
foamVtkOutput::patchWriter writer foamVtkOutput::patchWriter writer
( (
meshRef.mesh(), meshRef.mesh(),
binary,
nearCellValue,
outputName, outputName,
fmtType,
nearCellValue,
labelList{patchi} labelList{patchi}
); );
@ -1168,7 +1165,6 @@ int main(int argc, char *argv[])
/ (meshRef.useSubMesh() ? cellSetName : fz.name()) / (meshRef.useSubMesh() ? cellSetName : fz.name())
+ "_" + "_"
+ timeDesc + timeDesc
+ ".vtk"
); );
Info<< " FaceZone : " Info<< " FaceZone : "
<< relativeName(runTime, outputName) << nl; << relativeName(runTime, outputName) << nl;
@ -1181,10 +1177,10 @@ int main(int argc, char *argv[])
foamVtkOutput::surfaceMeshWriter writer foamVtkOutput::surfaceMeshWriter writer
( (
binary,
pp, pp,
fz.name(), fz.name(),
outputName outputName,
fmtType
); );
// Number of fields // Number of fields
@ -1214,7 +1210,7 @@ int main(int argc, char *argv[])
fileName outputName fileName outputName
( (
fvPath/cloud::prefix/cloudName/cloudName fvPath/cloud::prefix/cloudName/cloudName
+ "_" + timeDesc + ".vtk" + "_" + timeDesc
); );
Info<< " Lagrangian: " Info<< " Lagrangian: "
<< relativeName(runTime, outputName) << nl; << relativeName(runTime, outputName) << nl;
@ -1267,10 +1263,9 @@ int main(int argc, char *argv[])
foamVtkOutput::lagrangianWriter writer foamVtkOutput::lagrangianWriter writer
( (
meshRef.mesh(), meshRef.mesh(),
binary,
outputName,
cloudName, cloudName,
false outputName,
fmtType
); );
// Write number of fields // Write number of fields
@ -1299,9 +1294,9 @@ int main(int argc, char *argv[])
foamVtkOutput::lagrangianWriter writer foamVtkOutput::lagrangianWriter writer
( (
meshRef.mesh(), meshRef.mesh(),
binary,
outputName,
cloudName, cloudName,
outputName,
fmtType,
true true
); );

View File

@ -32,30 +32,30 @@ License
Foam::foamVtkOutput::lagrangianWriter::lagrangianWriter Foam::foamVtkOutput::lagrangianWriter::lagrangianWriter
( (
const fvMesh& mesh, const fvMesh& mesh,
const bool binary,
const fileName& fName,
const word& cloudName, const word& cloudName,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool dummyCloud const bool dummyCloud
) )
: :
mesh_(mesh), mesh_(mesh),
format_(), format_(),
cloudName_(cloudName), cloudName_(cloudName),
os_(fName.c_str()), os_(),
nParcels_(0) nParcels_(0)
{ {
format_ = foamVtkOutput::newFormatter outputOptions opts(outOpts);
( opts.legacy(true); // Legacy only, no append
os_,
(
binary
? foamVtkOutput::LEGACY_BINARY
: foamVtkOutput::LEGACY_ASCII
)
);
os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
format_ = opts.newFormatter(os_);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), mesh_.time().caseName()) foamVtkOutput::legacy::fileHeader(format(), mesh_.time().caseName())
<< "DATASET POLYDATA" << nl; << "DATASET POLYDATA" << nl;
}
if (dummyCloud) if (dummyCloud)
{ {
@ -80,6 +80,12 @@ Foam::foamVtkOutput::lagrangianWriter::lagrangianWriter
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::lagrangianWriter::~lagrangianWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::foamVtkOutput::lagrangianWriter::beginParcelData void Foam::foamVtkOutput::lagrangianWriter::beginParcelData

View File

@ -40,7 +40,7 @@ SourceFiles
#include "Cloud.H" #include "Cloud.H"
#include "volFields.H" #include "volFields.H"
#include "pointFields.H" #include "pointFields.H"
#include "foamVtkOutput.H" #include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -76,13 +76,17 @@ public:
lagrangianWriter lagrangianWriter
( (
const fvMesh& mesh, const fvMesh& mesh,
const bool binary, const word& cloudName,
const fileName&, const fileName& baseName,
const word&, const foamVtkOutput::outputOptions outOpts,
const bool dummyCloud const bool dummyCloud = false
); );
//- Destructor
~lagrangianWriter();
// Member Functions // Member Functions
inline std::ofstream& os() inline std::ofstream& os()

View File

@ -30,21 +30,27 @@ License
Foam::foamVtkOutput::internalWriter::internalWriter Foam::foamVtkOutput::internalWriter::internalWriter
( (
const fvMesh& mesh, const fvMesh& mesh,
enum foamVtkOutput::formatType fmtType,
const foamVtkCells& cells, const foamVtkCells& cells,
const fileName& outputName const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
) )
: :
mesh_(mesh), mesh_(mesh),
format_(), format_(),
vtkCells_(cells), vtkCells_(cells),
os_(outputName.c_str()) os_()
{ {
format_ = foamVtkOutput::newFormatter(os_, fmtType); outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
// Write header os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtu")).c_str());
format_ = opts.newFormatter(os_);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), mesh.time().caseName()) foamVtkOutput::legacy::fileHeader(format(), mesh.time().caseName())
<< "DATASET UNSTRUCTURED_GRID" << nl; << "DATASET UNSTRUCTURED_GRID" << nl;
}
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
@ -84,6 +90,12 @@ Foam::foamVtkOutput::internalWriter::internalWriter
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::internalWriter::~internalWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -42,6 +42,7 @@ SourceFiles
#include "foamVtkCells.H" #include "foamVtkCells.H"
#include "foamVtkOutputFields.H" #include "foamVtkOutputFields.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -78,12 +79,16 @@ public:
internalWriter internalWriter
( (
const fvMesh& mesh, const fvMesh& mesh,
enum foamVtkOutput::formatType fmtType,
const foamVtkCells& cells, const foamVtkCells& cells,
const fileName& outputName const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
); );
//- Destructor
~internalWriter();
// Member Functions // Member Functions
inline std::ofstream& os() inline std::ofstream& os()

View File

@ -31,9 +31,9 @@ License
Foam::foamVtkOutput::patchWriter::patchWriter Foam::foamVtkOutput::patchWriter::patchWriter
( (
const fvMesh& mesh, const fvMesh& mesh,
const bool binary, const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool nearCellValue, const bool nearCellValue,
const fileName& fName,
const labelList& patchIDs const labelList& patchIDs
) )
: :
@ -41,20 +41,18 @@ Foam::foamVtkOutput::patchWriter::patchWriter
format_(), format_(),
nearCellValue_(nearCellValue), nearCellValue_(nearCellValue),
patchIDs_(patchIDs), patchIDs_(patchIDs),
os_(fName.c_str()) os_()
{ {
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
format_ = opts.newFormatter(os_);
const polyBoundaryMesh& patches = mesh.boundaryMesh(); const polyBoundaryMesh& patches = mesh.boundaryMesh();
format_ = foamVtkOutput::newFormatter if (opts.legacy())
( {
os_,
(
binary
? foamVtkOutput::LEGACY_BINARY
: foamVtkOutput::LEGACY_ASCII
)
);
foamVtkOutput::legacy::fileHeader foamVtkOutput::legacy::fileHeader
( (
format(), format(),
@ -64,6 +62,7 @@ Foam::foamVtkOutput::patchWriter::patchWriter
: "patches" : "patches"
) )
) << "DATASET POLYDATA" << nl; ) << "DATASET POLYDATA" << nl;
}
//------------------------------------------------------------------ //------------------------------------------------------------------
@ -120,6 +119,12 @@ Foam::foamVtkOutput::patchWriter::patchWriter
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::patchWriter::~patchWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::foamVtkOutput::patchWriter::beginCellData(label nFields) void Foam::foamVtkOutput::patchWriter::beginCellData(label nFields)

View File

@ -42,7 +42,7 @@ SourceFiles
#include "pointFields.H" #include "pointFields.H"
#include "indirectPrimitivePatch.H" #include "indirectPrimitivePatch.H"
#include "PrimitivePatchInterpolation.H" #include "PrimitivePatchInterpolation.H"
#include "foamVtkOutput.H" #include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -82,13 +82,17 @@ public:
patchWriter patchWriter
( (
const fvMesh& mesh, const fvMesh& mesh,
const bool binary, const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool nearCellValue, const bool nearCellValue,
const fileName& fName,
const labelList& patchIDs const labelList& patchIDs
); );
//- Destructor
~patchWriter();
// Member Functions // Member Functions
inline std::ofstream& os() inline std::ofstream& os()

View File

@ -30,28 +30,27 @@ License
Foam::foamVtkOutput::surfaceMeshWriter::surfaceMeshWriter Foam::foamVtkOutput::surfaceMeshWriter::surfaceMeshWriter
( (
const bool binary,
const indirectPrimitivePatch& pp, const indirectPrimitivePatch& pp,
const word& name, const word& name,
const fileName& fName const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
) )
: :
pp_(pp), pp_(pp),
format_(), format_(),
os_(fName.c_str()) os_()
{ {
format_ = foamVtkOutput::newFormatter outputOptions opts(outOpts);
( opts.legacy(true); // Legacy only, no append
os_,
(
binary
? foamVtkOutput::LEGACY_BINARY
: foamVtkOutput::LEGACY_ASCII
)
);
os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
format_ = opts.newFormatter(os_);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), name) foamVtkOutput::legacy::fileHeader(format(), name)
<< "DATASET POLYDATA" << nl; << "DATASET POLYDATA" << nl;
}
//------------------------------------------------------------------ //------------------------------------------------------------------
@ -81,6 +80,12 @@ Foam::foamVtkOutput::surfaceMeshWriter::surfaceMeshWriter
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::surfaceMeshWriter::~surfaceMeshWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::foamVtkOutput::surfaceMeshWriter::beginCellData(label nFields) void Foam::foamVtkOutput::surfaceMeshWriter::beginCellData(label nFields)

View File

@ -41,7 +41,7 @@ SourceFiles
#include "volFields.H" #include "volFields.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "indirectPrimitivePatch.H" #include "indirectPrimitivePatch.H"
#include "foamVtkOutput.H" #include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -72,13 +72,17 @@ public:
//- Construct from components //- Construct from components
surfaceMeshWriter surfaceMeshWriter
( (
const bool binary,
const indirectPrimitivePatch& pp, const indirectPrimitivePatch& pp,
const word& name, const word& name,
const fileName& const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
); );
//- Destructor
~surfaceMeshWriter();
// Member Functions // Member Functions
inline std::ofstream& os() inline std::ofstream& os()

View File

@ -34,26 +34,23 @@ License
void Foam::foamVtkOutput::writeSurfFields void Foam::foamVtkOutput::writeSurfFields
( (
const bool binary,
const fvMesh& mesh, const fvMesh& mesh,
const fileName& fileName, const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const UPtrList<const surfaceVectorField>& surfVectorFields const UPtrList<const surfaceVectorField>& surfVectorFields
) )
{ {
std::ofstream os(fileName.c_str()); outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
autoPtr<foamVtkOutput::formatter> format = foamVtkOutput::newFormatter std::ofstream os((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
( autoPtr<foamVtkOutput::formatter> format = opts.newFormatter(os);
os,
(
binary
? foamVtkOutput::LEGACY_BINARY
: foamVtkOutput::LEGACY_ASCII
)
);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), "surfaceFields") foamVtkOutput::legacy::fileHeader(format(), "surfaceFields")
<< "DATASET POLYDATA" << nl; << "DATASET POLYDATA" << nl;
}
const pointField& fc = mesh.faceCentres(); const pointField& fc = mesh.faceCentres();

View File

@ -38,6 +38,7 @@ SourceFiles
#include "fvMesh.H" #include "fvMesh.H"
#include "surfaceMesh.H" #include "surfaceMesh.H"
#include "surfaceFieldsFwd.H" #include "surfaceFieldsFwd.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -49,9 +50,9 @@ namespace foamVtkOutput
//- Write surface vector fields //- Write surface vector fields
void writeSurfFields void writeSurfFields
( (
const bool binary,
const fvMesh& mesh, const fvMesh& mesh,
const fileName& fileName, const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const UPtrList<const surfaceVectorField>& surfVectorFields const UPtrList<const surfaceVectorField>& surfVectorFields
); );

View File

@ -23,8 +23,9 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "foamVtkCells.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "foamVtkCells.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -59,6 +60,33 @@ Foam::foamVtkCells::foamVtkCells
} }
Foam::foamVtkCells::foamVtkCells
(
const foamVtkOutput::outputOptions outOpts,
const bool decompose
)
:
foamVtkCells
(
(outOpts.legacy() ? contentType::LEGACY : contentType::XML),
decompose
)
{}
Foam::foamVtkCells::foamVtkCells
(
const polyMesh& mesh,
const foamVtkOutput::outputOptions outOpts,
const bool decompose
)
:
foamVtkCells(outOpts, decompose)
{
reset(mesh);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkCells::~foamVtkCells() Foam::foamVtkCells::~foamVtkCells()

View File

@ -61,6 +61,12 @@ namespace Foam
// Forward declaration of classes // Forward declaration of classes
class polyMesh; class polyMesh;
namespace foamVtkOutput
{
class outputOptions;
}
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class foamVtkCells Declaration Class foamVtkCells Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -132,6 +138,23 @@ public:
const bool decompose = false const bool decompose = false
); );
//- Construct from components.
// Optionally with polyhedral decomposition.
foamVtkCells
(
const foamVtkOutput::outputOptions outOpts,
const bool decompose = false
);
//- Construct from components and create the output information
// immediately
foamVtkCells
(
const polyMesh& mesh,
const foamVtkOutput::outputOptions outOpts,
const bool decompose = false
);
//- Destructor //- Destructor
~foamVtkCells(); ~foamVtkCells();

View File

@ -79,7 +79,6 @@ void Foam::vtkSetWriter<Type>::write
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
} }
os << "POINT_DATA " << points.size() << nl os << "POINT_DATA " << points.size() << nl
<< " FIELD attributes " << valueSetNames.size() << nl; << " FIELD attributes " << valueSetNames.size() << nl;

View File

@ -24,11 +24,15 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "foamVtkAppendBase64Formatter.H" #include "foamVtkAppendBase64Formatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::appendBase64Formatter::name_ = "append"; const char* Foam::foamVtkOutput::appendBase64Formatter::name_ = "append";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::appendBase64Formatter::opts_(formatType::APPEND_BASE64);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -51,6 +55,13 @@ Foam::foamVtkOutput::appendBase64Formatter::~appendBase64Formatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::appendBase64Formatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::appendBase64Formatter::name() const const char* Foam::foamVtkOutput::appendBase64Formatter::name() const
{ {
return name_; return name_;

View File

@ -56,6 +56,7 @@ class appendBase64Formatter
// Private Data Members // Private Data Members
static const char* name_; static const char* name_;
static const outputOptions opts_;
// Private Member Functions // Private Member Functions
@ -81,11 +82,8 @@ public:
// Member Functions // Member Functions
//- The output formatType is APPEND_BASE64. //- The output is APPEND_BASE64.
virtual enum formatType format() const virtual const outputOptions& opts() const;
{
return formatType::APPEND_BASE64;
}
//- Output name for XML type ("append") //- Output name for XML type ("append")
virtual const char* name() const; virtual const char* name() const;

View File

@ -24,12 +24,16 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "foamVtkAppendRawFormatter.H" #include "foamVtkAppendRawFormatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::appendRawFormatter::name_ = "append"; const char* Foam::foamVtkOutput::appendRawFormatter::name_ = "append";
const char* Foam::foamVtkOutput::appendRawFormatter::encoding_ = "raw"; const char* Foam::foamVtkOutput::appendRawFormatter::encoding_ = "raw";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::appendRawFormatter::opts_(formatType::APPEND_BINARY);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -59,6 +63,13 @@ Foam::foamVtkOutput::appendRawFormatter::~appendRawFormatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::appendRawFormatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::appendRawFormatter::name() const const char* Foam::foamVtkOutput::appendRawFormatter::name() const
{ {
return name_; return name_;

View File

@ -56,6 +56,8 @@ class appendRawFormatter
static const char* name_; static const char* name_;
static const char* encoding_; static const char* encoding_;
static const outputOptions opts_;
// Private Member Functions // Private Member Functions
@ -88,11 +90,8 @@ public:
// Member Functions // Member Functions
//- The output formatType is APPEND_BINARY. //- The output is APPEND_BINARY.
virtual enum formatType format() const virtual const outputOptions& opts() const;
{
return formatType::APPEND_BINARY;
}
//- Output name for XML type ("append") //- Output name for XML type ("append")
virtual const char* name() const; virtual const char* name() const;

View File

@ -24,11 +24,15 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "foamVtkAsciiFormatter.H" #include "foamVtkAsciiFormatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::asciiFormatter::name_ = "ascii"; const char* Foam::foamVtkOutput::asciiFormatter::name_ = "ascii";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::asciiFormatter::opts_(formatType::INLINE_ASCII);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -89,6 +93,13 @@ Foam::foamVtkOutput::asciiFormatter::~asciiFormatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::asciiFormatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::asciiFormatter::name() const const char* Foam::foamVtkOutput::asciiFormatter::name() const
{ {
return name_; return name_;

View File

@ -57,6 +57,7 @@ class asciiFormatter
// Private Data Members // Private Data Members
static const char* name_; static const char* name_;
static const outputOptions opts_;
//- Track the current output position //- Track the current output position
unsigned short pos_; unsigned short pos_;
@ -95,11 +96,8 @@ public:
// Member Functions // Member Functions
//- The output formatType is INLINE_ASCII. //- The output is INLINE_ASCII.
virtual enum formatType format() const virtual const outputOptions& opts() const;
{
return formatType::INLINE_ASCII;
}
//- Name for the XML output type ("ascii") //- Name for the XML output type ("ascii")
virtual const char* name() const; virtual const char* name() const;

View File

@ -24,11 +24,15 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "foamVtkBase64Formatter.H" #include "foamVtkBase64Formatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::base64Formatter::name_ = "binary"; const char* Foam::foamVtkOutput::base64Formatter::name_ = "binary";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::base64Formatter::opts_(formatType::INLINE_BASE64);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -51,6 +55,13 @@ Foam::foamVtkOutput::base64Formatter::~base64Formatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::base64Formatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::base64Formatter::name() const const char* Foam::foamVtkOutput::base64Formatter::name() const
{ {
return name_; return name_;

View File

@ -33,6 +33,7 @@ Description
#ifndef foamVtkBase64Formatter_H #ifndef foamVtkBase64Formatter_H
#define foamVtkBase64Formatter_H #define foamVtkBase64Formatter_H
#include "foamVtkFormatter.H"
#include "foamVtkBase64Layer.H" #include "foamVtkBase64Layer.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -53,7 +54,7 @@ class base64Formatter
// Private Data Members // Private Data Members
static const char* name_; static const char* name_;
static const char* encoding_; static const outputOptions opts_;
// Private Member Functions // Private Member Functions
@ -64,6 +65,7 @@ class base64Formatter
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const base64Formatter&) = delete; void operator=(const base64Formatter&) = delete;
public: public:
// Constructors // Constructors
@ -78,11 +80,8 @@ public:
// Member Functions // Member Functions
//- The output formatType is INLINE_BASE64. //- The output is INLINE_BASE64.
virtual enum formatType format() const virtual const outputOptions& opts() const;
{
return formatType::INLINE_BASE64;
}
//- Name for the XML output type ("binary") //- Name for the XML output type ("binary")
virtual const char* name() const; virtual const char* name() const;

View File

@ -64,6 +64,7 @@ class foamVtkBase64Layer
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const foamVtkBase64Layer&) = delete; void operator=(const foamVtkBase64Layer&) = delete;
protected: protected:
// Protected Member Functions // Protected Member Functions

View File

@ -57,6 +57,8 @@ namespace Foam
namespace foamVtkOutput namespace foamVtkOutput
{ {
class outputOptions;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class formatter Declaration Class formatter Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -111,8 +113,8 @@ public:
//- Access to the underlying output stream //- Access to the underlying output stream
inline std::ostream& os(); inline std::ostream& os();
//- The output formatType. //- The format-type / output options.
virtual enum formatType format() const = 0; virtual const outputOptions& opts() const = 0;
//- Name for the XML output type or the legacy output type. //- Name for the XML output type or the legacy output type.
virtual const char* name() const = 0; virtual const char* name() const = 0;
@ -195,6 +197,17 @@ public:
const bool leaveOpen = false const bool leaveOpen = false
); );
//- Add a "VTKFile" XML tag for contentType, followed by a tag for
// the contentType itself. Optionally leave the contentType tag
// open for adding additional attributes.
// \return formatter for chaining
inline formatter& beginVTKFile
(
const vtkFileTag& contentType,
const word& contentVersion,
const bool leaveOpen = false
);
//- Add a "AppendedData" XML tag with the current encoding and output //- Add a "AppendedData" XML tag with the current encoding and output
// the requisite '_' prefix. // the requisite '_' prefix.
// \return formatter for chaining // \return formatter for chaining
@ -206,6 +219,11 @@ public:
template<class Type, int nComp=0> template<class Type, int nComp=0>
formatter& openDataArray(const word& dataName); formatter& openDataArray(const word& dataName);
//- Open "DataArray" XML tag
// \return formatter for chaining
template<class Type, int nComp=0>
formatter& openDataArray(const vtkFileTag& tagEnum);
//- Insert a single "PDataArray" XML entry tag. //- Insert a single "PDataArray" XML entry tag.
// For some entries, the name is optional. // For some entries, the name is optional.

View File

@ -72,6 +72,23 @@ Foam::foamVtkOutput::formatter::tag(const vtkFileTag& tagEnum)
} }
inline Foam::foamVtkOutput::formatter&
Foam::foamVtkOutput::formatter::beginVTKFile
(
const vtkFileTag& contentType,
const word& contentVersion,
const bool leaveOpen
)
{
return beginVTKFile
(
vtkFileTagNames[contentType],
contentVersion,
leaveOpen
);
}
inline Foam::foamVtkOutput::formatter& inline Foam::foamVtkOutput::formatter&
Foam::foamVtkOutput::formatter::endDataArray() Foam::foamVtkOutput::formatter::endDataArray()
{ {

View File

@ -68,6 +68,17 @@ Foam::foamVtkOutput::formatter::openDataArray
} }
template<class Type, int nComp>
Foam::foamVtkOutput::formatter&
Foam::foamVtkOutput::formatter::openDataArray
(
const vtkFileTag& tagEnum
)
{
return openDataArray<Type, nComp>(vtkFileTagNames[tagEnum]);
}
template<class Type, int nComp> template<class Type, int nComp>
Foam::foamVtkOutput::formatter& Foam::foamVtkOutput::formatter&
Foam::foamVtkOutput::formatter::PDataArray Foam::foamVtkOutput::formatter::PDataArray

View File

@ -24,11 +24,15 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "foamVtkLegacyAsciiFormatter.H" #include "foamVtkLegacyAsciiFormatter.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::legacyAsciiFormatter::legacyName_ = "ASCII"; const char* Foam::foamVtkOutput::legacyAsciiFormatter::legacyName_ = "ASCII";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::legacyAsciiFormatter::opts_(formatType::LEGACY_ASCII);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -59,6 +63,13 @@ Foam::foamVtkOutput::legacyAsciiFormatter::~legacyAsciiFormatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::legacyAsciiFormatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::legacyAsciiFormatter::name() const const char* Foam::foamVtkOutput::legacyAsciiFormatter::name() const
{ {
return legacyName_; return legacyName_;

View File

@ -56,6 +56,10 @@ class legacyAsciiFormatter
// Private Data Members // Private Data Members
static const char* legacyName_; static const char* legacyName_;
static const outputOptions opts_;
// Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
legacyAsciiFormatter(const legacyAsciiFormatter&) = delete; legacyAsciiFormatter(const legacyAsciiFormatter&) = delete;
@ -81,11 +85,8 @@ public:
// Member Functions // Member Functions
//- The output formatType is LEGACY_ASCII. //- The output is LEGACY_ASCII.
virtual enum formatType format() const virtual const outputOptions& opts() const;
{
return formatType::LEGACY_ASCII;
}
//- Name for the legacy ascii output type ("ASCII") //- Name for the legacy ascii output type ("ASCII")
virtual const char* name() const; virtual const char* name() const;

View File

@ -24,12 +24,16 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "foamVtkLegacyRawFormatter.H" #include "foamVtkLegacyRawFormatter.H"
#include "foamVtkOutputOptions.H"
#include "endian.H" #include "endian.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* Foam::foamVtkOutput::legacyRawFormatter::legacyName_ = "BINARY"; const char* Foam::foamVtkOutput::legacyRawFormatter::legacyName_ = "BINARY";
const Foam::foamVtkOutput::outputOptions
Foam::foamVtkOutput::legacyRawFormatter::opts_(formatType::LEGACY_BINARY);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -62,6 +66,13 @@ Foam::foamVtkOutput::legacyRawFormatter::~legacyRawFormatter()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::legacyRawFormatter::opts() const
{
return opts_;
}
const char* Foam::foamVtkOutput::legacyRawFormatter::name() const const char* Foam::foamVtkOutput::legacyRawFormatter::name() const
{ {
return legacyName_; return legacyName_;

View File

@ -58,6 +58,7 @@ class legacyRawFormatter
// Private Data Members // Private Data Members
static const char* legacyName_; static const char* legacyName_;
static const outputOptions opts_;
// Private Member Functions // Private Member Functions
@ -91,11 +92,8 @@ public:
// Member Functions // Member Functions
//- The output formatType is LEGACY_BINARY. //- The output is LEGACY_BINARY.
virtual enum formatType format() const virtual const outputOptions& opts() const;
{
return formatType::LEGACY_BINARY;
}
//- Name for the legacy binary output type ("BINARY") //- Name for the legacy binary output type ("BINARY")
virtual const char* name() const; virtual const char* name() const;

View File

@ -70,27 +70,27 @@ Foam::foamVtkOutput::newFormatter
switch (fmtType) switch (fmtType)
{ {
case INLINE_ASCII: case formatType::INLINE_ASCII:
fmt.set(new foamVtkOutput::asciiFormatter(os, prec)); fmt.set(new foamVtkOutput::asciiFormatter(os, prec));
break; break;
case INLINE_BASE64: case formatType::INLINE_BASE64:
fmt.set(new foamVtkOutput::base64Formatter(os)); fmt.set(new foamVtkOutput::base64Formatter(os));
break; break;
case APPEND_BASE64: case formatType::APPEND_BASE64:
fmt.set(new foamVtkOutput::appendBase64Formatter(os)); fmt.set(new foamVtkOutput::appendBase64Formatter(os));
break; break;
case APPEND_BINARY: case formatType::APPEND_BINARY:
fmt.set(new foamVtkOutput::appendRawFormatter(os)); fmt.set(new foamVtkOutput::appendRawFormatter(os));
break; break;
case LEGACY_ASCII: case formatType::LEGACY_ASCII:
fmt.set(new foamVtkOutput::legacyAsciiFormatter(os, prec)); fmt.set(new foamVtkOutput::legacyAsciiFormatter(os, prec));
break; break;
case LEGACY_BINARY: case formatType::LEGACY_BINARY:
fmt.set(new foamVtkOutput::legacyRawFormatter(os)); fmt.set(new foamVtkOutput::legacyRawFormatter(os));
break; break;
} }

View File

@ -70,7 +70,6 @@ namespace foamVtkOutput
//- Return a default asciiFormatter //- Return a default asciiFormatter
autoPtr<foamVtkOutput::formatter> newFormatter(std::ostream& os); autoPtr<foamVtkOutput::formatter> newFormatter(std::ostream& os);
//- Return a new formatter based on the specified format type //- Return a new formatter based on the specified format type
autoPtr<foamVtkOutput::formatter> newFormatter autoPtr<foamVtkOutput::formatter> newFormatter
( (

View File

@ -35,20 +35,40 @@ Foam::foamVtkOutput::outputOptions::ascii(bool on)
{ {
switch (fmtType_) switch (fmtType_)
{ {
case INLINE_BASE64: fmtType_ = INLINE_ASCII; break; case formatType::INLINE_BASE64:
case APPEND_BINARY: fmtType_ = APPEND_BASE64; break; fmtType_ = formatType::INLINE_ASCII;
case LEGACY_BINARY: fmtType_ = LEGACY_ASCII; break; break;
default: break; // no change
case formatType::APPEND_BINARY:
fmtType_ = formatType::APPEND_BASE64;
break;
case formatType::LEGACY_BINARY:
fmtType_ = formatType::LEGACY_ASCII;
break;
default: // No change
break;
} }
} }
else else
{ {
switch (fmtType_) switch (fmtType_)
{ {
case INLINE_ASCII: fmtType_ = INLINE_BASE64; break; case formatType::INLINE_ASCII:
case APPEND_BASE64: fmtType_ = APPEND_BINARY; break; fmtType_ = formatType::INLINE_BASE64;
case LEGACY_ASCII: fmtType_ = LEGACY_BINARY; break; break;
default: break; // no change
case formatType::APPEND_BASE64:
fmtType_ = formatType::APPEND_BINARY;
break;
case formatType::LEGACY_ASCII:
fmtType_ = formatType::LEGACY_BINARY;
break;
default: // No change
break;
} }
} }
@ -63,20 +83,34 @@ Foam::foamVtkOutput::outputOptions::append(bool on)
{ {
switch (fmtType_) switch (fmtType_)
{ {
case INLINE_ASCII: fmtType_ = APPEND_BASE64; break; case formatType::INLINE_ASCII:
case LEGACY_ASCII: fmtType_ = APPEND_BASE64; break; case formatType::LEGACY_ASCII:
case INLINE_BASE64: fmtType_ = APPEND_BINARY; break; fmtType_ = formatType::APPEND_BASE64;
case LEGACY_BINARY: fmtType_ = APPEND_BINARY; break; break;
default: break; // no change
case formatType::INLINE_BASE64:
case formatType::LEGACY_BINARY:
fmtType_ = formatType::APPEND_BINARY;
break;
default: // No change
break;
} }
} }
else else
{ {
switch (fmtType_) switch (fmtType_)
{ {
case APPEND_BASE64: fmtType_ = INLINE_ASCII; break; case formatType::APPEND_BASE64:
case APPEND_BINARY: fmtType_ = INLINE_BASE64; break; fmtType_ = formatType::INLINE_ASCII;
default: break; // no change break;
case formatType::APPEND_BINARY:
fmtType_ = formatType::INLINE_BASE64;
break;
default: // No change
break;
} }
} }
@ -91,20 +125,34 @@ Foam::foamVtkOutput::outputOptions::legacy(bool on)
{ {
switch (fmtType_) switch (fmtType_)
{ {
case INLINE_ASCII: fmtType_ = LEGACY_ASCII; break; case formatType::INLINE_ASCII:
case INLINE_BASE64: fmtType_ = LEGACY_BINARY; break; case formatType::APPEND_BASE64:
case APPEND_BASE64: fmtType_ = LEGACY_ASCII; break; fmtType_ = formatType::LEGACY_ASCII;
case APPEND_BINARY: fmtType_ = LEGACY_BINARY; break; break;
default: break; // no change
case formatType::INLINE_BASE64:
case formatType::APPEND_BINARY:
fmtType_ = formatType::LEGACY_BINARY;
break;
default: // no change
break;
} }
} }
else else
{ {
switch (fmtType_) switch (fmtType_)
{ {
case LEGACY_ASCII: fmtType_ = INLINE_ASCII; break; case formatType::LEGACY_ASCII:
case LEGACY_BINARY: fmtType_ = INLINE_BASE64; break; fmtType_ = formatType::INLINE_ASCII;
default: break; // no change break;
case formatType::LEGACY_BINARY:
fmtType_ = formatType::INLINE_BASE64;
break;
default: // no change
break;
} }
} }
@ -112,16 +160,24 @@ Foam::foamVtkOutput::outputOptions::legacy(bool on)
} }
Foam::foamVtkOutput::outputOptions&
Foam::foamVtkOutput::outputOptions::precision(unsigned prec)
{
precision_ = prec;
return *this;
}
Foam::string Foam::foamVtkOutput::outputOptions::description() const Foam::string Foam::foamVtkOutput::outputOptions::description() const
{ {
switch (fmtType_) switch (fmtType_)
{ {
case INLINE_ASCII: return "xml ascii"; case formatType::INLINE_ASCII: return "xml ascii";
case INLINE_BASE64: return "xml base64"; case formatType::INLINE_BASE64: return "xml base64";
case APPEND_BASE64: return "xml-append base64"; case formatType::APPEND_BASE64: return "xml-append base64";
case APPEND_BINARY: return "xml-append binary"; case formatType::APPEND_BINARY: return "xml-append binary";
case LEGACY_ASCII: return "legacy ascii"; case formatType::LEGACY_ASCII: return "legacy ascii";
case LEGACY_BINARY: return "legacy binary"; case formatType::LEGACY_BINARY: return "legacy binary";
} }
return ""; return "";

View File

@ -28,6 +28,9 @@ Description
Encapsulated combinations of output format options. Encapsulated combinations of output format options.
This is primarily useful when defining the output type based on some This is primarily useful when defining the output type based on some
command-line arguments or dictionary contents. command-line arguments or dictionary contents.
However, it can also be a useful alternative to using the underlying
enumeration directly, since this class provides additional methods
not possible with an enum.
SourceFiles SourceFiles
foamVtkOutputOptions.C foamVtkOutputOptions.C
@ -53,8 +56,6 @@ namespace foamVtkOutput
class outputOptions class outputOptions
{ {
private:
// Private Member Data // Private Member Data
//- The output style tuning //- The output style tuning
@ -64,7 +65,6 @@ private:
HEADER = 0x01 //!< Emit xml header HEADER = 0x01 //!< Emit xml header
}; };
//- The output format type //- The output format type
formatType fmtType_; formatType fmtType_;
@ -79,7 +79,8 @@ public:
//- Construct null - XML insitu ASCII format with default precision //- Construct null - XML insitu ASCII format with default precision
inline outputOptions(); inline outputOptions();
//- Construct with specified format //- Construct with specified format.
// This constructor should remain non-explicit.
inline outputOptions(enum formatType fmtType); inline outputOptions(enum formatType fmtType);
@ -94,7 +95,7 @@ public:
// Access // Access
//- The output format type //- The output format type
inline formatType format() const; inline formatType fmt() const;
//- True if writer uses legacy file format //- True if writer uses legacy file format
inline bool legacy() const; inline bool legacy() const;
@ -111,6 +112,9 @@ public:
//- True if output format is ASCII //- True if output format is ASCII
inline bool ascii() const; inline bool ascii() const;
//- Return the ASCII write precision
inline unsigned precision() const;
// Edit // Edit
@ -131,12 +135,12 @@ public:
//- Set the write precision to be used for new ASCII formatters //- Set the write precision to be used for new ASCII formatters
// \return outputOptions for chaining // \return outputOptions for chaining
inline const outputOptions& precision(unsigned prec) const; outputOptions& precision(unsigned prec);
// Other // Other
//- Report description about the option selected //- A text description about the output option selected
string description() const; string description() const;
}; };

View File

@ -23,12 +23,14 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "foamVtkOutput.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::foamVtkOutput::outputOptions::outputOptions() inline Foam::foamVtkOutput::outputOptions::outputOptions()
: :
fmtType_(INLINE_ASCII), fmtType_(formatType::INLINE_ASCII),
precision_(IOstream::defaultPrecision()) precision_(IOstream::defaultPrecision())
{} {}
@ -55,7 +57,7 @@ Foam::foamVtkOutput::outputOptions::newFormatter(std::ostream& os) const
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
inline Foam::foamVtkOutput::formatType inline Foam::foamVtkOutput::formatType
Foam::foamVtkOutput::outputOptions::format() const Foam::foamVtkOutput::outputOptions::fmt() const
{ {
return fmtType_; return fmtType_;
} }
@ -63,7 +65,11 @@ Foam::foamVtkOutput::outputOptions::format() const
inline bool Foam::foamVtkOutput::outputOptions::legacy() const inline bool Foam::foamVtkOutput::outputOptions::legacy() const
{ {
return (fmtType_ & formatType::LEGACY_ASCII & formatType::LEGACY_BINARY); return
(
fmtType_ == formatType::LEGACY_ASCII
|| fmtType_ == formatType::LEGACY_BINARY
);
} }
@ -75,7 +81,11 @@ inline bool Foam::foamVtkOutput::outputOptions::xml() const
inline bool Foam::foamVtkOutput::outputOptions::append() const inline bool Foam::foamVtkOutput::outputOptions::append() const
{ {
return (fmtType_ & formatType::APPEND_BASE64 & formatType::APPEND_BINARY); return
(
fmtType_ == formatType::APPEND_BASE64
|| fmtType_ == formatType::APPEND_BINARY
);
} }
@ -87,15 +97,13 @@ inline bool Foam::foamVtkOutput::outputOptions::insitu() const
inline bool Foam::foamVtkOutput::outputOptions::ascii() const inline bool Foam::foamVtkOutput::outputOptions::ascii() const
{ {
return !(fmtType_ & 0xF); return !(unsigned(fmtType_) & 0x0F);
} }
inline const Foam::foamVtkOutput::outputOptions& inline unsigned Foam::foamVtkOutput::outputOptions::precision() const
Foam::foamVtkOutput::outputOptions::precision(unsigned prec) const
{ {
precision_ = prec; return precision_;
return *this;
} }

View File

@ -48,7 +48,7 @@ namespace foamVtkOutput
//- The output format type for file contents. //- The output format type for file contents.
// Upper bits for output type, lower bits for the format itself. // Upper bits for output type, lower bits for the format itself.
enum formatType enum class formatType
{ {
/** XML inline ASCII, using the asciiFormatter */ /** XML inline ASCII, using the asciiFormatter */
INLINE_ASCII = 0, INLINE_ASCII = 0,

View File

@ -106,12 +106,11 @@ bool Foam::functionObjects::writeVTK::write()
} }
// Create file and write header // Create file and write header
fileName outputName const fileName outputName
( (
fvPath/vtkName fvPath/vtkName
+ "_" + "_"
+ timeDesc + timeDesc
+ ".vtk"
); );
Info<< " Internal : " << outputName << endl; Info<< " Internal : " << outputName << endl;
@ -127,9 +126,9 @@ bool Foam::functionObjects::writeVTK::write()
foamVtkOutput::internalWriter writer foamVtkOutput::internalWriter writer
( (
mesh_, mesh_,
foamVtkOutput::LEGACY_ASCII,
foamVtkMeshCells, foamVtkMeshCells,
outputName outputName,
foamVtkOutput::formatType::LEGACY_ASCII
); );

View File

@ -34,22 +34,24 @@ License
void Foam::foamVtkOutput::writeCellSetFaces void Foam::foamVtkOutput::writeCellSetFaces
( (
const bool binary,
const primitiveMesh& mesh, const primitiveMesh& mesh,
const cellSet& set, const cellSet& set,
const fileName& fileName const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
) )
{ {
std::ofstream os(fileName.c_str()); outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
autoPtr<foamVtkOutput::formatter> format = std::ofstream os((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
foamVtkOutput::outputOptions().legacy(true).ascii(!binary).newFormatter
(
os
);
autoPtr<foamVtkOutput::formatter> format = opts.newFormatter(os);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), set.name()) foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl; << "DATASET POLYDATA" << nl;
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -87,7 +89,7 @@ void Foam::foamVtkOutput::writeCellSetFaces
} }
} }
labelList faceLabels = cellFaces.sortedToc(); const labelList faceLabels = cellFaces.sortedToc();
labelList faceValues(cellFaces.size()); labelList faceValues(cellFaces.size());
forAll(faceLabels, facei) forAll(faceLabels, facei)

View File

@ -39,6 +39,7 @@ SourceFiles
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "uindirectPrimitivePatch.H" #include "uindirectPrimitivePatch.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -55,10 +56,10 @@ namespace foamVtkOutput
// The data are the original cell ids // The data are the original cell ids
void writeCellSetFaces void writeCellSetFaces
( (
const bool binary,
const primitiveMesh& mesh, const primitiveMesh& mesh,
const cellSet& set, const cellSet& set,
const fileName& fileName const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
); );
} // End namespace foamVtkOutput } // End namespace foamVtkOutput

View File

@ -34,27 +34,29 @@ License
void Foam::foamVtkOutput::writeFaceSet void Foam::foamVtkOutput::writeFaceSet
( (
const bool binary,
const primitiveMesh& mesh, const primitiveMesh& mesh,
const faceSet& set, const faceSet& set,
const fileName& fileName const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
) )
{ {
std::ofstream os(fileName.c_str()); outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
autoPtr<foamVtkOutput::formatter> format = std::ofstream os((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
foamVtkOutput::outputOptions().legacy(true).ascii(!binary).newFormatter
(
os
);
autoPtr<foamVtkOutput::formatter> format = opts.newFormatter(os);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), set.name()) foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl; << "DATASET POLYDATA" << nl;
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Faces of set with OpenFOAM faceID as value // Faces of set with OpenFOAM faceID as value
labelList faceLabels = set.sortedToc(); const labelList faceLabels = set.sortedToc();
uindirectPrimitivePatch pp uindirectPrimitivePatch pp
( (

View File

@ -36,6 +36,8 @@ SourceFiles
#ifndef foamVtkWriteFaceSet_H #ifndef foamVtkWriteFaceSet_H
#define foamVtkWriteFaceSet_H #define foamVtkWriteFaceSet_H
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
@ -51,10 +53,10 @@ namespace foamVtkOutput
// Only one data which is original pointID. // Only one data which is original pointID.
void writeFaceSet void writeFaceSet
( (
const bool binary,
const primitiveMesh& mesh, const primitiveMesh& mesh,
const faceSet& set, const faceSet& set,
const fileName& fileName const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
); );

View File

@ -33,22 +33,24 @@ License
void Foam::foamVtkOutput::writePointSet void Foam::foamVtkOutput::writePointSet
( (
const bool binary,
const primitiveMesh& mesh, const primitiveMesh& mesh,
const pointSet& set, const pointSet& set,
const fileName& fileName const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
) )
{ {
std::ofstream os(fileName.c_str()); outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
autoPtr<foamVtkOutput::formatter> format = std::ofstream os((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
foamVtkOutput::outputOptions().legacy(true).ascii(!binary).newFormatter
(
os
);
autoPtr<foamVtkOutput::formatter> format = opts.newFormatter(os);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), set.name()) foamVtkOutput::legacy::fileHeader(format(), set.name())
<< "DATASET POLYDATA" << nl; << "DATASET POLYDATA" << nl;
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------

View File

@ -36,6 +36,8 @@ SourceFiles
#ifndef foamVtkWritePointSet_H #ifndef foamVtkWritePointSet_H
#define foamVtkWritePointSet_H #define foamVtkWritePointSet_H
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
@ -51,10 +53,10 @@ namespace foamVtkOutput
// The data are the original point ids. // The data are the original point ids.
void writePointSet void writePointSet
( (
const bool binary,
const primitiveMesh& mesh, const primitiveMesh& mesh,
const pointSet& set, const pointSet& set,
const fileName& fileName const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
); );