Go to the documentation of this file.
4 #ifndef DUNE_SUBSAMPLINGVTKWRITER_HH
5 #define DUNE_SUBSAMPLINGVTKWRITER_HH
10 #include <dune/common/indent.hh>
11 #include <dune/geometry/type.hh>
12 #include <dune/geometry/virtualrefinement.hh>
35 template<
class Gr
idView >
42 typedef typename GridView::Grid::ctype ctype;
43 typedef typename GridView::template Codim< 0 >::Entity Entity;
44 typedef VirtualRefinement<dim, ctype> Refinement;
45 typedef typename Refinement::IndexVector IndexVector;
46 typedef typename Refinement::ElementIterator SubElementIterator;
47 typedef typename Refinement::VertexIterator SubVertexIterator;
84 if(intervals_.intervals() < 1) {
85 DUNE_THROW(Dune::IOError,
"SubsamplingVTKWriter: Negative Subsampling " << intervals_.intervals() <<
" must not be used!");
100 DUNE_DEPRECATED_MSG(
"SubsampligVTKWriter(GV,int,bool) is deprecated, use SubsamplingVTKWriter(GV,Dune::refinement{Intervals|Levels}(int),bool)")
112 template<
typename SubIterator>
113 struct IteratorSelector
116 SubElementIterator
refinementBegin(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubElementIterator>)
118 return refinement.eBegin(intervals);
121 SubVertexIterator
refinementBegin(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubVertexIterator>)
123 return refinement.vBegin(intervals);
126 SubElementIterator
refinementEnd(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubElementIterator>)
128 return refinement.eEnd(intervals);
131 SubVertexIterator
refinementEnd(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubVertexIterator>)
133 return refinement.vEnd(intervals);
136 template<
typename Data,
typename Iterator,
typename SubIterator>
137 void writeData(
VTK::VTUWriter& writer,
const Data& data,
const Iterator begin,
const Iterator end,
int nentries, IteratorSelector<SubIterator> sis)
139 for (
auto it = data.begin(),
146 std::size_t writecomps = fieldInfo.
size();
147 switch (fieldInfo.
type())
155 DUNE_THROW(IOError,
"Cannot write VTK vectors with more than 3 components (components was " << writecomps <<
")");
159 DUNE_THROW(NotImplemented,
"VTK output for tensors not implemented yet");
161 std::shared_ptr<VTK::DataArrayWriter> p
163 if(!p->writeIsNoop())
164 for (Iterator eit = begin; eit!=end; ++eit)
166 const Entity & e = *eit;
168 Refinement &refinement =
169 buildRefinement<dim, ctype>(eit->type(),
170 subsampledGeometryType(eit->type()));
176 f.write(sit.coords(),*p);
178 for(
unsigned j = f.fieldInfo().size(); j < writecomps; j++)
212 void addVertexData (
const V& v,
const std::string &name,
int ncomps=1);
214 void addCellData (
const V& v,
const std::string &name,
int ncomps=1);
216 Dune::RefinementIntervals intervals;
217 bool coerceToSimplex;
221 template <
class Gr
idView>
227 for (
CellIterator it=this->cellBegin(); it!=cellEnd(); ++it)
229 Refinement &refinement = buildRefinement<dim, ctype>(it->type(), subsampledGeometryType(it->type()));
231 ncells += refinement.nElements(intervals);
232 nvertices += refinement.nVertices(intervals);
233 ncorners += refinement.nElements(intervals) * refinement.eBegin(intervals).vertexIndices().size();
239 template <
class Gr
idView>
242 if(celldata.size() == 0)
248 std::string defaultScalarField, defaultVectorField;
249 std::tie(defaultScalarField, defaultVectorField) = this->getDataNames(celldata);
251 writer.
beginCellData(defaultScalarField, defaultVectorField);
252 writeData(writer,celldata,cellBegin(),cellEnd(),ncells,IteratorSelector<SubElementIterator>());
257 template <
class Gr
idView>
260 if(vertexdata.size() == 0)
266 std::string defaultScalarField, defaultVectorField;
267 std::tie(defaultScalarField, defaultVectorField) = this->getDataNames(vertexdata);
270 writeData(writer,vertexdata,cellBegin(),cellEnd(),nvertices,IteratorSelector<SubVertexIterator>());
275 template <
class Gr
idView>
280 std::shared_ptr<VTK::DataArrayWriter> p
281 (writer.
makeArrayWriter(
"Coordinates", 3, nvertices, this->coordPrecision()));
285 Refinement &refinement =
286 buildRefinement<dim, ctype>(i->type(),
287 subsampledGeometryType(i->type()));
288 for(SubVertexIterator sit = refinement.vBegin(intervals),
289 send = refinement.vEnd(intervals);
292 FieldVector<ctype, dimw> coords = i->geometry().global(sit.coords());
293 for (
int j=0; j<std::min(
int(dimw),3); j++)
295 for (
int j=std::min(
int(dimw),3); j<3; j++)
306 template <
class Gr
idView>
313 std::shared_ptr<VTK::DataArrayWriter> p1
320 GeometryType coercedToType = subsampledGeometryType(i->type());
321 Refinement &refinement =
322 buildRefinement<dim, ctype>(i->type(), coercedToType);
323 for(SubElementIterator sit = refinement.eBegin(intervals),
324 send = refinement.eEnd(intervals);
327 IndexVector indices = sit.vertexIndices();
328 for(
unsigned int ii = 0; ii < indices.size(); ++ii)
331 offset += refinement.nVertices(intervals);
338 std::shared_ptr<VTK::DataArrayWriter> p2
345 Refinement &refinement =
346 buildRefinement<dim, ctype>(i->type(),
347 subsampledGeometryType(i->type()));
348 unsigned int verticesPerCell =
349 refinement.eBegin(intervals).vertexIndices().size();
350 for(
int element = 0; element < refinement.nElements(intervals);
353 offset += verticesPerCell;
363 std::shared_ptr<VTK::DataArrayWriter> p3
368 GeometryType coerceTo = subsampledGeometryType(it->type());
369 Refinement &refinement =
370 buildRefinement<dim, ctype>(it->type(), coerceTo);
372 for(
int i = 0; i < refinement.nElements(intervals); ++i)
381 #endif // DUNE_SUBSAMPLINGVTKWRITER_HH
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: vtuwriter.hh:203
std::list< VTKLocalFunction > celldata
Definition: vtkwriter.hh:1537
SubElementIterator refinementBegin(const Refinement &refinement, Dune::RefinementIntervals intervals, IteratorSelector< SubElementIterator >)
Definition: subsamplingvtkwriter.hh:116
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: subsamplingvtkwriter.hh:258
DUNE_DEPRECATED_MSG("SubsampligVTKWriter(GV,int,bool) is deprecated, use SubsamplingVTKWriter(GV,Dune::refinement{Intervals|Levels}(int),bool)") explicit SubsamplingVTKWriter(const GridView &gridView
Construct a SubsamplingVTKWriter working on a specific GridView.
void endPoints()
finish section for the point coordinates
Definition: vtuwriter.hh:247
SubVertexIterator refinementBegin(const Refinement &refinement, Dune::RefinementIntervals intervals, IteratorSelector< SubVertexIterator >)
Definition: subsamplingvtkwriter.hh:121
void writeData(VTK::VTUWriter &writer, const Data &data, const Iterator begin, const Iterator end, int nentries, IteratorSelector< SubIterator > sis)
Definition: subsamplingvtkwriter.hh:137
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:96
CellIterator cellBegin() const
Definition: vtkwriter.hh:393
int nvertices
Definition: vtkwriter.hh:1545
DataArrayWriter * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems, Precision prec)
acquire a DataArrayWriter
Definition: vtuwriter.hh:378
@ vector
vector-valued field (always 3D, will be padded if necessary)
Iterator over the grids elements.
Definition: vtkwriter.hh:380
virtual void countEntities(int &nvertices, int &ncells, int &ncorners)
count the vertices, cells and corners
Definition: subsamplingvtkwriter.hh:222
int ncells
Definition: vtkwriter.hh:1544
CellIterator cellEnd() const
Definition: vtkwriter.hh:398
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: vtuwriter.hh:165
std::list< VTKLocalFunction > vertexdata
Definition: vtkwriter.hh:1538
Writer for the output of subsampled grid functions in the vtk format.
Definition: subsamplingvtkwriter.hh:36
virtual bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:87
void write(T data)
write one element of data
Definition: dataarraywriter.hh:67
void beginPoints()
start section for the point coordinates
Definition: vtuwriter.hh:236
Provides file i/o for the visualization toolkit.
void endCellData()
finish CellData section
Definition: vtuwriter.hh:218
virtual void writeCellData(VTK::VTUWriter &writer)
write cell data
Definition: subsamplingvtkwriter.hh:240
@ nonconforming
Output non-conforming data.
Definition: common.hh:80
int ncorners
Definition: vtkwriter.hh:1546
@ dimension
The dimension of the grid.
Definition: common/gridview.hh:127
std::list< VTKLocalFunction >::const_iterator FunctionIterator
Definition: vtkwriter.hh:372
std::size_t size() const
The number of components in the data field.
Definition: common.hh:412
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: subsamplingvtkwriter.hh:276
SubVertexIterator refinementEnd(const Refinement &refinement, Dune::RefinementIntervals intervals, IteratorSelector< SubVertexIterator >)
Definition: subsamplingvtkwriter.hh:131
Precision precision() const
The precision used for the output of the data field.
Definition: common.hh:418
VertexIterator vertexEnd() const
Definition: vtkwriter.hh:511
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:78
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: subsamplingvtkwriter.hh:307
void endCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:283
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:199
Type type() const
The type of the data field.
Definition: common.hh:406
void endPointData()
finish PointData section
Definition: vtuwriter.hh:180
VTK::OutputType outputtype
Definition: vtkwriter.hh:1562
@ dimensionworld
The dimension of the world the grid lives in.
Definition: common/gridview.hh:131
VertexIterator vertexBegin() const
Definition: vtkwriter.hh:504
Grid view abstract base class.
Definition: common/gridview.hh:59
int bool coerceToSimplex_
Definition: subsamplingvtkwriter.hh:102
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:709
int level_
Definition: subsamplingvtkwriter.hh:102
@ tensor
tensor field (always 3x3)
SubElementIterator refinementEnd(const Refinement &refinement, Dune::RefinementIntervals intervals, IteratorSelector< SubElementIterator >)
Definition: subsamplingvtkwriter.hh:126
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:91
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:319
int renumber(const Dune::GeometryType &t, int i)
renumber VTK <-> Dune
Definition: common.hh:234
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:645
Descriptor struct for VTK fields.
Definition: common.hh:375
void beginCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:272
Include standard header files.
Definition: agrid.hh:58
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:180
VTK::Precision coordPrecision() const
get the precision with which coordinates are written out
Definition: vtkwriter.hh:778