4 #ifndef DUNE_SUBSAMPLINGVTKWRITER_HH
5 #define DUNE_SUBSAMPLINGVTKWRITER_HH
9 #include <dune/common/indent.hh>
10 #include <dune/geometry/type.hh>
11 #include <dune/geometry/virtualrefinement.hh>
34 template<
class Gr
idView >
41 typedef typename GridView::Grid::ctype ctype;
42 typedef VirtualRefinement<dim, ctype> Refinement;
43 typedef typename Refinement::IndexVector IndexVector;
44 typedef typename Refinement::ElementIterator SubElementIterator;
45 typedef typename Refinement::VertexIterator SubVertexIterator;
74 unsigned int level_,
bool coerceToSimplex_ =
false)
76 , level(level_), coerceToSimplex(coerceToSimplex_)
81 if(geometryType.isCube() && !coerceToSimplex) { }
82 else geometryType.makeSimplex(dim);
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()));
128 ncells += refinement.nElements(level);
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;
164 shared_ptr<VTK::DataArrayWriter<float> > p
166 if(!p->writeIsNoop())
169 Refinement &refinement =
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;
217 shared_ptr<VTK::DataArrayWriter<float> > p
219 if(!p->writeIsNoop())
222 Refinement &refinement =
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>
247 shared_ptr<VTK::DataArrayWriter<float> > p
249 if(!p->writeIsNoop())
252 Refinement &refinement =
253 buildRefinement<dim, ctype>(i->type(),
254 subsampledGeometryType(i->type()));
255 for(SubVertexIterator sit = refinement.vBegin(level),
256 send = refinement.vEnd(level);
259 FieldVector<ctype, dimw> coords = i->geometry().global(sit.coords());
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>
280 shared_ptr<VTK::DataArrayWriter<int> > p1
283 if(!p1->writeIsNoop()) {
287 GeometryType coercedToType = subsampledGeometryType(i->type());
288 Refinement &refinement =
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)
298 offset += refinement.nVertices(level);
305 shared_ptr<VTK::DataArrayWriter<int> > p2
307 if(!p2->writeIsNoop()) {
312 Refinement &refinement =
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;
330 shared_ptr<VTK::DataArrayWriter<unsigned char> > p3
332 if(!p3->writeIsNoop())
335 GeometryType coerceTo = subsampledGeometryType(it->type());
336 Refinement &refinement =
337 buildRefinement<dim, ctype>(it->type(), coerceTo);
339 for(
int i = 0; i < refinement.nElements(level); ++i)
348 #endif // DUNE_SUBSAMPLINGVTKWRITER_HH
The dimension of the world the grid lives in.
Definition: common/gridview.hh:124
Writer for the ouput of grid functions in the vtk format.Writes arbitrary grid functions (living on c...
Definition: vtkwriter.hh:60
VertexIterator vertexBegin() const
Definition: vtkwriter.hh:232
std::list< VTKFunctionPtr > celldata
Definition: vtkwriter.hh:1068
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
The dimension of the grid.
Definition: common/gridview.hh:120
void endCellData()
finish CellData section
Definition: vtuwriter.hh:218
void beginPoints()
start section for the point coordinates
Definition: vtuwriter.hh:236
Provides file i/o for the visualization toolkit.
virtual void writeCellData(VTK::VTUWriter &writer)
write cell data
Definition: subsamplingvtkwriter.hh:136
int ncells
Definition: vtkwriter.hh:1075
CellIterator cellEnd() const
Definition: vtkwriter.hh:129
int ncorners
Definition: vtkwriter.hh:1077
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:195
Iterator over the grids elements.
Definition: vtkwriter.hh:111
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: subsamplingvtkwriter.hh:274
std::list< VTKFunctionPtr > vertexdata
Definition: vtkwriter.hh:1069
void endPointData()
finish PointData section
Definition: vtuwriter.hh:180
SubsamplingVTKWriter(const GridView &gridView, unsigned int level_, bool coerceToSimplex_=false)
Construct a SubsamplingVTKWriter working on a specific GridView.
Definition: subsamplingvtkwriter.hh:73
Definition: alugrid/common/declaration.hh:20
Grid view abstract base classInterface class for a view on grids. Grids return two types of view...
Definition: common/gridview.hh:56
CellIterator cellBegin() const
Definition: vtkwriter.hh:124
void endCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:283
VTK::OutputType outputtype
Definition: vtkwriter.hh:1085
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: vtuwriter.hh:203
Writer for the output of subsampled grid functions in the vtk format.Writes arbitrary grid functions ...
Definition: subsamplingvtkwriter.hh:35
virtual void countEntities(int &nvertices, int &ncells, int &ncorners)
count the vertices, cells and corners
Definition: subsamplingvtkwriter.hh:119
int renumber(const Dune::GeometryType &t, int i)
renumber VTK <-> Dune
Definition: common.hh:224
int nvertices
Definition: vtkwriter.hh:1076
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: subsamplingvtkwriter.hh:189
void beginCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:272
void addVertexData(VTKFunction *p)
Add a grid function that lives on the vertices of the grid to the visualization.
Definition: vtkwriter.hh:416
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: subsamplingvtkwriter.hh:243
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:96
void endPoints()
finish section for the point coordinates
Definition: vtuwriter.hh:247
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: vtuwriter.hh:165
VertexIterator vertexEnd() const
Definition: vtkwriter.hh:239
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:352
DataArrayWriter< T > * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems)
aquire a DataArrayWriter
Definition: vtuwriter.hh:379
std::list< VTKFunctionPtr >::const_iterator FunctionIterator
Definition: vtkwriter.hh:103