1 #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_MUTABLE_HH 2 #define DUNE_FEM_FUNCTION_LOCALFUNCTION_MUTABLE_HH 3 4 //-s system includes 5 #include <cassert> 6 #include <utility> 7 8 //- Dune includes 9 #include <dune/fem/function/localfunction/localfunction.hh> 10 11 namespace Dune 12 { 13 14 namespace Fem 15 { 16 17 template< class > 18 struct DiscreteFunctionTraits; 19 20 //************************************************************************** 21 // 22 // --MutableLocalFunction 23 // 24 //************************************************************************** 25 //! Manages the getting and deleting of local function pointers and 26 //! acts like a local functions 27 template < class DiscreteFunction > 28 class MutableLocalFunction 29 : public LocalFunction< typename DiscreteFunctionTraits< DiscreteFunction > :: DiscreteFunctionSpaceType :: BasisFunctionSetType, 30 typename DiscreteFunctionTraits< DiscreteFunction > :: LocalDofVectorType > 31 { 32 typedef MutableLocalFunction< DiscreteFunction > ThisType; 33 typedef LocalFunction< typename DiscreteFunctionTraits< DiscreteFunction > :: DiscreteFunctionSpaceType :: BasisFunctionSetType, 34 typename DiscreteFunctionTraits< DiscreteFunction > :: LocalDofVectorType > BaseType; 35 36 public: 37 //! type of DiscreteFunction 38 typedef DiscreteFunction DiscreteFunctionType; 39 40 //! type of the entity, the local function lives on is given by the space 41 typedef typename BaseType::EntityType EntityType; 42 43 //! type of local Dof vector object 44 typedef typename BaseType::LocalDofVectorType LocalDofVectorType; 45 46 //! type of BasisFunctionSet 47 typedef typename BaseType::BasisFunctionSetType BasisFunctionSetType; 48 49 //! Constructor creating empty local function from given discrete function MutableLocalFunction(DiscreteFunctionType & discreteFunction)50 explicit MutableLocalFunction ( DiscreteFunctionType &discreteFunction ) 51 : BaseType( LocalDofVectorType( discreteFunction.localDofVectorAllocator() ) ), 52 discreteFunction_( &discreteFunction ) 53 {} 54 55 //! Constructor creating empty local function from given discrete function MutableLocalFunction(const DiscreteFunctionType & discreteFunction)56 explicit MutableLocalFunction ( const DiscreteFunctionType &discreteFunction ) 57 : BaseType( LocalDofVectorType( discreteFunction.localDofVectorAllocator() ) ), 58 discreteFunction_( &const_cast<DiscreteFunctionType &>( discreteFunction ) ) 59 {} 60 61 //! Constructor creating local function from given discrete function and entity, not empty MutableLocalFunction(DiscreteFunctionType & discreteFunction,const EntityType & entity)62 explicit MutableLocalFunction ( DiscreteFunctionType &discreteFunction, const EntityType &entity ) 63 : BaseType( discreteFunction.space().basisFunctionSet( entity ), LocalDofVectorType( discreteFunction.localDofVectorAllocator() ) ), 64 discreteFunction_( &discreteFunction ) 65 { 66 discreteFunction.getLocalDofReferences( entity, localDofVector() ); 67 } 68 69 //! Constructor creating local function from given discrete function and entity, not empty MutableLocalFunction(const DiscreteFunctionType & dFunction,const EntityType & entity)70 explicit MutableLocalFunction ( const DiscreteFunctionType &dFunction, const EntityType &entity ) 71 : BaseType( dFunction.space().basisFunctionSet( entity ), LocalDofVectorType( dFunction.localDofVectorAllocator() ) ), 72 discreteFunction_( &const_cast<DiscreteFunctionType &>( dFunction ) ) 73 { 74 discreteFunction().getLocalDofReferences( entity, localDofVector() ); 75 } 76 77 //! copy constructor MutableLocalFunction(const ThisType & other)78 MutableLocalFunction ( const ThisType &other ) 79 : BaseType( static_cast< const BaseType& > ( other ) ), discreteFunction_( other.discreteFunction_ ) 80 {} 81 82 //! move constructor MutableLocalFunction(ThisType && other)83 MutableLocalFunction ( ThisType &&other ) 84 : BaseType( static_cast< BaseType&& > ( other ) ), discreteFunction_( other.discreteFunction_ ) 85 {} 86 87 ThisType& operator= ( const ThisType& ) = delete; 88 ThisType& operator= ( ThisType&& ) = delete; 89 90 using BaseType::localDofVector; 91 init(const EntityType & entity)92 void init ( const EntityType &entity ) 93 { 94 BaseType::init( discreteFunction().space().basisFunctionSet( entity ) ); 95 discreteFunction().getLocalDofReferences( entity, localDofVector() ); 96 } 97 bind(const EntityType & entity)98 void bind ( const EntityType &entity ) 99 { 100 init(entity); 101 } 102 unbind()103 void unbind() { BaseType::unbind(); } 104 discreteFunction() const105 const DiscreteFunctionType &discreteFunction () const 106 { 107 return *discreteFunction_; 108 } discreteFunction()109 DiscreteFunctionType &discreteFunction () 110 { 111 return *discreteFunction_; 112 } 113 114 protected: 115 DiscreteFunctionType *discreteFunction_; 116 }; 117 118 } // namespace Fem 119 120 } // namespace Dune 121 122 #endif // #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_MUTABLE_HH 123