4#ifndef DUNE_SUBSAMPLINGVTKWRITER_HH
5#define DUNE_SUBSAMPLINGVTKWRITER_HH
13#include <dune/grid/io/file/vtk/vtuwriter.hh>
34 template<
class Gr
idView >
41 typedef typename GridView::Grid::ctype ctype;
48 typedef typename Base::FunctionIterator FunctionIterator;
49 using Base::cellBegin;
54 using Base::nvertices;
55 using Base::outputtype;
56 using Base::vertexBegin;
57 using Base::vertexEnd;
58 using Base::vertexdata;
74 unsigned int level_,
bool coerceToSimplex_ =
false)
75 :
Base(gridView, VTK::nonconforming)
76 , level(level_), coerceToSimplex(coerceToSimplex_)
81 if(geometryType.isCube() && !coerceToSimplex) { }
82 else geometryType.makeSimplex(dim);
88 virtual void countEntities(
int &nvertices,
int &ncells,
int &ncorners);
111 void addVertexData (
const V& v,
const std::string &name,
int ncomps=1);
114 bool coerceToSimplex;
118 template <
class Gr
idView>
124 for (
CellIterator it=this->cellBegin(); it!=cellEnd(); ++it)
126 Refinement &refinement = buildRefinement<dim, ctype>(it->type(), subsampledGeometryType(it->type()));
129 nvertices += refinement.
nVertices(level);
130 ncorners += refinement.
nElements(level) * refinement.
eBegin(level).vertexIndices().size();
135 template <
class Gr
idView>
138 if(celldata.size() == 0)
141 std::string scalars =
"";
142 for (FunctionIterator it=celldata.begin(); it!=celldata.end(); ++it)
143 if ((*it)->ncomps()==1)
145 scalars = (*it)->name();
148 std::string vectors =
"";
149 for (FunctionIterator it=celldata.begin(); it!=celldata.end(); ++it)
150 if ((*it)->ncomps()>1)
152 vectors = (*it)->name();
157 for (FunctionIterator it=celldata.begin(); it!=celldata.end(); ++it)
161 unsigned writecomps = (*it)->ncomps();
162 if(writecomps == 2) writecomps = 3;
166 if(!p->writeIsNoop())
170 buildRefinement<dim, ctype>(i->type(),
171 subsampledGeometryType(i->type()));
172 for(SubElementIterator sit = refinement.
eBegin(level),
173 send = refinement.
eEnd(level);
176 for (
int j=0; j<(*it)->ncomps(); j++)
177 p->write((*it)->evaluate(j,*i,sit.coords()));
179 for(
unsigned j = (*it)->ncomps(); j < writecomps; j++)
188 template <
class Gr
idView>
191 if(vertexdata.size() == 0)
194 std::string scalars =
"";
195 for (FunctionIterator it=vertexdata.begin(); it!=vertexdata.end(); ++it)
196 if ((*it)->ncomps()==1)
198 scalars = (*it)->name();
201 std::string vectors =
"";
202 for (FunctionIterator it=vertexdata.begin(); it!=vertexdata.end(); ++it)
203 if ((*it)->ncomps()>1)
205 vectors = (*it)->name();
210 for (FunctionIterator it=vertexdata.begin(); it!=vertexdata.end(); ++it)
214 unsigned writecomps = (*it)->ncomps();
215 if(writecomps == 2) writecomps = 3;
219 if(!p->writeIsNoop())
223 buildRefinement<dim, ctype>(i->type(),
224 subsampledGeometryType(i->type()));
225 for(SubVertexIterator sit = refinement.
vBegin(level),
226 send = refinement.
vEnd(level);
229 for (
int j=0; j<(*it)->ncomps(); j++)
230 p->write((*it)->evaluate(j,*i,sit.coords()));
233 for(
unsigned j = (*it)->ncomps(); j < writecomps; j++)
242 template <
class Gr
idView>
249 if(!p->writeIsNoop())
253 buildRefinement<dim, ctype>(i->type(),
254 subsampledGeometryType(i->type()));
255 for(SubVertexIterator sit = refinement.
vBegin(level),
256 send = refinement.
vEnd(level);
260 for (
int j=0; j<std::min(
int(dimw),3); j++)
262 for (
int j=std::min(
int(dimw),3); j<3; j++)
273 template <
class Gr
idView>
283 if(!p1->writeIsNoop()) {
287 GeometryType coercedToType = subsampledGeometryType(i->type());
289 buildRefinement<dim, ctype>(i->type(), coercedToType);
290 for(SubElementIterator sit = refinement.
eBegin(level),
291 send = refinement.
eEnd(level);
294 IndexVector indices = sit.vertexIndices();
295 for(
unsigned int ii = 0; ii < indices.size(); ++ii)
296 p1->write(offset+indices[VTK::renumber(coercedToType, ii)]);
307 if(!p2->writeIsNoop()) {
313 buildRefinement<dim, ctype>(i->type(),
314 subsampledGeometryType(i->type()));
315 unsigned int verticesPerCell =
316 refinement.
eBegin(level).vertexIndices().size();
317 for(
int element = 0; element < refinement.
nElements(level);
320 offset += verticesPerCell;
332 if(!p3->writeIsNoop())
335 GeometryType coerceTo = subsampledGeometryType(it->type());
337 buildRefinement<dim, ctype>(it->type(), coerceTo);
338 int vtktype = VTK::geometryType(coerceTo);
339 for(
int i = 0; i < refinement.
nElements(level); ++i)
vector space out of a tensor product of fields.
Definition: fvector.hh:92
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Grid view abstract base class.
Definition: gridview.hh:57
@ dimensionworld
The dimension of the world the grid lives in.
Definition: gridview.hh:124
@ dimension
The dimension of the grid.
Definition: gridview.hh:120
Writer for the output of subsampled grid functions in the vtk format.
Definition: subsamplingvtkwriter.hh:37
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: subsamplingvtkwriter.hh:243
SubsamplingVTKWriter(const GridView &gridView, unsigned int level_, bool coerceToSimplex_=false)
Construct a SubsamplingVTKWriter working on a specific GridView.
Definition: subsamplingvtkwriter.hh:73
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: subsamplingvtkwriter.hh:189
virtual void countEntities(int &nvertices, int &ncells, int &ncorners)
count the vertices, cells and corners
Definition: subsamplingvtkwriter.hh:119
virtual void writeCellData(VTK::VTUWriter &writer)
write cell data
Definition: subsamplingvtkwriter.hh:136
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: subsamplingvtkwriter.hh:274
Iterator over the grids elements.
Definition: vtkwriter.hh:112
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:60
void addVertexData(VTKFunction *p)
Add a grid function that lives on the vertices of the grid to the visualization.
Definition: vtkwriter.hh:416
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:96
void endCellData()
finish CellData section
Definition: vtuwriter.hh:218
void beginCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:272
DataArrayWriter< T > * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems)
aquire a DataArrayWriter
Definition: vtuwriter.hh:379
void endPointData()
finish PointData section
Definition: vtuwriter.hh:180
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: vtuwriter.hh:203
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: vtuwriter.hh:165
void endPoints()
finish section for the point coordinates
Definition: vtuwriter.hh:247
void endCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:283
void beginPoints()
start section for the point coordinates
Definition: vtuwriter.hh:236
VirtualRefinement base class.
Definition: virtualrefinement.hh:292
VertexIterator vEnd(int level) const
Get a VertexIterator.
Definition: virtualrefinement.cc:44
ElementIterator eBegin(int level) const
Get an ElementIterator.
Definition: virtualrefinement.cc:52
Codim< 0 >::SubEntityIterator ElementIterator
The ElementIterator of the VirtualRefinement.
Definition: virtualrefinement.hh:299
ElementIterator eEnd(int level) const
Get an ElementIterator.
Definition: virtualrefinement.cc:60
virtual int nVertices(int level) const =0
Get the number of Vertices.
VertexIterator vBegin(int level) const
Get a VertexIterator.
Definition: virtualrefinement.cc:36
std::vector< int > IndexVector
The IndexVector of the VirtualRefinement.
Definition: virtualrefinement.hh:312
Codim< dimension >::SubEntityIterator VertexIterator
The VertexIterator of the VirtualRefinement.
Definition: virtualrefinement.hh:297
virtual int nElements(int level) const =0
Get the number of Elements.
A reference counting smart pointer.
Definition: shared_ptr.hh:64
This file contains the virtual wrapper around refinement.
void reset()
Decrease the reference count by one and free the memory if the reference count has reached 0.
Definition: shared_ptr.hh:354
Utility class for handling nested indentation in output.
Dune namespace.
Definition: alignment.hh:14
A unique label for each type of element that can occur in a grid.
Provides file i/o for the visualization toolkit.