4 #ifndef DUNE_GRID_IO_FILE_VTK_FUNCTIONWRITER_HH
5 #define DUNE_GRID_IO_FILE_VTK_FUNCTIONWRITER_HH
12 #include <dune/common/exceptions.hh>
13 #include <dune/common/fvector.hh>
14 #include <dune/common/shared_ptr.hh>
16 #include <dune/geometry/referenceelements.hh>
31 template<
typename Cell_>
33 typedef typename Cell_::ctype DF;
34 static const unsigned mydim = Cell_::mydimension;
35 typedef GenericReferenceElements<DF, mydim> Refelems;
38 typedef FieldVector<DF, mydim>
Domain;
42 virtual std::string
name()
const = 0;
45 virtual unsigned ncomps()
const = 0;
58 DUNE_THROW(NotImplemented,
"FunctionWriterBase::write(const Cell&, "
59 "const Domain&): Either the derived class " <<
60 typeid(*this).name() <<
" failed to implement this method "
61 "or this method is not meant to be called on the derived "
62 "class and was called in error.");
69 virtual void write(
const Cell& cell,
unsigned cornerIndex) {
71 Refelems::general(cell.type()).position(cornerIndex, mydim));
85 template<
typename Func>
90 shared_ptr<const Func> func;
91 shared_ptr<DataArrayWriter<float> > arraywriter;
99 virtual std::string
name()
const {
return func->name(); }
103 if(func->ncomps() == 2)
return 3;
104 else return func->ncomps();
116 return !arraywriter->writeIsNoop();
122 for(
int d = 0; d < func->ncomps(); ++d)
123 arraywriter->write(func->evaluate(d, cell, xl));
124 for(
unsigned d = func->ncomps(); d <
ncomps(); ++d)
125 arraywriter->write(0);
140 template<
typename Cell>
146 shared_ptr<DataArrayWriter<float> > arraywriter;
151 virtual std::string
name()
const {
return "Coordinates"; }
154 virtual unsigned ncomps()
const {
return 3; }
165 return !arraywriter->writeIsNoop();
170 FieldVector<typename Base::Cell::ctype, Base::Cell::dimensionworld> xg
171 = cell.geometry().global(xl);
172 for(
unsigned d = 0; d < 3 && d < Base::Cell::dimensionworld; ++d)
173 arraywriter->write(xg[d]);
174 for(
unsigned d = Base::Cell::dimensionworld; d < 3; ++d)
175 arraywriter->write(0);
184 template<
typename IteratorFactory>
189 static const unsigned mydim = Base::Cell::mydimension;
191 const IteratorFactory& factory;
192 shared_ptr<DataArrayWriter<unsigned> > arraywriter;
193 std::vector<unsigned> pointIndices;
202 virtual std::string
name()
const {
return "connectivity"; }
205 virtual unsigned ncomps()
const {
return 1; }
216 if(arraywriter->writeIsNoop())
220 pointIndices.resize(factory.indexSet().size(mydim));
221 const typename IteratorFactory::PointIterator& pend =
223 typename IteratorFactory::PointIterator pit = factory.beginPoints();
224 unsigned counter = 0;
226 pointIndices[factory.indexSet().subIndex
227 (pit->cell(), pit->duneIndex(), mydim)] = counter;
237 if(pointIndices.size() == 0)
239 arraywriter->write(pointIndices[factory.indexSet().subIndex
240 (cell, cornerIndex, mydim)]);
245 pointIndices.clear();
250 template<
typename Cell>
254 shared_ptr<DataArrayWriter<unsigned> > arraywriter;
259 virtual std::string
name()
const {
return "connectivity"; }
262 virtual unsigned ncomps()
const {
return 1; }
274 return !arraywriter->writeIsNoop();
277 virtual void write(
const Cell& cell,
unsigned cornerIndex)
279 arraywriter->write(counter);
289 template<
typename Cell>
295 shared_ptr<DataArrayWriter<unsigned> > arraywriter;
300 virtual std::string
name()
const {
return "offsets"; }
303 virtual unsigned ncomps()
const {
return 1; }
315 return !arraywriter->writeIsNoop();
319 offset += cell.geometry().corners();
320 arraywriter->write(offset);
329 template<
typename Cell>
335 shared_ptr<DataArrayWriter<unsigned char> > arraywriter;
339 virtual std::string
name()
const {
return "types"; }
342 virtual unsigned ncomps()
const {
return 1; }
353 return !arraywriter->writeIsNoop();
371 #endif // DUNE_GRID_IO_FILE_VTK_FUNCTIONWRITER_HH