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;
82 if(intervals_.intervals() < 1) {
83 DUNE_THROW(Dune::IOError,
"SubsamplingVTKWriter: Negative Subsampling " << intervals_.intervals() <<
" must not be used!");
98 DUNE_DEPRECATED_MSG(
"SubsampligVTKWriter(GV,int,bool) is deprecated, use SubsamplingVTKWriter(GV,Dune::refinement{Intervals|Levels}(int),bool)")
110 template<
typename SubIterator>
111 struct IteratorSelector
114 SubElementIterator
refinementBegin(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubElementIterator>)
116 return refinement.eBegin(intervals);
119 SubVertexIterator
refinementBegin(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubVertexIterator>)
121 return refinement.vBegin(intervals);
124 SubElementIterator
refinementEnd(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubElementIterator>)
126 return refinement.eEnd(intervals);
129 SubVertexIterator
refinementEnd(
const Refinement& refinement, Dune::RefinementIntervals intervals, IteratorSelector<SubVertexIterator>)
131 return refinement.vEnd(intervals);
134 template<
typename Data,
typename Iterator,
typename SubIterator>
135 void writeData(
VTK::VTUWriter& writer,
const Data& data,
const Iterator begin,
const Iterator end,
int nentries, IteratorSelector<SubIterator> sis)
137 for (
auto it = data.begin(),
144 std::size_t writecomps = fieldInfo.
size();
145 switch (fieldInfo.
type())
153 DUNE_THROW(IOError,
"Cannot write VTK vectors with more than 3 components (components was " << writecomps <<
")");
157 DUNE_THROW(NotImplemented,
"VTK output for tensors not implemented yet");
159 std::shared_ptr<VTK::DataArrayWriter<float> > p
161 if(!p->writeIsNoop())
162 for (Iterator eit = begin; eit!=end; ++eit)
164 const Entity & e = *eit;
166 Refinement &refinement =
167 buildRefinement<dim, ctype>(eit->type(),
168 subsampledGeometryType(eit->type()));
174 f.write(sit.coords(),*p);
176 for(
unsigned j = f.fieldInfo().size(); j < writecomps; j++)
210 void addVertexData (
const V& v,
const std::string &name,
int ncomps=1);
212 void addCellData (
const V& v,
const std::string &name,
int ncomps=1);
214 Dune::RefinementIntervals intervals;
215 bool coerceToSimplex;
219 template <
class Gr
idView>
225 for (
CellIterator it=this->cellBegin(); it!=cellEnd(); ++it)
227 Refinement &refinement = buildRefinement<dim, ctype>(it->type(), subsampledGeometryType(it->type()));
229 ncells += refinement.nElements(intervals);
230 nvertices += refinement.nVertices(intervals);
231 ncorners += refinement.nElements(intervals) * refinement.eBegin(intervals).vertexIndices().size();
237 template <
class Gr
idView>
240 if(celldata.size() == 0)
246 std::string defaultScalarField, defaultVectorField;
247 std::tie(defaultScalarField, defaultVectorField) = this->getDataNames(celldata);
249 writer.
beginCellData(defaultScalarField, defaultVectorField);
250 writeData(writer,celldata,cellBegin(),cellEnd(),ncells,IteratorSelector<SubElementIterator>());
255 template <
class Gr
idView>
258 if(vertexdata.size() == 0)
264 std::string defaultScalarField, defaultVectorField;
265 std::tie(defaultScalarField, defaultVectorField) = this->getDataNames(vertexdata);
268 writeData(writer,vertexdata,cellBegin(),cellEnd(),nvertices,IteratorSelector<SubVertexIterator>());
273 template <
class Gr
idView>
278 std::shared_ptr<VTK::DataArrayWriter<float> > p
280 if(!p->writeIsNoop())
283 Refinement &refinement =
284 buildRefinement<dim, ctype>(i->type(),
285 subsampledGeometryType(i->type()));
286 for(SubVertexIterator sit = refinement.vBegin(intervals),
287 send = refinement.vEnd(intervals);
290 FieldVector<ctype, dimw> coords = i->geometry().global(sit.coords());
291 for (
int j=0; j<std::min(
int(dimw),3); j++)
293 for (
int j=std::min(
int(dimw),3); j<3; j++)
304 template <
class Gr
idView>
311 std::shared_ptr<VTK::DataArrayWriter<int> > p1
314 if(!p1->writeIsNoop()) {
318 GeometryType coercedToType = subsampledGeometryType(i->type());
319 Refinement &refinement =
320 buildRefinement<dim, ctype>(i->type(), coercedToType);
321 for(SubElementIterator sit = refinement.eBegin(intervals),
322 send = refinement.eEnd(intervals);
325 IndexVector indices = sit.vertexIndices();
326 for(
unsigned int ii = 0; ii < indices.size(); ++ii)
329 offset += refinement.nVertices(intervals);
336 std::shared_ptr<VTK::DataArrayWriter<int> > p2
338 if(!p2->writeIsNoop()) {
343 Refinement &refinement =
344 buildRefinement<dim, ctype>(i->type(),
345 subsampledGeometryType(i->type()));
346 unsigned int verticesPerCell =
347 refinement.eBegin(intervals).vertexIndices().size();
348 for(
int element = 0; element < refinement.nElements(intervals);
351 offset += verticesPerCell;
361 std::shared_ptr<VTK::DataArrayWriter<unsigned char> > p3
363 if(!p3->writeIsNoop())
366 GeometryType coerceTo = subsampledGeometryType(it->type());
367 Refinement &refinement =
368 buildRefinement<dim, ctype>(it->type(), coerceTo);
370 for(
int i = 0; i < refinement.nElements(intervals); ++i)
379 #endif // DUNE_SUBSAMPLINGVTKWRITER_HH
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: subsamplingvtkwriter.hh:305
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:634
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: vtuwriter.hh:203
int ncells
Definition: vtkwriter.hh:1448
CellIterator cellEnd() const
Definition: vtkwriter.hh:343
int level_
Definition: subsamplingvtkwriter.hh:100
SubElementIterator refinementEnd(const Refinement &refinement, Dune::RefinementIntervals intervals, IteratorSelector< SubElementIterator >)
Definition: subsamplingvtkwriter.hh:124
@ dimension
The dimension of the grid.
Definition: common/gridview.hh:127
void endPointData()
finish PointData section
Definition: vtuwriter.hh:180
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
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:587
Iterator over the grids elements.
Definition: vtkwriter.hh:325
void endCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:283
@ dimensionworld
The dimension of the world the grid lives in.
Definition: common/gridview.hh:131
Provides file i/o for the visualization toolkit.
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:88
std::list< VTKLocalFunction > celldata
Definition: vtkwriter.hh:1441
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: vtuwriter.hh:165
VertexIterator vertexBegin() const
Definition: vtkwriter.hh:449
DataArrayWriter< T > * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems)
acquire a DataArrayWriter
Definition: vtuwriter.hh:379
SubsamplingVTKWriter(const GridView &gridView, Dune::RefinementIntervals intervals_, bool coerceToSimplex_=false)
Construct a SubsamplingVTKWriter working on a specific GridView.
Definition: subsamplingvtkwriter.hh:77
void endCellData()
finish CellData section
Definition: vtuwriter.hh:218
int nvertices
Definition: vtkwriter.hh:1449
virtual void writeCellData(VTK::VTUWriter &writer)
write cell data
Definition: subsamplingvtkwriter.hh:238
Descriptor struct for VTK fields.
Definition: common.hh:314
virtual void countEntities(int &nvertices, int &ncells, int &ncorners)
count the vertices, cells and corners
Definition: subsamplingvtkwriter.hh:220
std::list< VTKLocalFunction >::const_iterator FunctionIterator
Definition: vtkwriter.hh:317
@ tensor
tensor field (always 3x3)
void endPoints()
finish section for the point coordinates
Definition: vtuwriter.hh:247
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:197
VTK::OutputType outputtype
Definition: vtkwriter.hh:1465
std::list< VTKLocalFunction > vertexdata
Definition: vtkwriter.hh:1442
void beginCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:272
SubVertexIterator refinementBegin(const Refinement &refinement, Dune::RefinementIntervals intervals, IteratorSelector< SubVertexIterator >)
Definition: subsamplingvtkwriter.hh:119
VertexIterator vertexEnd() const
Definition: vtkwriter.hh:456
int ncorners
Definition: vtkwriter.hh:1450
SubElementIterator refinementBegin(const Refinement &refinement, Dune::RefinementIntervals intervals, IteratorSelector< SubElementIterator >)
Definition: subsamplingvtkwriter.hh:114
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: subsamplingvtkwriter.hh:274
SubVertexIterator refinementEnd(const Refinement &refinement, Dune::RefinementIntervals intervals, IteratorSelector< SubVertexIterator >)
Definition: subsamplingvtkwriter.hh:129
@ vector
vector-valued field (always 3D, will be padded if necessary)
int bool coerceToSimplex_
Definition: subsamplingvtkwriter.hh:100
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:96
int renumber(const Dune::GeometryType &t, int i)
renumber VTK <-> Dune
Definition: common.hh:232
Grid view abstract base class.
Definition: common/gridview.hh:59
Include standard header files.
Definition: agrid.hh:58
@ nonconforming
Output non-conforming data.
Definition: common.hh:78
void beginPoints()
start section for the point coordinates
Definition: vtuwriter.hh:236
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: subsamplingvtkwriter.hh:256
std::size_t size() const
The number of components in the data field.
Definition: common.hh:350
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 writeData(VTK::VTUWriter &writer, const Data &data, const Iterator begin, const Iterator end, int nentries, IteratorSelector< SubIterator > sis)
Definition: subsamplingvtkwriter.hh:135
Type type() const
The type of the data field.
Definition: common.hh:344
Writer for the output of subsampled grid functions in the vtk format.
Definition: subsamplingvtkwriter.hh:36
CellIterator cellBegin() const
Definition: vtkwriter.hh:338