From f5a45e44136481ab693cf921cc2a34e9544b418c Mon Sep 17 00:00:00 2001 From: Oliver Sander <sander@igpm.rwth-aachen.de> Date: Fri, 21 Mar 2014 16:19:05 +0000 Subject: [PATCH] Add a wrapper that makes a dune-functions function space basis look like a dune-fufem one This short class wraps a dune-functions-style function space basis and implements the interface of dune-fufem bases. That way you can now technically use dune-functions bases to assemble all your problems. Caveats: - constraints are not supported [[Imported from SVN: r13072]] --- dune/fufem/functionspacebases/CMakeLists.txt | 1 + dune/fufem/functionspacebases/Makefile.am | 1 + .../functionspacebases/dunefunctionsbasis.hh | 89 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 dune/fufem/functionspacebases/dunefunctionsbasis.hh diff --git a/dune/fufem/functionspacebases/CMakeLists.txt b/dune/fufem/functionspacebases/CMakeLists.txt index 2dd5465d..ea603052 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 f4b77405..72009017 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 00000000..e82e022e --- /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 + -- GitLab