dune-fem  2.4.1-rc
instationary.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_FUNCTION_COMMON_INSTATIONARY_HH
2 #define DUNE_FEM_FUNCTION_COMMON_INSTATIONARY_HH
3 
4 #include <functional>
5 #include <type_traits>
6 #include <utility>
7 
9 
10 namespace Dune
11 {
12 
13  namespace Fem
14  {
15 
16  // BasicInstationaryFunction
17  // -------------------------
18 
31  template< class FunctionSpace, class Function >
33  : public Dune::Fem::Function< FunctionSpace, Function >
34  {
35  public:
40  explicit BasicInstationaryFunction ( double time )
41  : time_( time )
42  {}
43 
56  double setTime ( double time ) { return (time_ = time); }
57 
59  double time () const { return time_; }
60 
63  private:
64  double time_;
65  };
66 
67 
68 
69 #ifndef DOXYGEN
70 
71  namespace __InstationaryFunction
72  {
73 
74  // HoldCopy
75  // --------
76 
77  template< class Function >
78  struct HoldCopy
79  {
80  explicit HoldCopy ( Function function )
81  : function_( std::move( function ) )
82  {}
83 
84  const Function &get () const noexcept { return function_; }
85 
86  private:
87  Function function_;
88  };
89 
90 
91 
92  // HoldReference
93  // -------------
94 
95  template< class Function >
96  struct HoldReference
97  {
98  explicit HoldReference ( const Function &function )
99  : function_( function )
100  {}
101 
102  const Function &get () const noexcept { return function_.get(); }
103 
104  private:
105  std::reference_wrapper< const Function > function_;
106  };
107 
108  } // namespace __InstationaryFunction
109 
110 #endif // #ifndef DOXYGEN
111 
112 
113 
114  // InstationaryFunction
115  // --------------------
116 
152  template< class Function,
153  template< class > class StoragePolicy = __InstationaryFunction::HoldCopy >
155  : public BasicInstationaryFunction< typename Function::FunctionSpaceType, InstationaryFunction< Function, StoragePolicy > >,
156  private StoragePolicy< Function >
157  {
159  typedef StoragePolicy< Function > StoragePolicyType;
160 
161  public:
164 
169  InstationaryFunction ( const Function &function, double time )
170  : BaseType( time ),
171  StoragePolicyType( function )
172  {}
173 
174  InstationaryFunction ( Function &&function, double time )
175  : BaseType( time ),
176  StoragePolicyType( std::move( function ) )
177  {}
178 
186  void evaluate ( const DomainType &x, typename BaseType::RangeType &value ) const
187  {
188  this->get().evaluate( x, this->time(), value );
189  }
190 
192  void jacobian ( const DomainType &x, typename BaseType::JacobianRangeType &jacobian ) const
193  {
194  this->get().jacobian( x, this->time(), jacobian );
195  }
196 
198  void hessian ( const DomainType &x, typename BaseType::HessianRangeType &hessian ) const
199  {
200  this->get().hessian( x, this->time(), hessian );
201  }
202 
204  };
205 
206 
207 
208  // instationaryFunction
209  // --------------------
210 
211  template< class Function >
213  instationaryFunction ( Function function, double time )
214  {
216  return InstationaryFunctionType( std::move( function ), time );
217  }
218 
219  template< class Function >
220  InstationaryFunction< typename std::remove_const< Function >::type, __InstationaryFunction::HoldReference >
221  instationaryFunction ( std::reference_wrapper< Function > function, double time )
222  {
223  typedef InstationaryFunction< typename std::remove_const< Function >::type, __InstationaryFunction::HoldReference > InstationaryFunctionType;
224  return InstationaryFunctionType( function.get(), time );
225  }
226 
227  } // namespace Fem
228 
229 } // namespace Dune
230 
231 #endif // #ifndef DUNE_FEM_FUNCTION_COMMON_INSTATIONARY_HH
BaseType::DomainType DomainType
domain type
Definition: instationary.hh:163
void evaluate(const DomainType &x, typename BaseType::RangeType &value) const
evaluate the function
Definition: instationary.hh:186
InstationaryFunction< Function, __InstationaryFunction::HoldCopy > instationaryFunction(Function function, double time)
Definition: instationary.hh:213
InstationaryFunction(Function &&function, double time)
Definition: instationary.hh:174
FunctionSpaceType::DomainType DomainType
domain type
Definition: function.hh:66
void jacobian(const DomainType &x, JacobianRangeType &jacobian) const
evaluate the Jacobian of the function
Definition: function.hh:121
void hessian(const DomainType &x, HessianRangeType &hessian) const
evaluate the hessian of the function
Definition: function.hh:131
double time() const
return set time
Definition: instationary.hh:59
FunctionSpaceType::RangeType RangeType
range type
Definition: function.hh:68
void jacobian(const DomainType &x, typename BaseType::JacobianRangeType &jacobian) const
evaluate the Jacobian of the function
Definition: instationary.hh:192
FunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian type
Definition: function.hh:70
double setTime(double time)
set time to give value
Definition: instationary.hh:56
Definition: coordinate.hh:4
STL namespace.
void move(ArrayInterface< T > &array, const unsigned int oldOffset, const unsigned int newOffset, const unsigned int length)
Definition: array_inline.hh:38
Function()
default constructor
Definition: function.hh:82
implementation of a Dune::Fem::Function taking an instationary function
Definition: instationary.hh:154
InstationaryFunction(const Function &function, double time)
Definition: instationary.hh:169
void hessian(const DomainType &x, typename BaseType::HessianRangeType &hessian) const
evaluate the hessian of the function
Definition: instationary.hh:198
Abstract class representing a function.
Definition: function.hh:43
basic wrapper class (still a CRTP) for instationary functions
Definition: instationary.hh:32
FunctionSpaceType::HessianRangeType HessianRangeType
hessian type
Definition: function.hh:72
BasicInstationaryFunction(double time)
Definition: instationary.hh:40
void evaluate(const DomainType &x, RangeType &value) const
evaluate the function
Definition: function.hh:111