6#ifndef DUNE_SUBSAMPLINGVTKWRITER_HH
7#define DUNE_SUBSAMPLINGVTKWRITER_HH
12#include <dune/common/indent.hh>
13#include <dune/geometry/type.hh>
14#include <dune/geometry/virtualrefinement.hh>
37 template<
class Gr
idView >
44 typedef typename GridView::Grid::ctype ctype;
45 typedef typename GridView::template Codim< 0 >::Entity Entity;
46 typedef VirtualRefinement<dim, ctype> Refinement;
47 typedef typename Refinement::IndexVector IndexVector;
48 typedef typename Refinement::ElementIterator SubElementIterator;
49 typedef typename Refinement::VertexIterator SubVertexIterator;
81 Dune::RefinementIntervals intervals_,
bool coerceToSimplex_ =
false,
84 , intervals(intervals_), coerceToSimplex(coerceToSimplex_)
86 if(intervals_.intervals() < 1) {
87 DUNE_THROW(Dune::IOError,
"SubsamplingVTKWriter: Refinement intervals must be larger than zero! (One interval means no subsampling)");
97 template<
typename SubIterator>
98 struct IteratorSelector
101 SubElementIterator refinementBegin(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubElementIterator>)
103 return refinement.eBegin(intervals);
106 SubVertexIterator refinementBegin(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubVertexIterator>)
108 return refinement.vBegin(intervals);
111 SubElementIterator refinementEnd(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubElementIterator>)
113 return refinement.eEnd(intervals);
116 SubVertexIterator refinementEnd(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubVertexIterator>)
118 return refinement.vEnd(intervals);
121 template<
typename Data,
typename Iterator,
typename SubIterator>
122 void writeData(VTK::VTUWriter& writer,
const Data& data,
const Iterator begin,
const Iterator end,
int nentries, IteratorSelector<SubIterator> sis)
124 for (
auto it = data.begin(),
130 VTK::FieldInfo fieldInfo = f.fieldInfo();
131 std::size_t writecomps = fieldInfo.size();
132 switch (fieldInfo.type())
140 DUNE_THROW(IOError,
"Cannot write VTK vectors with more than 3 components (components was " << writecomps <<
")");
144 DUNE_THROW(NotImplemented,
"VTK output for tensors not implemented yet");
146 std::shared_ptr<VTK::DataArrayWriter> p
147 (writer.makeArrayWriter(f.name(), writecomps, nentries, fieldInfo.precision()));
148 if(!p->writeIsNoop())
149 for (Iterator eit = begin; eit!=end; ++eit)
151 const Entity & e = *eit;
153 Refinement &refinement =
154 buildRefinement<dim, ctype>(eit->type(),
155 subsampledGeometryType(eit->type()));
156 for(SubIterator sit = refinementBegin(refinement,intervals,sis),
157 send = refinementEnd(refinement,intervals,sis);
161 f.write(sit.coords(),*p);
163 for(
unsigned j = f.fieldInfo().size(); j < writecomps; j++)
174 virtual void countEntities(
int &nvertices_,
int &ncells_,
int &ncorners_);
197 void addVertexData (
const V& v,
const std::string &name,
int ncomps=1);
199 void addCellData (
const V& v,
const std::string &name,
int ncomps=1);
201 Dune::RefinementIntervals intervals;
202 bool coerceToSimplex;
206 template <
class Gr
idView>
212 for (
CellIterator it=this->cellBegin(); it!=cellEnd(); ++it)
214 Refinement &refinement = buildRefinement<dim, ctype>(it->type(), subsampledGeometryType(it->type()));
216 ncells_ += refinement.nElements(intervals);
217 nvertices_ += refinement.nVertices(intervals);
218 ncorners_ += refinement.nElements(intervals) * refinement.eBegin(intervals).vertexIndices().size();
224 template <
class Gr
idView>
227 if(celldata.size() == 0)
233 std::string defaultScalarField, defaultVectorField;
234 std::tie(defaultScalarField, defaultVectorField) = this->getDataNames(celldata);
236 writer.
beginCellData(defaultScalarField, defaultVectorField);
237 writeData(writer,celldata,cellBegin(),cellEnd(),ncells,IteratorSelector<SubElementIterator>());
242 template <
class Gr
idView>
245 if(vertexdata.size() == 0)
251 std::string defaultScalarField, defaultVectorField;
252 std::tie(defaultScalarField, defaultVectorField) = this->getDataNames(vertexdata);
255 writeData(writer,vertexdata,cellBegin(),cellEnd(),nvertices,IteratorSelector<SubVertexIterator>());
260 template <
class Gr
idView>
265 std::shared_ptr<VTK::DataArrayWriter> p
266 (writer.
makeArrayWriter(
"Coordinates", 3, nvertices, this->coordPrecision()));
267 if(!p->writeIsNoop())
270 Refinement &refinement =
271 buildRefinement<dim, ctype>(i->type(),
272 subsampledGeometryType(i->type()));
273 for(SubVertexIterator sit = refinement.vBegin(intervals),
274 send = refinement.vEnd(intervals);
277 FieldVector<ctype, dimw> coords = i->geometry().global(sit.coords());
278 for (
int j=0; j<
std::min(
int(dimw),3); j++)
280 for (
int j=
std::min(
int(dimw),3); j<3; j++)
291 template <
class Gr
idView>
298 std::shared_ptr<VTK::DataArrayWriter> p1
301 if(!p1->writeIsNoop()) {
305 GeometryType coercedToType = subsampledGeometryType(i->type());
306 Refinement &refinement =
307 buildRefinement<dim, ctype>(i->type(), coercedToType);
308 for(SubElementIterator sit = refinement.eBegin(intervals),
309 send = refinement.eEnd(intervals);
312 IndexVector indices = sit.vertexIndices();
313 for(
unsigned int ii = 0; ii < indices.size(); ++ii)
316 offset += refinement.nVertices(intervals);
323 std::shared_ptr<VTK::DataArrayWriter> p2
325 if(!p2->writeIsNoop()) {
330 Refinement &refinement =
331 buildRefinement<dim, ctype>(i->type(),
332 subsampledGeometryType(i->type()));
333 unsigned int verticesPerCell =
334 refinement.eBegin(intervals).vertexIndices().size();
335 for(
int element = 0; element < refinement.nElements(intervals);
338 offset += verticesPerCell;
348 std::shared_ptr<VTK::DataArrayWriter> p3
350 if(!p3->writeIsNoop())
353 GeometryType coerceTo = subsampledGeometryType(it->type());
354 Refinement &refinement =
355 buildRefinement<dim, ctype>(it->type(), coerceTo);
357 for(
int i = 0; i < refinement.nElements(intervals); ++i)
Provides file i/o for the visualization toolkit.
static constexpr int dimension
The dimension of the grid.
Definition: common/gridview.hh:148
static constexpr int dimensionworld
The dimension of the world the grid lives in.
Definition: common/gridview.hh:151
Include standard header files.
Definition: agrid.hh:60
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:348
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:271
int renumber(const Dune::GeometryType &t, int i)
renumber VTK <-> Dune
Definition: common.hh:186
@ nonconforming
Output non-conforming data.
Definition: common.hh:81
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:151
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Grid view abstract base class.
Definition: common/gridview.hh:66
@ tensor
tensor field (always 3x3)
@ vector
vector-valued field (always 3D, will be padded if necessary)
Writer for the output of subsampled grid functions in the vtk format.
Definition: subsamplingvtkwriter.hh:40
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: subsamplingvtkwriter.hh:261
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: subsamplingvtkwriter.hh:243
SubsamplingVTKWriter(const GridView &gridView, Dune::RefinementIntervals intervals_, bool coerceToSimplex_=false, VTK::Precision coordPrecision=VTK::Precision::float32)
Construct a SubsamplingVTKWriter working on a specific GridView.
Definition: subsamplingvtkwriter.hh:80
virtual void countEntities(int &nvertices_, int &ncells_, int &ncorners_)
count the vertices, cells and corners
Definition: subsamplingvtkwriter.hh:207
virtual void writeCellData(VTK::VTUWriter &writer)
write cell data
Definition: subsamplingvtkwriter.hh:225
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: subsamplingvtkwriter.hh:292
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:95
VertexIterator vertexBegin() const
Definition: vtkwriter.hh:508
void addVertexData(const std::shared_ptr< const VTKFunction > &p)
Add a grid function that lives on the vertices of the grid to the visualization.
Definition: vtkwriter.hh:713
CellIterator cellEnd() const
Definition: vtkwriter.hh:402
std::list< VTKLocalFunction > vertexdata
Definition: vtkwriter.hh:1585
void addCellData(const std::shared_ptr< const VTKFunction > &p)
Add a grid function that lives on the cells of the grid to the visualization.
Definition: vtkwriter.hh:649
CellIterator cellBegin() const
Definition: vtkwriter.hh:397
VTK::OutputType outputtype
Definition: vtkwriter.hh:1609
std::list< VTKLocalFunction > celldata
Definition: vtkwriter.hh:1584
VTK::Precision coordPrecision() const
get the precision with which coordinates are written out
Definition: vtkwriter.hh:782
std::list< VTKLocalFunction >::const_iterator FunctionIterator
Definition: vtkwriter.hh:376
int nvertices
Definition: vtkwriter.hh:1592
int ncells
Definition: vtkwriter.hh:1591
VertexIterator vertexEnd() const
Definition: vtkwriter.hh:515
int ncorners
Definition: vtkwriter.hh:1593
Iterator over the grids elements.
Definition: vtkwriter.hh:385
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:98
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