6#ifndef DUNE_GRID_IO_FILE_VTK_FUNCTIONWRITER_HH
7#define DUNE_GRID_IO_FILE_VTK_FUNCTIONWRITER_HH
15#include <dune/common/exceptions.hh>
16#include <dune/common/fvector.hh>
18#include <dune/geometry/referenceelements.hh>
33 template<
typename Cell_>
35 typedef typename Cell_::Geometry::ctype DF;
36 static const unsigned mydim = Cell_::mydimension;
37 typedef ReferenceElements<DF, mydim> Refelems;
40 typedef FieldVector<DF, mydim>
Domain;
44 virtual std::string
name()
const = 0;
60 DUNE_THROW(NotImplemented,
"FunctionWriterBase::write(const Cell&, "
61 "const Domain&): Either the derived class " <<
62 typeid(*this).name() <<
" failed to implement this method "
63 "or this method is not meant to be called on the derived "
64 "class and was called in error.");
71 virtual void write(
const Cell& cell,
unsigned cornerIndex) {
73 Refelems::general(cell.type()).position(cornerIndex, mydim));
87 template<
typename Func>
92 std::shared_ptr<const Func> func;
94 std::shared_ptr<DataArrayWriter> arraywriter;
99 : func(func_), precision_(prec)
103 virtual std::string
name()
const {
return func->name(); }
107 if(func->ncomps() == 2)
return 3;
108 else return func->ncomps();
119 nitems, precision_));
120 return !arraywriter->writeIsNoop();
126 for(
int d = 0; d < func->ncomps(); ++d)
127 arraywriter->write(func->evaluate(d, cell, xl));
128 for(
unsigned d = func->ncomps(); d <
ncomps(); ++d)
129 arraywriter->write(0);
144 template<
typename Cell>
151 std::shared_ptr<DataArrayWriter> arraywriter;
159 virtual std::string
name()
const {
return "Coordinates"; }
162 virtual unsigned ncomps()
const {
return 3; }
172 nitems, precision_));
173 return !arraywriter->writeIsNoop();
178 FieldVector<typename Base::Cell::Geometry::ctype, Base::Cell::Geometry::coorddimension> xg
179 = cell.geometry().global(xl);
180 for(
unsigned d = 0; d < 3 && d < Base::Cell::Geometry::coorddimension; ++d)
181 arraywriter->write(xg[d]);
182 for(
unsigned d = Base::Cell::Geometry::coorddimension; d < 3; ++d)
183 arraywriter->write(0);
192 template<
typename IteratorFactory>
197 static const unsigned mydim = Base::Cell::mydimension;
199 const IteratorFactory& factory;
200 std::shared_ptr<DataArrayWriter> arraywriter;
201 std::vector<unsigned> pointIndices;
210 virtual std::string
name()
const {
return "connectivity"; }
213 virtual unsigned ncomps()
const {
return 1; }
224 if(arraywriter->writeIsNoop())
228 pointIndices.resize(factory.indexSet().size(mydim));
229 const typename IteratorFactory::PointIterator& pend =
231 typename IteratorFactory::PointIterator pit = factory.beginPoints();
232 unsigned counter = 0;
234 pointIndices[factory.indexSet().subIndex
235 (pit->cell(), pit->duneIndex(), mydim)] = counter;
245 if(pointIndices.size() == 0)
247 arraywriter->write(pointIndices[factory.indexSet().subIndex
248 (cell, cornerIndex, mydim)]);
253 pointIndices.clear();
258 template<
typename Cell>
262 std::shared_ptr<DataArrayWriter> arraywriter;
267 virtual std::string
name()
const {
return "connectivity"; }
270 virtual unsigned ncomps()
const {
return 1; }
282 return !arraywriter->writeIsNoop();
287 arraywriter->write(counter);
297 template<
typename Cell>
303 std::shared_ptr<DataArrayWriter> arraywriter;
308 virtual std::string
name()
const {
return "offsets"; }
311 virtual unsigned ncomps()
const {
return 1; }
323 return !arraywriter->writeIsNoop();
327 offset += cell.geometry().corners();
328 arraywriter->write(offset);
337 template<
typename Cell>
343 std::shared_ptr<DataArrayWriter> arraywriter;
347 virtual std::string
name()
const {
return "types"; }
350 virtual unsigned ncomps()
const {
return 1; }
361 return !arraywriter->writeIsNoop();
Data array writers for the VTKWriter.
Common stuff for the VTKWriter.
Include standard header files.
Definition: agrid.hh:60
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:271
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:151
Base class for function writers.
Definition: functionwriter.hh:34
virtual std::string name() const =0
return name
virtual unsigned ncomps() const =0
return number of components of the vector
virtual void write(const Cell &, const Domain &)
write at the given position
Definition: functionwriter.hh:59
Cell_ Cell
Definition: functionwriter.hh:41
virtual void addArray(PVTUWriter &writer)=0
add this field to the given parallel writer
virtual void endWrite()=0
signal end of writing
FieldVector< DF, mydim > Domain
Definition: functionwriter.hh:40
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)=0
start writing with the given writer
virtual ~FunctionWriterBase()
destructor
Definition: functionwriter.hh:78
virtual void write(const Cell &cell, unsigned cornerIndex)
write at the given corner
Definition: functionwriter.hh:71
Base class for function writers.
Definition: functionwriter.hh:90
VTKFunctionWriter(const std::shared_ptr< const Func > &func_, VTK::Precision prec=VTK::Precision::float32)
Definition: functionwriter.hh:97
virtual std::string name() const
return name
Definition: functionwriter.hh:103
virtual unsigned ncomps() const
return number of components of the vector
Definition: functionwriter.hh:106
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)
start writing with the given writer
Definition: functionwriter.hh:117
virtual void addArray(PVTUWriter &writer)
add this field to the given parallel writer
Definition: functionwriter.hh:112
virtual void write(const typename Base::Cell &cell, const typename Base::Domain &xl)
write at the given position
Definition: functionwriter.hh:124
virtual void endWrite()
signal end of writing
Definition: functionwriter.hh:133
writer for the Coordinates array
Definition: functionwriter.hh:147
virtual void write(const typename Base::Cell &cell, const typename Base::Domain &xl)
write at the given position
Definition: functionwriter.hh:176
virtual std::string name() const
return name
Definition: functionwriter.hh:159
virtual void endWrite()
signal end of writing
Definition: functionwriter.hh:186
virtual unsigned ncomps() const
return number of components of the vector
Definition: functionwriter.hh:162
virtual void addArray(PVTUWriter &writer)
add this field to the given parallel writer
Definition: functionwriter.hh:165
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)
start writing with the given writer
Definition: functionwriter.hh:170
CoordinatesWriter(VTK::Precision prec=VTK::Precision::float32)
Definition: functionwriter.hh:154
writer for the connectivity array in conforming mode
Definition: functionwriter.hh:195
virtual void addArray(PVTUWriter &writer)
add this field to the given parallel writer
Definition: functionwriter.hh:216
virtual std::string name() const
return name
Definition: functionwriter.hh:210
virtual void write(const typename Base::Cell &cell, unsigned cornerIndex)
write at the given corner
Definition: functionwriter.hh:242
ConformingConnectivityWriter(const IteratorFactory &factory_)
create a writer with the given iteratorfactory
Definition: functionwriter.hh:205
virtual unsigned ncomps() const
return number of components of the vector
Definition: functionwriter.hh:213
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)
start writing with the given writer
Definition: functionwriter.hh:221
virtual void endWrite()
signal end of writing
Definition: functionwriter.hh:251
writer for the connectivity array in nonconforming mode
Definition: functionwriter.hh:261
virtual unsigned ncomps() const
return number of components of the vector
Definition: functionwriter.hh:270
virtual std::string name() const
return name
Definition: functionwriter.hh:267
virtual void write(const Cell &, unsigned)
write at the given corner
Definition: functionwriter.hh:285
virtual void addArray(PVTUWriter &writer)
add this field to the given parallel writer
Definition: functionwriter.hh:273
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)
start writing with the given writer
Definition: functionwriter.hh:278
virtual void endWrite()
signal end of writing
Definition: functionwriter.hh:291
writer for the offsets array
Definition: functionwriter.hh:300
virtual void addArray(PVTUWriter &writer)
add this field to the given parallel writer
Definition: functionwriter.hh:314
virtual void endWrite()
signal end of writing
Definition: functionwriter.hh:331
virtual std::string name() const
return name
Definition: functionwriter.hh:308
virtual void write(const Cell &cell, const typename Base::Domain &)
write at the given position
Definition: functionwriter.hh:326
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)
start writing with the given writer
Definition: functionwriter.hh:319
virtual unsigned ncomps() const
return number of components of the vector
Definition: functionwriter.hh:311
writer for the types array
Definition: functionwriter.hh:340
virtual unsigned ncomps() const
return number of components of the vector
Definition: functionwriter.hh:350
virtual bool beginWrite(VTUWriter &writer, std::size_t nitems)
start writing with the given writer
Definition: functionwriter.hh:358
virtual std::string name() const
return name
Definition: functionwriter.hh:347
virtual void write(const Cell &cell, const typename Base::Domain &)
write at the given position
Definition: functionwriter.hh:364
virtual void addArray(PVTUWriter &writer)
add this field to the given parallel writer
Definition: functionwriter.hh:353
virtual void endWrite()
signal end of writing
Definition: functionwriter.hh:368
Dump a .vtu/.vtp files contents to a stream.
Definition: pvtuwriter.hh:62
void addArray(const std::string &name, unsigned ncomps, Precision prec)
Add an array to the output file.
Definition: pvtuwriter.hh:207
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:98
DataArrayWriter * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems, Precision prec)
acquire a DataArrayWriter
Definition: vtuwriter.hh:380