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] <<
')';
79 outputState expected1,
83 reportBadState(
os, expected1)
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 state_(outputState::CLOSED),
294 contentType_(contentType),
320 if (notState(outputState::CLOSED))
328 format_.reset(
nullptr);
331 nCellData_ = nPointData_ = 0;
345 if (!outputFile_.has_ext(ext()))
348 outputFile_.ext(ext());
364 mkDir(outputFile_.path());
366 os_.open(outputFile_);
368 format_ = opts_.newFormatter(os_);
371 state_ = outputState::OPENED;
382 format_.reset(
nullptr);
386 state_ = outputState::CLOSED;
388 nCellData_ = nPointData_ = 0;
394 if (isState(outputState::DECLARED))
399 if (notState(outputState::OPENED))
404 state_ = outputState::DECLARED;
420 format().xmlComment(title);
423 format().beginVTKFile(contentType_);
434 if (legacy() && !nFields)
return false;
436 if (isState(outputState::OPENED))
440 if (notState(outputState::DECLARED))
455 format().beginFieldData();
470 state_ = outputState::DECLARED;
472 if (format_ && !legacy())
490 if (format_ && !legacy())
508 if (format_ && !legacy())
520 if (isState(outputState::OPENED) || isState(outputState::DECLARED))
531 if (!format_)
return;
539 format().writeTimeValue(timeValue);
568 ) <<
" for procID field" <<
nl <<
endl 578 ? globalIndex(globalIndex::gatherOnly{}, nValues)
579 : globalIndex(globalIndex::gatherNone{}, nValues)
582 const label totalCount =
procAddr.totalSize();
584 this->beginDataArray<label>(
"procID", totalCount);
593 for (
const label proci :
procAddr.allProcs())
607 this->endDataArray();
autoPtr< vtk::formatter > format_
The VTK formatter in use (only valid on master process)
A class for handling file names.
void checkFormatterValidity() const
Verify that formatter in either allocated or not required.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool append() const noexcept
True if output format uses an append mode.
const word fileExtension
Legacy file extension ("vtk")
vtk::outputOptions opts_
Requested output options.
constexpr char nl
The newline '\n' character (0x0a)
void endDataArray()
Flush formatter and end of DataArray output (non-legacy)
bool enter_CellData(label nEntries, label nFields)
Trigger change state to CellData.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
bool enter_PointData(label nEntries, label nFields)
Trigger change state to PointData.
void beginFieldData(vtk::formatter &fmt, label nFields)
Emit legacy FIELD FieldData nFields.
void beginPointData(vtk::formatter &fmt, label nPoints, label nFields)
Emit legacy POINT_DATA nPoints, FIELD FieldData nFields.
void writeTimeValue(scalar timeValue)
Write "TimeValue" FieldData (name as per Catalyst output)
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
outputState
Internal tracking of the output state.
fileWriter(const fileWriter &)=delete
No copy construct.
bool endFieldData()
Explicitly end FieldData output and switch to DECLARED state.
bool parallel_
Parallel writing (via master)
void endPoints()
End of a POINTS DataArray.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Ostream & reportBadState(Ostream &, outputState expected) const
Generate message reporting bad writer state.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
void beginPoints(std::ostream &os, label nPoints)
Emit header for POINTS (with trailing newline).
virtual ~fileWriter()
Destructor.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
bool enter_Piece()
Trigger change state to Piece. Resets nCellData_, nPointData_.
void fileHeader(std::ostream &os, const std::string &title, bool binary)
Emit header for legacy file (vtk DataFile Version 2.0)
bool writeProcIDs(const label nValues)
Write nValues of processor ids as CellData or PointData (no-op in serial)
void writeTimeValue(vtk::formatter &fmt, scalar timeValue)
Emit "TimeValue" for a FIELD entry (name as per Catalyst output)
bool endCellData()
Explicitly end CellData output and switch to PIECE state.
void beginCellData(vtk::formatter &fmt, label nCells, label nFields)
Emit legacy CELL_DATA nCells, FIELD FieldData nFields.
bool endPointData()
Explicitly end PointData output and switch to PIECE state.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
virtual bool open(const fileName &file, bool parallel=UPstream::parRun())
Open file for writing (creates parent directory).
bool remove_ext()
Remove extension, returning true if string changed.
const Foam::Enum< fileTag > fileTagNames
Strings corresponding to the vtk XML tags.
bool beginFieldData(label nFields=0)
Begin FieldData output section for specified number of fields.
word format(conversionProperties.get< word >("format"))
virtual bool beginFile(std::string title="")
Write file header (non-collective)
void beginPoints(const label nPoints)
Start of a POINTS DataArray.
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
#define WarningInFunction
Report a warning using Foam::Warning.
fileTag
Some common XML tags for vtk files.
globalIndex procAddr(aMesh.nFaces())
static const Enum< outputState > stateNames
Names for the output state (for messages, not for file output).
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.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
bool endPiece()
Explicitly end Piece output and switch to DECLARED state.
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
bool exit_File()
Emit file footer (end data, end piece, end file)