Go to the documentation of this file.
40 { outputState::CLOSED,
"closed" },
41 { outputState::OPENED,
"opened" },
42 { outputState::DECLARED,
"declared" },
43 { outputState::FIELD_DATA,
"FieldData" },
44 { outputState::PIECE,
"Piece" },
45 { outputState::CELL_DATA,
"CellData" },
58 <<
"unallocated formatter" <<
endl
70 os <<
"Bad writer state (" << stateNames[state_]
71 <<
") - should be (" << stateNames[expected] <<
')';
83 reportBadState(
os, expected)
84 <<
" or (" << stateNames[expected2] <<
')';
94 if (isState(outputState::OPENED))
98 if (notState(outputState::DECLARED))
104 nCellData_ = nPointData_ = 0;
121 state_ = outputState::DECLARED;
149 if (legacy() && !nFields)
return false;
186 if (legacy() && !nFields)
return false;
198 format().beginPointData();
226 const uint64_t payLoad =
227 vtk::sizeofData<float, 3>(
nPoints);
233 format().writeSize(payLoad);
261 if (isState(outputState::DECLARED))
263 if (format_ && !legacy())
265 format().endTag(contentType_).endVTKFile();
267 state_ = outputState::OPENED;
272 if (isState(outputState::CLOSED) || isState(outputState::OPENED))
293 contentType_(contentType),
296 state_(outputState::CLOSED),
320 if (notState(outputState::CLOSED))
328 format_.reset(
nullptr);
331 nCellData_ = nPointData_ = 0;
346 if (!outputFile_.hasExt(ext()))
349 outputFile_.ext(ext());
365 mkDir(outputFile_.path());
367 os_.open(outputFile_);
369 format_ = opts_.newFormatter(os_);
372 state_ = outputState::OPENED;
383 format_.reset(
nullptr);
387 state_ = outputState::CLOSED;
389 nCellData_ = nPointData_ = 0;
395 if (isState(outputState::DECLARED))
400 if (notState(outputState::OPENED))
405 state_ = outputState::DECLARED;
421 format().xmlComment(title);
424 format().beginVTKFile(contentType_);
435 if (legacy() && !nFields)
return false;
437 if (isState(outputState::OPENED))
441 if (notState(outputState::DECLARED))
456 format().beginFieldData();
471 state_ = outputState::DECLARED;
473 if (format_ && !legacy())
491 if (format_ && !legacy())
509 if (format_ && !legacy())
521 if (isState(outputState::OPENED) || isState(outputState::DECLARED))
532 if (!format_)
return;
540 format().writeTimeValue(timeValue);
561 <<
" for procID field" <<
nl <<
endl
575 const label totalCount = (parallel_ ? procSizes.
size() : nValues);
577 this->beginDataArray<label>(
"procID", totalCount);
600 this->endDataArray();
Encapsulated combinations of output format options. This is primarily useful when defining the output...
bool enter_Piece()
Trigger change state to Piece. Resets nCellData_, nPointData_.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
void close()
End the file contents and close the file after writing.
A class for handling file names.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
const word fileExtension
Legacy file extension ("vtk")
bool enter_CellData(label nEntries, label nFields)
Trigger change state to CellData.
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
bool endCellData()
Explicitly end CellData output and switch to PIECE state.
void writeTimeValue(scalar timeValue)
Write "TimeValue" FieldData (name as per Catalyst output)
bool beginFieldData(label nFields=0)
Begin FieldData output section for specified number of fields.
static bool master(const label communicator=worldComm)
Am I the master process.
void beginPointData(vtk::formatter &fmt, label nPoints, label nFields)
Emit legacy POINT_DATA nPoints, FIELD FieldData nFields.
label localSize() const
My local size.
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Ostream & endl(Ostream &os)
Add newline and flush stream.
void beginFieldData(vtk::formatter &fmt, label nFields)
Emit legacy FIELD FieldData nFields.
static const Enum< outputState > stateNames
Names for the output state (for messages, not for file output).
autoPtr< vtk::formatter > format_
The VTK formatter in use (only valid on master process)
bool open(const fileName &file, bool parallel=Pstream::parRun())
Open file for writing (creates parent directory).
word format(conversionProperties.get< word >("format"))
fileWriter(const fileWriter &)=delete
No copy construct.
void writeTimeValue(vtk::formatter &fmt, scalar timeValue)
Emit "TimeValue" for a FIELD entry (name as per Catalyst output)
bool enter_PointData(label nEntries, label nFields)
Trigger change state to PointData.
bool removeExt()
Remove extension, returning true if string changed.
virtual ~fileWriter()
Destructor.
bool endPiece()
Explicitly end Piece output and switch to DECLARED state.
void checkFormatterValidity() const
Verify that formatter in either allocated or not required.
void beginPoints(std::ostream &os, label nPoints)
Emit header for POINTS (with trailing newline).
bool parallel_
Writing in parallel (via master)
void fileHeader(std::ostream &os, const std::string &title, bool binary)
Emit header for legacy file (vtk DataFile Version 2.0)
OBJstream os(runTime.globalPath()/outputName)
bool endPointData()
Explicitly end PointData output and switch to PIECE state.
fileTag
Some common XML tags for vtk files.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
const Foam::Enum< fileTag > fileTagNames
Strings corresponding to the vtk XML tags.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void beginCellData(vtk::formatter &fmt, label nCells, label nFields)
Emit legacy CELL_DATA nCells, FIELD FieldData nFields.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
bool exit_File()
Emit file footer (end data, end piece, end file)
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
label size() const
Global sum of localSizes.
Ostream & reportBadState(Ostream &, outputState expected) const
Generate message reporting bad writer state.
static bool & parRun() noexcept
Test if this a parallel run.
void endPoints()
End of a POINTS DataArray.
bool writeProcIDs(const label nValues)
Write nValues of processor ids as CellData (no-op in serial)
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
void endDataArray()
Flush formatter and end of DataArray output (non-legacy)
outputState
Internal tracking of the output state.
bool endFieldData()
Explicitly end FieldData output and switch to DECLARED state.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
#define WarningInFunction
Report a warning using Foam::Warning.
void beginPoints(const label nPoints)
Start of a POINTS DataArray.