Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data). These output formats are structured as DECLARED, FIELD_DATA, PIECE followed by any CELL_DATA or POINT_DATA. More...
Public Member Functions | |
fileWriter (const vtk::fileTag contentType, const vtk::outputOptions opts) | |
Construct from components. More... | |
virtual | ~fileWriter () |
Destructor. More... | |
vtk::fileTag | contentType () const |
The content type. More... | |
vtk::outputOptions | opts () const |
The output options in use. More... | |
word | ext () const |
File extension for current format type. More... | |
bool | legacy () const |
Commonly used query. More... | |
bool | parallel () const |
Parallel output requested? More... | |
const word & | state () const |
The output state in printable format. More... | |
const fileName & | output () const |
The current output file name. More... | |
bool | open (const fileName &file, bool parallel=Pstream::parRun()) |
Open file for writing (creates parent directory). More... | |
void | close () |
End the file contents and close the file after writing. More... | |
virtual bool | beginFile (std::string title="") |
Write file header (non-collective) More... | |
bool | beginFieldData (label nFields=0) |
Begin FieldData output section for specified number of fields. More... | |
virtual bool | writeGeometry ()=0 |
Write mesh topology. More... | |
virtual bool | beginCellData (label nFields=0)=0 |
Begin CellData output section for specified number of fields. More... | |
virtual bool | beginPointData (label nFields=0)=0 |
Begin PointData for specified number of fields. More... | |
label | nCellData () const |
Return the number of CellData written for the Piece thus far. More... | |
label | nPointData () const |
Return the number of PointData written for the Piece thus far. More... | |
bool | endFieldData () |
Explicitly end FieldData output and switch to DECLARED state. More... | |
bool | endCellData () |
Explicitly end CellData output and switch to PIECE state. More... | |
bool | endPointData () |
Explicitly end PointData output and switch to PIECE state. More... | |
void | writeTimeValue (scalar timeValue) |
Write "TimeValue" FieldData (name as per Catalyst output) More... | |
Protected Types | |
enum | outputState { CLOSED = 0, OPENED, DECLARED, FIELD_DATA, PIECE, CELL_DATA, POINT_DATA } |
Internal tracking of the output state. More... | |
Protected Member Functions | |
std::ofstream & | os () |
The backend ostream in use. More... | |
vtk::formatter & | format () |
The VTK formatter in use. More... | |
bool | isState (outputState test) const |
True if the output state corresponds to the test state. More... | |
bool | notState (outputState test) const |
True if the output state does not correspond to the test state. More... | |
template<class Type > | |
void | writeUniform (const word &fieldName, const Type &val, const label nValues) |
Write uniform field content. More... | |
bool | enter_Piece () |
Trigger change state to Piece. Resets nCellData_, nPointData_. More... | |
bool | endPiece () |
Explicitly end Piece output and switch to DECLARED state. More... | |
bool | enter_CellData (label nEntries, label nFields) |
Trigger change state to CellData. More... | |
bool | enter_PointData (label nEntries, label nFields) |
Trigger change state to PointData. More... | |
bool | exit_File () |
Emit file footer (end data, end piece, end file) More... | |
fileWriter (const fileWriter &)=delete | |
No copy construct. More... | |
void | operator= (const fileWriter &)=delete |
No copy assignment. More... | |
Protected Attributes | |
vtk::fileTag | contentType_ |
The content type. More... | |
outputOptions | opts_ |
The requested output options. More... | |
bool | parallel_ |
Writing in parallel (via master) More... | |
outputState | state_ |
The output state. More... | |
label | nCellData_ |
The number of CellData written for the Piece thus far. More... | |
label | nPointData_ |
The number of PointData written for the Piece thus far. More... | |
fileName | outputFile_ |
The output file name. More... | |
autoPtr< vtk::formatter > | format_ |
The VTK formatter in use (master process) More... | |
std::ofstream | os_ |
The backend ostream in use (master process) More... | |
Static Protected Attributes | |
static const Enum< outputState > | stateNames |
Names for the output state (for messages, not for file output). More... | |
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data). These output formats are structured as DECLARED, FIELD_DATA, PIECE followed by any CELL_DATA or POINT_DATA.
This writer base tracks these expected output states internally to help avoid logic errors in the callers.
The FieldData element must be placed prior to writing any geometry Piece. This moves the information to the front of the output file for visibility and simplifies the logic when creating multi-piece geometries.
Definition at line 66 of file foamVtkFileWriter.H.
|
protected |
Internal tracking of the output state.
Enumerator | |
---|---|
CLOSED | File is closed. |
OPENED | File is opened. |
DECLARED | File contents declared (VTKFile header written) |
FIELD_DATA | Inside FieldData. |
PIECE | Inside Piece (after geometry write) |
CELL_DATA | Inside CellData. |
POINT_DATA | Inside PointData. |
Definition at line 73 of file foamVtkFileWriter.H.
|
protecteddelete |
No copy construct.
fileWriter | ( | const vtk::fileTag | contentType, |
const vtk::outputOptions | opts | ||
) |
Construct from components.
Definition at line 210 of file foamVtkFileWriter.C.
|
virtual |
Destructor.
Definition at line 232 of file foamVtkFileWriter.C.
|
inlineprotected |
The backend ostream in use.
Definition at line 30 of file foamVtkFileWriterI.H.
References fileWriter::os_.
|
inlineprotected |
The VTK formatter in use.
Definition at line 36 of file foamVtkFileWriterI.H.
Referenced by patchMeshWriter::beginPiece(), and lagrangianWriter::write().
|
inlineprotected |
True if the output state corresponds to the test state.
Definition at line 42 of file foamVtkFileWriterI.H.
Referenced by fileWriter::enter_Piece(), and lagrangianWriter::write().
|
inlineprotected |
True if the output state does not correspond to the test state.
Definition at line 48 of file foamVtkFileWriterI.H.
Referenced by fileWriter::enter_Piece().
|
protected |
Write uniform field content.
No context checking (eg, file-open, CellData, PointData, etc)
Definition at line 35 of file foamVtkFileWriterTemplates.C.
References format(), and Foam::vtk::write().
|
protected |
Trigger change state to Piece. Resets nCellData_, nPointData_.
Definition at line 51 of file foamVtkFileWriter.C.
References fileWriter::beginFile(), fileWriter::endFieldData(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, fileWriter::isState(), fileWriter::nCellData_, fileWriter::notState(), fileWriter::nPointData_, Foam::vtk::PIECE, fileWriter::state_, and fileWriter::stateNames.
|
protected |
Explicitly end Piece output and switch to DECLARED state.
Ignored (no-op) if not currently in the PIECE state.
Definition at line 74 of file foamVtkFileWriter.C.
References format(), and Foam::vtk::PIECE.
|
protected |
Trigger change state to CellData.
Legacy requires both parameters. XML doesn't require either.
Definition at line 96 of file foamVtkFileWriter.C.
References Foam::vtk::legacy::beginCellData(), Foam::vtk::CELL_DATA, Foam::exit(), Foam::FatalError, FatalErrorInFunction, format(), and Foam::vtk::PIECE.
|
protected |
Trigger change state to PointData.
Legacy requires both parameters. XML doesn't require either.
Definition at line 135 of file foamVtkFileWriter.C.
References Foam::vtk::legacy::beginPointData(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, format(), Foam::vtk::PIECE, and Foam::vtk::POINT_DATA.
|
protected |
Emit file footer (end data, end piece, end file)
Definition at line 174 of file foamVtkFileWriter.C.
References Foam::endl(), Foam::vtk::fileTagNames, format(), Foam::nl, and WarningInFunction.
|
protecteddelete |
No copy assignment.
|
inline |
The content type.
Definition at line 56 of file foamVtkFileWriterI.H.
|
inline |
The output options in use.
Definition at line 62 of file foamVtkFileWriterI.H.
Referenced by indirectPatchWriter::ext(), patchMeshWriter::ext(), surfaceWriter::ext(), and internalMeshWriter::ext().
|
inline |
File extension for current format type.
Definition at line 68 of file foamVtkFileWriterI.H.
References word::ext().
Referenced by vtkWriter::write().
|
inline |
Commonly used query.
Definition at line 74 of file foamVtkFileWriterI.H.
Referenced by patchMeshWriter::beginPiece(), lagrangianWriter::lagrangianWriter(), and surfaceFieldWriter::surfaceFieldWriter().
|
inline |
Parallel output requested?
Definition at line 80 of file foamVtkFileWriterI.H.
|
inline |
The output state in printable format.
Definition at line 86 of file foamVtkFileWriterI.H.
|
inline |
The current output file name.
Definition at line 92 of file foamVtkFileWriterI.H.
bool open | ( | const fileName & | file, |
bool | parallel = Pstream::parRun() |
||
) |
Open file for writing (creates parent directory).
The file name is normally without an extension, this will be added according to the content-type and the output format (legacy/xml). If the file name has an extension, it will be used where if appropriate or changed to suit the format (legacy/xml) type.
Definition at line 240 of file foamVtkFileWriter.C.
References Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::vtk::fileExtension, Foam::vtk::legacy::fileExtension, UPstream::master(), Foam::mkDir(), UPstream::parRun(), and fileName::removeExt().
void close | ( | ) |
End the file contents and close the file after writing.
Definition at line 301 of file foamVtkFileWriter.C.
|
virtual |
Write file header (non-collective)
Reimplemented in lagrangianWriter, patchMeshWriter, surfaceWriter, internalMeshWriter, indirectPatchWriter, and surfaceFieldWriter.
Definition at line 317 of file foamVtkFileWriter.C.
References Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::vtk::legacy::fileHeader(), and format().
Referenced by surfaceFieldWriter::beginFile(), indirectPatchWriter::beginFile(), surfaceWriter::beginFile(), internalMeshWriter::beginFile(), patchMeshWriter::beginFile(), lagrangianWriter::beginFile(), and fileWriter::enter_Piece().
bool beginFieldData | ( | label | nFields = 0 | ) |
Begin FieldData output section for specified number of fields.
nFields | is for legacy format only. When nFields=0, this a no-op for legacy format. |
Definition at line 358 of file foamVtkFileWriter.C.
References Foam::vtk::legacy::beginFieldData(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::vtk::FIELD_DATA, and format().
|
pure virtual |
Write mesh topology.
Also writes the file header if not previously written.
Implemented in lagrangianWriter, patchMeshWriter, surfaceWriter, internalMeshWriter, indirectPatchWriter, and surfaceFieldWriter.
|
pure virtual |
Begin CellData output section for specified number of fields.
Must be called prior to writing any cell data fields.
nFields | is for legacy format only. When nFields=0, this a no-op for legacy format. |
Implemented in patchMeshWriter, surfaceWriter, internalMeshWriter, indirectPatchWriter, surfaceFieldWriter, and lagrangianWriter.
|
pure virtual |
Begin PointData for specified number of fields.
Must be called prior to writing any point data fields.
nFields | is for legacy format only. When nFields=0, this a no-op for legacy format. |
Implemented in patchMeshWriter, surfaceWriter, internalMeshWriter, indirectPatchWriter, surfaceFieldWriter, and lagrangianWriter.
|
inline |
Return the number of CellData written for the Piece thus far.
Definition at line 98 of file foamVtkFileWriterI.H.
|
inline |
Return the number of PointData written for the Piece thus far.
Definition at line 104 of file foamVtkFileWriterI.H.
bool endFieldData | ( | ) |
Explicitly end FieldData output and switch to DECLARED state.
Ignored (no-op) if not currently in the FIELD_DATA state.
Definition at line 392 of file foamVtkFileWriter.C.
References Foam::vtk::FIELD_DATA, and format().
Referenced by fileWriter::enter_Piece().
bool endCellData | ( | ) |
Explicitly end CellData output and switch to PIECE state.
Ignored (no-op) if not currently in the CELL_DATA state.
Definition at line 410 of file foamVtkFileWriter.C.
References Foam::vtk::CELL_DATA, format(), and Foam::vtk::PIECE.
bool endPointData | ( | ) |
Explicitly end PointData output and switch to PIECE state.
Ignored (no-op) if not currently in the POINT_DATA state.
Definition at line 428 of file foamVtkFileWriter.C.
References format(), Foam::vtk::PIECE, and Foam::vtk::POINT_DATA.
void writeTimeValue | ( | scalar | timeValue | ) |
Write "TimeValue" FieldData (name as per Catalyst output)
Must be called within the FIELD_DATA state.
Definition at line 446 of file foamVtkFileWriter.C.
References Foam::vtk::legacy::beginFieldData(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::vtk::FIELD_DATA, format(), and Foam::vtk::legacy::writeTimeValue().
Referenced by surfaceWriter::writeTimeValue().
|
staticprotected |
Names for the output state (for messages, not for file output).
Definition at line 85 of file foamVtkFileWriter.H.
Referenced by fileWriter::enter_Piece(), and lagrangianWriter::write().
|
protected |
The content type.
Definition at line 89 of file foamVtkFileWriter.H.
|
protected |
The requested output options.
Definition at line 92 of file foamVtkFileWriter.H.
|
protected |
Writing in parallel (via master)
Definition at line 95 of file foamVtkFileWriter.H.
Referenced by patchMeshWriter::beginPiece(), and lagrangianWriter::write().
|
protected |
The output state.
Definition at line 98 of file foamVtkFileWriter.H.
Referenced by fileWriter::enter_Piece(), and lagrangianWriter::write().
|
protected |
The number of CellData written for the Piece thus far.
Definition at line 101 of file foamVtkFileWriter.H.
Referenced by fileWriter::enter_Piece(), and lagrangianWriter::write().
|
protected |
The number of PointData written for the Piece thus far.
Definition at line 104 of file foamVtkFileWriter.H.
Referenced by fileWriter::enter_Piece(), and lagrangianWriter::write().
|
protected |
The output file name.
Definition at line 107 of file foamVtkFileWriter.H.
|
protected |
The VTK formatter in use (master process)
Definition at line 110 of file foamVtkFileWriter.H.
Referenced by patchMeshWriter::beginPiece(), and lagrangianWriter::write().
|
protected |
The backend ostream in use (master process)
Definition at line 113 of file foamVtkFileWriter.H.
Referenced by fileWriter::os().