diff --git a/dumux/io/vtkmultiwriter.hh b/dumux/io/vtkmultiwriter.hh index fe87d1bfd22a8af28b7e38b3e6544eea36eebca5..573326cdb602b7a897aae6dc7fb9f7dc8f64f0bb 100644 --- a/dumux/io/vtkmultiwriter.hh +++ b/dumux/io/vtkmultiwriter.hh @@ -32,12 +32,11 @@ #include <memory> #include <string> -#include "vtknestedfunction.hh" - #include <dune/common/fvector.hh> #include <dune/istl/bvector.hh> #include <dune/grid/io/file/vtk/vtkwriter.hh> +#include <dune/grid/io/file/vtk/function.hh> #include <dumux/common/valgrind.hh> @@ -47,6 +46,98 @@ #endif namespace Dumux { + +/*! + * \ingroup InputOutput + * \brief Provides a vector-valued function using Dune::FieldVectors + * as elements. + * DEPRECATED will be removed once this header is removed + */ +template <class GridView, class Mapper, class Buffer> +class VtkNestedFunction : public Dune::VTKFunction<GridView> +{ + enum { dim = GridView::dimension }; + using ctype = typename GridView::ctype; + using Element = typename GridView::template Codim<0>::Entity; + using ReferenceElements = Dune::ReferenceElements<ctype, dim>; + +public: + VtkNestedFunction(std::string name, + const GridView &gridView, + const Mapper &mapper, + const Buffer &buf, + int codim, + int numComp) + : name_(name) + , gridView_(gridView) + , mapper_(mapper) + , buf_(buf) + , codim_(codim) + , numComp_(numComp) + { + assert(std::size_t(buf_.size()) == std::size_t(mapper_.size())); + } + + virtual std::string name () const + { return name_; } + + virtual int ncomps() const + { return numComp_; } + + virtual double evaluate(int mycomp, + const Element &element, + const Dune::FieldVector< ctype, dim > &xi) const + { + int idx; + if (codim_ == 0) { + // cells. map element to the index + idx = mapper_.index(element); + } + else if (codim_ == dim) { + // find vertex which is closest to xi in local + // coordinates. This code is based on Dune::P1VTKFunction + double min=1e100; + int imin=-1; + Dune::GeometryType geomType = element.type(); + int n = element.subEntities(dim); + + for (int i=0; i < n; ++i) + { + Dune::FieldVector<ctype,dim> local = + ReferenceElements::general(geomType).position(i,dim); + local -= xi; + if (local.infinity_norm()<min) + { + min = local.infinity_norm(); + imin = i; + } + } + + // map vertex to an index + idx = mapper_.subIndex(element, imin, codim_); + } + else + DUNE_THROW(Dune::InvalidStateException, + "Only element and vertex based vector " + " fields are supported so far."); + + double val = buf_[idx][mycomp]; + using std::abs; + if (abs(val) < std::numeric_limits<float>::min()) + val = 0; + + return val; + } + +private: + const std::string name_; + const GridView gridView_; + const Mapper &mapper_; + const Buffer &buf_; + int codim_; + int numComp_; +}; + /*! * \ingroup InputOutput * \brief Simplifies writing multi-file VTK datasets. diff --git a/dumux/io/vtknestedfunction.hh b/dumux/io/vtknestedfunction.hh index 1fa34c2f8226e7a1bc4c0aab84b741ad44c4365e..cb35bec5780c1c2247712631080286846a2bbb3b 100644 --- a/dumux/io/vtknestedfunction.hh +++ b/dumux/io/vtknestedfunction.hh @@ -25,104 +25,9 @@ #ifndef VTK_NESTED_FUNCTION_HH #define VTK_NESTED_FUNCTION_HH -#include <string> - -#include <dune/common/fvector.hh> -#include <dune/istl/bvector.hh> -#include <dune/grid/io/file/vtk/function.hh> - -namespace Dumux { - -/*! - * \ingroup InputOutput - * \brief Provides a vector-valued function using Dune::FieldVectors - * as elements. - */ -template <class GridView, class Mapper, class Buffer> -class VtkNestedFunction : public Dune::VTKFunction<GridView> -{ - enum { dim = GridView::dimension }; - using ctype = typename GridView::ctype; - using Element = typename GridView::template Codim<0>::Entity; - using ReferenceElements = Dune::ReferenceElements<ctype, dim>; - -public: - VtkNestedFunction(std::string name, - const GridView &gridView, - const Mapper &mapper, - const Buffer &buf, - int codim, - int numComp) - : name_(name) - , gridView_(gridView) - , mapper_(mapper) - , buf_(buf) - , codim_(codim) - , numComp_(numComp) - { - assert(std::size_t(buf_.size()) == std::size_t(mapper_.size())); - } - - virtual std::string name () const - { return name_; } - - virtual int ncomps() const - { return numComp_; } - - virtual double evaluate(int mycomp, - const Element &element, - const Dune::FieldVector< ctype, dim > &xi) const - { - int idx; - if (codim_ == 0) { - // cells. map element to the index - idx = mapper_.index(element); - } - else if (codim_ == dim) { - // find vertex which is closest to xi in local - // coordinates. This code is based on Dune::P1VTKFunction - double min=1e100; - int imin=-1; - Dune::GeometryType geomType = element.type(); - int n = element.subEntities(dim); - - for (int i=0; i < n; ++i) - { - Dune::FieldVector<ctype,dim> local = - ReferenceElements::general(geomType).position(i,dim); - local -= xi; - if (local.infinity_norm()<min) - { - min = local.infinity_norm(); - imin = i; - } - } - - // map vertex to an index - idx = mapper_.subIndex(element, imin, codim_); - } - else - DUNE_THROW(Dune::InvalidStateException, - "Only element and vertex based vector " - " fields are supported so far."); - - double val = buf_[idx][mycomp]; - using std::abs; - if (abs(val) < std::numeric_limits<float>::min()) - val = 0; - - return val; - } - -private: - const std::string name_; - const GridView gridView_; - const Mapper &mapper_; - const Buffer &buf_; - int codim_; - int numComp_; -}; - -} // end namespace Dumux +// This header is deprecated. The class implementation has been moved +// to the deprecated header dumux/io/vtkmultiwriter.hh to avoid double deprecation warnings. +// Remove this header once dumux/io/vtkmultiwriter.hh is removed. +#include <dumux/io/vtkmultiwriter.hh> #endif