mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -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)
|
||||
opts.legacy(true);
|
||||
|
||||
if (!args.optionFound("ascii"))
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Using ASCII rather than binary VTK format since "
|
||||
<< "floatScalar and/or label are not 4 bytes in size."
|
||||
<< nl << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
)
|
||||
);
|
||||
outputOptions opts(outOpts);
|
||||
opts.legacy(true); // Legacy only, no append
|
||||
|
||||
foamVtkOutput::legacy::fileHeader(format(), mesh_.time().caseName())
|
||||
<< "DATASET POLYDATA" << nl;
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user