dune-grid 2.9.0
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Dune::VTKWriter< GridView > Class Template Reference

Writer for the ouput of grid functions in the vtk format. More...

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

Inheritance diagram for Dune::VTKWriter< GridView >:
Inheritance graph

Classes

class  CellIterator
 Iterator over the grids elements. More...
 
class  CornerIterator
 Iterate over the elements' corners. More...
 
class  VertexIterator
 Iterate over the grid's vertices. More...
 
class  VTKLocalFunction
 Type erasure wrapper for VTK data sets. More...
 

Public Types

typedef Dune::VTKFunction< GridViewVTKFunction
 

Public Member Functions

 VTKWriter (const GridView &gridView, VTK::DataMode dm=VTK::conforming, VTK::Precision coordPrecision=VTK::Precision::float32)
 Construct a VTKWriter working on a specific GridView. More...
 
void addCellData (const std::shared_ptr< const VTKFunction > &p)
 Add a grid function that lives on the cells of the grid to the visualization. More...
 
template<typename F >
void addCellData (F &&f, VTK::FieldInfo vtkFieldInfo)
 Add a function by sampling it on the element centers. More...
 
template<class Container >
void addCellData (const Container &v, const std::string &name, int ncomps=1, VTK::Precision prec=VTK::Precision::float32)
 Add a grid function (represented by container) that lives on the cells of the grid to the visualization. More...
 
void addVertexData (const std::shared_ptr< const VTKFunction > &p)
 Add a grid function that lives on the vertices of the grid to the visualization. More...
 
template<typename F >
void addVertexData (F &&f, VTK::FieldInfo vtkFieldInfo)
 Add a function by sampling it on the grid vertices. More...
 
template<class Container >
void addVertexData (const Container &v, const std::string &name, int ncomps=1, VTK::Precision prec=VTK::Precision::float32)
 Add a grid function (represented by container) that lives on the vertices of the grid to the visualization output. More...
 
void clear ()
 clear list of registered functions More...
 
VTK::Precision coordPrecision () const
 get the precision with which coordinates are written out More...
 
virtual ~VTKWriter ()
 destructor More...
 
std::string write (const std::string &name, VTK::OutputType type=VTK::ascii)
 write output (interface might change later) More...
 
std::string pwrite (const std::string &name, const std::string &path, const std::string &extendpath, VTK::OutputType type=VTK::ascii)
 write output (interface might change later) More...
 

Protected Types

typedef std::list< VTKLocalFunction >::const_iterator FunctionIterator
 

Protected Member Functions

CellIterator cellBegin () const
 
CellIterator cellEnd () const
 
VertexIterator vertexBegin () const
 
VertexIterator vertexEnd () const
 
CornerIterator cornerBegin () const
 
CornerIterator cornerEnd () const
 
std::string getParallelPieceName (const std::string &name, const std::string &path, int commRank, int commSize) const
 return name of a parallel piece file (or header name) More...
 
std::string getParallelHeaderName (const std::string &name, const std::string &path, int commSize) const
 return name of a parallel header file More...
 
std::string getSerialPieceName (const std::string &name, const std::string &path) const
 return name of a serial piece file More...
 
std::string write (const std::string &name, VTK::OutputType type, const int commRank, const int commSize)
 write output (interface might change later) More...
 
std::string pwrite (const std::string &name, const std::string &path, const std::string &extendpath, VTK::OutputType ot, const int commRank, const int commSize)
 write output; interface might change later More...
 
std::string getFormatString () const
 
std::string getTypeString () const
 
virtual void countEntities (int &nvertices_, int &ncells_, int &ncorners_)
 count the vertices, cells and corners More...
 
template<typename T >
std::tuple< std::string, std::string > getDataNames (const T &data) const
 
template<typename Data , typename Iterator >
void writeData (VTK::VTUWriter &writer, const Data &data, const Iterator begin, const Iterator end, int nentries)
 
virtual void writeCellData (VTK::VTUWriter &writer)
 write cell data More...
 
virtual void writeVertexData (VTK::VTUWriter &writer)
 write vertex data More...
 
virtual void writeGridPoints (VTK::VTUWriter &writer)
 write the positions of vertices More...
 
virtual void writeGridCells (VTK::VTUWriter &writer)
 write the connectivity array More...
 
bool checkForPolyhedralCells () const
 
virtual void writeCellFaces (VTK::VTUWriter &writer)
 write the connectivity array More...
 
template<class CornerIterator , class IndexSet , class T >
void fillFaceVertices (CornerIterator it, const CornerIterator end, const IndexSet &indexSet, std::vector< T > &faces, std::vector< T > &faceOffsets)
 

Static Protected Member Functions

template<class Entity , class IndexSet , class T >
static void fillFacesForElement (const Entity &element, const IndexSet &indexSet, const std::vector< T > &vertices, T &offset, std::vector< T > &faces, std::vector< T > &faceOffsets)
 

Protected Attributes

std::list< VTKLocalFunctioncelldata
 
std::list< VTKLocalFunctionvertexdata
 
GridView gridView_
 
int ncells
 
int nvertices
 
int ncorners
 
VTK::OutputType outputtype
 

Detailed Description

template<class GridView>
class Dune::VTKWriter< GridView >

Writer for the ouput of grid functions in the vtk format.

Writes arbitrary grid functions (living on cells or vertices of a grid) to a file suitable for easy visualization with The Visualization Toolkit (VTK).

Member Typedef Documentation

◆ FunctionIterator

template<class GridView >
typedef std::list<VTKLocalFunction>::const_iterator Dune::VTKWriter< GridView >::FunctionIterator
protected

◆ VTKFunction

template<class GridView >
typedef Dune::VTKFunction< GridView > Dune::VTKWriter< GridView >::VTKFunction

Constructor & Destructor Documentation

◆ VTKWriter()

template<class GridView >
Dune::VTKWriter< GridView >::VTKWriter ( const GridView gridView,
VTK::DataMode  dm = VTK::conforming,
VTK::Precision  coordPrecision = VTK::Precision::float32 
)
inlineexplicit

Construct a VTKWriter working on a specific GridView.

Parameters
gridViewThe gridView the grid functions live on. (E. g. a LevelGridView.)
dmThe data mode.
coordPrecisionthe precision with which to write out the coordinates

◆ ~VTKWriter()

template<class GridView >
virtual Dune::VTKWriter< GridView >::~VTKWriter ( )
inlinevirtual

destructor

Member Function Documentation

◆ addCellData() [1/3]

template<class GridView >
template<class Container >
void Dune::VTKWriter< GridView >::addCellData ( const Container &  v,
const std::string &  name,
int  ncomps = 1,
VTK::Precision  prec = VTK::Precision::float32 
)
inline

Add a grid function (represented by container) that lives on the cells of the grid to the visualization.

The container has to have random access via operator[] (e.g. std::vector). The value of the grid function for an arbitrary element will be accessed by calling operator[] with the index (corresponding to the index from the MGMC mapper on the grid view) of the element. For vector valued data all components for an element are assumed to be consecutive.

Parameters
vThe container with the values of the grid function for each cell.
nameA name to identify the grid function.
ncompsNumber of components (default is 1).

◆ addCellData() [2/3]

template<class GridView >
void Dune::VTKWriter< GridView >::addCellData ( const std::shared_ptr< const VTKFunction > &  p)
inline

Add a grid function that lives on the cells of the grid to the visualization.

Parameters
pstd::shared_ptr to the function to visualize

◆ addCellData() [3/3]

template<class GridView >
template<typename F >
void Dune::VTKWriter< GridView >::addCellData ( F &&  f,
VTK::FieldInfo  vtkFieldInfo 
)
inline

Add a function by sampling it on the element centers.

Parameters
fThe function to be written to the file

The object f can be one of several things. Depending on what it is exactly, its object life-time is influenced in different ways:

  • If f has the method bind(), then a copy of f is stored, regardless of whether f is an l- or r-value.
  • If f can be localized by calling localFunction(f), then a copy of localFunction(f) is stored, but f is never stored, regardless of whether f is an l- or r-value.
  • If f supports neither bind() or localFunction(), then a copy of f is stored, regardless if f is an l- or r-value.

The previous paragraph actually refers to parts of the dune-functions interface, and you may want to read up on that if you want to write functions to VTK.

Deprecated:
f may also be a VTKFunction object, but you are strongly discouraged from using VTKFunctions.

◆ addVertexData() [1/3]

template<class GridView >
template<class Container >
void Dune::VTKWriter< GridView >::addVertexData ( const Container &  v,
const std::string &  name,
int  ncomps = 1,
VTK::Precision  prec = VTK::Precision::float32 
)
inline

Add a grid function (represented by container) that lives on the vertices of the grid to the visualization output.

The container has to have random access via operator[] (e.g. std::vector). The value of the grid function for an arbitrary element will be accessed by calling operator[] with the index (corresponding to the index from the MGMC mapper on the grid view) of the vertex. For vector valued data all components for a vertex are assumed to be consecutive.

Parameters
vThe container with the values of the grid function for each vertex.
nameA name to identify the grid function.
ncompsNumber of components (default is 1).

◆ addVertexData() [2/3]

template<class GridView >
void Dune::VTKWriter< GridView >::addVertexData ( const std::shared_ptr< const VTKFunction > &  p)
inline

Add a grid function that lives on the vertices of the grid to the visualization.

Parameters
pstd::shared_ptr to the function to visualize

◆ addVertexData() [3/3]

template<class GridView >
template<typename F >
void Dune::VTKWriter< GridView >::addVertexData ( F &&  f,
VTK::FieldInfo  vtkFieldInfo 
)
inline

Add a function by sampling it on the grid vertices.

Parameters
fThe function to be written to the file

The object f can be one of several things. Depending on what it is exactly, its object life-time is influenced in different ways:

  • If f has the method bind(), then a copy of f is stored, regardless of whether f is an l- or r-value.
  • If f can be localized by calling localFunction(f), then a copy of localFunction(f) is stored, but f is never stored, regardless of whether f is an l- or r-value.
  • If f supports neither bind() or localFunction(), then a copy of f is stored, regardless if f is an l- or r-value.

The previous paragraph actually refers to parts of the dune-functions interface, and you may want to read up on that if you want to write functions to VTK.

Deprecated:
f may also be a VTKFunction object, but you are strongly discouraged from using VTKFunctions.

◆ cellBegin()

template<class GridView >
CellIterator Dune::VTKWriter< GridView >::cellBegin ( ) const
inlineprotected

◆ cellEnd()

template<class GridView >
CellIterator Dune::VTKWriter< GridView >::cellEnd ( ) const
inlineprotected

◆ checkForPolyhedralCells()

template<class GridView >
bool Dune::VTKWriter< GridView >::checkForPolyhedralCells ( ) const
inlineprotected

◆ clear()

template<class GridView >
void Dune::VTKWriter< GridView >::clear ( )
inline

clear list of registered functions

◆ coordPrecision()

template<class GridView >
VTK::Precision Dune::VTKWriter< GridView >::coordPrecision ( ) const
inline

get the precision with which coordinates are written out

◆ cornerBegin()

template<class GridView >
CornerIterator Dune::VTKWriter< GridView >::cornerBegin ( ) const
inlineprotected

◆ cornerEnd()

template<class GridView >
CornerIterator Dune::VTKWriter< GridView >::cornerEnd ( ) const
inlineprotected

◆ countEntities()

template<class GridView >
virtual void Dune::VTKWriter< GridView >::countEntities ( int &  nvertices_,
int &  ncells_,
int &  ncorners_ 
)
inlineprotectedvirtual

count the vertices, cells and corners

Reimplemented in Dune::SubsamplingVTKWriter< GridView >.

◆ fillFacesForElement()

template<class GridView >
template<class Entity , class IndexSet , class T >
static void Dune::VTKWriter< GridView >::fillFacesForElement ( const Entity &  element,
const IndexSet &  indexSet,
const std::vector< T > &  vertices,
T &  offset,
std::vector< T > &  faces,
std::vector< T > &  faceOffsets 
)
inlinestaticprotected

◆ fillFaceVertices()

template<class GridView >
template<class CornerIterator , class IndexSet , class T >
void Dune::VTKWriter< GridView >::fillFaceVertices ( CornerIterator  it,
const CornerIterator  end,
const IndexSet &  indexSet,
std::vector< T > &  faces,
std::vector< T > &  faceOffsets 
)
inlineprotected

◆ getDataNames()

template<class GridView >
template<typename T >
std::tuple< std::string, std::string > Dune::VTKWriter< GridView >::getDataNames ( const T &  data) const
inlineprotected

◆ getFormatString()

template<class GridView >
std::string Dune::VTKWriter< GridView >::getFormatString ( ) const
inlineprotected

◆ getParallelHeaderName()

template<class GridView >
std::string Dune::VTKWriter< GridView >::getParallelHeaderName ( const std::string &  name,
const std::string &  path,
int  commSize 
) const
inlineprotected

return name of a parallel header file

Parameters
nameBase name of the VTK output. This should be without any directory parts and without a filename extension.
pathDirectory part of the resulting header name. May be empty, in which case the resulting name will not have a directory part. If non-empty, may or may not have a trailing '/'. If a trailing slash is missing, one is appended implicitly.
commSizeNumber of processes writing a parallel vtk output.

◆ getParallelPieceName()

template<class GridView >
std::string Dune::VTKWriter< GridView >::getParallelPieceName ( const std::string &  name,
const std::string &  path,
int  commRank,
int  commSize 
) const
inlineprotected

return name of a parallel piece file (or header name)

Parameters
nameBase name of the VTK output. This should be without any directory parts and without a filename extension.
pathDirectory part of the resulting piece name. May be empty, in which case the resulting name will not have a directory part. If non-empty, may or may not have a trailing '/'. If a trailing slash is missing, one is appended implicitly.
commRankRank of the process to generate a piece name for. if (-1) then the header is created.
commSizeNumber of processes writing a parallel vtk output.

◆ getSerialPieceName()

template<class GridView >
std::string Dune::VTKWriter< GridView >::getSerialPieceName ( const std::string &  name,
const std::string &  path 
) const
inlineprotected

return name of a serial piece file

This is similar to getParallelPieceName, but skips the prefixes for commSize ("s####-") and commRank ("p####-").

Parameters
nameBase name of the VTK output. This should be without any directory parts and without a filename extension.
pathDirectory part of the resulting piece name. May be empty, in which case the resulting name will not have a directory part. If non-empty, may or may not have a trailing '/'. If a trailing slash is missing, one is appended implicitly.

◆ getTypeString()

template<class GridView >
std::string Dune::VTKWriter< GridView >::getTypeString ( ) const
inlineprotected

◆ pwrite() [1/2]

template<class GridView >
std::string Dune::VTKWriter< GridView >::pwrite ( const std::string &  name,
const std::string &  path,
const std::string &  extendpath,
VTK::OutputType  ot,
const int  commRank,
const int  commSize 
)
inlineprotected

write output; interface might change later

Parameters
nameBase name of the output files. This should not contain any directory part and not filename extensions. It will be used both for each processes piece as well as the parallel collection file.
pathDirectory where to put the parallel collection (.pvtu/.pvtp) file. If it is relative, it is taken realtive to the current directory.
extendpathDirectory where to put the piece file (.vtu/.vtp) of this process. If it is relative, it is taken relative to the directory denoted by path.
otHow to encode the data in the file.
commRankRank of the current process.
commSizeNumber of processes taking part in this write operation.
Note
Currently, extendpath may not be absolute unless path is absolute, because that would require the value of the current directory.
Exceptions
NotImplementedExtendpath is absolute but path is relative.
IOErrorFailed to open a file.

◆ pwrite() [2/2]

template<class GridView >
std::string Dune::VTKWriter< GridView >::pwrite ( const std::string &  name,
const std::string &  path,
const std::string &  extendpath,
VTK::OutputType  type = VTK::ascii 
)
inline

write output (interface might change later)

"pwrite" means "path write" (i.e. write somewhere else than the current directory). The "p" does not mean this method has a monopoly on parallel writing, the regular write(const std::string &, VTK::OutputType) method can do that just fine.

Parameters
nameBase name of the output files. This should not contain any directory part and not filename extensions. It will be used both for each processes piece as well as the parallel collection file.
pathDirectory where to put the parallel collection (.pvtu/.pvtp) file. If it is relative, it is taken relative to the current directory.
extendpathDirectory where to put the piece file (.vtu/.vtp) of this process. If it is relative, it is taken relative to the directory denoted by path.
typeHow to encode the data in the file.
Note
Currently, extendpath may not be absolute unless path is absolute, because that would require the value of the current directory.
Exceptions
NotImplementedExtendpath is absolute but path is relative.
IOErrorFailed to open a file.

◆ vertexBegin()

template<class GridView >
VertexIterator Dune::VTKWriter< GridView >::vertexBegin ( ) const
inlineprotected

◆ vertexEnd()

template<class GridView >
VertexIterator Dune::VTKWriter< GridView >::vertexEnd ( ) const
inlineprotected

◆ write() [1/2]

template<class GridView >
std::string Dune::VTKWriter< GridView >::write ( const std::string &  name,
VTK::OutputType  type,
const int  commRank,
const int  commSize 
)
inlineprotected

write output (interface might change later)

This method can be used in parallel as well as in serial programs. For serial runs (commSize=1) it chooses other names without the "s####-p####-" prefix for the .vtu/.vtp files and omits writing of the .pvtu/pvtp file however. For parallel runs (commSize > 1) it is the same as a call to pwrite() with name and path constructed from a given filename possibly containing a path, and extendpath="".

Parameters
nameBase name of the output files. This should not contain any directory part and no filename extensions.
typeHow to encode the data in the file.
commRankRank of the current process.
commSizeNumber of processes taking part in this write operation.

◆ write() [2/2]

template<class GridView >
std::string Dune::VTKWriter< GridView >::write ( const std::string &  name,
VTK::OutputType  type = VTK::ascii 
)
inline

write output (interface might change later)

This method can be used in parallel as well as in serial programs. For serial runs (commSize=1) it chooses other names without the "s####-p####-" prefix for the .vtu/.vtp files and omits writing of the .pvtu/pvtp file however. For parallel runs (commSize > 1) it is the same as a call to pwrite() with name and path constructed from a given filename possibly containing a path, and extendpath="".

Parameters
[in]namebasic name to write (may not contain a path)
[in]typetype of output (e.g,, ASCII) (optional)

◆ writeCellData()

template<class GridView >
virtual void Dune::VTKWriter< GridView >::writeCellData ( VTK::VTUWriter writer)
inlineprotectedvirtual

write cell data

Reimplemented in Dune::SubsamplingVTKWriter< GridView >.

◆ writeCellFaces()

template<class GridView >
virtual void Dune::VTKWriter< GridView >::writeCellFaces ( VTK::VTUWriter writer)
inlineprotectedvirtual

write the connectivity array

◆ writeData()

template<class GridView >
template<typename Data , typename Iterator >
void Dune::VTKWriter< GridView >::writeData ( VTK::VTUWriter writer,
const Data &  data,
const Iterator  begin,
const Iterator  end,
int  nentries 
)
inlineprotected

◆ writeGridCells()

template<class GridView >
virtual void Dune::VTKWriter< GridView >::writeGridCells ( VTK::VTUWriter writer)
inlineprotectedvirtual

write the connectivity array

Reimplemented in Dune::SubsamplingVTKWriter< GridView >.

◆ writeGridPoints()

template<class GridView >
virtual void Dune::VTKWriter< GridView >::writeGridPoints ( VTK::VTUWriter writer)
inlineprotectedvirtual

write the positions of vertices

Reimplemented in Dune::SubsamplingVTKWriter< GridView >.

◆ writeVertexData()

template<class GridView >
virtual void Dune::VTKWriter< GridView >::writeVertexData ( VTK::VTUWriter writer)
inlineprotectedvirtual

write vertex data

Reimplemented in Dune::SubsamplingVTKWriter< GridView >.

Member Data Documentation

◆ celldata

template<class GridView >
std::list<VTKLocalFunction> Dune::VTKWriter< GridView >::celldata
protected

◆ gridView_

template<class GridView >
GridView Dune::VTKWriter< GridView >::gridView_
protected

◆ ncells

template<class GridView >
int Dune::VTKWriter< GridView >::ncells
protected

◆ ncorners

template<class GridView >
int Dune::VTKWriter< GridView >::ncorners
protected

◆ nvertices

template<class GridView >
int Dune::VTKWriter< GridView >::nvertices
protected

◆ outputtype

template<class GridView >
VTK::OutputType Dune::VTKWriter< GridView >::outputtype
protected

◆ vertexdata

template<class GridView >
std::list<VTKLocalFunction> Dune::VTKWriter< GridView >::vertexdata
protected

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