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" },
46 { outputState::POINT_DATA,
"PointData" },
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))
103 state_ = outputState::PIECE;
104 nCellData_ = nPointData_ = 0;
116 if (notState(outputState::PIECE))
121 state_ = outputState::DECLARED;
135 if (isState(outputState::CELL_DATA))
return false;
140 if (notState(outputState::PIECE))
149 if (legacy() && !nFields)
return false;
151 state_ = outputState::CELL_DATA;
172 if (isState(outputState::POINT_DATA))
return false;
177 if (notState(outputState::PIECE))
186 if (legacy() && !nFields)
return false;
188 state_ = outputState::POINT_DATA;
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))
294 contentType_(contentType),
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))
446 state_ = outputState::FIELD_DATA;
456 format().beginFieldData();
466 if (notState(outputState::FIELD_DATA))
471 state_ = outputState::DECLARED;
473 if (format_ && !legacy())
484 if (notState(outputState::CELL_DATA))
489 state_ = outputState::PIECE;
491 if (format_ && !legacy())
502 if (notState(outputState::POINT_DATA))
507 state_ = outputState::PIECE;
509 if (format_ && !legacy())
521 if (isState(outputState::OPENED) || isState(outputState::DECLARED))
525 if (notState(outputState::FIELD_DATA))
532 if (!format_)
return;
540 format().writeTimeValue(timeValue);
554 if (isState(outputState::CELL_DATA))
561 <<
" for procID field" <<
nl <<
endl
575 const label totalCount =
procAddr.totalSize();
577 this->beginDataArray<label>(
"procID", totalCount);
586 for (
const label proci :
procAddr.allProcs())
600 this->endDataArray();
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
globalIndex procAddr(aMesh.nFaces())
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
static bool & parRun() noexcept
Test if this a parallel run.
A class for handling file names.
bool removeExt()
Remove extension, returning true if string changed.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
int myProcNo() const noexcept
Return processor number.
splitCell * master() const
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data)....
bool enter_Piece()
Trigger change state to Piece. Resets nCellData_, nPointData_.
bool enter_CellData(label nEntries, label nFields)
Trigger change state to CellData.
static const Enum< outputState > stateNames
Names for the output state (for messages, not for file output).
void beginPoints(const label nPoints)
Start of a POINTS DataArray.
bool endCellData()
Explicitly end CellData output and switch to PIECE state.
autoPtr< vtk::formatter > format_
The VTK formatter in use (only valid on master process)
void close()
End the file contents and close the file after writing.
bool parallel_
Parallel writing (via master)
void endPoints()
End of a POINTS DataArray.
void checkFormatterValidity() const
Verify that formatter in either allocated or not required.
void endDataArray()
Flush formatter and end of DataArray output (non-legacy)
bool exit_File()
Emit file footer (end data, end piece, end file)
bool enter_PointData(label nEntries, label nFields)
Trigger change state to PointData.
bool endFieldData()
Explicitly end FieldData output and switch to DECLARED state.
bool endPointData()
Explicitly end PointData output and switch to PIECE state.
virtual ~fileWriter()
Destructor.
vtk::outputOptions opts_
Requested output options.
virtual bool beginFile(std::string title="")
Write file header (non-collective)
outputState
Internal tracking of the output state.
Ostream & reportBadState(Ostream &, outputState expected) const
Generate message reporting bad writer state.
bool endPiece()
Explicitly end Piece output and switch to DECLARED state.
void writeTimeValue()
Write the currently set time as "TimeValue" FieldData.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
bool append() const noexcept
True if output format uses an append mode.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
const word fileExtension
Legacy file extension ("vtk")
void beginPoints(std::ostream &os, label nPoints)
Emit header for POINTS (with trailing newline).
void beginCellData(vtk::formatter &fmt, label nCells, label nFields)
Emit legacy CELL_DATA nCells, FIELD FieldData nFields.
void fileHeader(std::ostream &os, const std::string &title, bool binary)
Emit header for legacy file (vtk DataFile Version 2.0)
void beginPointData(vtk::formatter &fmt, label nPoints, label nFields)
Emit legacy POINT_DATA nPoints, FIELD FieldData nFields.
void writeTimeValue(vtk::formatter &fmt, scalar timeValue)
Emit "TimeValue" for a FIELD entry (name as per Catalyst output)
void beginFieldData(vtk::formatter &fmt, label nFields)
Emit legacy FIELD FieldData nFields.
fileTag
Some common XML tags for vtk files.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
const Foam::Enum< fileTag > fileTagNames
Strings corresponding to the vtk XML tags.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Ostream & endl(Ostream &os)
Add newline and flush stream.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
word format(conversionProperties.get< word >("format"))
static constexpr char open