dune-grid 2.9.0
Public Types | Public Member Functions | Public Attributes | List of all members
Dune::VTK::VTUWriter Class Reference

Dump a .vtu/.vtp files contents to a stream. More...

#include <dune/grid/io/file/vtk/vtuwriter.hh>

Public Types

enum  Phase { main , appended }
 

Public Member Functions

 VTUWriter (std::ostream &stream_, OutputType outputType, FileType fileType_)
 create a VTUWriter object More...
 
 ~VTUWriter ()
 write footer More...
 
void beginPointData (const std::string &scalars="", const std::string &vectors="")
 start PointData section More...
 
void endPointData ()
 finish PointData section More...
 
void beginCellData (const std::string &scalars="", const std::string &vectors="")
 start CellData section More...
 
void endCellData ()
 finish CellData section More...
 
void beginPoints ()
 start section for the point coordinates More...
 
void endPoints ()
 finish section for the point coordinates More...
 
void beginCells ()
 start section for the grid cells/PolyData lines More...
 
void endCells ()
 start section for the grid cells/PolyData lines More...
 
void beginMain (unsigned ncells, unsigned npoints)
 start the main PolyData/UnstructuredGrid section More...
 
void endMain ()
 finish the main PolyData/UnstructuredGrid section More...
 
bool beginAppended ()
 start the appended data section More...
 
void endAppended ()
 finish the appended data section More...
 
DataArrayWritermakeArrayWriter (const std::string &name, unsigned ncomps, unsigned nitems, Precision prec)
 acquire a DataArrayWriter More...
 

Public Attributes

std::ostream & stream
 
enum Dune::VTK::VTUWriter::Phase phase
 

Detailed Description

Dump a .vtu/.vtp files contents to a stream.

This will help generating a .vtu/.vtp file. Typical use is like this:

{
// create writer, writes begin tag
// write the main header
writer.beginMain(ncells, nvertices);
dumpEverything(writer);
writer.endMain();
// write the appended section, if required by the outputtype
if(writer.beginAppended())
dumpEverything(writer);
writer.endAppended();
// end scope so the destructor gets called and the closing tag is written
}
@ appendedraw
Output is to the file is appended raw binary.
Definition: common.hh:49
@ polyData
for .vtp files (PolyData)
Definition: common.hh:254
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:98

The method dumpEverything() then looks something like this:

void dumpEverything(VTUWriter& writer)
{
// dump cell data (optional)
writer.beginCellData();
for(each cell data field) {
shared_ptr<DataArrayWriter> arraywriter
(writer.makeArrayWriter(field.name, field.ncomps, ncells, precision));
// iterate over the points and write data for each
}
writer.endCellData();
// dump point data (optional)
writer.beginPointData();
for(each point data field) {
shared_ptr<DataArrayWriter> arraywriter
(writer.makeArrayWriter(field.name, field.ncomps, npoints, precision));
// iterate over the points and write data for each
}
writer.endPointData();
// dump point coordinates
writer.beginPoints();
{
shared_ptr<DataArrayWriter> arraywriter
(writer.makeArrayWriter("Coordinates", 3, npoints, precision));
// iterate over the points and write data for each
}
writer.endPoints();
// dump cells
writer.beginCells();
{ // connectivity
shared_ptr<DataArrayWriter> arraywriter
(writer.makeArrayWriter("connectivity", 1, ncorners, precision));
// iterate over the cells and write data for each
}
{ // connectivity
shared_ptr<DataArrayWriter> arraywriter
(writer.makeArrayWriter("offsets", 1, ncells, precision));
// iterate over the cells and write data for each
}
if(fileType == unstructuredGrid) { // types
shared_ptr<DataArrayWriter> arraywriter
(writer.makeArrayWriter("types", 1, ncells, precision));
// iterate over the cells and write data for each
}
writer.endCells();
}
@ unstructuredGrid
for .vtu files (UnstructuredGrid)
Definition: common.hh:256
DataArrayWriter * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems, Precision prec)
acquire a DataArrayWriter
Definition: vtuwriter.hh:380
void endCellData()
finish CellData section
Definition: vtuwriter.hh:220
void beginCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:274
void endPointData()
finish PointData section
Definition: vtuwriter.hh:182
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: vtuwriter.hh:205
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: vtuwriter.hh:167
void endPoints()
finish section for the point coordinates
Definition: vtuwriter.hh:249
void endCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:285
void beginPoints()
start section for the point coordinates
Definition: vtuwriter.hh:238

Member Enumeration Documentation

◆ Phase

Enumerator
main 
appended 

Constructor & Destructor Documentation

◆ VTUWriter()

Dune::VTK::VTUWriter::VTUWriter ( std::ostream &  stream_,
OutputType  outputType,
FileType  fileType_ 
)
inline

create a VTUWriter object

Parameters
stream_Stream to write to.
outputTypeHow to encode data.
fileType_Whether to write PolyData (1D) or UnstructuredGrid (nD) format.

Create object and write header.

◆ ~VTUWriter()

Dune::VTK::VTUWriter::~VTUWriter ( )
inline

write footer

Member Function Documentation

◆ beginAppended()

bool Dune::VTK::VTUWriter::beginAppended ( )
inline

start the appended data section

Returns
A value indicating whether the is an actual appended section required.

If this function returns true, an appended section is actually required. In this case, between the call to this method and to endAppended(), there should be literally the same calls (including the same arguments) as between the calls to beginMain() and endMain(). The only exception is, that if a DataArrayWriter in the main section indicated that the calls to write could be skipped, this is not necessarily true in the appended section also (you will have to ask the DataArrayWriter again).

If this function returns false, no appended section is required and a call to endAppeded() should immediately follow the call to this function.

◆ beginCellData()

void Dune::VTK::VTUWriter::beginCellData ( const std::string &  scalars = "",
const std::string &  vectors = "" 
)
inline

start CellData section

Parameters
scalarsName of field to which should be marked as default scalars field. If this is the empty string, don't set any default.
vectorsName of field to which should be marked as default vectors field. If this is the empty string, don't set any default.

If there are no CellData fields, the call to this function may be skipped, together with the corresponding call to endCellData().

◆ beginCells()

void Dune::VTK::VTUWriter::beginCells ( )
inline

start section for the grid cells/PolyData lines

Between the call to this method an the following call to the endCells(), there must be two or three fields written:

  • "connectivity" of type Int32 with 3 components, number of items is the number of corners (that may be different from number of vertices!)
  • "offsets" of type Int32 with one component, number of items is number of cells.
  • for UnstructuredGrid, "types" of type UInt8 with one component, number of items is number of cells.

◆ beginMain()

void Dune::VTK::VTUWriter::beginMain ( unsigned  ncells,
unsigned  npoints 
)
inline

start the main PolyData/UnstructuredGrid section

Parameters
ncellsNumber of cells/lines.
npointsNumber of points.

Between the call to this method and to endMain(), there should be calls to dump the actual data:

◆ beginPointData()

void Dune::VTK::VTUWriter::beginPointData ( const std::string &  scalars = "",
const std::string &  vectors = "" 
)
inline

start PointData section

Parameters
scalarsName of field to which should be marked as default scalars field. If this is the empty string, don't set any default.
vectorsName of field to which should be marked as default vectors field. If this is the empty string, don't set any default.

If there are no PointData fields, the call to this function may be skipped, together with the corresponding call to endPointData().

◆ beginPoints()

void Dune::VTK::VTUWriter::beginPoints ( )
inline

start section for the point coordinates

Between the call to this method an the following call to the endPoints(), there must be a single field written. The name must be "Coordinates", it must have 3 components, and the number of items must be the number of points.

◆ endAppended()

void Dune::VTK::VTUWriter::endAppended ( )
inline

finish the appended data section

◆ endCellData()

void Dune::VTK::VTUWriter::endCellData ( )
inline

finish CellData section

◆ endCells()

void Dune::VTK::VTUWriter::endCells ( )
inline

start section for the grid cells/PolyData lines

◆ endMain()

void Dune::VTK::VTUWriter::endMain ( )
inline

finish the main PolyData/UnstructuredGrid section

◆ endPointData()

void Dune::VTK::VTUWriter::endPointData ( )
inline

finish PointData section

◆ endPoints()

void Dune::VTK::VTUWriter::endPoints ( )
inline

finish section for the point coordinates

◆ makeArrayWriter()

DataArrayWriter * Dune::VTK::VTUWriter::makeArrayWriter ( const std::string &  name,
unsigned  ncomps,
unsigned  nitems,
Precision  prec 
)
inline

acquire a DataArrayWriter

Template Parameters
TType of the data to write.
Parameters
nameName of the array to write.
ncompsNumber of components of the vectors in the array.
nitemsNumber of vectors in the array (number of cells/number of points/number of corners).

There should never be more than one DataArrayWriter created by the same VTUWriter around. The returned object should be freed with delete.

Member Data Documentation

◆ phase

enum Dune::VTK::VTUWriter::Phase Dune::VTK::VTUWriter::phase

◆ stream

std::ostream& Dune::VTK::VTUWriter::stream

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