24#ifndef DUMUX_IO_VTK_FUNCTION_HH
25#define DUMUX_IO_VTK_FUNCTION_HH
30#include <dune/common/typetraits.hh>
31#include <dune/common/fvector.hh>
32#include <dune/common/reservedvector.hh>
34#include <dune/grid/common/mcmgmapper.hh>
35#include <dune/grid/io/file/vtk/common.hh>
36#include <dune/grid/io/file/vtk/function.hh>
48 if constexpr (Dune::IsIndexable<std::decay_t<decltype(std::declval<Field>()[0])>>{})
50 if constexpr (Dune::IsIndexable<std::decay_t<decltype(std::declval<Field>()[0][0])>>{})
51 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
69template <
typename Gr
idView,
typename Mapper,
typename F>
72 enum {
dim = GridView::dimension };
73 using ctype =
typename GridView::ctype;
74 using Element =
typename GridView::template Codim<0>::Entity;
79 int ncomps() const final {
return nComps_; }
82 std::string
name() const final {
return name_; }
85 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>&)
const final
90 {
return precision_; }
96 const std::string&
name,
98 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
99 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
101 if (field.size()!=(
unsigned int)(mapper.size()))
102 DUNE_THROW(Dune::IOError,
"VectorP0VTKFunction: size mismatch between field "
103 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
108 const std::string name_;
110 const Mapper& mapper_;
111 Dumux::Vtk::Precision precision_;
122template <
typename Gr
idView,
typename Mapper,
typename F>
125 enum {
dim = GridView::dimension };
126 using ctype =
typename GridView::ctype;
127 using Element =
typename GridView::template Codim<0>::Entity;
132 int ncomps() const final {
return nComps_; }
135 std::string
name() const final {
return name_; }
138 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const final
140 const unsigned int dim = Element::mydimension;
141 const unsigned int nVertices = e.subEntities(
dim);
143 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
144 for (
unsigned i = 0; i < nVertices; ++i)
148 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
149 return interpolation.global(xi);
154 {
return precision_; }
158 const Mapper& mapper,
160 const std::string&
name,
162 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
163 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
165 if (field.size()!=(
unsigned int)( mapper.size() ))
166 DUNE_THROW(Dune::IOError,
"VectorP1VTKFunction: size mismatch between field "
167 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
171 const std::string name_;
173 const Mapper& mapper_;
174 Dumux::Vtk::Precision precision_;
189template <
typename Gr
idView,
typename Mapper,
typename F>
192 enum {
dim = GridView::dimension };
193 using ctype =
typename GridView::ctype;
194 using Element =
typename GridView::template Codim<0>::Entity;
199 int ncomps() const final {
return nComps_; }
202 std::string
name() const final {
return name_; }
205 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const final
207 const unsigned int dim = Element::mydimension;
208 const unsigned int nVertices = e.subEntities(
dim);
210 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
211 for (
unsigned i = 0; i < nVertices; ++i)
212 cornerValues[i] = accessEntry_(mycomp, mapper_.index(e), i);
215 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
216 return interpolation.global(xi);
221 {
return precision_; }
225 const Mapper& mapper,
227 const std::string&
name,
229 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
230 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
232 if (field.size()!=(
unsigned int)(mapper.size()))
233 DUNE_THROW(Dune::IOError,
"VectorP1NonConformingVTKFunction: size mismatch between field "
234 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
238 double accessEntry_([[maybe_unused]]
int mycomp, [[maybe_unused]]
int eIdx, [[maybe_unused]]
int cornerIdx)
const
240 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0])>{})
242 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0][0])>{})
243 return field_[eIdx][cornerIdx][mycomp];
245 return field_[eIdx][cornerIdx];
248 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
252 const std::string name_;
254 const Mapper& mapper_;
255 Dumux::Vtk::Precision precision_;
270template <
typename Gr
idView,
typename Mapper,
typename F>
273 static constexpr int dim = GridView::dimension;
274 using ctype =
typename GridView::ctype;
275 using Element =
typename GridView::template Codim<0>::Entity;
280 int ncomps() const final {
return nComps_; }
283 std::string
name() const final {
return name_; }
286 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& localPos)
const final
288 const unsigned int dim = Element::mydimension;
289 const unsigned int nFaces = e.subEntities(1);
292 using Coefficients = Dune::ReservedVector<ctype, 2*dim>;
293 Coefficients faceValues;
294 faceValues.resize(nFaces);
295 for (
int i = 0; i < nFaces; ++i)
296 faceValues[i] = accessEntry_(mycomp, mapper_.index(e), i);
298 using ShapeValues = std::vector<Dune::FieldVector<ctype, 1>>;
300 feCache_.
get(e.type()).localBasis().evaluateFunction(localPos, N);
302 for (
int i = 0; i < N.size(); ++i)
303 result += faceValues[i]*N[i];
309 {
return precision_; }
313 const GridView& gridView,
314 const Mapper& mapper,
316 const std::string&
name,
318 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32
320 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
322 if (field.size()!=(
unsigned int)(mapper.size()))
323 DUNE_THROW(Dune::IOError,
"VectorP1FaceNonConformingVTKFunction: size mismatch between field "
324 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
328 double accessEntry_([[maybe_unused]]
int mycomp, [[maybe_unused]]
int eIdx, [[maybe_unused]]
int faceIdx)
const
330 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0])>{})
332 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0][0])>{})
333 return field_[eIdx][faceIdx][mycomp];
335 return field_[eIdx][faceIdx];
338 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
342 const std::string name_;
344 const Mapper& mapper_;
345 Dumux::Vtk::Precision precision_;
346 NonconformingFECache<ctype, ctype, dim> feCache_ = {};
355template<
class Gr
idView>
358 static constexpr int dim = GridView::dimension;
359 using ctype =
typename GridView::ctype;
360 using Element =
typename GridView::template Codim<0>::Entity;
364 template <
typename F,
class Mapper>
365 Field(
const GridView& gridView,
const Mapper& mapper, F
const& f,
366 const std::string&
name,
int numComp = 1,
int codim = 0,
367 Dune::VTK::DataMode dm = Dune::VTK::conforming,
368 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
371 if constexpr (dim > 1)
375 if (dm == Dune::VTK::conforming)
376 field_ = std::make_shared< VectorP1VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
378 field_ = std::make_shared< VectorP1NonConformingVTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
382 if (dm == Dune::VTK::conforming)
383 DUNE_THROW(Dune::NotImplemented,
"Only non-conforming output is implemented");
385 field_ = std::make_shared< VectorP1FaceNonConformingVTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
388 field_ = std::make_shared< VectorP0VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
390 DUNE_THROW(Dune::NotImplemented,
"Only element, face or vertex quantities allowed.");
396 if (dm == Dune::VTK::conforming)
397 field_ = std::make_shared< VectorP1VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
399 field_ = std::make_shared< VectorP1NonConformingVTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
402 field_ = std::make_shared< VectorP0VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
404 DUNE_THROW(Dune::NotImplemented,
"Only element or vertex quantities allowed.");
409 std::string
name ()
const {
return field_->name(); }
412 int ncomps()
const {
return field_->ncomps(); }
416 {
return field_->precision(); }
419 int codim()
const {
return codim_; }
423 const Element &element,
424 const Dune::FieldVector< ctype, dim > &xi)
const
425 {
return field_->evaluate(mycomp,
element, xi); }
428 std::shared_ptr<const Dune::VTKFunction<GridView>>
get()
const
434 std::shared_ptr<Dune::VTKFunction<GridView>> field_;
A finite element cache for the non-conforming FE spaces RT and CR.
Vtk output precision options available in Dumux.
Definition: fieldtype.hh:27
double accessEntry(const Field &f, int mycomp, int i)
Definition: function.hh:46
const FiniteElementType & get(const Dune::GeometryType >) const
Get local finite element for given GeometryType.
Definition: nonconformingfecache.hh:58
a VTK function that supports both scalar and vector values for each element
Definition: function.hh:71
typename GridView::ctype ctype
Definition: function.hh:73
typename GridView::template Codim< 0 >::Entity Element
Definition: function.hh:74
@ dim
Definition: function.hh:72
std::string name() const final
get name
Definition: function.hh:82
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:93
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &) const final
evaluate
Definition: function.hh:85
int ncomps() const final
return number of components
Definition: function.hh:79
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: function.hh:89
a VTK function that supports both scalar and vector values for each vertex
Definition: function.hh:124
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: function.hh:153
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &xi) const final
evaluate
Definition: function.hh:138
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:157
@ dim
Definition: function.hh:125
typename GridView::template Codim< 0 >::Entity Element
Definition: function.hh:127
typename GridView::ctype ctype
Definition: function.hh:126
std::string name() const final
get name
Definition: function.hh:135
int ncomps() const final
return number of components
Definition: function.hh:132
A VTK function that supports both scalar and vector values for each vertex. This expects the data to ...
Definition: function.hh:191
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &xi) const final
evaluate
Definition: function.hh:205
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:224
typename GridView::template Codim< 0 >::Entity Element
Definition: function.hh:194
@ dim
Definition: function.hh:192
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: function.hh:220
int ncomps() const final
return number of components
Definition: function.hh:199
typename GridView::ctype ctype
Definition: function.hh:193
std::string name() const final
get name
Definition: function.hh:202
A VTK function that supports both scalar and vector values for each face. This expects the data to be...
Definition: function.hh:272
std::string name() const final
get name
Definition: function.hh:283
int ncomps() const final
return number of components
Definition: function.hh:280
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &localPos) const final
evaluate
Definition: function.hh:286
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition: function.hh:308
typename GridView::template Codim< 0 >::Entity Element
Definition: function.hh:275
VectorP1FaceNonConformingVTKFunction(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:312
static constexpr int dim
Definition: function.hh:273
typename GridView::ctype ctype
Definition: function.hh:274
struct that can hold any field that fulfills the VTKFunction interface
Definition: function.hh:357
double evaluate(int mycomp, const Element &element, const Dune::FieldVector< ctype, dim > &xi) const
element-local evaluation of the field
Definition: function.hh:422
std::string name() const
return the name of this field
Definition: function.hh:409
int ncomps() const
return the number of components of this field
Definition: function.hh:412
std::shared_ptr< const Dune::VTKFunction< GridView > > get() const
returns the underlying vtk function
Definition: function.hh:428
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:365
Dumux::Vtk::Precision precision() const
return the precision of this field
Definition: function.hh:415
int codim() const
codimension of the entities on which the field values live
Definition: function.hh:419