dune-fem  2.4.1-rc
const.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_CONST_HH
2 #define DUNE_FEM_FUNCTION_LOCALFUNCTION_CONST_HH
3 
4 #include <utility>
5 #include <type_traits>
6 
7 #include <dune/common/dynvector.hh>
10 
11 namespace Dune
12 {
13 
14  namespace Fem
15  {
16 
17  // external forward declerations
18  // -----------------------------
19 
20  template<class>
21  struct DiscreteFunctionTraits;
22 
23  template<class>
25 
26 
27  // internal forward declerations
28  // -----------------------------
29 
30  template< class DiscreteFunction >
32 
33 
34  template < class BasisFunctionSet, class LocalDofVector >
36  : public LocalFunction< BasisFunctionSet, LocalDofVector >
37  {
40 
41  public:
43  typedef typename BaseType::DofType DofType;
44 
47 
50 
53 
55  typedef typename BaseType::SizeType SizeType;
56 
59 
60  explicit BasicConstLocalFunction ( const BasisFunctionSetType & basisFunctionSet ) : BaseType( basisFunctionSet ) {}
61 
62  explicit BasicConstLocalFunction ( const LocalDofVectorType &localDofVector ) : BaseType( localDofVector ) {}
63 
64  BasicConstLocalFunction ( const BasisFunctionSetType &basisFunctionSet, const LocalDofVectorType &localDofVector )
65  : BaseType( basisFunctionSet, localDofVector )
66  {}
67 
68  explicit BasicConstLocalFunction ( LocalDofVectorType &&localDofVector ) : BaseType( localDofVector ) {}
69 
70  BasicConstLocalFunction ( const BasisFunctionSetType &basisFunctionSet, LocalDofVectorType &&localDofVector )
71  : BaseType( basisFunctionSet, localDofVector )
72  {}
73 
74  BasicConstLocalFunction ( const BaseType &other ) : BaseType( other ) {}
75 
76  BasicConstLocalFunction ( const ThisType &other ) : BaseType( static_cast<const BaseType &>( other ) ) {}
77  BasicConstLocalFunction ( ThisType && other ) : BaseType( static_cast<BaseType&&>(other) ) {}
78 
79  using BaseType::operator[];
81 
82  protected:
83  DofType &operator[] ( SizeType num )
84  {
85  return static_cast< BaseType &>( *this )[ num ];
86  }
87 
88  using BaseType::clear;
89  using BaseType::assign;
90  using BaseType::operator +=;
91  using BaseType::operator -=;
92  using BaseType::axpy;
93  };
94 
112  template< class DiscreteFunction >
113  class ConstLocalFunction
114  : public BasicConstLocalFunction<
115  typename DiscreteFunctionTraits<
116  typename std::remove_const< DiscreteFunction > :: type >::DiscreteFunctionSpaceType::BasisFunctionSetType,
117  Dune::DynamicVector< typename DiscreteFunctionTraits< typename std::remove_const< DiscreteFunction > :: type >::DofType,
118  typename DiscreteFunctionTraits< typename std::remove_const< DiscreteFunction > :: type >::LocalDofVectorAllocatorType
119  :: template rebind< typename DiscreteFunctionTraits< typename std::remove_const< DiscreteFunction >::type > ::DofType > ::other > >
120  {
122  typedef BasicConstLocalFunction< typename DiscreteFunctionTraits< typename std::remove_const< DiscreteFunction > :: type >::DiscreteFunctionSpaceType::BasisFunctionSetType,
123  Dune::DynamicVector< typename DiscreteFunctionTraits< typename std::remove_const< DiscreteFunction > :: type >::DofType,
124  typename DiscreteFunctionTraits< typename std::remove_const< DiscreteFunction > :: type > :: LocalDofVectorAllocatorType
125  :: template rebind< typename DiscreteFunctionTraits< typename std::remove_const< DiscreteFunction >::type >::DofType >::other > >
126  BaseType;
127 
128  public:
129  typedef typename std::remove_const< DiscreteFunction >::type DiscreteFunctionType;
130  typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
131 
132  typedef typename BaseType::DofType DofType;
136 
150  explicit ConstLocalFunction ( const DiscreteFunctionType &df )
151  : BaseType( LocalDofVectorType( df.localDofVectorAllocator() ) ),
152  discreteFunction_( &df )
153  {
154  }
155 
157  ConstLocalFunction ( const typename DiscreteFunctionType::LocalFunctionType &localFunction )
158  : BaseType( localFunction.basisFunctionSet(), LocalDofVectorType( localFunction.size(), localFunction.discreteFunction().localDofVectorAllocator() ) ),
159  discreteFunction_( &localFunction.discreteFunction() )
160  {
161  std::copy( localFunction.localDofVector().begin(), localFunction.localDofVector().end(), localDofVector().begin() );
162  }
163 
177  ConstLocalFunction ( const DiscreteFunctionType &df, const EntityType &entity )
178  : BaseType( df.space().basisFunctionSet( entity ), LocalDofVectorType( df.localDofVectorAllocator() ) ),
179  discreteFunction_( &df )
180  {
181  discreteFunction().getLocalDofs( entity, localDofVector() );
182  }
183 
185  ConstLocalFunction ( const ThisType &other )
186  : BaseType( static_cast<const BaseType &>( other ) ),
187  discreteFunction_( other.discreteFunction_ )
188  {}
189 
191  ConstLocalFunction ( ThisType &&other )
192  : BaseType( static_cast< BaseType &&>( other ) ),
193  discreteFunction_( other.discreteFunction_ )
194  {}
195 
197 
199  void init ( const EntityType &entity )
200  {
201  BaseType::init( discreteFunction().space().basisFunctionSet( entity ) );
202  discreteFunction().getLocalDofs( entity, localDofVector() );
203  }
204 
205  const DiscreteFunctionType& discreteFunction() const { return *discreteFunction_; }
206 
207  protected:
208  const DiscreteFunctionType* discreteFunction_;
209  };
210 
211  } // namespace Fem
212 
213 } // namespace Dune
214 
215 #endif // #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_CONST_HH
ConstLocalFunction(const DiscreteFunctionType &df, const EntityType &entity)
constructor creating a local function and binding it to an entity
Definition: const.hh:177
ConstLocalFunction(const ThisType &other)
copy constructor
Definition: const.hh:185
BasicConstLocalFunction(const BasisFunctionSetType &basisFunctionSet, LocalDofVectorType &&localDofVector)
Definition: const.hh:70
BaseType::LocalDofVectorType LocalDofVectorType
Definition: const.hh:135
const DiscreteFunctionType * discreteFunction_
Definition: const.hh:208
BasicConstLocalFunction(const LocalDofVectorType &localDofVector)
Definition: const.hh:62
Traits class for a DiscreteFunction.
Definition: discretefunction.hh:60
BaseType::EntityType EntityType
type of Entity
Definition: const.hh:46
ConstLocalFunction(ThisType &&other)
move constructor
Definition: const.hh:191
BasicConstLocalFunction()
default ctor
Definition: const.hh:58
BaseType::EntityType EntityType
Definition: const.hh:133
BaseType::SizeType SizeType
type of SizeType
Definition: const.hh:55
ConstLocalFunction(const typename DiscreteFunctionType::LocalFunctionType &localFunction)
cast a MutableLocalFunction into this one !!! expensive !!!
Definition: const.hh:157
const BasisFunctionSetType & basisFunctionSet() const
obtain the basis function set for this local function
Definition: localfunction.hh:279
interface for local functions
Definition: localfunction.hh:41
ConstLocalFunction(const DiscreteFunctionType &df)
constructor creating a local function without binding it to an entity
Definition: const.hh:150
BaseType::LocalDofVectorType LocalDofVectorType
type of LocalDofVector
Definition: const.hh:52
BaseType::DofType DofType
type of Dof
Definition: const.hh:43
BasicConstLocalFunction(const BasisFunctionSetType &basisFunctionSet)
Definition: const.hh:60
Definition: coordinate.hh:4
DofType & operator[](SizeType num)
Definition: const.hh:83
BaseType::BasisFunctionSetType BasisFunctionSetType
type of BasisFunctionSet
Definition: const.hh:49
void clear()
set all DoFs to zero
Definition: localfunction.hh:170
const EntityType & entity() const
obtain the entity, this local function lives on
Definition: localfunction.hh:285
BaseType::DofType DofType
Definition: const.hh:132
BasicConstLocalFunction(ThisType &&other)
Definition: const.hh:77
BasicConstLocalFunction(const BasisFunctionSetType &basisFunctionSet, const LocalDofVectorType &localDofVector)
Definition: const.hh:64
void init(const EntityType &entity)
interface for local functions :: init
Definition: const.hh:199
std::remove_const< DiscreteFunction >::type DiscreteFunctionType
Definition: const.hh:129
Dune::DynamicVector< DiscreteFunctionTraits< std::remove_const< DiscreteFunction >::type >::DofType, DiscreteFunctionTraits< std::remove_const< DiscreteFunction >::type >::LocalDofVectorAllocatorType::template rebind< DiscreteFunctionTraits< std::remove_const< DiscreteFunction >::type >::DofType >::other > LocalDofVectorType
type of local Dof Vector
Definition: localfunction.hh:50
A constant local function carrying values for one entity.
Definition: const.hh:31
void init(const BasisFunctionSetType &basisFunctionSet)
Definition: localfunction.hh:288
Definition: const.hh:35
BasicConstLocalFunction(const BaseType &other)
Definition: const.hh:74
const DiscreteFunctionType & discreteFunction() const
Definition: const.hh:205
void assign(const LocalFunction< BasisFunctionSet, T > &other)
assign all DoFs of this local function
Definition: localfunction.hh:164
BasicConstLocalFunction(LocalDofVectorType &&localDofVector)
Definition: const.hh:68
BasicConstLocalFunction(const ThisType &other)
Definition: const.hh:76
Definition: const.hh:24
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: const.hh:130
SizeType size() const
Definition: localfunction.hh:342
BaseType::BasisFunctionSetType BasisFunctionSetType
Definition: const.hh:134
Definition: basisfunctionset/basisfunctionset.hh:31
ThisType & axpy(const RangeFieldType s, const LocalFunction< BasisFunctionSet, T > &other)
add a multiple of another local function to this one
Definition: localfunction.hh:202
const LocalDofVectorType & localDofVector() const
return const reference to local Dof Vector
Definition: localfunction.hh:386