Commit c4f13494 authored by Mark Olesen's avatar Mark Olesen
Browse files

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.
parent 03944c2a
EXE_INC = \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
$(COMP_FLAGS)
......
......@@ -76,7 +76,7 @@ void writeVTK
(
const polyMesh& mesh,
const topoSet& currentSet,
const fileName& vtkName
const fileName& vtkBaseName
)
{
if (isA<faceSet>(currentSet))
......@@ -84,10 +84,10 @@ void writeVTK
// Faces of set with OpenFOAM faceID as value
foamVtkOutput::writeFaceSet
(
true,
mesh,
currentSet,
mesh.time().path()/vtkName
mesh.time().path()/vtkBaseName,
foamVtkOutput::formatType::LEGACY_BINARY
);
}
else if (isA<cellSet>(currentSet))
......@@ -95,20 +95,20 @@ void writeVTK
// External faces of cellset with OpenFOAM cellID as value
foamVtkOutput::writeCellSetFaces
(
true,
mesh,
currentSet,
mesh.time().path()/vtkName
mesh.time().path()/vtkBaseName,
foamVtkOutput::formatType::LEGACY_BINARY
);
}
else if (isA<pointSet>(currentSet))
{
foamVtkOutput::writePointSet
(
true,
mesh,
currentSet,
mesh.time().path()/vtkName
mesh.time().path()/vtkBaseName,
foamVtkOutput::formatType::LEGACY_BINARY
);
}
else
......@@ -123,58 +123,58 @@ void writeVTK
void printHelp(Ostream& os)
{
os << "Please type 'help', 'list', 'quit', 'time ddd'"
<< " or a set command after prompt." << endl
<< "'list' will show all current cell/face/point sets." << endl
<< "'time ddd' will change the current time." << endl
<< endl
<< "A set command should be of the following form" << endl
<< endl
<< " or a set command after prompt." << nl
<< "'list' will show all current cell/face/point sets." << nl
<< "'time ddd' will change the current time." << nl
<< nl
<< "A set command should be of the following form" << nl
<< nl
<< " cellSet|faceSet|pointSet <setName> <action> <source>"
<< endl
<< endl
<< "The <action> is one of" << endl
<< " list - prints the contents of the set" << endl
<< " clear - clears the set" << endl
<< " invert - inverts the set" << endl
<< " remove - remove the set" << endl
<< " new <source> - sets to set to the source set" << endl
<< " add <source> - adds all elements from the source set" << endl
<< " delete <source> - deletes ,," << endl
<< nl
<< nl
<< "The <action> is one of" << nl
<< " list - prints the contents of the set" << nl
<< " clear - clears the set" << nl
<< " invert - inverts the set" << nl
<< " remove - remove the set" << nl
<< " new <source> - sets to set to the source set" << nl
<< " add <source> - adds all elements from the source set" << nl
<< " delete <source> - deletes ,," << nl
<< " subset <source> - combines current set with the source set"
<< endl
<< endl
<< nl
<< nl
<< "The sources come in various forms. Type a wrong source"
<< " to see all the types available." << endl
<< endl
<< " to see all the types available." << nl
<< nl
<< "Example: pick up all cells connected by point or face to patch"
<< " movingWall" << endl
<< endl
<< "Pick up all faces of patch:" << endl
<< " faceSet f0 new patchToFace movingWall" << endl
<< "Add faces 0,1,2:" << endl
<< " faceSet f0 add labelToFace (0 1 2)" << endl
<< "Pick up all points used by faces in faceSet f0:" << endl
<< " pointSet p0 new faceToPoint f0 all" << endl
<< "Pick up cell which has any face in f0:" << endl
<< " cellSet c0 new faceToCell f0 any" << endl
<< "Add cells which have any point in p0:" << endl
<< " cellSet c0 add pointToCell p0 any" << endl
<< "List set:" << endl
<< " cellSet c0 list" << endl
<< endl
<< "Zones can be set using zoneSets from corresponding sets:" << endl
<< " cellZoneSet c0Zone new setToCellZone c0" << endl
<< " faceZoneSet f0Zone new setToFaceZone f0" << endl
<< endl
<< "or if orientation is important:" << endl
<< " faceZoneSet f0Zone new setsToFaceZone f0 c0" << endl
<< endl
<< "ZoneSets can be manipulated using the general actions:" << endl
<< " list - prints the contents of the set" << endl
<< " clear - clears the set" << endl
<< " movingWall" << nl
<< nl
<< "Pick up all faces of patch:" << nl
<< " faceSet f0 new patchToFace movingWall" << nl
<< "Add faces 0,1,2:" << nl
<< " faceSet f0 add labelToFace (0 1 2)" << nl
<< "Pick up all points used by faces in faceSet f0:" << nl
<< " pointSet p0 new faceToPoint f0 all" << nl
<< "Pick up cell which has any face in f0:" << nl
<< " cellSet c0 new faceToCell f0 any" << nl
<< "Add cells which have any point in p0:" << nl
<< " cellSet c0 add pointToCell p0 any" << nl
<< "List set:" << nl
<< " cellSet c0 list" << nl
<< nl
<< "Zones can be set using zoneSets from corresponding sets:" << nl
<< " cellZoneSet c0Zone new setToCellZone c0" << nl
<< " faceZoneSet f0Zone new setToFaceZone f0" << nl
<< nl
<< "or if orientation is important:" << nl
<< " faceZoneSet f0Zone new setsToFaceZone f0 c0" << nl
<< nl
<< "ZoneSets can be manipulated using the general actions:" << nl
<< " list - prints the contents of the set" << nl
<< " clear - clears the set" << nl
<< " invert - inverts the set (undefined orientation)"
<< endl
<< " remove - remove the set" << endl
<< nl
<< " remove - remove the set" << nl
<< endl;
}
......@@ -513,7 +513,6 @@ bool doCommand
"VTK"/currentSet.name()/currentSet.name()
+ "_"
+ name(mesh.time().timeIndex())
+ ".vtk"
);
Info<< " Writing " << currentSet.name()
......
......@@ -239,24 +239,32 @@ labelList getSelectedPatches
// Process args for output options
// Default from foamVtkOutputOptions is inline ASCII xml
//
enum foamVtkOutput::formatType getOutputOptions(const argList& args)
foamVtkOutput::outputOptions getOutputOptions(const argList& args)
{
if (!args.optionFound("ascii"))
foamVtkOutput::outputOptions opts;
{
if (sizeof(floatScalar) != 4 || sizeof(label) != 4)
{
WarningInFunction
<< "Using ASCII rather than binary VTK format since "
<< "floatScalar and/or label are not 4 bytes in size."
<< nl << endl;
}
else
opts.legacy(true);
if (!args.optionFound("ascii"))
{
return foamVtkOutput::formatType::LEGACY_BINARY;
if (sizeof(floatScalar) != 4 || sizeof(label) != 4)
{
opts.ascii(true);
WarningInFunction
<< "Using ASCII rather than binary VTK format since "
<< "floatScalar and/or label are not 4 bytes in size."
<< nl << endl;
}
else
{
opts.ascii(false);
}
}
}
return foamVtkOutput::formatType::LEGACY_ASCII;
return opts;
}
......@@ -398,10 +406,9 @@ int main(int argc, char *argv[])
const bool doLinks = !args.optionFound("noLinks");
const bool useTimeName = args.optionFound("useTimeName");
const bool noLagrangian = args.optionFound("noLagrangian");
const bool nearCellValue = args.optionFound("nearCellValue");
const enum foamVtkOutput::formatType fmtType = getOutputOptions(args);
const bool binary = (fmtType == foamVtkOutput::formatType::LEGACY_BINARY);
const bool nearCellValue = args.optionFound("nearCellValue");
const foamVtkOutput::outputOptions fmtType = getOutputOptions(args);
if (nearCellValue)
{
......@@ -495,11 +502,7 @@ int main(int argc, char *argv[])
meshSubsetHelper meshRef(mesh, meshSubsetHelper::SET, cellSetName);
// Collect decomposition information etc.
foamVtkCells foamVtkMeshCells
(
foamVtkCells::contentType::LEGACY,
decomposePoly
);
foamVtkCells foamVtkMeshCells(fmtType, decomposePoly);
Info<< "VTK mesh topology: "
<< timer.cpuTimeIncrement() << " s, "
......@@ -545,17 +548,16 @@ int main(int argc, char *argv[])
fvPath/set.name()/set.name()
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " faceSet : "
<< relativeName(runTime, outputName) << nl;
foamVtkOutput::writeFaceSet
(
binary,
meshRef.mesh(),
set,
outputName
outputName,
fmtType
);
continue;
}
......@@ -574,17 +576,16 @@ int main(int argc, char *argv[])
fvPath/set.name()/set.name()
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " pointSet : "
<< relativeName(runTime, outputName) << nl;
foamVtkOutput::writePointSet
(
binary,
meshRef.mesh(),
set,
outputName
outputName,
fmtType
);
continue;
}
......@@ -594,7 +595,7 @@ int main(int argc, char *argv[])
IOobjectList objects(mesh, runTime.timeName());
HashSet<word> selectedFields;
bool specifiedFields = args.optionReadIfPresent
const bool specifiedFields = args.optionReadIfPresent
(
"fields",
selectedFields
......@@ -836,7 +837,6 @@ int main(int argc, char *argv[])
fvPath/vtkName
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " Internal : "
<< relativeName(runTime, outputName) << endl;
......@@ -845,9 +845,9 @@ int main(int argc, char *argv[])
foamVtkOutput::internalWriter writer
(
meshRef.baseMesh(),
fmtType,
foamVtkMeshCells,
outputName
outputName,
fmtType
);
// CellData
......@@ -963,14 +963,13 @@ int main(int argc, char *argv[])
/ "surfaceFields"
+ "_"
+ timeDesc
+ ".vtk"
);
foamVtkOutput::writeSurfFields
(
binary,
meshRef.mesh(),
outputName,
fmtType,
sVectorFld
);
}
......@@ -995,7 +994,6 @@ int main(int argc, char *argv[])
/ (meshRef.useSubMesh() ? cellSetName : "allPatches")
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " Combined patches : "
<< relativeName(runTime, outputName) << nl;
......@@ -1003,9 +1001,9 @@ int main(int argc, char *argv[])
foamVtkOutput::patchWriter writer
(
meshRef.mesh(),
binary,
nearCellValue,
outputName,
fmtType,
nearCellValue,
getSelectedPatches(patches, excludePatches)
);
......@@ -1064,7 +1062,6 @@ int main(int argc, char *argv[])
/ (meshRef.useSubMesh() ? cellSetName : pp.name())
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " Patch : "
<< relativeName(runTime, outputName) << nl;
......@@ -1072,9 +1069,9 @@ int main(int argc, char *argv[])
foamVtkOutput::patchWriter writer
(
meshRef.mesh(),
binary,
nearCellValue,
outputName,
fmtType,
nearCellValue,
labelList{patchi}
);
......@@ -1168,7 +1165,6 @@ int main(int argc, char *argv[])
/ (meshRef.useSubMesh() ? cellSetName : fz.name())
+ "_"
+ timeDesc
+ ".vtk"
);
Info<< " FaceZone : "
<< relativeName(runTime, outputName) << nl;
......@@ -1181,10 +1177,10 @@ int main(int argc, char *argv[])
foamVtkOutput::surfaceMeshWriter writer
(
binary,
pp,
fz.name(),
outputName
outputName,
fmtType
);
// Number of fields
......@@ -1214,7 +1210,7 @@ int main(int argc, char *argv[])
fileName outputName
(
fvPath/cloud::prefix/cloudName/cloudName
+ "_" + timeDesc + ".vtk"
+ "_" + timeDesc
);
Info<< " Lagrangian: "
<< relativeName(runTime, outputName) << nl;
......@@ -1267,10 +1263,9 @@ int main(int argc, char *argv[])
foamVtkOutput::lagrangianWriter writer
(
meshRef.mesh(),
binary,
outputName,
cloudName,
false
outputName,
fmtType
);
// Write number of fields
......@@ -1299,9 +1294,9 @@ int main(int argc, char *argv[])
foamVtkOutput::lagrangianWriter writer
(
meshRef.mesh(),
binary,
outputName,
cloudName,
outputName,
fmtType,
true
);
......
......@@ -32,30 +32,30 @@ License
Foam::foamVtkOutput::lagrangianWriter::lagrangianWriter
(
const fvMesh& mesh,
const bool binary,
const fileName& fName,
const word& cloudName,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool dummyCloud
)
:
mesh_(mesh),
format_(),
cloudName_(cloudName),
os_(fName.c_str()),
os_(),
nParcels_(0)
{
format_ = foamVtkOutput::newFormatter
(
os_,
(
binary
? foamVtkOutput::LEGACY_BINARY
: foamVtkOutput::LEGACY_ASCII
)
);
foamVtkOutput::legacy::fileHeader(format(), mesh_.time().caseName())
<< "DATASET POLYDATA" << nl;
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtp")).c_str());
format_ = opts.newFormatter(os_);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), mesh_.time().caseName())
<< "DATASET POLYDATA" << nl;
}
if (dummyCloud)
{
......@@ -80,6 +80,12 @@ Foam::foamVtkOutput::lagrangianWriter::lagrangianWriter
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::lagrangianWriter::~lagrangianWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::foamVtkOutput::lagrangianWriter::beginParcelData
......
......@@ -40,7 +40,7 @@ SourceFiles
#include "Cloud.H"
#include "volFields.H"
#include "pointFields.H"
#include "foamVtkOutput.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -76,13 +76,17 @@ public:
lagrangianWriter
(
const fvMesh& mesh,
const bool binary,
const fileName&,
const word&,
const bool dummyCloud
const word& cloudName,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool dummyCloud = false
);
//- Destructor
~lagrangianWriter();
// Member Functions
inline std::ofstream& os()
......
......@@ -30,21 +30,27 @@ License
Foam::foamVtkOutput::internalWriter::internalWriter
(
const fvMesh& mesh,
enum foamVtkOutput::formatType fmtType,
const foamVtkCells& cells,
const fileName& outputName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
)
:
mesh_(mesh),
format_(),
vtkCells_(cells),
os_(outputName.c_str())
os_()
{
format_ = foamVtkOutput::newFormatter(os_, fmtType);
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append
// Write header
foamVtkOutput::legacy::fileHeader(format(), mesh.time().caseName())
<< "DATASET UNSTRUCTURED_GRID" << nl;
os_.open((baseName + (opts.legacy() ? ".vtk" : ".vtu")).c_str());
format_ = opts.newFormatter(os_);
if (opts.legacy())
{
foamVtkOutput::legacy::fileHeader(format(), mesh.time().caseName())
<< "DATASET UNSTRUCTURED_GRID" << nl;
}
//------------------------------------------------------------------
//
......@@ -84,6 +90,12 @@ Foam::foamVtkOutput::internalWriter::internalWriter
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::foamVtkOutput::internalWriter::~internalWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......
......@@ -42,6 +42,7 @@ SourceFiles
#include "foamVtkCells.H"
#include "foamVtkOutputFields.H"
#include "foamVtkOutputOptions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -78,12 +79,16 @@ public:
internalWriter
(
const fvMesh& mesh,
enum foamVtkOutput::formatType fmtType,
const foamVtkCells& cells,
const fileName& outputName
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts
);
//- Destructor
~internalWriter();
// Member Functions
inline std::ofstream& os()
......
......@@ -31,9 +31,9 @@ License
Foam::foamVtkOutput::patchWriter::patchWriter
(
const fvMesh& mesh,
const bool binary,
const fileName& baseName,
const foamVtkOutput::outputOptions outOpts,
const bool nearCellValue,
const fileName& fName,
const labelList& patchIDs
)
:
......@@ -41,29 +41,28 @@ Foam::foamVtkOutput::patchWriter::patchWriter
format_(),
nearCellValue_(nearCellValue),
patchIDs_(patchIDs),
os_(fName.c_str())
os_()
{
outputOptions opts(outOpts);
opts.legacy(true); // Legacy only, no append