12#ifndef DUMUX_IO_VTK_FUNCTION_HH
13#define DUMUX_IO_VTK_FUNCTION_HH
18#include <dune/common/typetraits.hh>
19#include <dune/common/fvector.hh>
21#include <dune/grid/common/mcmgmapper.hh>
22#include <dune/grid/io/file/vtk/common.hh>
23#include <dune/grid/io/file/vtk/function.hh>
35 if constexpr (Dune::IsIndexable<std::decay_t<decltype(std::declval<Field>()[0])>>{})
37 if constexpr (Dune::IsIndexable<std::decay_t<decltype(std::declval<Field>()[0][0])>>{})
38 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
56template <
typename Gr
idView,
typename Mapper,
typename F>
59 enum {
dim = GridView::dimension };
60 using ctype =
typename GridView::ctype;
61 using Element =
typename GridView::template Codim<0>::Entity;
66 int ncomps() const final {
return nComps_; }
69 std::string
name() const final {
return name_; }
72 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>&)
const final
77 {
return precision_; }
83 const std::string&
name,
85 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
86 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
88 if (field.size()!=(
unsigned int)(mapper.size()))
89 DUNE_THROW(Dune::IOError,
"VectorP0VTKFunction: size mismatch between field "
90 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
95 const std::string name_;
97 const Mapper& mapper_;
98 Dumux::Vtk::Precision precision_;
109template <
typename Gr
idView,
typename Mapper,
typename F>
112 enum {
dim = GridView::dimension };
113 using ctype =
typename GridView::ctype;
114 using Element =
typename GridView::template Codim<0>::Entity;
119 int ncomps() const final {
return nComps_; }
122 std::string
name() const final {
return name_; }
125 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const final
127 const unsigned int dim = Element::mydimension;
128 const unsigned int nVertices = e.subEntities(
dim);
130 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
131 for (
unsigned i = 0; i < nVertices; ++i)
135 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
136 return interpolation.global(xi)[0];
141 {
return precision_; }
145 const Mapper& mapper,
147 const std::string&
name,
149 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
150 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
152 if (field.size()!=(
unsigned int)( mapper.size() ))
153 DUNE_THROW(Dune::IOError,
"VectorP1VTKFunction: size mismatch between field "
154 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
158 const std::string name_;
160 const Mapper& mapper_;
161 Dumux::Vtk::Precision precision_;
176template <
typename Gr
idView,
typename Mapper,
typename F>
179 enum {
dim = GridView::dimension };
180 using ctype =
typename GridView::ctype;
181 using Element =
typename GridView::template Codim<0>::Entity;
186 int ncomps() const final {
return nComps_; }
189 std::string
name() const final {
return name_; }
192 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& xi)
const final
194 const unsigned int dim = Element::mydimension;
195 const unsigned int nVertices = e.subEntities(
dim);
197 std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices);
198 for (
unsigned i = 0; i < nVertices; ++i)
199 cornerValues[i] = accessEntry_(mycomp, mapper_.index(e), i);
202 const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues));
203 return interpolation.global(xi)[0];
208 {
return precision_; }
212 const Mapper& mapper,
214 const std::string&
name,
216 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
217 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
219 if (field.size()!=(
unsigned int)(mapper.size()))
220 DUNE_THROW(Dune::IOError,
"VectorP1NonConformingVTKFunction: size mismatch between field "
221 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
225 double accessEntry_([[maybe_unused]]
int mycomp, [[maybe_unused]]
int eIdx, [[maybe_unused]]
int cornerIdx)
const
227 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0])>{})
229 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0][0])>{})
230 return field_[eIdx][cornerIdx][mycomp];
232 return field_[eIdx][cornerIdx];
235 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
239 const std::string name_;
241 const Mapper& mapper_;
242 Dumux::Vtk::Precision precision_;
257template <
typename Gr
idView,
typename Mapper,
typename F>
260 static constexpr int dim = GridView::dimension;
261 using ctype =
typename GridView::ctype;
262 using Element =
typename GridView::template Codim<0>::Entity;
267 int ncomps() const final {
return nComps_; }
270 std::string
name() const final {
return name_; }
273 double evaluate(
int mycomp,
const Element& e,
const Dune::FieldVector<ctype, dim>& localPos)
const final
275 using ShapeValues = std::vector<Dune::FieldVector<ctype, 1>>;
277 feCache_.get(e.type()).localBasis().evaluateFunction(localPos, N);
279 const auto eIdx = mapper_.index(e);
281 for (
int i = 0; i < N.size(); ++i)
282 result += accessEntry_(mycomp, eIdx, i)*N[i][0];
288 {
return precision_; }
292 const GridView& gridView,
293 const Mapper& mapper,
295 const std::string&
name,
297 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32
299 : field_(field), name_(
name), nComps_(nComps), mapper_(mapper), precision_(
precision)
301 if (field.size()!=(
unsigned int)(mapper.size()))
302 DUNE_THROW(Dune::IOError,
"VectorP1FaceNonConformingVTKFunction: size mismatch between field "
303 <<
name <<
" (" << field.size() <<
") and mapper (" << mapper.size() <<
")");
307 double accessEntry_([[maybe_unused]]
int mycomp, [[maybe_unused]]
int eIdx, [[maybe_unused]]
int faceIdx)
const
309 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0])>{})
311 if constexpr (Dune::IsIndexable<decltype(std::declval<F>()[0][0])>{})
312 return field_[eIdx][faceIdx][mycomp];
314 return field_[eIdx][faceIdx];
317 DUNE_THROW(Dune::InvalidStateException,
"Invalid field type");
321 const std::string name_;
323 const Mapper& mapper_;
324 Dumux::Vtk::Precision precision_;
325 NonconformingFECache<ctype, ctype, dim> feCache_ = {};
334template<
class Gr
idView>
337 static constexpr int dim = GridView::dimension;
338 using ctype =
typename GridView::ctype;
339 using Element =
typename GridView::template Codim<0>::Entity;
343 template <
typename F,
class Mapper>
344 Field(
const GridView& gridView,
const Mapper& mapper, F
const& f,
345 const std::string&
name,
int numComp = 1,
int codim = 0,
346 Dune::VTK::DataMode dm = Dune::VTK::conforming,
347 Dumux::Vtk::Precision
precision = Dumux::Vtk::Precision::float32)
350 if constexpr (dim > 1)
354 if (dm == Dune::VTK::conforming)
355 field_ = std::make_shared< VectorP1VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
357 field_ = std::make_shared< VectorP1NonConformingVTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
361 if (dm == Dune::VTK::conforming)
362 DUNE_THROW(Dune::NotImplemented,
"Only non-conforming output is implemented");
364 field_ = std::make_shared< VectorP1FaceNonConformingVTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
367 field_ = std::make_shared< VectorP0VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
369 DUNE_THROW(Dune::NotImplemented,
"Only element, face or vertex quantities allowed.");
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);
381 field_ = std::make_shared< VectorP0VTKFunction<GridView, Mapper, F> >(gridView, mapper, f,
name, numComp,
precision);
383 DUNE_THROW(Dune::NotImplemented,
"Only element or vertex quantities allowed.");
388 std::string
name ()
const {
return field_->name(); }
391 int ncomps()
const {
return field_->ncomps(); }
395 {
return field_->precision(); }
398 int codim()
const {
return codim_; }
403 const Dune::FieldVector< ctype, dim > &xi)
const
404 {
return field_->evaluate(mycomp,
element, xi); }
407 std::shared_ptr<const Dune::VTKFunction<GridView>>
get()
const
413 std::shared_ptr<Dune::VTKFunction<GridView>> field_;
struct that can hold any field that fulfills the VTKFunction interface
Definition function.hh:336
double evaluate(int mycomp, const Element &element, const Dune::FieldVector< ctype, dim > &xi) const
element-local evaluation of the field
Definition function.hh:401
std::string name() const
return the name of this field
Definition function.hh:388
int ncomps() const
return the number of components of this field
Definition function.hh:391
std::shared_ptr< const Dune::VTKFunction< GridView > > get() const
returns the underlying vtk function
Definition function.hh:407
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:344
Dumux::Vtk::Precision precision() const
return the precision of this field
Definition function.hh:394
int codim() const
codimension of the entities on which the field values live
Definition function.hh:398
Definition function.hh:30
double accessEntry(const Field &f, int mycomp, int i)
Definition function.hh:33
Definition fieldtype.hh:15
Vtk output precision options available in Dumux.
typename GridView::ctype ctype
Definition function.hh:60
@ dim
Definition function.hh:59
typename GridView::template Codim< 0 >::Entity Element
Definition function.hh:61
std::string name() const final
get name
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:80
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &) const final
evaluate
Definition function.hh:72
int ncomps() const final
return number of components
Definition function.hh:66
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition function.hh:76
Dumux::Vtk::Precision precision() const final
get output precision for the field
Definition function.hh:140
double evaluate(int mycomp, const Element &e, const Dune::FieldVector< ctype, dim > &xi) const final
evaluate
Definition function.hh:125
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:144
typename GridView::template Codim< 0 >::Entity Element
Definition function.hh:114
typename GridView::ctype ctype
Definition function.hh:113
std::string name() const final
get name
Definition function.hh:122
@ dim
Definition function.hh:112
int ncomps() const final
return number of components
Definition function.hh:119