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

Inheritance diagram for fileWriter:
[legend]
Collaboration diagram for fileWriter:
[legend]

Public Member Functions

 fileWriter (const vtk::fileTag contentType, const vtk::outputOptions opts)
 Construct from components. More...
 
virtual ~fileWriter ()
 Destructor. More...
 
vtk::fileTag contentType () const noexcept
 The content type. More...
 
vtk::outputOptions opts () const noexcept
 The output options in use. More...
 
word ext () const
 File extension for current format type. More...
 
bool legacy () const noexcept
 Commonly used query. More...
 
bool parallel () const noexcept
 Parallel output requested? More...
 
const wordstate () const
 The output state in printable format. More...
 
const fileNameoutput () const noexcept
 The current output file name. More...
 
virtual 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 noexcept
 Return the number of CellData written for the Piece thus far. More...
 
label nPointData () const noexcept
 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 : 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. More...
 
OstreamreportBadState (Ostream &, outputState expected) const
 Generate message reporting bad writer state. More...
 
OstreamreportBadState (Ostream &, outputState, outputState) const
 Generate message reporting bad writer state. More...
 
std::ofstream & os () noexcept
 The backend ostream in use. More...
 
vtk::formatterformat ()
 The VTK formatter in use. FatalError for off-processor. More...
 
bool isState (outputState test) const noexcept
 True if output state corresponds to the test state. More...
 
bool notState (outputState test) const noexcept
 True if output state does not correspond to the test state. More...
 
template<class Type >
void beginDataArray (const word &fieldName, const label nValues)
 Start of a field or DataArray output (legacy or non-legacy). More...
 
void endDataArray ()
 Flush formatter and end of DataArray output (non-legacy) More...
 
void beginPoints (const label nPoints)
 Start of a POINTS DataArray. More...
 
void endPoints ()
 End of a POINTS DataArray. 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...
 
template<class Type >
void writeUniform (const word &fieldName, const Type &val, const label nValues)
 Write uniform field content. More...
 
template<class Type >
void writeBasicField (const word &fieldName, const UList< Type > &field)
 Write basic (primitive) field content. More...
 
bool writeProcIDs (const label nValues)
 Write nValues of processor ids as CellData (no-op in serial) More...
 
 fileWriter (const fileWriter &)=delete
 No copy construct. More...
 
void operator= (const fileWriter &)=delete
 No copy assignment. More...
 

Protected Attributes

outputState state_
 The output state. More...
 
vtk::fileTag contentType_
 The content type (PolyData, UnstructuredGrid ...) More...
 
bool parallel_
 Parallel writing (via master) More...
 
vtk::outputOptions opts_
 Requested output options. 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::formatterformat_
 The VTK formatter in use (only valid on master process) More...
 
std::ofstream os_
 The backend ostream in use (only opened on master process) More...
 

Static Protected Attributes

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

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

Member Enumeration Documentation

◆ outputState

enum outputState : uint8_t
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 75 of file foamVtkFileWriter.H.

Constructor & Destructor Documentation

◆ fileWriter() [1/2]

fileWriter ( const fileWriter )
protecteddelete

No copy construct.

◆ fileWriter() [2/2]

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

Construct from components.

Definition at line 287 of file foamVtkFileWriter.C.

References outputOptions::append(), and fileWriter::opts_.

Here is the call graph for this function:

◆ ~fileWriter()

~fileWriter ( )
virtual

Destructor.

Definition at line 310 of file foamVtkFileWriter.C.

Member Function Documentation

◆ checkFormatterValidity()

void checkFormatterValidity ( ) const
protected

Verify that formatter in either allocated or not required.

Definition at line 52 of file foamVtkFileWriter.C.

References Foam::endl(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, fileWriter::format_, splitCell::master(), and fileWriter::parallel_.

Here is the call graph for this function:

◆ reportBadState() [1/2]

Foam::Ostream & reportBadState ( Ostream os,
outputState  expected 
) const
protected

Generate message reporting bad writer state.

Definition at line 64 of file foamVtkFileWriter.C.

References os().

Referenced by internalWriter::write(), patchWriter::write(), lagrangianWriter::write(), coordSetWriter::writePointData(), internalMeshWriter::writeUniform(), patchMeshWriter::writeUniform(), and polyWriter::writeUniformValue().

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

◆ reportBadState() [2/2]

Foam::Ostream & reportBadState ( Ostream os,
outputState  expected,
outputState  expected2 
) const
protected

Generate message reporting bad writer state.

Definition at line 76 of file foamVtkFileWriter.C.

References os().

Here is the call graph for this function:

◆ os()

std::ofstream & os ( )
inlineprotectednoexcept

The backend ostream in use.

Definition at line 30 of file foamVtkFileWriterI.H.

References fileWriter::os_.

◆ format()

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

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

Definition at line 36 of file foamVtkFileWriterI.H.

Referenced by fileWriter::beginDataArray(), patchMeshWriter::beginPiece(), internalWriter::write(), patchWriter::write(), and coordSetWriter::writePointData().

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 42 of file foamVtkFileWriterI.H.

Referenced by internalWriter::write(), patchWriter::write(), lagrangianWriter::write(), coordSetWriter::writePointData(), internalMeshWriter::writeUniform(), patchMeshWriter::writeUniform(), and polyWriter::writeUniformValue().

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 48 of file foamVtkFileWriterI.H.

◆ beginDataArray()

void beginDataArray ( const word fieldName,
const label  nValues 
)
protected

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

Definition at line 34 of file foamVtkFileWriterTemplates.C.

References formatter::beginDataArray(), fileWriter::format(), fileWriter::format_, fileWriter::legacy(), and formatter::writeSize().

Here is the call graph for this function:

◆ endDataArray()

void endDataArray ( )
protected

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

Definition at line 206 of file foamVtkFileWriter.C.

References format().

Referenced by internalWriter::write(), patchWriter::write(), and coordSetWriter::writePointData().

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.

Definition at line 216 of file foamVtkFileWriter.C.

References Foam::vtk::legacy::beginPoints(), format(), nPoints, and Foam::vtk::POINTS.

Here is the call graph for this function:

◆ endPoints()

void endPoints ( )
protected

End of a POINTS DataArray.

Definition at line 239 of file foamVtkFileWriter.C.

References format(), and Foam::vtk::POINTS.

Here is the call graph for this function:

◆ enter_Piece()

bool enter_Piece ( )
protected

Trigger change state to Piece. Resets nCellData_, nPointData_.

Definition at line 89 of file foamVtkFileWriter.C.

References Foam::exit(), Foam::FatalError, and FatalErrorInFunction.

Here is the call 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.

Definition at line 110 of file foamVtkFileWriter.C.

References format().

Here is the call 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

Definition at line 132 of file foamVtkFileWriter.C.

References Foam::vtk::legacy::beginCellData(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, and format().

Here is the call 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

Definition at line 169 of file foamVtkFileWriter.C.

References Foam::vtk::legacy::beginPointData(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, and format().

Here is the call graph for this function:

◆ exit_File()

bool exit_File ( )
protected

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

Definition at line 255 of file foamVtkFileWriter.C.

References Foam::endl(), Foam::vtk::fileTagNames, format(), Foam::nl, and WarningInFunction.

Here is the call graph for this function:

◆ writeUniform()

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

Definition at line 88 of file foamVtkFileWriterTemplates.C.

References format(), Foam::reduce(), Foam::vtk::write(), and Foam::vtk::writeValueParallel().

Here is the call graph for this function:

◆ writeBasicField()

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

Write basic (primitive) field content.

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

Definition at line 118 of file foamVtkFileWriterTemplates.C.

References field(), format(), Foam::reduce(), Foam::vtk::writeList(), and Foam::vtk::writeListParallel().

Here is the call graph for this function:

◆ writeProcIDs()

bool writeProcIDs ( const label  nValues)
protected

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

Definition at line 545 of file foamVtkFileWriter.C.

References Foam::endl(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, format(), splitCell::master(), processorFaPatch::myProcNo(), Foam::nl, UPstream::parRun(), procAddr(), Foam::returnReduce(), and Foam::vtk::write().

Here is the call graph for this function:

◆ operator=()

void operator= ( const fileWriter )
protecteddelete

No copy assignment.

◆ contentType()

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

The content type.

Definition at line 56 of file foamVtkFileWriterI.H.

◆ opts()

Foam::vtk::outputOptions opts ( ) const
inlinenoexcept

The output options in use.

Definition at line 62 of file foamVtkFileWriterI.H.

Referenced by polyWriter::ext(), internalMeshWriter::ext(), and patchMeshWriter::ext().

Here is the caller graph for this function:

◆ ext()

Foam::word ext ( ) const
inline

File extension for current format type.

Definition at line 68 of file foamVtkFileWriterI.H.

References word::ext().

Referenced by vtkWriter::path(), and vtkWriter::write().

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

◆ legacy()

bool legacy ( ) const
inlinenoexcept

Commonly used query.

Definition at line 74 of file foamVtkFileWriterI.H.

Referenced by fileWriter::beginDataArray(), and patchMeshWriter::beginPiece().

Here is the caller graph for this function:

◆ parallel()

bool parallel ( ) const
inlinenoexcept

Parallel output requested?

Definition at line 80 of file foamVtkFileWriterI.H.

Referenced by coordSetWriter::coordSetWriter(), internalMeshWriter::internalMeshWriter(), lagrangianWriter::lagrangianWriter(), lineWriter::lineWriter(), patchMeshWriter::patchMeshWriter(), polyWriter::polyWriter(), surfaceFieldWriter::surfaceFieldWriter(), and surfaceWriter::surfaceWriter().

Here is the caller graph for this function:

◆ state()

const Foam::word & state ( ) const
inline

The output state in printable format.

Definition at line 86 of file foamVtkFileWriterI.H.

◆ output()

const Foam::fileName & output ( ) const
inlinenoexcept

The current output file name.

Definition at line 92 of file foamVtkFileWriterI.H.

◆ open()

bool open ( const fileName file,
bool  parallel = Pstream::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.

Definition at line 318 of file foamVtkFileWriter.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::vtk::fileExtension, Foam::vtk::legacy::fileExtension, splitCell::master(), Foam::mkDir(), UPstream::parRun(), and fileName::removeExt().

Referenced by searchableSurfaces::checkIntersection(), internalMeshWriter::internalMeshWriter(), lagrangianWriter::lagrangianWriter(), lineWriter::lineWriter(), patchMeshWriter::patchMeshWriter(), polyWriter::polyWriter(), surfaceFieldWriter::surfaceFieldWriter(), and surfaceWriter::surfaceWriter().

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

Definition at line 377 of file foamVtkFileWriter.C.

Referenced by searchableSurfaces::checkIntersection().

Here is the caller graph for this function:

◆ beginFile()

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

Write file header (non-collective)

Note
Expected calling states: (OPENED)

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

Definition at line 393 of file foamVtkFileWriter.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::vtk::legacy::fileHeader(), and format().

Referenced by surfaceFieldWriter::beginFile(), lineWriter::beginFile(), surfaceWriter::beginFile(), lagrangianWriter::beginFile(), coordSetWriter::beginFile(), internalMeshWriter::beginFile(), and patchMeshWriter::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).

Definition at line 432 of file foamVtkFileWriter.C.

References Foam::vtk::legacy::beginFieldData(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, and format().

Here is the call 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 surfaceFieldWriter, lineWriter, polyWriter, surfaceWriter, lagrangianWriter, coordSetWriter, internalMeshWriter, GenericPatchWriter< PatchType >, and patchMeshWriter.

◆ 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 surfaceFieldWriter, polyWriter, lagrangianWriter, internalMeshWriter, and patchMeshWriter.

◆ 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 surfaceFieldWriter, polyWriter, lagrangianWriter, internalMeshWriter, and patchMeshWriter.

◆ nCellData()

Foam::label nCellData ( ) const
inlinenoexcept

Return the number of CellData written for the Piece thus far.

Definition at line 98 of file foamVtkFileWriterI.H.

◆ nPointData()

Foam::label nPointData ( ) const
inlinenoexcept

Return the number of PointData written for the Piece thus far.

Definition at line 104 of file foamVtkFileWriterI.H.

◆ endFieldData()

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 464 of file foamVtkFileWriter.C.

References format().

Here is the call 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.

Definition at line 482 of file foamVtkFileWriter.C.

References format().

Referenced by lumpedPointMovement::writeVTP(), and lumpedPointMovement::writeZonesVTP().

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.

Definition at line 500 of file foamVtkFileWriter.C.

References format().

Referenced by lumpedPointMovement::writeVTP().

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.

Definition at line 518 of file foamVtkFileWriter.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, format(), and Foam::vtk::legacy::writeTimeValue().

Here is the call graph for this function:

Member Data Documentation

◆ stateNames

const Foam::Enum< Foam::vtk::fileWriter::outputState > stateNames
staticprotected

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

Definition at line 87 of file foamVtkFileWriter.H.

◆ state_

outputState state_
protected

The output state.

Definition at line 91 of file foamVtkFileWriter.H.

◆ contentType_

vtk::fileTag contentType_
protected

The content type (PolyData, UnstructuredGrid ...)

Definition at line 94 of file foamVtkFileWriter.H.

◆ parallel_

bool parallel_
protected

Parallel writing (via master)

Definition at line 97 of file foamVtkFileWriter.H.

Referenced by patchMeshWriter::beginPiece(), fileWriter::checkFormatterValidity(), internalWriter::write(), and patchWriter::write().

◆ opts_

◆ nCellData_

label nCellData_
protected

The number of CellData written for the Piece thus far.

Definition at line 103 of file foamVtkFileWriter.H.

Referenced by lagrangianWriter::write(), internalMeshWriter::writeUniform(), patchMeshWriter::writeUniform(), and polyWriter::writeUniformValue().

◆ nPointData_

◆ outputFile_

fileName outputFile_
protected

The output file name.

Definition at line 109 of file foamVtkFileWriter.H.

◆ format_

autoPtr<vtk::formatter> format_
protected

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

Definition at line 112 of file foamVtkFileWriter.H.

Referenced by fileWriter::beginDataArray(), patchMeshWriter::beginPiece(), fileWriter::checkFormatterValidity(), and internalWriter::write().

◆ os_

std::ofstream os_
protected

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

Definition at line 115 of file foamVtkFileWriter.H.

Referenced by fileWriter::os().


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