1 #ifndef DUNE_FEM_SPACE_FOURIER_FUNCTIONSET_HH 2 #define DUNE_FEM_SPACE_FOURIER_FUNCTIONSET_HH 9 #include <dune/common/fmatrix.hh> 10 #include <dune/common/fvector.hh> 11 #include <dune/common/power.hh> 26 template<
int dimension,
int Order >
29 static const int v = StaticPower< (2*Order+1), dimension >::power;
37 template<
class FunctionSpace,
int Order >
45 template<
class DomainFieldType,
class RangeFieldType,
int Order >
62 int order ()
const {
return order_; }
66 template<
class Functor >
69 functor( 0, RangeFieldType( 1 ) / RangeFieldType( 2 ) );
73 SizeType basisFunction = 1;
74 for(
int n = 1; n <= Order; ++n )
76 functor( basisFunction++,
std::cos( n*x[ 0 ] ) );
77 functor( basisFunction++,
std::sin( n*x[ 0 ] ) );
81 template<
class Functor >
84 functor( 0, RangeFieldType( 0 ) );
85 SizeType basisFunction = 1;
86 for(
int n = 1; n <= Order; ++n )
88 functor( basisFunction++, -n*
std::sin( n*x[ 0 ] ) );
89 functor( basisFunction++, n*
std::cos( n*x[ 0 ] ) );
93 template<
class Functor >
94 static void hessianEach (
const DomainType &x, Functor functor )
96 functor( 0, RangeFieldType( 0 ) );
97 SizeType basisFunction = 1;
98 for(
int n = 1; n <= Order; ++n )
100 functor( basisFunction++, -(n*n)*
std::cos( n*x[ 0 ] ) );
101 functor( basisFunction++, -(n*n)*
std::sin( n*x[ 0 ] ) );
113 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
144 struct MultiIndexIterator;
146 static IteratorType
begin () {
return IteratorType::begin(); }
147 static IteratorType
end () {
return IteratorType::end(); }
152 int order ()
const {
return order_; }
156 template<
class Functor >
159 prepare( Evaluate(), x );
161 const IteratorType end = ThisType::end();
162 for( IteratorType it = ThisType::begin(); it != end; ++it, ++index )
165 evaluate( *it, value );
166 assert( index == IteratorType::index( *it ) );
167 functor( index, value );
169 assert( index == size() );
172 template<
class Functor >
175 prepare( Jacobian(), x );
177 const IteratorType end = ThisType::end();
178 for( IteratorType it = ThisType::begin(); it != end; ++it, ++index )
180 JacobianRangeType jacobian;
181 evaluate( *it, jacobian );
182 assert( index == IteratorType::index( *it ) );
183 functor( index, jacobian );
185 assert( index == size() );
188 template<
class Functor >
191 prepare( Hessian(), x );
193 const IteratorType end = ThisType::end();
194 for( IteratorType it = ThisType::begin(); it != end; ++it, ++index )
196 HessianRangeType hessian;
197 evaluate( *it, hessian );
198 assert( index == IteratorType::index( *it ) );
199 functor( index, hessian );
201 assert( index == size() );
206 void evaluate (
const MultiIndexType &multiIndex, RangeType &value )
const 208 value = RangeType( RangeFieldType( 1 ) );
209 for( SizeType i = 0; i < dimDomain; ++i )
210 value *= buffer_[ i ][ multiIndex[ i ] ];
214 void evaluate (
const MultiIndexType &multiIndex, JacobianRangeType &jacobian )
const 216 jacobian = JacobianRangeType( 1 );
217 for(
int k = 0; k < dimDomain; ++k )
219 const RangeFieldType phi = buffer_[ k ][ multiIndex[ k ] ];
220 const RangeFieldType dphi = buffer_[ k ][ buffer_size + multiIndex[ k ] ];
221 for(
int i = 0; i < dimDomain; ++i )
222 jacobian[ 0 ][ i ] *= (k == i ? dphi : phi);
227 void evaluate (
const MultiIndexType &multiIndex, HessianRangeType &hessian )
const 229 for(
int i = 0; i < dimDomain; ++i )
230 for(
int j = 0; j < dimDomain; ++j )
231 hessian[ 0 ][ i ][ j ] = RangeFieldType( 1 );
233 for(
int k = 0; k < dimDomain; ++k )
235 const RangeFieldType phi = buffer_[ k ][ multiIndex[ k ] ];
236 const RangeFieldType dphi = buffer_[ k ][ buffer_size + multiIndex[ k ] ];
237 for(
int i = 0; i < dimDomain; ++i )
239 hessian[ 0 ][ i ][ i ] *= (k == i ? buffer_[ i ][ 2*buffer_size + multiIndex[ i ] ] : phi);
240 for(
int j = i+1; j < dimDomain; ++j )
242 RangeFieldType tmp = ( k == i || k == j ) ? dphi : phi;
243 hessian[ 0 ][ i ][ j ] *= tmp;
244 hessian[ 0 ][ j ][ i ] *= tmp;
251 void prepare (
const Evaluate &,
const DomainType &x )
const;
252 void prepare (
const Jacobian &,
const DomainType &x )
const;
253 void prepare (
const Hessian &,
const DomainType &x )
const;
258 mutable std::array< std::array< RangeFieldType, 3*buffer_size>, dimDomain > buffer_;
266 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
269 explicit Assign ( RangeFieldType *buffer ) : buffer_( buffer ) {}
271 void operator() (
const std::size_t i,
const RangeFieldType &value )
273 buffer_[ i ] = value;
277 void operator() (
const std::size_t i,
const FieldVector< T, 1 > &value )
279 (*this)( i, value[ 0 ] );
283 void operator() (
const std::size_t i,
const FieldMatrix< T, 1, 1 > &value )
285 (*this)( i, value[ 0 ][ 0 ] );
289 RangeFieldType *buffer_;
297 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
312 static ThisType
begin () {
return ThisType( 0 ); }
313 static ThisType
end () {
return ThisType( invalidIndex() ); }
315 ThisType operator++ ()
318 for(
int i = 0; i < dimDomain; ++i )
320 const int j = dimDomain-i-1;
321 if( ++multiIndex_[ j ] < N )
323 multiIndex_[ j ] = 0;
331 bool operator== (
const ThisType &other )
const {
return ( multiIndex_ == other.multiIndex_ ); }
333 bool operator!= (
const ThisType &other )
const {
return !( *
this == other ); }
344 for(
int i = dimDomain-1; i >= 0; --i )
346 index += multiIndex[ i ]*factor;
349 assert( index < size() );
362 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
367 for(
SizeType i = 0; i < dimDomain; ++i )
369 RangeFieldType *it = &buffer_[ i ][ 0 ];
370 Dune::FieldVector< DomainFieldType, 1 > y( x[ i ] );
371 FunctionSetImp::evaluateEach( y, Assign( it ) );
376 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
377 void FourierFunctionSet< FunctionSpace< DomainFieldType, RangeFieldType, dimDomain, 1 >, Order >
381 for(
SizeType i = 0; i < dimDomain; ++i )
383 RangeFieldType *it = &buffer_[ i ][ 0 ];
384 Dune::FieldVector< DomainFieldType, 1 > y( x[ i ] );
385 FunctionSetImp::evaluateEach( y, Assign( it ) );
386 FunctionSetImp::jacobianEach( y, Assign( it+buffer_size ) );
391 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
392 void FourierFunctionSet< FunctionSpace< DomainFieldType, RangeFieldType, dimDomain, 1 >, Order >
396 for(
SizeType i = 0; i < dimDomain; ++i )
398 RangeFieldType *it = &buffer_[ i ][ 0 ];
399 Dune::FieldVector< DomainFieldType, 1 > y( x[ i ] );
400 FunctionSetImp::evaluateEach( y, Assign( it ) );
401 FunctionSetImp::jacobianEach( y, Assign( it+buffer_size) );
402 FunctionSetImp::hessianEach( y, Assign( it+2*buffer_size ) );
410 #endif // #ifndef DUNE_FEM_SPACE_FOURIER_FUNCTIONSET_HH Assign(RangeFieldType *buffer)
Definition: space/fourier/functionset.hh:269
static void jacobianEach(const DomainType &x, Functor functor)
Definition: space/fourier/functionset.hh:82
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: space/fourier/functionset.hh:55
std::size_t SizeType
Definition: space/fourier/functionset.hh:126
static IteratorType begin()
Definition: space/fourier/functionset.hh:146
FourierFunctionSet(int order)
Definition: space/fourier/functionset.hh:60
Definition: space/fourier/functionset.hh:46
FunctionSpaceType::RangeType RangeType
Definition: space/fourier/functionset.hh:54
A vector valued function space.
Definition: functionspace.hh:16
static double sin(const Double &v)
Definition: double.hh:875
FunctionSpaceType::DomainType DomainType
Definition: space/fourier/functionset.hh:53
static ThisType begin()
Definition: space/fourier/functionset.hh:312
MultiIndexIterator(IndexType n)
Definition: space/fourier/functionset.hh:305
static constexpr T max(T a)
Definition: utility.hh:65
VectorSpaceTraits< DomainField, RangeField, dimD, dimR >::LinearMappingType JacobianRangeType
Intrinsic type used for the jacobian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:74
FieldVector< FieldMatrix< RangeFieldType, dimDomain, dimDomain >, dimRange > HessianRangeType
Intrinsic type used for the hessian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:78
static IteratorType end()
Definition: space/fourier/functionset.hh:147
SizeType index() const
Definition: space/fourier/functionset.hh:339
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: space/fourier/functionset.hh:56
FunctionSpace< DomainFieldType, RangeFieldType, dimDomain, 1 > FunctionSpaceType
Definition: space/fourier/functionset.hh:119
static SizeType size()
Definition: space/fourier/functionset.hh:154
void jacobianEach(const DomainType &x, Functor functor) const
Definition: space/fourier/functionset.hh:173
Definition: space/fourier/functionset.hh:38
bool operator!=(const Double &a, const Double &b)
Definition: double.hh:629
FourierFunctionSet(int order)
Definition: space/fourier/functionset.hh:150
static const int v
Definition: space/fourier/functionset.hh:29
static SizeType size()
Definition: space/fourier/functionset.hh:64
bool operator==(const Double &a, const Double &b)
Definition: double.hh:589
Definition: coordinate.hh:4
Definition: space/fourier/functionset.hh:27
static double cos(const Double &v)
Definition: double.hh:880
static ThisType end()
Definition: space/fourier/functionset.hh:313
static SizeType index(const MultiIndexType &multiIndex)
Definition: space/fourier/functionset.hh:341
std::size_t SizeType
Definition: space/fourier/functionset.hh:58
VectorSpaceTraits< DomainField, RangeField, dimD, dimR >::DomainType DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:66
FunctionSpace< DomainFieldType, RangeFieldType, 1, 1 > FunctionSpaceType
Definition: space/fourier/functionset.hh:51
void hessianEach(const DomainType &x, Functor functor) const
Definition: space/fourier/functionset.hh:189
Dune::FieldVector< int, dimDomain > MultiIndexType
Definition: space/fourier/functionset.hh:137
void evaluate(const MultiIndexType &multiIndex, HessianRangeType &hessian) const
Definition: space/fourier/functionset.hh:227
Double operator*(const Double &a, const Double &b)
Definition: double.hh:495
int order() const
Definition: space/fourier/functionset.hh:152
FunctionSpaceType::RangeType RangeType
Definition: space/fourier/functionset.hh:122
void evaluateEach(const DomainType &x, Functor functor) const
Definition: space/fourier/functionset.hh:157
int order() const
Definition: space/fourier/functionset.hh:62
MultiIndexIterator IteratorType
Definition: space/fourier/functionset.hh:144
MultiIndexIterator ThisType
Definition: space/fourier/functionset.hh:300
static void evaluateEach(const DomainType &x, Functor functor)
Definition: space/fourier/functionset.hh:67
static IndexType invalidIndex()
Definition: space/fourier/functionset.hh:307
void evaluate(const MultiIndexType &multiIndex, JacobianRangeType &jacobian) const
Definition: space/fourier/functionset.hh:214
VectorSpaceTraits< DomainField, RangeField, dimD, dimR >::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:70
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: space/fourier/functionset.hh:124
FunctionSpaceType::DomainType DomainType
Definition: space/fourier/functionset.hh:121
int IndexType
Definition: space/fourier/functionset.hh:303
Definition: space/fourier/functionset.hh:114
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: space/fourier/functionset.hh:123
void evaluate(const MultiIndexType &multiIndex, RangeType &value) const
Definition: space/fourier/functionset.hh:206
static void hessianEach(const DomainType &x, Functor functor)
Definition: space/fourier/functionset.hh:94