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 >
71 functor( 0,
RangeType( RangeFieldType( 1 ) / RangeFieldType( 2 ) ) );
76 for(
int n = 1; n <= Order; ++n )
78 functor( basisFunction++,
RangeType(
cos( n*x[ 0 ] ) ) );
79 functor( basisFunction++,
RangeType(
sin( n*x[ 0 ] ) ) );
83 template<
class Functor >
90 for(
int n = 1; n <= Order; ++n )
97 template<
class Functor >
104 for(
int n = 1; n <= Order; ++n )
119 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
150 struct MultiIndexIterator;
158 int order ()
const {
return order_; }
162 template<
class Functor >
165 prepare( Evaluate(), x );
168 for(
IteratorType it = ThisType::begin(); it != end; ++it, ++index )
171 evaluate( *it, value );
172 assert( index == IteratorType::index( *it ) );
173 functor( index, value );
175 assert( index == size() );
178 template<
class Functor >
181 prepare( Jacobian(), x );
184 for(
IteratorType it = ThisType::begin(); it != end; ++it, ++index )
187 evaluate( *it, jacobian );
188 assert( index == IteratorType::index( *it ) );
189 functor( index, jacobian );
191 assert( index == size() );
194 template<
class Functor >
197 prepare( Hessian(), x );
200 for(
IteratorType it = ThisType::begin(); it != end; ++it, ++index )
203 evaluate( *it, hessian );
204 assert( index == IteratorType::index( *it ) );
205 functor( index, hessian );
207 assert( index == size() );
214 value =
RangeType( RangeFieldType( 1 ) );
215 for(
SizeType i = 0; i < dimDomain; ++i )
216 value *= buffer_[ i ][ multiIndex[ i ] ];
223 for(
int k = 0; k < dimDomain; ++k )
225 const RangeFieldType phi = buffer_[ k ][ multiIndex[ k ] ];
226 const RangeFieldType dphi = buffer_[ k ][ buffer_size + multiIndex[ k ] ];
227 for(
int i = 0; i < dimDomain; ++i )
228 jacobian[ 0 ][ i ] *= (k == i ? dphi : phi);
235 for(
int i = 0; i < dimDomain; ++i )
236 for(
int j = 0; j < dimDomain; ++j )
237 hessian[ 0 ][ i ][ j ] = RangeFieldType( 1 );
239 for(
int k = 0; k < dimDomain; ++k )
241 const RangeFieldType phi = buffer_[ k ][ multiIndex[ k ] ];
242 const RangeFieldType dphi = buffer_[ k ][ buffer_size + multiIndex[ k ] ];
243 for(
int i = 0; i < dimDomain; ++i )
245 hessian[ 0 ][ i ][ i ] *= (k == i ? buffer_[ i ][ 2*buffer_size + multiIndex[ i ] ] : phi);
246 for(
int j = i+1; j < dimDomain; ++j )
248 RangeFieldType tmp = ( k == i || k == j ) ? dphi : phi;
249 hessian[ 0 ][ i ][ j ] *= tmp;
250 hessian[ 0 ][ j ][ i ] *= tmp;
257 void prepare (
const Evaluate &,
const DomainType &x )
const;
258 void prepare (
const Jacobian &,
const DomainType &x )
const;
259 void prepare (
const Hessian &,
const DomainType &x )
const;
264 mutable std::array< std::array< RangeFieldType, 3*buffer_size>, dimDomain > buffer_;
272 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
275 explicit Assign ( RangeFieldType *buffer ) : buffer_( buffer ) {}
277 void operator() (
const std::size_t i,
const RangeFieldType &value )
279 buffer_[ i ] = value;
283 void operator() (
const std::size_t i,
const FieldVector< T, 1 > &value )
285 (*this)( i, value[ 0 ] );
289 void operator() (
const std::size_t i,
const FieldMatrix< T, 1, 1 > &value )
291 (*this)( i, value[ 0 ][ 0 ] );
295 RangeFieldType *buffer_;
303 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
324 for(
int i = 0; i < dimDomain; ++i )
326 const int j = dimDomain-i-1;
327 if( ++multiIndex_[ j ] < N )
329 multiIndex_[ j ] = 0;
350 for(
int i = dimDomain-1; i >= 0; --i )
352 index += multiIndex[ i ]*factor;
355 assert( index < size() );
368 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
373 for(
SizeType i = 0; i < dimDomain; ++i )
375 RangeFieldType *it = &buffer_[ i ][ 0 ];
376 Dune::FieldVector< DomainFieldType, 1 > y( x[ i ] );
377 FunctionSetImp::evaluateEach( y, Assign( it ) );
382 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
387 for(
SizeType i = 0; i < dimDomain; ++i )
389 RangeFieldType *it = &buffer_[ i ][ 0 ];
390 Dune::FieldVector< DomainFieldType, 1 > y( x[ i ] );
391 FunctionSetImp::evaluateEach( y, Assign( it ) );
392 FunctionSetImp::jacobianEach( y, Assign( it+buffer_size ) );
397 template<
class DomainFieldType,
class RangeFieldType,
int dimDomain,
int Order >
402 for(
SizeType i = 0; i < dimDomain; ++i )
404 RangeFieldType *it = &buffer_[ i ][ 0 ];
405 Dune::FieldVector< DomainFieldType, 1 > y( x[ i ] );
406 FunctionSetImp::evaluateEach( y, Assign( it ) );
407 FunctionSetImp::jacobianEach( y, Assign( it+buffer_size) );
408 FunctionSetImp::hessianEach( y, Assign( it+2*buffer_size ) );
bool operator==(const DiscreteFunctionInterface< ImplX > &x, const DiscreteFunctionInterface< ImplY > &y)
Definition: common/discretefunction.hh:1053
bool operator!=(const DiscreteFunctionInterface< ImplX > &x, const DiscreteFunctionInterface< ImplY > &y)
Definition: common/discretefunction.hh:1059
Definition: bindguard.hh:11
Double operator*(const Double &a, const Double &b)
Definition: double.hh:506
static double cos(const Double &v)
Definition: double.hh:896
static double sin(const Double &v)
Definition: double.hh:891
Definition: explicitfieldvector.hh:75
A vector valued function space.
Definition: functionspace.hh:60
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
FunctionSpaceTraits::LinearMappingType JacobianRangeType
Intrinsic type used for the jacobian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:75
FunctionSpaceTraits::DomainType DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:67
Definition: space/fourier/functionset.hh:28
static const int v
Definition: space/fourier/functionset.hh:29
Definition: space/fourier/functionset.hh:38
Definition: space/fourier/functionset.hh:47
FunctionSpaceType::RangeType RangeType
Definition: space/fourier/functionset.hh:54
static void jacobianEach(const DomainType &x, Functor functor)
Definition: space/fourier/functionset.hh:84
FunctionSpace< DomainFieldType, RangeFieldType, 1, 1 > FunctionSpaceType
Definition: space/fourier/functionset.hh:51
static void hessianEach(const DomainType &x, Functor functor)
Definition: space/fourier/functionset.hh:98
std::size_t SizeType
Definition: space/fourier/functionset.hh:58
static void evaluateEach(const DomainType &x, Functor functor)
Definition: space/fourier/functionset.hh:67
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: space/fourier/functionset.hh:56
int order() const
Definition: space/fourier/functionset.hh:62
FourierFunctionSet(int order)
Definition: space/fourier/functionset.hh:60
static SizeType size()
Definition: space/fourier/functionset.hh:64
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: space/fourier/functionset.hh:55
FunctionSpaceType::DomainType DomainType
Definition: space/fourier/functionset.hh:53
Definition: space/fourier/functionset.hh:121
void evaluate(const MultiIndexType &multiIndex, HessianRangeType &hessian) const
Definition: space/fourier/functionset.hh:233
void evaluateEach(const DomainType &x, Functor functor) const
Definition: space/fourier/functionset.hh:163
std::size_t SizeType
Definition: space/fourier/functionset.hh:132
static SizeType size()
Definition: space/fourier/functionset.hh:160
void evaluate(const MultiIndexType &multiIndex, RangeType &value) const
Definition: space/fourier/functionset.hh:212
static IteratorType begin()
Definition: space/fourier/functionset.hh:152
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: space/fourier/functionset.hh:130
static IteratorType end()
Definition: space/fourier/functionset.hh:153
void jacobianEach(const DomainType &x, Functor functor) const
Definition: space/fourier/functionset.hh:179
void hessianEach(const DomainType &x, Functor functor) const
Definition: space/fourier/functionset.hh:195
int order() const
Definition: space/fourier/functionset.hh:158
void evaluate(const MultiIndexType &multiIndex, JacobianRangeType &jacobian) const
Definition: space/fourier/functionset.hh:220
FourierFunctionSet(int order)
Definition: space/fourier/functionset.hh:156
FunctionSpaceType::DomainType DomainType
Definition: space/fourier/functionset.hh:127
Dune::FieldVector< int, dimDomain > MultiIndexType
Definition: space/fourier/functionset.hh:147
FunctionSpace< DomainFieldType, RangeFieldType, dimDomain, 1 > FunctionSpaceType
Definition: space/fourier/functionset.hh:125
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: space/fourier/functionset.hh:129
FunctionSpaceType::RangeType RangeType
Definition: space/fourier/functionset.hh:128
MultiIndexIterator IteratorType
Definition: space/fourier/functionset.hh:151
Assign(RangeFieldType *buffer)
Definition: space/fourier/functionset.hh:275
static SizeType index(const MultiIndexType &multiIndex)
Definition: space/fourier/functionset.hh:347
static ThisType begin()
Definition: space/fourier/functionset.hh:318
SizeType index() const
Definition: space/fourier/functionset.hh:345
MultiIndexIterator ThisType
Definition: space/fourier/functionset.hh:306
static IndexType invalidIndex()
Definition: space/fourier/functionset.hh:313
static ThisType end()
Definition: space/fourier/functionset.hh:319
int IndexType
Definition: space/fourier/functionset.hh:309
MultiIndexIterator(IndexType n)
Definition: space/fourier/functionset.hh:311