dune-fem  2.8-git
localfiniteelement/shapefunctionset.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_SHAPEFUNCTIONSET_LOCALFUNCTIONS_HH
2 #define DUNE_FEM_SHAPEFUNCTIONSET_LOCALFUNCTIONS_HH
3 
4 // C++ includes
5 #include <cstddef>
6 #include <vector>
7 
8 // dune-common includes
9 #include <dune/common/exceptions.hh>
10 
11 // dune-fem includes
14 
15 namespace Dune
16 {
17 
18  namespace Fem
19  {
20 
21  // LocalFunctionsShapeFunctionSetTraits
22  // ------------------------------------
23 
24  template< class LocalBasis >
26  {
27 
28  typedef typename LocalBasis::Traits Traits;
29 
30  public:
31  typedef typename Traits::DomainType DomainType;
32  typedef typename DomainType::value_type DomainFieldType;
33  static const int dimDomain = DomainType::dimension;
34 
35  typedef typename Traits::RangeType RangeType;
36  typedef typename RangeType::value_type RangeFieldType;
37  static const int dimRange = RangeType::dimension;
38 
40  };
41 
42 
43 
44  // LocalFunctionsShapeFunctionSet
45  // ------------------------------
46 
47  template< class LocalBasis, int pSetId = -1 >
49  {
50  // this type
52  // traits class
54 
55  public:
61 
62  static const int pointSetId = pSetId;
63 
64  explicit LocalFunctionsShapeFunctionSet ( const LocalBasis &localBasis )
65  : localBasis_( localBasis )
66  {
67  values_.reserve( size() );
68  jacobians_.reserve( size() );
69  hessians_.resize( DomainType::dimension*(DomainType::dimension+1)/2. );
70  for (unsigned int i=0;i<hessians_.size();++i)
71  hessians_[i].reserve( size() );
72  }
73 
74  int order () const { return localBasis_.order(); }
75 
76  std::size_t size () const { return localBasis_.size(); }
77 
78  template< class Point, class Functor >
79  void evaluateEach ( const Point &x, Functor f ) const
80  {
81  localBasis_.evaluateFunction( coordinate( x ), values_ );
82  assert( values_.size() == size() );
83  callFunctor( values_, f );
84  }
85 
86  template< class Point, class Functor >
87  void jacobianEach ( const Point &x, Functor f ) const
88  {
89  localBasis_.evaluateJacobian( coordinate( x ), jacobians_ );
90  assert( jacobians_.size() == size() );
91  callFunctor( jacobians_, f );
92  }
93 
94  template< class Point, class Functor >
95  void hessianEach ( const Point &x, Functor f ) const
96  {
97  std::array<unsigned int, DomainType::dimension> multiIndex;
98  std::fill(multiIndex.begin(),multiIndex.end(),0);
99  unsigned int k = 0;
100  for (unsigned int i=0;i<DomainType::dimension;++i)
101  {
102  multiIndex[i] = 1;
103  for (unsigned int j=i;j<DomainType::dimension;++j)
104  {
105  multiIndex[j] += 1;
106  localBasis_.partial(multiIndex,coordinate(x),hessians_[k]);
107  multiIndex[j] -= 1;
108  ++k;
109  }
110  multiIndex[i] -= 1;
111  }
112  callFunctor( hessians_, f );
113  }
114 
115  private:
116  template< class T, class Functor >
117  static void callFunctor ( const std::vector< T > &v, Functor f )
118  {
119  typedef typename std::vector< T >::const_iterator Iterator;
120  std::size_t i = 0;
121  for( Iterator it = v.begin(); it != v.end(); ++it )
122  f( i++, *it );
123  }
124  template< class T, class Functor >
125  static void callFunctor ( const std::vector< std::vector<T> > &v, Functor f )
126  {
128  for (unsigned int b=0;b<v[0].size();++b)
129  {
130  unsigned int k = 0;
131  for (unsigned int i=0;i<DomainType::dimension;++i)
132  {
133  for (unsigned int j=i;j<DomainType::dimension;++j)
134  {
135  for (unsigned int r=0;r<RangeType::dimension;++r)
136  {
137  h[r][i][j] = v[b][k][r];
138  h[r][j][i] = v[b][k][r];
139  }
140  ++k;
141  }
142  }
143  f( b, h );
144  }
145  }
146 
147  const LocalBasis& localBasis_;
148  mutable std::vector< RangeType > values_;
149  mutable std::vector< JacobianRangeType > jacobians_;
150  mutable std::vector< std::vector< RangeType > > hessians_;
151  };
152 
153  } // namespace Fem
154 
155 } // namespace Dune
156 
157 #endif // #ifndef DUNE_FEM_SHAPEFUNCTIONSET_LOCALFUNCTIONS_HH
Definition: bindguard.hh:11
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:14
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: localfiniteelement/shapefunctionset.hh:26
RangeType::value_type RangeFieldType
Definition: localfiniteelement/shapefunctionset.hh:36
static const int dimRange
Definition: localfiniteelement/shapefunctionset.hh:37
static const int dimDomain
Definition: localfiniteelement/shapefunctionset.hh:33
Traits::RangeType RangeType
Definition: localfiniteelement/shapefunctionset.hh:35
Traits::DomainType DomainType
Definition: localfiniteelement/shapefunctionset.hh:31
DomainType::value_type DomainFieldType
Definition: localfiniteelement/shapefunctionset.hh:32
FunctionSpace< DomainFieldType, RangeFieldType, dimDomain, dimRange > FunctionSpaceType
Definition: localfiniteelement/shapefunctionset.hh:39
Definition: localfiniteelement/shapefunctionset.hh:49
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: localfiniteelement/shapefunctionset.hh:59
void evaluateEach(const Point &x, Functor f) const
Definition: localfiniteelement/shapefunctionset.hh:79
void hessianEach(const Point &x, Functor f) const
Definition: localfiniteelement/shapefunctionset.hh:95
FunctionSpaceType::RangeType RangeType
Definition: localfiniteelement/shapefunctionset.hh:58
void jacobianEach(const Point &x, Functor f) const
Definition: localfiniteelement/shapefunctionset.hh:87
std::size_t size() const
Definition: localfiniteelement/shapefunctionset.hh:76
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: localfiniteelement/shapefunctionset.hh:60
LocalFunctionsShapeFunctionSet(const LocalBasis &localBasis)
Definition: localfiniteelement/shapefunctionset.hh:64
int order() const
Definition: localfiniteelement/shapefunctionset.hh:74
FunctionSpaceType::DomainType DomainType
Definition: localfiniteelement/shapefunctionset.hh:57
static const int pointSetId
Definition: localfiniteelement/shapefunctionset.hh:62
Traits::FunctionSpaceType FunctionSpaceType
Definition: localfiniteelement/shapefunctionset.hh:56