24#ifndef DUMUX_IO_VTK_FUNCTION_HH
25#define DUMUX_IO_VTK_FUNCTION_HH
30#include <dune/common/typetraits.hh>
32#include <dune/grid/common/mcmgmapper.hh>
33#include <dune/grid/io/file/vtk/common.hh>
34#include <dune/grid/io/file/vtk/function.hh>
45 if constexpr (Dune::IsIndexable<std::decay_t<decltype(std::declval<Field>()[0])>>{})
47 if constexpr (Dune::IsIndexable<std::decay_t<decltype(std::declval<Field>()[0][0])>>{})
48 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
66template <
typename Gr
idView,
typename Mapper,
typename F>
69 enum {
dim = GridView::dimension };
70 using ctype =
typename GridView::ctype;
71 using Element =
typename GridView::template Codim<0>::Entity;
76 int ncomps() const final {
return nComps_; }
79 std::string
name() const final {
return name_; }
82 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>&)
const final
87 {
return precision_; }
93 const std::string&
name,
95 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
96 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
98 if (field.size()!=(
unsigned int)(mapper.size()))
99 DUNE_THROW(Dune::IOError,
"VectorP0VTKFunction: size mismatch between field "
100 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
105 const std::string name_;
107 const Mapper& mapper_;
108 Dumux::Vtk::Precision precision_;
119template <
typename Gr
idView,
typename Mapper,
typename F>
122 enum {
dim = GridView::dimension };
123 using ctype =
typename GridView::ctype;
124 using Element =
typename GridView::template Codim<0>::Entity;
129 int ncomps() const final {
return nComps_; }
132 std::string
name() const final {
return name_; }
135 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const final
137 const unsigned int dim = Element::mydimension;
138 const unsigned int nVertices = e.subEntities(
dim);
140 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
141 for (
unsigned i = 0; i < nVertices; ++i)
145 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
146 return interpolation.global(xi);
151 {
return precision_; }
155 const Mapper& mapper,
157 const std::string&
name,
159 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
160 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
162 if (field.size()!=(
unsigned int)( mapper.size() ))
163 DUNE_THROW(Dune::IOError,
"VectorP1VTKFunction: size mismatch between field "
164 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
168 const std::string name_;
170 const Mapper& mapper_;
171 Dumux::Vtk::Precision precision_;
186template <
typename Gr
idView,
typename Mapper,
typename F>
189 enum {
dim = GridView::dimension };
190 using ctype =
typename GridView::ctype;
191 using Element =
typename GridView::template Codim<0>::Entity;
196 int ncomps() const final {
return nComps_; }
199 std::string
name() const final {
return name_; }
202 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const final
204 const unsigned int dim = Element::mydimension;
205 const unsigned int nVertices = e.subEntities(
dim);
207 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
208 for (
unsigned i = 0; i < nVertices; ++i)
209 cornerValues[i] = accessEntry_(mycomp, mapper_.index(e), i);
212 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
213 return interpolation.global(xi);
218 {
return precision_; }
222 const Mapper& mapper,
224 const std::string&
name,
226 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
227 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
229 if (field.size()!=(
unsigned int)(mapper.size()))
230 DUNE_THROW(Dune::IOError,
"VectorP1NonConformingVTKFunction: size mismatch between field "
231 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
235 double accessEntry_([[maybe_unused]]
int mycomp, [[maybe_unused]]
int eIdx, [[maybe_unused]]
int cornerIdx)
const
237 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0])>{})
239 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0][0])>{})
240 return field_[eIdx][cornerIdx][mycomp];
242 return field_[eIdx][cornerIdx];
245 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
249 const std::string name_;
251 const Mapper& mapper_;
252 Dumux::Vtk::Precision precision_;
262template<
class Gr
idView>
265 enum { dim = GridView::dimension };
266 using ctype =
typename GridView::ctype;
267 using Element =
typename GridView::template Codim<0>::Entity;
271 template <
typename F,
class Mapper>
272 Field(
const GridView& gridView,
const Mapper& mapper, F
const& f,
273 const std::string&
name,
int numComp = 1,
int codim = 0,
274 Dune::VTK::DataMode dm = Dune::VTK::conforming,
275 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
278 if (
codim == GridView::dimension)
280 if (dm == Dune::VTK::conforming)
281 field_ = std::make_shared< VectorP1VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
283 field_ = std::make_shared< VectorP1NonConformingVTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
286 field_ = std::make_shared< VectorP0VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
288 DUNE_THROW(Dune::NotImplemented,
"Only element or vertex quantities allowed.");
292 std::string
name ()
const {
return field_->name(); }
295 int ncomps()
const {
return field_->ncomps(); }
299 {
return field_->precision(); }
302 int codim()
const {
return codim_; }
306 const Element &element,
307 const Dune::FieldVector< ctype, dim > &xi)
const
308 {
return field_->evaluate(mycomp,
element, xi); }
311 std::shared_ptr<const Dune::VTKFunction<GridView>>
get()
const
317 std::shared_ptr<Dune::VTKFunction<GridView>> field_;
Vtk output precision options available in Dumux.
Definition: fieldtype.hh:27
double accessEntry(const Field &f, int mycomp, int i)
Definition: function.hh:43
a VTK function that supports both scalar and vector values for each element
Definition: function.hh:68
typename GridView::ctype ctype
Definition: function.hh:70
typename GridView::template Codim< 0 >::Entity Element
Definition: function.hh:71
std::string name() const final
get name
Definition: function.hh:79
@ dim
Definition: function.hh:69
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: function.hh:90
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &) const final
evaluate
Definition: function.hh:82
int ncomps() const final
return number of components
Definition: function.hh:76
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: function.hh:86
a VTK function that supports both scalar and vector values for each vertex
Definition: function.hh:121
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: function.hh:150
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &xi) const final
evaluate
Definition: function.hh:135
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: function.hh:154
@ dim
Definition: function.hh:122
typename GridView::template Codim< 0 >::Entity Element
Definition: function.hh:124
typename GridView::ctype ctype
Definition: function.hh:123
std::string name() const final
get name
Definition: function.hh:132
int ncomps() const final
return number of components
Definition: function.hh:129
A VTK function that supports both scalar and vector values for each vertex. This expects the data to ...
Definition: function.hh:188
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &xi) const final
evaluate
Definition: function.hh:202
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: function.hh:221
typename GridView::template Codim< 0 >::Entity Element
Definition: function.hh:191
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: function.hh:217
int ncomps() const final
return number of components
Definition: function.hh:196
typename GridView::ctype ctype
Definition: function.hh:190
std::string name() const final
get name
Definition: function.hh:199
@ dim
Definition: function.hh:189
struct that can hold any field that fulfills the VTKFunction interface
Definition: function.hh:264
double evaluate(int mycomp, const Element &element, const Dune::FieldVector< ctype, dim > &xi) const
element-local evaluation of the field
Definition: function.hh:305
std::string name() const
return the name of this field
Definition: function.hh:292
int ncomps() const
return the number of components of this field
Definition: function.hh:295
std::shared_ptr< const Dune::VTKFunction< GridView > > get() const
returns the underlying vtk function
Definition: function.hh:311
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: function.hh:272
Dumux::Vtk::Precision precision() const
return the precision of this field
Definition: function.hh:298
int codim() const
codimension of the entities on which the field values live
Definition: function.hh:302