1 #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_LOCALFUNCTIONSETADAPTER_HH
2 #define DUNE_FEM_FUNCTION_LOCALFUNCTION_LOCALFUNCTIONSETADAPTER_HH
3 
4 #include <cassert>
5 #include <cstddef>
6 
7 #include <dune/fem/common/coordinate.hh>
8 
9 namespace Dune
10 {
11 
12   namespace Fem
13   {
14 
15     // LocalFunctionSetAdapter
16     // -----------------------
17 
18     /** \class LocalFunctionSetAdapter
19      *
20      *  \brief convert (global) function set to local function set
21      *
22      *  \tparam  Entity       entity type
23      *  \tparam  FunctionSet  implementation of FunctionSet
24      */
25     template< class Entity, class FunctionSet >
26     struct LocalFunctionSetAdapter
27     {
28       //! \brief entity type
29       typedef Entity EntityType;
30       //! \brief function set type
31       typedef FunctionSet FunctionSetType;
32 
33       //! \brief function space type
34       typedef typename FunctionSet::FunctionSpaceType FunctionSpaceType;
35 
36       //! \brief domain type
37       typedef typename FunctionSpaceType::DomainType DomainType;
38       //! \brief range type
39       typedef typename FunctionSpaceType::RangeType RangeType;
40       //! \brief jacobian range type
41       typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
42       //! \brief hessian range type
43       typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
44 
LocalFunctionSetAdapterDune::Fem::LocalFunctionSetAdapter45       explicit LocalFunctionSetAdapter ( const FunctionSet &functionSet = FunctionSet() )
46         : functionSet_( functionSet )
47       {}
48 
LocalFunctionSetAdapterDune::Fem::LocalFunctionSetAdapter49       explicit LocalFunctionSetAdapter ( const Entity &entity, const FunctionSet &functionSet = FunctionSet() )
50         : entity_( &entity ), functionSet_( functionSet )
51       {}
52 
53       /** \copydoc Dune::Fem::LocalFunctionSet::order() const */
orderDune::Fem::LocalFunctionSetAdapter54       int order () const { return functionSet_.order(); }
55 
56       /** \copydoc Dune::Fem::LocalFunctionSet::entity() const */
entityDune::Fem::LocalFunctionSetAdapter57       const EntityType &entity () const
58       {
59         assert( entity_ );
60         return *entity_;
61       }
62 
63       /** \copydoc Dune::Fem::LocalFunctionSet::size() const */
sizeDune::Fem::LocalFunctionSetAdapter64       std::size_t size () const { return functionSet().size(); }
65 
66       /** \copydoc Dune::Fem::LocalFunctionSet::evaluateEach() const */
67       template< class Point, class Functor >
evaluateEachDune::Fem::LocalFunctionSetAdapter68       void evaluateEach ( const Point &x, Functor functor ) const
69       {
70         DomainType y = geometry().global( coordinate( x ) );
71         functionSet().evaluateEach( y, functor );
72       }
73 
74       /** \copydoc Dune::Fem::LocalFunctionSet::jacobianEach() const */
75       template< class Point, class Functor >
jacobianEachDune::Fem::LocalFunctionSetAdapter76       void jacobianEach ( const Point &x, Functor functor ) const
77       {
78         DomainType y = geometry().global( coordinate( x ) );
79         functionSet().jacobianEach( y, functor );
80       }
81 
82       /** \copydoc Dune::Fem::LocalFunctionSet::hessianEach() const */
83       template< class Point, class Functor >
hessianEachDune::Fem::LocalFunctionSetAdapter84       void hessianEach ( const Point &x, Functor functor ) const
85       {
86         DomainType y = geometry().global( coordinate( x ) );
87         functionSet().hessianEach( y, functor );
88       }
89 
90 
91       // Non-interface methods
92       // ---------------------
93 
94       //! \brief return function set
functionSetDune::Fem::LocalFunctionSetAdapter95       const FunctionSetType functionSet () const { return functionSet_; }
96 
97     private:
geometryDune::Fem::LocalFunctionSetAdapter98       typename EntityType::Geometry geometry () const { return entity().geometry(); }
99 
100       const EntityType *entity_ = nullptr;
101       FunctionSetType functionSet_;
102     };
103 
104   } // namespace Fem
105 
106 } // namespace Dune
107 
108 #endif // #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_LOCALFUNCTIONSETADAPTER_HH
109