dune-localfunctions  2.3.1
rannacherturek3dlocalbasis.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_RANNACHER_TUREK_3D_LOCALBASIS_HH
4 #define DUNE_RANNACHER_TUREK_3D_LOCALBASIS_HH
5 
6 #include <vector>
7 
8 #include <dune/common/fvector.hh>
9 #include <dune/common/fmatrix.hh>
10 
12 
13 namespace Dune
14 {
15 
16  template< class D, class R >
18  {
19  static const int coefficients[ 6 ][ 6 ];
20 
21  public:
23  R, 1, FieldVector< R, 1 >,
24  FieldMatrix< R, 1, 3 > > Traits;
25 
27  unsigned int size () const
28  {
29  return 6;
30  }
31 
33  inline void evaluateFunction ( const typename Traits::DomainType &in,
34  std::vector< typename Traits::RangeType > &out ) const
35  {
36  typedef typename Traits::RangeFieldType RangeFieldType;
37  RangeFieldType y[ 6 ] = { 1, in[ 0 ], in[ 1 ], in[ 2 ],
38  in[ 0 ]*in[ 0 ] - in[ 1 ]*in[ 1 ],
39  in[ 1 ]*in[ 1 ] - in[ 2 ]*in[ 2 ] };
40  out.resize( size() );
41  for( unsigned int i = 0; i < size(); ++i )
42  {
43  out[ i ] = RangeFieldType( 0 );
44  for( unsigned int j = 0; j < 6; ++j )
45  out[ i ] += coefficients[ i ][ j ]*y[ j ];
46  out[ i ] /= RangeFieldType( 3 );
47  }
48  }
49 
51  inline void evaluateJacobian ( const typename Traits::DomainType &in,
52  std::vector< typename Traits::JacobianType > &out ) const
53  {
54  typedef typename Traits::RangeFieldType RangeFieldType;
55  RangeFieldType y0[ 5 ] = { 1, 0, 0, 2*in[ 0 ], 0 };
56  RangeFieldType y1[ 5 ] = { 0, 1, 0, -2*in[ 1 ], 2*in[ 1 ] };
57  RangeFieldType y2[ 5 ] = { 0, 0, 1, 0, -2*in[ 2 ] };
58 
59  out.resize( size() );
60  for( unsigned int i = 0; i < size(); ++i )
61  {
62  out[ i ] = RangeFieldType( 0 );
63  for( unsigned int j = 0; j < 5; ++j )
64  {
65  out[ i ][ 0 ][ 0 ] += coefficients[ i ][ j+1 ]*y0[ j ];
66  out[ i ][ 0 ][ 1 ] += coefficients[ i ][ j+1 ]*y1[ j ];
67  out[ i ][ 0 ][ 2 ] += coefficients[ i ][ j+1 ]*y2[ j ];
68  }
69  out[ i ] /= RangeFieldType( 3 );
70  }
71  }
72 
74  unsigned int order () const
75  {
76  return 2;
77  }
78  };
79 
80 
81 
82  // RannacherTurek3DLocalBasis::coefficients
83  // ----------------------------------------
84 
85  template< class D, class R >
86  const int RannacherTurek3DLocalBasis< D, R >
87  ::coefficients[ 6 ][ 6 ] = {{ 2, -7, 2, 2, 4, 2 },
88  { -1, -1, 2, 2, 4, 2 },
89  { 2, 2, -7, 2, -2, 2 },
90  { -1, 2, -1, 2, -2, 2 },
91  { 2, 2, 2, -7, -2, -4 },
92  { -1, 2, 2, -1, -2, -4 }};
93 
94 } //namespace Dune
95 
96 #endif // #ifndef DUNE_RANNACHER_TUREK_2D_LOCALBASIS_HH