diff --git a/dune/fufem/functionspacebases/CMakeLists.txt b/dune/fufem/functionspacebases/CMakeLists.txt index 2dd5465de2ab9f482c137d0c5cc39aae1fb958a1..ea603052cf7d5e00faf72d48cef8dc8224a44e79 100644 --- a/dune/fufem/functionspacebases/CMakeLists.txt +++ b/dune/fufem/functionspacebases/CMakeLists.txt @@ -2,6 +2,7 @@ install(FILES conformingbasis.hh dgpqkbasis.hh dofconstraints.hh + dunefunctionsbasis.hh extensionbasis.hh functionspacebasis.hh p0basis.hh diff --git a/dune/fufem/functionspacebases/Makefile.am b/dune/fufem/functionspacebases/Makefile.am index f4b774050a54b0639eb403046c35b8f28f508744..7200901722cd1314168ba8fdf7ae335fd3254bb6 100644 --- a/dune/fufem/functionspacebases/Makefile.am +++ b/dune/fufem/functionspacebases/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS = functionspacebasesdir = $(includedir)/dune/fufem/functionspacebases functionspacebases_HEADERS = conformingbasis.hh \ dofconstraints.hh \ + dunefunctionsbasis.hh \ extensionbasis.hh \ functionspacebasis.hh \ p0basis.hh \ diff --git a/dune/fufem/functionspacebases/dunefunctionsbasis.hh b/dune/fufem/functionspacebases/dunefunctionsbasis.hh new file mode 100644 index 0000000000000000000000000000000000000000..e82e022e29cda3d6b242a20a24b21fcfb339c095 --- /dev/null +++ b/dune/fufem/functionspacebases/dunefunctionsbasis.hh @@ -0,0 +1,89 @@ +#ifndef DUNE_FUFEM_FUNCTIONSPACEBASES_DUNEFUNCTIONSBASIS_HH +#define DUNE_FUFEM_FUNCTIONSPACEBASES_DUNEFUNCTIONSBASIS_HH + +/** + @file + @brief A wrapper around the function space bases from the dune-functions module + + @author Oliver Sander + */ + +#include <dune/fufem/functionspacebases/functionspacebasis.hh> + + +/** \brief Wrap a basis from dune-functions and make it look like a dune-fufem basis + * + * \tparam A function space basis from dune-functions + * + * This class exists for transition purposes only. In the long run, we want to use the function + * space bases from dune-functions directly in dune-fufem. However, get some experience with + * them, we start with this wrapper. + * + * Using this wrapper may be a bit slower than using either the dune-fufem or the dune-functions + * bases directly, because 'bind' needs to be called at each access to 'getLocalFiniteElement' + * and 'index'. I don't know whether the difference is significant. + */ +template <class DFBasis> +class DuneFunctionsBasis +: public FunctionSpaceBasis<typename DFBasis::GridView, + double, + typename DFBasis::LocalView::Tree::FiniteElement > +{ +protected: + typedef FunctionSpaceBasis<typename DFBasis::GridView,double,typename DFBasis::LocalView::Tree::FiniteElement> Base; + + typedef typename Base::Element Element; +public: + /** \brief GridView on which this basis is defined */ + typedef typename DFBasis::GridView GridView; + + /** \brief Number type used for basis function values */ + typedef typename Base::ReturnType ReturnType; + + /** \brief The LocalFiniteElement (in the dune-localfunctions sense of the word) + * that implements the local basis on each element + */ + typedef typename DFBasis::LocalView::Tree::FiniteElement LocalFiniteElement; + + /** \brief Constructor from a dune-functions basis */ + DuneFunctionsBasis(const DFBasis& dfBasis) + : Base(dfBasis.gridView()), + dfBasis_(dfBasis), + localView_(dfBasis.localView()) + {} + + /** \brief Return the total number of basis vectors in this basis + */ + size_t size() const + { + return dfBasis_.subIndexCount(); + } + + /** \brief Get a local finite element (i.e., a set of shape functions) for the given element + */ + const LocalFiniteElement& getLocalFiniteElement(const Element& element) const + { + localView_.bind(element); + return localView_.tree().finiteElement(); + } + + /** \brief Get the global index of the i-th local degree of freedom on element 'element' + */ + int index(const Element& element, const int i) const + { + localView_.bind(element); + return localView_.tree().globalIndex(i)[0]; + } + +protected: + + // The dune-functions basis we are wrapping + const DFBasis& dfBasis_; + + // Must be mutable, because it gets bound to individual elements during the const methods + // 'getLocalFiniteElement' and 'index'. + mutable typename DFBasis::LocalView localView_; +}; + +#endif +