24#ifndef VTK_FUNCTION_HH
25#define VTK_FUNCTION_HH
30#include <dune/grid/common/mcmgmapper.hh>
31#include <dune/grid/io/file/vtk/common.hh>
32#include <dune/grid/io/file/vtk/function.hh>
47template <
typename Gr
idView,
typename Mapper,
typename F>
50 enum {
dim = GridView::dimension };
51 using ctype =
typename GridView::ctype;
52 using Element =
typename GridView::template Codim<0>::Entity;
57 virtual int ncomps()
const {
return nComps_; }
60 virtual std::string
name()
const {
return name_; }
63 virtual double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>&)
const
64 {
return accessChooser_(mycomp, mapper_.index(e),
IsIndexable<
decltype(field_[0])>()); }
68 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper)
70 if (field.size()!=(
unsigned int)(mapper.size()))
71 DUNE_THROW(Dune::IOError,
"VectorP0VTKFunction: size mismatch between field "
72 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
78 double accessChooser_(
int mycomp,
int i, std::true_type)
const
79 {
return vectorFieldAccess_(mycomp, i,
IsIndexable<
decltype(field_[0][0])>()); }
82 double accessChooser_(
int mycomp,
int i, std::false_type)
const {
return field_[i]; }
85 double vectorFieldAccess_(
int mycomp,
int i, std::false_type)
const {
return field_[i][mycomp]; }
88 double vectorFieldAccess_(
int mycomp,
int i, std::true_type)
const { DUNE_THROW(Dune::InvalidStateException,
"Invalid field type"); }
91 const std::string name_;
93 const Mapper& mapper_;
104template <
typename Gr
idView,
typename Mapper,
typename F>
107 enum {
dim = GridView::dimension };
108 using ctype =
typename GridView::ctype;
109 using Element =
typename GridView::template Codim<0>::Entity;
114 virtual int ncomps()
const {
return nComps_; }
117 virtual std::string
name()
const {
return name_; }
120 virtual double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const
122 const unsigned int dim = Element::mydimension;
123 const unsigned int nVertices = e.subEntities(
dim);
125 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
126 for (
unsigned i = 0; i < nVertices; ++i)
127 cornerValues[i] = accessChooser_(mycomp, mapper_.subIndex(e, i,
dim),
IsIndexable<
decltype(field_[0])>());
130 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
131 return interpolation.global(xi);
136 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper)
138 if (field.size()!=(
unsigned int)( mapper.size() ))
139 DUNE_THROW(Dune::IOError,
"VectorP1VTKFunction: size mismatch between field "
140 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
145 double accessChooser_(
int mycomp,
int i, std::true_type)
const
146 {
return vectorFieldAccess_(mycomp, i,
IsIndexable<
decltype(field_[0][0])>()); }
149 double accessChooser_(
int mycomp,
int i, std::false_type)
const {
return field_[i]; }
152 double vectorFieldAccess_(
int mycomp,
int i, std::false_type)
const {
return field_[i][mycomp]; }
155 double vectorFieldAccess_(
int mycomp,
int i, std::true_type)
const { DUNE_THROW(Dune::InvalidStateException,
"Invalid field type"); }
158 const std::string name_;
160 const Mapper& mapper_;
175template <
typename Gr
idView,
typename Mapper,
typename F>
178 enum {
dim = GridView::dimension };
179 using ctype =
typename GridView::ctype;
180 using Element =
typename GridView::template Codim<0>::Entity;
185 virtual int ncomps()
const {
return nComps_; }
188 virtual std::string
name()
const {
return name_; }
191 virtual double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const
193 const unsigned int dim = Element::mydimension;
194 const unsigned int nVertices = e.subEntities(
dim);
196 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
197 for (
unsigned i = 0; i < nVertices; ++i)
198 cornerValues[i] = accessChooser_(mycomp, mapper_.index(e), i,
IsIndexable<
decltype(field_[0])>());
201 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
202 return interpolation.global(xi);
207 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper)
209 if (field.size()!=(
unsigned int)(mapper.size()))
210 DUNE_THROW(Dune::IOError,
"VectorP1NonConformingVTKFunction: size mismatch between field "
211 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
216 double accessChooser_(
int mycomp,
int eIdx,
int cornerIdx, std::true_type)
const
217 {
return fieldAccess_(mycomp, eIdx, cornerIdx,
IsIndexable<
decltype(field_[0][0])>()); }
220 double accessChooser_(
int mycomp,
int eIdx,
int cornerIdx, std::false_type)
const
221 { DUNE_THROW(Dune::InvalidStateException,
"Invalid field type"); }
224 double fieldAccess_(
int mycomp,
int eIdx,
int cornerIdx, std::false_type)
const
225 {
return field_[eIdx][cornerIdx]; }
228 double fieldAccess_(
int mycomp,
int eIdx,
int cornerIdx, std::true_type)
const
229 {
return field_[eIdx][cornerIdx][mycomp]; }
232 const std::string name_;
234 const Mapper& mapper_;
243template<
class Gr
idView>
246 enum { dim = GridView::dimension };
247 using ctype =
typename GridView::ctype;
248 using Element =
typename GridView::template Codim<0>::Entity;
252 template <
typename F,
class Mapper>
253 Field(
const GridView& gridView,
const Mapper& mapper, F
const& f,
254 const std::string&
name,
int numComp = 1,
int codim = 0,
255 Dune::VTK::DataMode dm = Dune::VTK::conforming)
258 if (
codim == GridView::dimension)
260 if (dm == Dune::VTK::conforming)
261 field_ = std::make_shared< VectorP1VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp);
263 field_ = std::make_shared< VectorP1NonConformingVTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp);
266 field_ = std::make_shared< VectorP0VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp);
268 DUNE_THROW(Dune::NotImplemented,
"Only element or vertex quantities allowed.");
274 virtual std::string
name ()
const {
return field_->name(); }
277 virtual int ncomps()
const {
return field_->ncomps(); }
280 int codim()
const {
return codim_; }
284 const Element &element,
285 const Dune::FieldVector< ctype, dim > &xi)
const
286 {
return field_->evaluate(mycomp, element, xi); }
289 std::shared_ptr<const Dune::VTKFunction<GridView>>
get()
const
295 std::shared_ptr<Dune::VTKFunction<GridView>> field_;
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
typename Dune::is_indexable< T, I > IsIndexable
We define our own is_indexable type in order to avoid several version checks throughout dumux....
Definition: typetraits.hh:48
a VTK function that supports both scalar and vector values for each element
Definition: vtkfunction.hh:49
typename GridView::ctype ctype
Definition: vtkfunction.hh:51
virtual double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &) const
evaluate
Definition: vtkfunction.hh:63
virtual std::string name() const
get name
Definition: vtkfunction.hh:60
typename GridView::template Codim< 0 >::Entity Element
Definition: vtkfunction.hh:52
virtual int ncomps() const
return number of components
Definition: vtkfunction.hh:57
VectorP0VTKFunction(const GridView &gridView, const Mapper &mapper, const F &field, const std::string &name, int nComps)
Constructor.
Definition: vtkfunction.hh:67
@ dim
Definition: vtkfunction.hh:50
a VTK function that supports both scalar and vector values for each vertex
Definition: vtkfunction.hh:106
@ dim
Definition: vtkfunction.hh:107
VectorP1VTKFunction(const GridView &gridView, const Mapper &mapper, const F &field, const std::string &name, int nComps)
Constructor.
Definition: vtkfunction.hh:135
virtual int ncomps() const
return number of components
Definition: vtkfunction.hh:114
virtual double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &xi) const
evaluate
Definition: vtkfunction.hh:120
virtual std::string name() const
get name
Definition: vtkfunction.hh:117
typename GridView::template Codim< 0 >::Entity Element
Definition: vtkfunction.hh:109
typename GridView::ctype ctype
Definition: vtkfunction.hh:108
A VTK function that supports both scalar and vector values for each vertex. This expects the data to ...
Definition: vtkfunction.hh:177
virtual double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &xi) const
evaluate
Definition: vtkfunction.hh:191
virtual int ncomps() const
return number of components
Definition: vtkfunction.hh:185
typename GridView::template Codim< 0 >::Entity Element
Definition: vtkfunction.hh:180
VectorP1NonConformingVTKFunction(const GridView &gridView, const Mapper &mapper, const F &field, const std::string &name, int nComps)
Constructor.
Definition: vtkfunction.hh:206
@ dim
Definition: vtkfunction.hh:178
typename GridView::ctype ctype
Definition: vtkfunction.hh:179
virtual std::string name() const
get name
Definition: vtkfunction.hh:188
struct that can hold any field that fulfills the VTKFunction interface
Definition: vtkfunction.hh:245
virtual ~Field()
Definition: vtkfunction.hh:271
std::shared_ptr< const Dune::VTKFunction< GridView > > get() const
returns the underlying vtk function
Definition: vtkfunction.hh:289
virtual std::string name() const
return the name of this field
Definition: vtkfunction.hh:274
virtual int ncomps() const
return the number of components of this field
Definition: vtkfunction.hh:277
int codim() const
codimension of the entities on which the field values live
Definition: vtkfunction.hh:280
virtual double evaluate(int mycomp, const Element &element, const Dune::FieldVector< ctype, dim > &xi) const
element-local evaluation of the field
Definition: vtkfunction.hh:283
Field(const GridView &gridView, const Mapper &mapper, F const &f, const std::string &name, int numComp=1, int codim=0, Dune::VTK::DataMode dm=Dune::VTK::conforming)
Definition: vtkfunction.hh:253