diff --git a/dumux/io/vtkoutputmodule.hh b/dumux/io/vtkoutputmodule.hh index e7e3f7187f31755d6e52940ab66bc502c8706645..b053d330ef769455730a42d227cd817717ad31a9 100644 --- a/dumux/io/vtkoutputmodule.hh +++ b/dumux/io/vtkoutputmodule.hh @@ -45,163 +45,162 @@ #include <dumux/common/parameters.hh> #include <dumux/discretization/methods.hh> -namespace Dumux -{ +namespace Dumux { +namespace Vtk { -namespace Vtk +//! struct that can hold any field that fulfills the VTKFunction interface +template<class GridView> +class Field { - //! struct that can hold any field that fulfills the VTKFunction interface - template<class GridView> - class Field - { - enum { dim = GridView::dimension }; - using ctype = typename GridView::ctype; - using Element = typename GridView::template Codim<0>::Entity; + enum { dim = GridView::dimension }; + using ctype = typename GridView::ctype; + using Element = typename GridView::template Codim<0>::Entity; - // a VTK function that supports both scalar and vector values for each element + // a VTK function that supports both scalar and vector values for each element #if DUNE_VERSION_NEWER(DUNE_COMMON,2,6) - template <typename F> - struct VectorP0VTKFunction : Dune::VTKFunction<GridView> - { - using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; + template <typename F> + struct VectorP0VTKFunction : Dune::VTKFunction<GridView> + { + using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; #else - template<typename F, typename Mapper> - struct VectorP0VTKFunction : Dune::VTKFunction<GridView> - { + template<typename F, typename Mapper> + struct VectorP0VTKFunction : Dune::VTKFunction<GridView> + { #endif - public: - //! return number of components - virtual int ncomps () const - { return nComps_; } - - //! evaluate - virtual double evaluate (int mycomp, const Element& e, - const Dune::FieldVector<ctype,dim>&) const - { return accessChooser_(mycomp, mapper_.index(e), Dune::is_indexable<decltype(field_[0])>()); } - - //! get name - virtual std::string name () const - { return name_; } - - VectorP0VTKFunction(const GridView &gridView, const Mapper& mapper, const F& field, const std::string& name, int nComps) - : field_(field), name_(name), nComps_(nComps), mapper_(mapper) - { - if (field.size()!=(unsigned int)(gridView.size(0))) - DUNE_THROW(Dune::IOError, "NestedP0VTKFunction: size mismatch"); - } - private: - double accessChooser_(int mycomp, int i, std::true_type) const - { return field_[i][mycomp]; } + public: + //! return number of components + virtual int ncomps () const + { return nComps_; } - double accessChooser_(int mycomp, int i, std::false_type) const - { return field_[i]; } + //! evaluate + virtual double evaluate (int mycomp, const Element& e, + const Dune::FieldVector<ctype,dim>&) const + { return accessChooser_(mycomp, mapper_.index(e), Dune::is_indexable<decltype(field_[0])>()); } - const F& field_; - const std::string name_; - int nComps_; - const Mapper& mapper_; - }; + //! get name + virtual std::string name () const + { return name_; } - // a VTK function that supports both scalar and vector values for each vertex -#if DUNE_VERSION_NEWER(DUNE_COMMON,2,6) - template <typename F> - struct VectorP1VTKFunction : Dune::VTKFunction<GridView> + VectorP0VTKFunction(const GridView &gridView, const Mapper& mapper, const F& field, const std::string& name, int nComps) + : field_(field), name_(name), nComps_(nComps), mapper_(mapper) { - using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; + if (field.size()!=(unsigned int)(gridView.size(0))) + DUNE_THROW(Dune::IOError, "NestedP0VTKFunction: size mismatch"); + } + private: + double accessChooser_(int mycomp, int i, std::true_type) const + { return field_[i][mycomp]; } + + double accessChooser_(int mycomp, int i, std::false_type) const + { return field_[i]; } + + const F& field_; + const std::string name_; + int nComps_; + const Mapper& mapper_; + }; + + // a VTK function that supports both scalar and vector values for each vertex +#if DUNE_VERSION_NEWER(DUNE_COMMON,2,6) + template <typename F> + struct VectorP1VTKFunction : Dune::VTKFunction<GridView> + { + using Mapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>; #else - template<typename F, typename Mapper> - struct VectorP1VTKFunction : Dune::VTKFunction<GridView> - { + template<typename F, typename Mapper> + struct VectorP1VTKFunction : Dune::VTKFunction<GridView> + { #endif - public: - //! return number of components - virtual int ncomps () const - { return nComps_; } - - //! evaluate - virtual double evaluate (int mycomp, const Element& e, - const Dune::FieldVector<ctype,dim>& xi) const - { - const unsigned int dim = Element::mydimension; - const unsigned int nVertices = e.subEntities(dim); + public: + //! return number of components + virtual int ncomps () const + { return nComps_; } + + //! evaluate + virtual double evaluate (int mycomp, const Element& e, + const Dune::FieldVector<ctype,dim>& xi) const + { + const unsigned int dim = Element::mydimension; + const unsigned int nVertices = e.subEntities(dim); - std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices); - for (unsigned i = 0; i < nVertices; ++i) - cornerValues[i] = accessChooser_(mycomp, mapper_.subIndex(e, i, dim), Dune::is_indexable<decltype(field_[0])>()); + std::vector<Dune::FieldVector<ctype, 1>> cornerValues(nVertices); + for (unsigned i = 0; i < nVertices; ++i) + cornerValues[i] = accessChooser_(mycomp, mapper_.subIndex(e, i, dim), Dune::is_indexable<decltype(field_[0])>()); - // (Ab)use the MultiLinearGeometry class to do multi-linear interpolation between scalars - const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues)); - return interpolation.global(xi); - } + // (Ab)use the MultiLinearGeometry class to do multi-linear interpolation between scalars + const Dune::MultiLinearGeometry<ctype, dim, 1> interpolation(e.type(), std::move(cornerValues)); + return interpolation.global(xi); + } - //! get name - virtual std::string name () const - { return name_; } + //! get name + virtual std::string name () const + { return name_; } - VectorP1VTKFunction(const GridView &gridView, const Mapper& mapper, const F& field, const std::string& name, int nComps) - : field_(field), name_(name), nComps_(nComps), mapper_(mapper) - { - if (field.size()!=(unsigned int)(gridView.size(GridView::dimension))) - DUNE_THROW(Dune::IOError, "NestedP1VTKFunction: size mismatch"); - } - private: - double accessChooser_(int mycomp, int i, std::true_type) const - { return field_[i][mycomp]; } + VectorP1VTKFunction(const GridView &gridView, const Mapper& mapper, const F& field, const std::string& name, int nComps) + : field_(field), name_(name), nComps_(nComps), mapper_(mapper) + { + if (field.size()!=(unsigned int)(gridView.size(GridView::dimension))) + DUNE_THROW(Dune::IOError, "NestedP1VTKFunction: size mismatch"); + } + private: + double accessChooser_(int mycomp, int i, std::true_type) const + { return field_[i][mycomp]; } - double accessChooser_(int mycomp, int i, std::false_type) const - { return field_[i]; } + double accessChooser_(int mycomp, int i, std::false_type) const + { return field_[i]; } - const F& field_; - const std::string name_; - int nComps_; - const Mapper& mapper_; - }; + const F& field_; + const std::string name_; + int nComps_; + const Mapper& mapper_; + }; - public: - // template constructor selects the right VTKFunction implementation - template <typename F, class Mapper> - Field(const GridView& gridView, const Mapper& mapper, F const& f, - const std::string& name, int numComp = 1, int codim = 0) - : codim_(codim) - { - if (codim == GridView::dimension) +public: + // template constructor selects the right VTKFunction implementation + template <typename F, class Mapper> + Field(const GridView& gridView, const Mapper& mapper, F const& f, + const std::string& name, int numComp = 1, int codim = 0) + : codim_(codim) + { + if (codim == GridView::dimension) #if DUNE_VERSION_NEWER(DUNE_COMMON,2,6) - field_ = std::make_shared<VectorP1VTKFunction<F>>(gridView, mapper, f, name, numComp); + field_ = std::make_shared<VectorP1VTKFunction<F>>(gridView, mapper, f, name, numComp); #else - field_ = std::make_shared<VectorP1VTKFunction<F, Mapper>>(gridView, mapper, f, name, numComp); + field_ = std::make_shared<VectorP1VTKFunction<F, Mapper>>(gridView, mapper, f, name, numComp); #endif - else if (codim == 0) + else if (codim == 0) #if DUNE_VERSION_NEWER(DUNE_COMMON,2,6) - field_ = std::make_shared<VectorP0VTKFunction<F>>(gridView, mapper, f, name, numComp); + field_ = std::make_shared<VectorP0VTKFunction<F>>(gridView, mapper, f, name, numComp); #else - field_ = std::make_shared<VectorP0VTKFunction<F, Mapper>>(gridView, mapper, f, name, numComp); + field_ = std::make_shared<VectorP0VTKFunction<F, Mapper>>(gridView, mapper, f, name, numComp); #endif - else - DUNE_THROW(Dune::NotImplemented, "Only element or vertex quantities allowed."); - } + else + DUNE_THROW(Dune::NotImplemented, "Only element or vertex quantities allowed."); + } - virtual std::string name () const - { return field_->name(); } + virtual std::string name () const + { return field_->name(); } - virtual int ncomps() const - { return field_->ncomps(); } + virtual int ncomps() const + { return field_->ncomps(); } - virtual double evaluate(int mycomp, - const Element &element, - const Dune::FieldVector< ctype, dim > &xi) const - { return field_->evaluate(mycomp, element, xi); } + virtual double evaluate(int mycomp, + const Element &element, + const Dune::FieldVector< ctype, dim > &xi) const + { return field_->evaluate(mycomp, element, xi); } - int codim() const - { return codim_; } + int codim() const + { return codim_; } - const std::shared_ptr<Dune::VTKFunction<GridView>>& get() const - { return field_; } + const std::shared_ptr<Dune::VTKFunction<GridView>>& get() const + { return field_; } + +private: + int codim_; + // can point to anything fulfilling the VTKFunction interface + std::shared_ptr<Dune::VTKFunction<GridView>> field_; +}; - private: - int codim_; - // can point to anything fulfilling the VTKFunction interface - std::shared_ptr<Dune::VTKFunction<GridView>> field_; - }; } // end namespace Vtk /*!