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;
76 int level_,
bool coerceToSimplex_ =
false)
78 , level(level_), coerceToSimplex(coerceToSimplex_)
81 DUNE_THROW(Dune::IOError,
"SubsamplingVTKWriter: Negative Subsampling " << level_ <<
" must not be used!");
87 if(geometryType.isCube() && !coerceToSimplex) { }
88 else geometryType.makeSimplex(dim);
93 template<
typename SubIterator>
94 struct IteratorSelector
97 SubElementIterator refinementBegin(
const Refinement& refinement,
int level, IteratorSelector<SubElementIterator>)
99 return refinement.eBegin(level);
102 SubVertexIterator refinementBegin(
const Refinement& refinement,
int level, IteratorSelector<SubVertexIterator>)
104 return refinement.vBegin(level);
107 SubElementIterator refinementEnd(
const Refinement& refinement,
int level, IteratorSelector<SubElementIterator>)
109 return refinement.eEnd(level);
112 SubVertexIterator refinementEnd(
const Refinement& refinement,
int level, IteratorSelector<SubVertexIterator>)
114 return refinement.vEnd(level);
117 template<
typename Data,
typename Iterator,
typename SubIterator>
118 void writeData(
VTK::VTUWriter& writer,
const Data& data,
const Iterator begin,
const Iterator end,
int nentries, IteratorSelector<SubIterator> sis)
120 for (
auto it = data.begin(),
127 std::size_t writecomps = fieldInfo.
size();
128 switch (fieldInfo.
type())
136 DUNE_THROW(IOError,
"Cannot write VTK vectors with more than 3 components (components was " << writecomps <<
")");
140 DUNE_THROW(NotImplemented,
"VTK output for tensors not implemented yet");
142 std::shared_ptr<VTK::DataArrayWriter<float> > p
144 if(!p->writeIsNoop())
145 for (Iterator eit = begin; eit!=end; ++eit)
147 const Entity & e = *eit;
149 Refinement &refinement =
150 buildRefinement<dim, ctype>(eit->type(),
151 subsampledGeometryType(eit->type()));
152 for(SubIterator sit = refinementBegin(refinement,level,sis),
153 send = refinementEnd(refinement,level,sis);
157 f.write(sit.coords(),*p);
159 for(
unsigned j = f.fieldInfo().size(); j < writecomps; j++)
193 void addVertexData (
const V& v,
const std::string &name,
int ncomps=1);
195 void addCellData (
const V& v,
const std::string &name,
int ncomps=1);
198 bool coerceToSimplex;
202 template <
class Gr
idView>
210 Refinement &refinement = buildRefinement<dim, ctype>(it->type(), subsampledGeometryType(it->type()));
212 ncells += refinement.nElements(level);
213 nvertices += refinement.nVertices(level);
214 ncorners += refinement.nElements(level) * refinement.eBegin(level).vertexIndices().size();
220 template <
class Gr
idView>
229 std::string defaultScalarField, defaultVectorField;
232 writer.
beginCellData(defaultScalarField, defaultVectorField);
238 template <
class Gr
idView>
247 std::string defaultScalarField, defaultVectorField;
256 template <
class Gr
idView>
261 std::shared_ptr<VTK::DataArrayWriter<float> > p
263 if(!p->writeIsNoop())
266 Refinement &refinement =
267 buildRefinement<dim, ctype>(i->type(),
268 subsampledGeometryType(i->type()));
269 for(SubVertexIterator sit = refinement.vBegin(level),
270 send = refinement.vEnd(level);
273 FieldVector<ctype, dimw> coords = i->geometry().global(sit.coords());
274 for (
int j=0; j<
std::min(
int(dimw),3); j++)
276 for (
int j=std::min(
int(dimw),3); j<3; j++)
287 template <
class Gr
idView>
294 std::shared_ptr<VTK::DataArrayWriter<int> > p1
297 if(!p1->writeIsNoop()) {
301 GeometryType coercedToType = subsampledGeometryType(i->type());
302 Refinement &refinement =
303 buildRefinement<dim, ctype>(i->type(), coercedToType);
304 for(SubElementIterator sit = refinement.eBegin(level),
305 send = refinement.eEnd(level);
308 IndexVector indices = sit.vertexIndices();
309 for(
unsigned int ii = 0; ii < indices.size(); ++ii)
312 offset += refinement.nVertices(level);
319 std::shared_ptr<VTK::DataArrayWriter<int> > p2
321 if(!p2->writeIsNoop()) {
326 Refinement &refinement =
327 buildRefinement<dim, ctype>(i->type(),
328 subsampledGeometryType(i->type()));
329 unsigned int verticesPerCell =
330 refinement.eBegin(level).vertexIndices().size();
331 for(
int element = 0; element < refinement.nElements(level);
334 offset += verticesPerCell;
344 std::shared_ptr<VTK::DataArrayWriter<unsigned char> > p3
346 if(!p3->writeIsNoop())
349 GeometryType coerceTo = subsampledGeometryType(it->type());
350 Refinement &refinement =
351 buildRefinement<dim, ctype>(it->type(), coerceTo);
353 for(
int i = 0; i < refinement.nElements(level); ++i)
362 #endif // DUNE_SUBSAMPLINGVTKWRITER_HH Writer for the ouput of grid functions in the vtk format.Writes arbitrary grid functions (living on c...
Definition: vtkwriter.hh:87
Output non-conforming data.
Definition: common.hh:78
CellIterator cellEnd() const
Definition: vtkwriter.hh:344
SubsamplingVTKWriter(const GridView &gridView, int level_, bool coerceToSimplex_=false)
Construct a SubsamplingVTKWriter working on a specific GridView.
Definition: subsamplingvtkwriter.hh:75
std::list< VTKLocalFunction > vertexdata
Definition: vtkwriter.hh:1437
tensor field (always 3x3)
void beginPoints()
start section for the point coordinates
Definition: vtuwriter.hh:236
virtual void writeCellData(VTK::VTUWriter &writer)
write cell data
Definition: subsamplingvtkwriter.hh:221
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: vtuwriter.hh:203
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
std::tuple< std::string, std::string > getDataNames(const T &data) const
Definition: vtkwriter.hh:1116
VTK::OutputType outputtype
Definition: vtkwriter.hh:1460
void endPointData()
finish PointData section
Definition: vtuwriter.hh:180
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:632
void endPoints()
finish section for the point coordinates
Definition: vtuwriter.hh:247
vector-valued field (always 3D, will be padded if necessary)
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: vtuwriter.hh:165
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:197
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:346
void beginCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:272
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:588
Descriptor struct for VTK fields.
Definition: common.hh:314
void endCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:283
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: subsamplingvtkwriter.hh:257
std::list< VTKLocalFunction >::const_iterator FunctionIterator
Definition: vtkwriter.hh:318
Type type() const
The type of the data field.
Definition: common.hh:344
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: subsamplingvtkwriter.hh:239
VertexIterator vertexBegin() const
Definition: vtkwriter.hh:450
DataArrayWriter< T > * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems)
acquire a DataArrayWriter
Definition: vtuwriter.hh:379
CellIterator cellBegin() const
Definition: vtkwriter.hh:339
virtual void countEntities(int &nvertices, int &ncells, int &ncorners)
count the vertices, cells and corners
Definition: subsamplingvtkwriter.hh:203
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:96
Iterator over the grids elements.
Definition: vtkwriter.hh:326
Include standard header files.
Definition: agrid.hh:59
int nvertices
Definition: vtkwriter.hh:1444
std::list< VTKLocalFunction > celldata
Definition: vtkwriter.hh:1436
int ncorners
Definition: vtkwriter.hh:1445
The dimension of the grid.
Definition: common/gridview.hh:128
std::size_t size() const
The number of components in the data field.
Definition: common.hh:350
Provides file i/o for the visualization toolkit.
void endCellData()
finish CellData section
Definition: vtuwriter.hh:218
int ncells
Definition: vtkwriter.hh:1443
int renumber(const Dune::GeometryType &t, int i)
renumber VTK <-> Dune
Definition: common.hh:232
Writer for the output of subsampled grid functions in the vtk format.Writes arbitrary grid functions ...
Definition: subsamplingvtkwriter.hh:36
Grid view abstract base class.
Definition: common/gridview.hh:59
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: subsamplingvtkwriter.hh:288
The dimension of the world the grid lives in.
Definition: common/gridview.hh:132
VertexIterator vertexEnd() const
Definition: vtkwriter.hh:457