24#ifndef DUMUX_IO_VTK_FUNCTION_HH
25#define DUMUX_IO_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>
47 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
65template <
typename Gr
idView,
typename Mapper,
typename F>
68 enum {
dim = GridView::dimension };
69 using ctype =
typename GridView::ctype;
70 using Element =
typename GridView::template Codim<0>::Entity;
75 int ncomps() const final {
return nComps_; }
78 std::string
name() const final {
return name_; }
81 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>&)
const final
86 {
return precision_; }
92 const std::string&
name,
94 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
95 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
97 if (field.size()!=(
unsigned int)(mapper.size()))
98 DUNE_THROW(Dune::IOError,
"VectorP0VTKFunction: size mismatch between field "
99 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
104 const std::string name_;
106 const Mapper& mapper_;
107 Dumux::Vtk::Precision precision_;
118template <
typename Gr
idView,
typename Mapper,
typename F>
121 enum {
dim = GridView::dimension };
122 using ctype =
typename GridView::ctype;
123 using Element =
typename GridView::template Codim<0>::Entity;
128 int ncomps() const final {
return nComps_; }
131 std::string
name() const final {
return name_; }
134 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const final
136 const unsigned int dim = Element::mydimension;
137 const unsigned int nVertices = e.subEntities(
dim);
139 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
140 for (
unsigned i = 0; i < nVertices; ++i)
144 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
145 return interpolation.global(xi);
150 {
return precision_; }
154 const Mapper& mapper,
156 const std::string&
name,
158 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
159 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
161 if (field.size()!=(
unsigned int)( mapper.size() ))
162 DUNE_THROW(Dune::IOError,
"VectorP1VTKFunction: size mismatch between field "
163 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
167 const std::string name_;
169 const Mapper& mapper_;
170 Dumux::Vtk::Precision precision_;
185template <
typename Gr
idView,
typename Mapper,
typename F>
188 enum {
dim = GridView::dimension };
189 using ctype =
typename GridView::ctype;
190 using Element =
typename GridView::template Codim<0>::Entity;
195 int ncomps() const final {
return nComps_; }
198 std::string
name() const final {
return name_; }
201 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const final
203 const unsigned int dim = Element::mydimension;
204 const unsigned int nVertices = e.subEntities(
dim);
206 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
207 for (
unsigned i = 0; i < nVertices; ++i)
208 cornerValues[i] = accessEntry_(mycomp, mapper_.index(e), i);
211 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
212 return interpolation.global(xi);
217 {
return precision_; }
221 const Mapper& mapper,
223 const std::string&
name,
225 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
226 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
228 if (field.size()!=(
unsigned int)(mapper.size()))
229 DUNE_THROW(Dune::IOError,
"VectorP1NonConformingVTKFunction: size mismatch between field "
230 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
234 double accessEntry_([[maybe_unused]]
int mycomp, [[maybe_unused]]
int eIdx, [[maybe_unused]]
int cornerIdx)
const
239 return field_[eIdx][cornerIdx][mycomp];
241 return field_[eIdx][cornerIdx];
244 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
248 const std::string name_;
250 const Mapper& mapper_;
251 Dumux::Vtk::Precision precision_;
261template<
class Gr
idView>
264 enum { dim = GridView::dimension };
265 using ctype =
typename GridView::ctype;
266 using Element =
typename GridView::template Codim<0>::Entity;
270 template <
typename F,
class Mapper>
271 Field(
const GridView& gridView,
const Mapper& mapper, F
const& f,
272 const std::string&
name,
int numComp = 1,
int codim = 0,
273 Dune::VTK::DataMode dm = Dune::VTK::conforming,
274 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
277 if (
codim == GridView::dimension)
279 if (dm == Dune::VTK::conforming)
280 field_ = std::make_shared< VectorP1VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
282 field_ = std::make_shared< VectorP1NonConformingVTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
285 field_ = std::make_shared< VectorP0VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
287 DUNE_THROW(Dune::NotImplemented,
"Only element or vertex quantities allowed.");
291 std::string
name ()
const {
return field_->name(); }
294 int ncomps()
const {
return field_->ncomps(); }
298 {
return field_->precision(); }
301 int codim()
const {
return codim_; }
305 const Element &element,
306 const Dune::FieldVector< ctype, dim > &xi)
const
307 {
return field_->evaluate(mycomp, element, xi); }
310 std::shared_ptr<const Dune::VTKFunction<GridView>>
get()
const
316 std::shared_ptr<Dune::VTKFunction<GridView>> field_;
Vtk output precision options available in Dumux.
typename Dune::IsIndexable< T, I > IsIndexable
We define our own is_indexable type in order to avoid several version checks throughout dumux....
Definition: typetraits.hh:43
Definition: vtkfunction.hh:37
double accessEntry(const Field &f, int mycomp, int i)
Definition: vtkfunction.hh:42
a VTK function that supports both scalar and vector values for each element
Definition: vtkfunction.hh:67
typename GridView::ctype ctype
Definition: vtkfunction.hh:69
typename GridView::template Codim< 0 >::Entity Element
Definition: vtkfunction.hh:70
std::string name() const final
get name
Definition: vtkfunction.hh:78
@ dim
Definition: vtkfunction.hh:68
VectorP0VTKFunction(const GridView &gridView, const Mapper &mapper, const F &field, const std::string &name, int nComps, Dumux::Vtk::Precision precision=Dumux::Vtk::Precision::float32)
Constructor.
Definition: vtkfunction.hh:89
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &) const final
evaluate
Definition: vtkfunction.hh:81
int ncomps() const final
return number of components
Definition: vtkfunction.hh:75
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: vtkfunction.hh:85
a VTK function that supports both scalar and vector values for each vertex
Definition: vtkfunction.hh:120
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: vtkfunction.hh:149
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &xi) const final
evaluate
Definition: vtkfunction.hh:134
VectorP1VTKFunction(const GridView &gridView, const Mapper &mapper, const F &field, const std::string &name, int nComps, Dumux::Vtk::Precision precision=Dumux::Vtk::Precision::float32)
Constructor.
Definition: vtkfunction.hh:153
@ dim
Definition: vtkfunction.hh:121
typename GridView::template Codim< 0 >::Entity Element
Definition: vtkfunction.hh:123
typename GridView::ctype ctype
Definition: vtkfunction.hh:122
std::string name() const final
get name
Definition: vtkfunction.hh:131
int ncomps() const final
return number of components
Definition: vtkfunction.hh:128
A VTK function that supports both scalar and vector values for each vertex. This expects the data to ...
Definition: vtkfunction.hh:187
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &xi) const final
evaluate
Definition: vtkfunction.hh:201
VectorP1NonConformingVTKFunction(const GridView &gridView, const Mapper &mapper, const F &field, const std::string &name, int nComps, Dumux::Vtk::Precision precision=Dumux::Vtk::Precision::float32)
Constructor.
Definition: vtkfunction.hh:220
typename GridView::template Codim< 0 >::Entity Element
Definition: vtkfunction.hh:190
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: vtkfunction.hh:216
int ncomps() const final
return number of components
Definition: vtkfunction.hh:195
typename GridView::ctype ctype
Definition: vtkfunction.hh:189
std::string name() const final
get name
Definition: vtkfunction.hh:198
@ dim
Definition: vtkfunction.hh:188
struct that can hold any field that fulfills the VTKFunction interface
Definition: vtkfunction.hh:263
double evaluate(int mycomp, const Element &element, const Dune::FieldVector< ctype, dim > &xi) const
element-local evaluation of the field
Definition: vtkfunction.hh:304
std::string name() const
return the name of this field
Definition: vtkfunction.hh:291
int ncomps() const
return the number of components of this field
Definition: vtkfunction.hh:294
std::shared_ptr< const Dune::VTKFunction< GridView > > get() const
returns the underlying vtk function
Definition: vtkfunction.hh:310
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, Dumux::Vtk::Precision precision=Dumux::Vtk::Precision::float32)
Definition: vtkfunction.hh:271
Dumux::Vtk::Precision precision() const
return the precision of this field
Definition: vtkfunction.hh:297
int codim() const
codimension of the entities on which the field values live
Definition: vtkfunction.hh:301