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;
78 Dune::RefinementIntervals intervals_,
bool coerceToSimplex_ =
false)
80 , intervals(intervals_), coerceToSimplex(coerceToSimplex_)
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)")
100 int level_,
bool coerceToSimplex_ = false)
107 return (geometryType.isCube() && !coerceToSimplex ?
geometryType : GeometryTypes::simplex(dim));
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()));
169 for(SubIterator sit = refinementBegin(refinement,intervals,sis),
170 send = refinementEnd(refinement,intervals,sis);
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>
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>
246 std::string defaultScalarField, defaultVectorField;
249 writer.
beginCellData(defaultScalarField, defaultVectorField);
255 template <
class Gr
idView>
264 std::string defaultScalarField, defaultVectorField;
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 void endCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:283
std::size_t size() const
The number of components in the data field.
Definition: common.hh:350
Output non-conforming data.
Definition: common.hh:78
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: vtuwriter.hh:203
void endPoints()
finish section for the point coordinates
Definition: vtuwriter.hh:247
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: subsamplingvtkwriter.hh:305
The dimension of the world the grid lives in.
Definition: common/gridview.hh:131
CellIterator cellEnd() const
Definition: vtkwriter.hh:343
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:197
int ncorners
Definition: vtkwriter.hh:1450
VTK::OutputType outputtype
Definition: vtkwriter.hh:1465
virtual void writeCellData(VTK::VTUWriter &writer)
write cell data
Definition: subsamplingvtkwriter.hh:238
DataArrayWriter< T > * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems)
acquire a DataArrayWriter
Definition: vtuwriter.hh:379
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: subsamplingvtkwriter.hh:256
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: subsamplingvtkwriter.hh:274
void beginPoints()
start section for the point coordinates
Definition: vtuwriter.hh:236
Writer for the output of subsampled grid functions in the vtk format.Writes arbitrary grid functions ...
Definition: subsamplingvtkwriter.hh:36
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: vtuwriter.hh:165
Descriptor struct for VTK fields.
Definition: common.hh:314
std::tuple< std::string, std::string > getDataNames(const T &data) const
Definition: vtkwriter.hh:1121
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:96
SubsamplingVTKWriter(const GridView &gridView, Dune::RefinementIntervals intervals_, bool coerceToSimplex_=false)
Construct a SubsamplingVTKWriter working on a specific GridView.
Definition: subsamplingvtkwriter.hh:77
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
int nvertices
Definition: vtkwriter.hh:1449
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:346
std::list< VTKLocalFunction > celldata
Definition: vtkwriter.hh:1441
tensor field (always 3x3)
std::list< VTKLocalFunction > vertexdata
Definition: vtkwriter.hh:1442
int renumber(const Dune::GeometryType &t, int i)
renumber VTK <-> Dune
Definition: common.hh:232
Type type() const
The type of the data field.
Definition: common.hh:344
Grid view abstract base class.
Definition: common/gridview.hh:59
void beginCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:272
The dimension of the grid.
Definition: common/gridview.hh:127
vector-valued field (always 3D, will be padded if necessary)
Provides file i/o for the visualization toolkit.
VertexIterator vertexBegin() const
Definition: vtkwriter.hh:449
int ncells
Definition: vtkwriter.hh:1448
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 endCellData()
finish CellData section
Definition: vtuwriter.hh:218
void endPointData()
finish PointData section
Definition: vtuwriter.hh:180
Writer for the ouput of grid functions in the vtk format.Writes arbitrary grid functions (living on c...
Definition: vtkwriter.hh:88
CellIterator cellBegin() const
Definition: vtkwriter.hh:338
VertexIterator vertexEnd() const
Definition: vtkwriter.hh:456
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
Include standard header files.
Definition: agrid.hh:58