Loading...
Searching...
No Matches
fileWriter Class Referenceabstract

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...

#include <foamVtkFileWriter.H>

Inheritance diagram for fileWriter:
Collaboration diagram for fileWriter:

Public Member Functions

 fileWriter (const vtk::fileTag contentType, const vtk::outputOptions opts)
 Construct from components.
virtual ~fileWriter ()
 Destructor.
vtk::fileTag contentType () const noexcept
 The content type.
vtk::outputOptions opts () const noexcept
 The output options in use.
word ext () const
 File extension for current format type.
bool legacy () const noexcept
 Commonly used query.
bool parallel () const noexcept
 Parallel output requested?
const wordstate () const
 The output state in printable format.
const fileNameoutput () const noexcept
 The current output file name.
virtual bool open (const fileName &file, bool parallel=UPstream::parRun())
 Open file for writing (creates parent directory).
void close ()
 End the file contents and close the file after writing.
virtual bool beginFile (std::string title="")
 Write file header (non-collective).
bool beginFieldData (label nFields=0)
 Begin FieldData output section for specified number of fields.
virtual bool writeGeometry ()=0
 Write mesh topology.
virtual bool beginCellData (label nFields=0)=0
 Begin CellData output section for specified number of fields.
virtual bool beginPointData (label nFields=0)=0
 Begin PointData for specified number of fields.
bool isCellData () const noexcept
 True if output state corresponds to CELL_DATA.
bool isPointData () const noexcept
 True if output state corresponds to POINT_DATA.
label nCellData () const noexcept
 The number of CellData written for the Piece thus far.
label nPointData () const noexcept
 The number of PointData written for the Piece thus far.
bool endFieldData ()
 Explicitly end FieldData output and switch to DECLARED state.
bool endCellData ()
 Explicitly end CellData output and switch to PIECE state.
bool endPointData ()
 Explicitly end PointData output and switch to PIECE state.
void writeTimeValue (scalar timeValue)
 Write "TimeValue" FieldData (name as per Catalyst output).

Protected Types

enum class  outputState : uint8_t {
  CLOSED = 0 , OPENED , DECLARED , FIELD_DATA ,
  PIECE , CELL_DATA , POINT_DATA
}
 Internal tracking of the output state. More...

Protected Member Functions

void checkFormatterValidity () const
 Verify that formatter in either allocated or not required.
OstreamreportBadState (Ostream &, outputState expected) const
 Generate message reporting bad writer state.
OstreamreportBadState (Ostream &, outputState, outputState) const
 Generate message reporting bad writer state.
std::ofstream & os () noexcept
 The backend ostream in use.
vtk::formatterformat ()
 The VTK formatter in use. FatalError for off-processor.
bool isState (outputState test) const noexcept
 True if output state corresponds to the test state.
bool notState (outputState test) const noexcept
 True if output state does not correspond to the test state.
template<class Type>
void beginDataArray (const word &fieldName, const label nValues)
 Start of a field or DataArray output (legacy or non-legacy).
void endDataArray ()
 Flush formatter and end of DataArray output (non-legacy).
void beginPoints (const label nPoints)
 Start of a POINTS DataArray.
void endPoints ()
 End of a POINTS DataArray.
bool enter_Piece ()
 Trigger change state to Piece. Resets nCellData_, nPointData_.
bool endPiece ()
 Explicitly end Piece output and switch to DECLARED state.
bool enter_CellData (label nEntries, label nFields)
 Trigger change state to CellData.
bool enter_PointData (label nEntries, label nFields)
 Trigger change state to PointData.
bool exit_File ()
 Emit file footer (end data, end piece, end file).
template<class Type>
void writeUniform (const word &fieldName, const Type &val, const label nValues)
 Write uniform field content.
template<class Type>
void writeBasicField (const word &fieldName, const UList< Type > &field)
 Write basic (primitive) field content.
bool writeProcIDs (const label nValues)
 Write nValues of processor ids as CellData or PointData (no-op in serial).
 fileWriter (const fileWriter &)=delete
 No copy construct.
void operator= (const fileWriter &)=delete
 No copy assignment.

Protected Attributes

outputState state_
 The output state.
vtk::fileTag contentType_
 The content type (PolyData, UnstructuredGrid ...).
bool parallel_
 Parallel writing (via master).
vtk::outputOptions opts_
 Requested output options.
label nCellData_
 The number of CellData written for the Piece thus far.
label nPointData_
 The number of PointData written for the Piece thus far.
fileName outputFile_
 The output file name.
autoPtr< vtk::formatterformat_
 The VTK formatter in use (only valid on master process).
std::ofstream os_
 The backend ostream in use (only opened on master process).

Static Protected Attributes

static const Enum< outputStatestateNames
 Names for the output state (for messages, not for file output).

Detailed Description

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.

Source files

Definition at line 65 of file foamVtkFileWriter.H.

Member Enumeration Documentation

◆ outputState

enum class outputState : uint8_t
strongprotected

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 74 of file foamVtkFileWriter.H.

Constructor & Destructor Documentation

◆ fileWriter() [1/2]

fileWriter ( const fileWriter & )
protecteddelete

No copy construct.

References fileWriter().

Referenced by fileWriter(), fileWriter(), operator=(), and ~fileWriter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fileWriter() [2/2]

fileWriter ( const vtk::fileTag contentType,
const vtk::outputOptions opts )

Construct from components.

References contentType(), fileWriter(), and opts().

Here is the call graph for this function:

◆ ~fileWriter()

virtual ~fileWriter ( )
virtual

Destructor.

References contentType(), ext(), fileWriter(), legacy(), Foam::noexcept, opts(), output(), parallel(), and state().

Here is the call graph for this function:

Member Function Documentation

◆ checkFormatterValidity()

void checkFormatterValidity ( ) const
protected

Verify that formatter in either allocated or not required.

◆ reportBadState() [1/2]

Ostream & reportBadState ( Ostream & ,
outputState expected ) const
protected

Generate message reporting bad writer state.

◆ reportBadState() [2/2]

Ostream & reportBadState ( Ostream & ,
outputState ,
outputState  ) const
protected

Generate message reporting bad writer state.

References format(), isState(), Foam::noexcept, and notState().

Here is the call graph for this function:

◆ os()

std::ofstream & os ( )
inlineprotectednoexcept

The backend ostream in use.

Definition at line 23 of file foamVtkFileWriterI.H.

References Foam::noexcept, and os_.

◆ format()

Foam::vtk::formatter & format ( )
inlineprotected

The VTK formatter in use. FatalError for off-processor.

Definition at line 29 of file foamVtkFileWriterI.H.

References format_.

Referenced by reportBadState().

Here is the caller graph for this function:

◆ isState()

bool isState ( outputState test) const
inlineprotectednoexcept

True if output state corresponds to the test state.

Definition at line 35 of file foamVtkFileWriterI.H.

References state_.

Referenced by reportBadState().

Here is the caller graph for this function:

◆ notState()

bool notState ( outputState test) const
inlineprotectednoexcept

True if output state does not correspond to the test state.

Definition at line 41 of file foamVtkFileWriterI.H.

References state_.

Referenced by reportBadState().

Here is the caller graph for this function:

◆ beginDataArray()

template<class Type>
void beginDataArray ( const word & fieldName,
const label nValues )
protected

Start of a field or DataArray output (legacy or non-legacy).

References beginDataArray().

Referenced by beginDataArray().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endDataArray()

void endDataArray ( )
protected

Flush formatter and end of DataArray output (non-legacy).

References endDataArray().

Referenced by endDataArray().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginPoints()

void beginPoints ( const label nPoints)
protected

Start of a POINTS DataArray.

References beginPoints(), and nPoints.

Referenced by beginPoints().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endPoints()

void endPoints ( )
protected

End of a POINTS DataArray.

References endPoints().

Referenced by endPoints().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter_Piece()

bool enter_Piece ( )
protected

Trigger change state to Piece. Resets nCellData_, nPointData_.

References enter_Piece().

Referenced by enter_Piece().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endPiece()

bool endPiece ( )
protected

Explicitly end Piece output and switch to DECLARED state.

Ignored (no-op) if not currently in the PIECE state.

References endPiece().

Referenced by endPiece().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter_CellData()

bool enter_CellData ( label nEntries,
label nFields )
protected

Trigger change state to CellData.

Legacy requires both parameters. XML doesn't require either.

Returns
True if the state changed

References enter_CellData().

Referenced by enter_CellData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter_PointData()

bool enter_PointData ( label nEntries,
label nFields )
protected

Trigger change state to PointData.

Legacy requires both parameters. XML doesn't require either.

Returns
True if the state changed

References enter_PointData().

Referenced by enter_PointData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exit_File()

bool exit_File ( )
protected

Emit file footer (end data, end piece, end file).

References exit_File().

Referenced by exit_File().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeUniform()

template<class Type>
void writeUniform ( const word & fieldName,
const Type & val,
const label nValues )
protected

Write uniform field content.

No context checking (eg, file-open, CellData, PointData, etc) The value and count can be different on each processor

References writeUniform().

Referenced by writeUniform().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeBasicField()

template<class Type>
void writeBasicField ( const word & fieldName,
const UList< Type > & field )
protected

Write basic (primitive) field content.

No context checking (eg, file-open, CellData, PointData, etc)

References field(), and writeBasicField().

Referenced by writeBasicField().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeProcIDs()

bool writeProcIDs ( const label nValues)
protected

Write nValues of processor ids as CellData or PointData (no-op in serial).

References writeProcIDs().

Referenced by writeProcIDs(), and GenericPatchWriter< indirectPrimitivePatch >::writeProcIDs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

void operator= ( const fileWriter & )
protecteddelete

No copy assignment.

References fileWriter().

Here is the call graph for this function:

◆ contentType()

Foam::vtk::fileTag contentType ( ) const
inlinenoexcept

The content type.

Definition at line 49 of file foamVtkFileWriterI.H.

References contentType_, and Foam::noexcept.

Referenced by fileWriter(), and ~fileWriter().

Here is the caller graph for this function:

◆ opts()

◆ ext()

Foam::word ext ( ) const
inline

File extension for current format type.

Definition at line 61 of file foamVtkFileWriterI.H.

References contentType_, and opts_.

Referenced by vtkWriter::write(), ~fileWriter(), internalMeshWriter::~internalMeshWriter(), lagrangianWriter::~lagrangianWriter(), patchMeshWriter::~patchMeshWriter(), polyWriter::~polyWriter(), and surfaceFieldWriter::~surfaceFieldWriter().

Here is the caller graph for this function:

◆ legacy()

bool legacy ( ) const
inlinenoexcept

Commonly used query.

Definition at line 67 of file foamVtkFileWriterI.H.

References Foam::noexcept, and opts_.

Referenced by ~fileWriter().

Here is the caller graph for this function:

◆ parallel()

◆ state()

const Foam::word & state ( ) const
inline

The output state in printable format.

Definition at line 79 of file foamVtkFileWriterI.H.

References state_, and stateNames.

Referenced by ~fileWriter().

Here is the caller graph for this function:

◆ output()

const Foam::fileName & output ( ) const
inlinenoexcept

The current output file name.

Definition at line 85 of file foamVtkFileWriterI.H.

References Foam::noexcept, and outputFile_.

Referenced by ~fileWriter().

Here is the caller graph for this function:

◆ open()

virtual bool open ( const fileName & file,
bool parallel = UPstream::parRun() )
virtual

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.

Note
Expected calling states: (CLOSED).

Reimplemented in coordSetWriter.

References open(), and parallel().

Referenced by open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close()

void close ( )

End the file contents and close the file after writing.

Note
Expected calling states: (PIECE | CELL_DATA | POINT_DATA).

References close().

Referenced by close(), and topOVariablesBase::writeSurfaceFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginFile()

virtual bool beginFile ( std::string title = "")
virtual

Write file header (non-collective).

Note
Expected calling states: (OPENED)

Reimplemented in coordSetWriter, GenericPatchWriter< PatchType >, GenericPatchWriter< indirectPrimitivePatch >, GenericPatchWriter< primitivePatch >, GenericPatchWriter< uindirectPrimitivePatch >, internalMeshWriter, lagrangianWriter, lineWriter, patchMeshWriter, surfaceFieldWriter, and surfaceWriter.

References beginFile().

Referenced by beginFile(), and GenericPatchWriter< indirectPrimitivePatch >::beginFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginFieldData()

bool beginFieldData ( label nFields = 0)

Begin FieldData output section for specified number of fields.

Parameters
nFieldsis for legacy format only. When nFields=0, this a no-op for legacy format.
Note
Expected calling states: (OPENED | DECLARED).

References beginFieldData().

Referenced by beginFieldData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeGeometry()

virtual bool writeGeometry ( )
pure virtual

Write mesh topology.

Also writes the file header if not previously written.

Note
Must be called prior to writing CellData or PointData

Implemented in coordSetWriter, GenericPatchWriter< PatchType >, GenericPatchWriter< indirectPrimitivePatch >, GenericPatchWriter< primitivePatch >, GenericPatchWriter< uindirectPrimitivePatch >, internalMeshWriter, lagrangianWriter, lineWriter, patchMeshWriter, polyWriter, surfaceFieldWriter, and surfaceWriter.

References writeGeometry().

Referenced by writeGeometry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginCellData()

virtual bool beginCellData ( label nFields = 0)
pure virtual

Begin CellData output section for specified number of fields.

Must be called prior to writing any cell data fields.

Parameters
nFieldsis for legacy format only. When nFields=0, this a no-op for legacy format.
Note
Expected calling states: (PIECE | POINT_DATA).
Returns
True if the state changed

Implemented in internalMeshWriter, lagrangianWriter, patchMeshWriter, polyWriter, and surfaceFieldWriter.

References beginCellData().

Referenced by beginCellData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginPointData()

virtual bool beginPointData ( label nFields = 0)
pure virtual

Begin PointData for specified number of fields.

Must be called prior to writing any point data fields.

Parameters
nFieldsis for legacy format only. When nFields=0, this a no-op for legacy format.
Note
Expected calling states: (PIECE | CELL_DATA).
Returns
True if the state changed

Implemented in internalMeshWriter, lagrangianWriter, patchMeshWriter, polyWriter, and surfaceFieldWriter.

References beginPointData(), isCellData(), isPointData(), nCellData(), Foam::noexcept, and nPointData().

Referenced by beginPointData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCellData()

bool isCellData ( ) const
inlinenoexcept

True if output state corresponds to CELL_DATA.

Definition at line 103 of file foamVtkFileWriterI.H.

References CELL_DATA, Foam::noexcept, and state_.

Referenced by beginPointData().

Here is the caller graph for this function:

◆ isPointData()

bool isPointData ( ) const
inlinenoexcept

True if output state corresponds to POINT_DATA.

Definition at line 109 of file foamVtkFileWriterI.H.

References Foam::noexcept, POINT_DATA, and state_.

Referenced by beginPointData(), and GenericPatchWriter< indirectPrimitivePatch >::writeProcIDs().

Here is the caller graph for this function:

◆ nCellData()

Foam::label nCellData ( ) const
inlinenoexcept

The number of CellData written for the Piece thus far.

Definition at line 91 of file foamVtkFileWriterI.H.

References nCellData_, and Foam::noexcept.

Referenced by beginPointData().

Here is the caller graph for this function:

◆ nPointData()

Foam::label nPointData ( ) const
inlinenoexcept

The number of PointData written for the Piece thus far.

Definition at line 97 of file foamVtkFileWriterI.H.

References Foam::noexcept, and nPointData_.

Referenced by beginPointData().

Here is the caller graph for this function:

◆ endFieldData()

bool endFieldData ( )

Explicitly end FieldData output and switch to DECLARED state.

Ignored (no-op) if not currently in the FIELD_DATA state.

References endFieldData().

Referenced by endFieldData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endCellData()

bool endCellData ( )

Explicitly end CellData output and switch to PIECE state.

Ignored (no-op) if not currently in the CELL_DATA state.

References endCellData().

Referenced by endCellData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endPointData()

bool endPointData ( )

Explicitly end PointData output and switch to PIECE state.

Ignored (no-op) if not currently in the POINT_DATA state.

References endPointData().

Referenced by endPointData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeTimeValue()

void writeTimeValue ( scalar timeValue)

Write "TimeValue" FieldData (name as per Catalyst output).

Must be called within the FIELD_DATA state.

Note
As a convenience this can also be called from (OPENED | DECLARED) states, in which case it invokes beginFieldData(1) internally.

References writeTimeValue().

Referenced by coordSetWriter::writeGeometry(), lineWriter::writeGeometry(), surfaceWriter::writeGeometry(), and writeTimeValue().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ stateNames

const Enum<outputState> stateNames
staticprotected

Names for the output state (for messages, not for file output).

Definition at line 88 of file foamVtkFileWriter.H.

Referenced by state().

◆ state_

outputState state_
protected

The output state.

Definition at line 94 of file foamVtkFileWriter.H.

Referenced by isCellData(), isPointData(), isState(), notState(), and state().

◆ contentType_

vtk::fileTag contentType_
protected

The content type (PolyData, UnstructuredGrid ...).

Definition at line 99 of file foamVtkFileWriter.H.

Referenced by contentType(), and ext().

◆ parallel_

bool parallel_
protected

Parallel writing (via master).

Definition at line 104 of file foamVtkFileWriter.H.

Referenced by parallel().

◆ opts_

vtk::outputOptions opts_
protected

Requested output options.

Definition at line 109 of file foamVtkFileWriter.H.

Referenced by ext(), legacy(), and opts().

◆ nCellData_

label nCellData_
protected

The number of CellData written for the Piece thus far.

Definition at line 114 of file foamVtkFileWriter.H.

Referenced by nCellData().

◆ nPointData_

label nPointData_
protected

The number of PointData written for the Piece thus far.

Definition at line 119 of file foamVtkFileWriter.H.

Referenced by nPointData().

◆ outputFile_

fileName outputFile_
protected

The output file name.

Definition at line 124 of file foamVtkFileWriter.H.

Referenced by output().

◆ format_

autoPtr<vtk::formatter> format_
protected

The VTK formatter in use (only valid on master process).

Definition at line 129 of file foamVtkFileWriter.H.

Referenced by format().

◆ os_

std::ofstream os_
protected

The backend ostream in use (only opened on master process).

Definition at line 134 of file foamVtkFileWriter.H.

Referenced by os().


The documentation for this class was generated from the following files: