dune-fem 2.8.0
Loading...
Searching...
No Matches
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
10namespace 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 >
212 InstationaryFunction< Function, __InstationaryFunction::HoldCopy >
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
STL namespace.
Definition: bindguard.hh:11
std::tuple_element< i, Tuple >::type & get(Dune::TypeIndexedTuple< Tuple, Types > &tuple)
Definition: typeindexedtuple.hh:122
InstationaryFunction< Function, __InstationaryFunction::HoldCopy > instationaryFunction(Function function, double time)
Definition: instationary.hh:213
Definition: explicitfieldvector.hh:75
Abstract class representing a function.
Definition: common/function.hh:50
FunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian type
Definition: common/function.hh:70
basic wrapper class (still a CRTP) for instationary functions
Definition: instationary.hh:34
double setTime(double time)
set time to give value
Definition: instationary.hh:56
BasicInstationaryFunction(double time)
Definition: instationary.hh:40
double time() const
return set time
Definition: instationary.hh:59
implementation of a Dune::Fem::Function taking an instationary function
Definition: instationary.hh:157
BaseType::DomainType DomainType
domain type
Definition: instationary.hh:163
void jacobian(const DomainType &x, typename BaseType::JacobianRangeType &jacobian) const
evaluate the Jacobian of the function
Definition: instationary.hh:192
void hessian(const DomainType &x, typename BaseType::HessianRangeType &hessian) const
evaluate the hessian of the function
Definition: instationary.hh:198
void evaluate(const DomainType &x, typename BaseType::RangeType &value) const
evaluate the function
Definition: instationary.hh:186
InstationaryFunction(Function &&function, double time)
Definition: instationary.hh:174
InstationaryFunction(const Function &function, double time)
Definition: instationary.hh:169
DType DomainType
domain vector space (for usage in derived classes) This can either be for example a discrete function...
Definition: mapping.hh:57
RType RangeType
range vector space (for usage in derived classes) This can either be for example a discrete function ...
Definition: mapping.hh:63