dune-localfunctions  2.5.1
rannacherturek2dlocalbasis.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_2D_LOCALBASIS_HH
4 #define DUNE_RANNACHER_TUREK_2D_LOCALBASIS_HH
5 
6 #include <numeric>
7 #include <vector>
8 
9 #include <dune/common/fvector.hh>
10 #include <dune/common/fmatrix.hh>
11 
13 
14 namespace Dune
15 {
16 
17  template< class D, class R >
19  {
21  R, 1, FieldVector< R, 1 >,
22  FieldMatrix< R, 1, 2 > > Traits;
23 
25  unsigned int size () const
26  {
27  return 4;
28  }
29 
31  inline void evaluateFunction ( const typename Traits::DomainType &in,
32  std::vector< typename Traits::RangeType > &out ) const
33  {
34  out.resize(4);
35  typename Traits::DomainFieldType qbase = in[0]*in[0]-in[1]*in[1];
36  out[0] = .75 - 2*in[0] + in[1] + qbase;
37  out[1] = -.25 + in[1] + qbase;
38  out[2] = .75 + in[0] - 2*in[1] - qbase;
39  out[3] = -.25 + in[0] - qbase;
40  }
41 
43  inline void evaluateJacobian ( const typename Traits::DomainType &in,
44  std::vector< typename Traits::JacobianType > &out ) const
45  {
46  out.resize(4);
47 
48  // see http://www.dune-project.org/doc/doxygen/html/classDune_1_1C1LocalBasisInterface.html#d6f8368f8aa43439cc7ef10419f6e2ea
49  // out[i][j][k] = d_k \phi^i_j , where \phi^i_j is the j'th component of the i'th shape function.
50 
51  out[0][0][0] = -2 + 2*in[0]; out[0][0][1] = 1 - 2*in[1];
52  out[1][0][0] = 2*in[0]; out[1][0][1] = 1 - 2*in[1];
53  out[2][0][0] = 1 - 2*in[0]; out[2][0][1] = -2 + 2*in[1];
54  out[3][0][0] = 1 - 2*in[0]; out[3][0][1] = 2*in[1];
55  }
56 
58  void partial (const std::array<unsigned int, 2>& order,
59  const typename Traits::DomainType& in, // position
60  std::vector<typename Traits::RangeType>& out) const // return value
61  {
62  auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
63  if (totalOrder == 0) {
64  evaluateFunction(in, out);
65  } else if (totalOrder == 1) {
66  auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
67  out.resize(size());
68 
69  switch (direction) {
70  case 0:
71  out[0] = -2 + 2*in[0];
72  out[1] = 2*in[0];
73  out[2] = 1 - 2*in[0];
74  out[3] = 1 - 2*in[0];
75  break;
76  case 1:
77  out[0] = 1 - 2*in[1];
78  out[1] = 1 - 2*in[1];
79  out[2] = -2 + 2*in[1];
80  out[3] = 2*in[1];
81  break;
82  default:
83  DUNE_THROW(RangeError, "Component out of range.");
84  }
85  } else if (totalOrder == 2) {
86  auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 2));
87  out.resize(size());
88 
89  switch (direction) {
90  case 0:
91  out[0] = out[1] = 2;
92  out[2] = out[3] =-2;
93  break;
94  case 1:
95  out[0] = out[1] =-2;
96  out[2] = out[3] = 2;
97  break;
98  default:
99  out[0] = out[1] = out[2] = out[3] = 0;
100  break;
101  }
102  } else {
103  out[0] = out[1] = out[2] = out[3] = 0;
104  }
105  }
106 
108  unsigned int order () const
109  {
110  // must be 2 here since it contains x^2 and x^2
111  return 2;
112  }
113  };
114 
115 } //namespace Dune
116 
117 #endif // #ifndef DUNE_RANNACHER_TUREK_2D_LOCALBASIS_HH
unsigned int order() const
polynomial order of the shape functions
Definition: rannacherturek2dlocalbasis.hh:108
unsigned int size() const
number of shape functions
Definition: rannacherturek2dlocalbasis.hh:25
Definition: brezzidouglasmarini1cube2dlocalbasis.hh:15
D DomainType
domain type
Definition: localbasis.hh:49
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
evaluate jacobian of all shape functions
Definition: rannacherturek2dlocalbasis.hh:43
Definition: rannacherturek2dlocalbasis.hh:18
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
evaluate all shape functions
Definition: rannacherturek2dlocalbasis.hh:31
DF DomainFieldType
Export type for domain field.
Definition: localbasis.hh:40
LocalBasisTraits< D, 2, FieldVector< D, 2 >, R, 1, FieldVector< R, 1 >, FieldMatrix< R, 1, 2 > > Traits
Definition: rannacherturek2dlocalbasis.hh:22
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:37
void partial(const std::array< unsigned int, 2 > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of all shape functions.
Definition: rannacherturek2dlocalbasis.hh:58