Dune Core Modules (2.6.0)

pyramidp1localbasis.hh
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_PYRAMID_P1_LOCALBASIS_HH
4 #define DUNE_PYRAMID_P1_LOCALBASIS_HH
5 
6 #include <numeric>
7 
8 #include <dune/common/fmatrix.hh>
9 
10 #include <dune/localfunctions/common/localbasis.hh>
11 
12 
13 namespace Dune
14 {
25  template<class D, class R>
27  {
28  public:
32 
34  unsigned int size () const
35  {
36  return 5;
37  }
38 
40  inline void evaluateFunction (const typename Traits::DomainType& in, // position
41  std::vector<typename Traits::RangeType>& out) const // return value
42  {
43  out.resize(5);
44 
45  if(in[0] > in[1])
46  {
47  out[0] = (1-in[0])*(1-in[1])-in[2]*(1-in[1]);
48  out[1] = in[0]*(1-in[1])-in[2]*in[1];
49  out[2] = (1-in[0])*in[1]-in[2]*in[1];
50  out[3] = in[0]*in[1]+in[2]*in[1];
51  }
52  else
53  {
54  out[0] = (1-in[0])*(1-in[1])-in[2]*(1-in[0]);
55  out[1] = in[0]*(1-in[1])-in[2]*in[0];
56  out[2] = (1-in[0])*in[1]-in[2]*in[0];
57  out[3] = in[0]*in[1]+in[2]*in[0];
58  }
59 
60 
61  out[4] = in[2];
62 
63 
64  }
65 
67  inline void
68  evaluateJacobian (const typename Traits::DomainType& in, // position
69  std::vector<typename Traits::JacobianType>& out) const // return value
70  {
71  out.resize(5);
72 
73  if(in[0] > in[1])
74  {
75  out[0][0][0] = -1 + in[1]; out[0][0][1] = -1 + in[0] + in[2]; out[0][0][2] = -1 + in[1];
76  out[1][0][0] = 1 - in[1]; out[1][0][1] = -in[0] - in[2]; out[1][0][2] = -in[1];
77  out[2][0][0] = -in[1]; out[2][0][1] = 1 - in[0] - in[2]; out[2][0][2] = -in[1];
78  out[3][0][0] = in[1]; out[3][0][1] = in[0]+in[2]; out[3][0][2] = in[1];
79  }
80  else
81  {
82  out[0][0][0] = -1 + in[1] + in[2]; out[0][0][1] = -1 + in[0]; out[0][0][2] = -1 + in[0];
83  out[1][0][0] = 1 - in[1] - in[2]; out[1][0][1] = -in[0]; out[1][0][2] = -in[0];
84  out[2][0][0] = -in[1] - in[2]; out[2][0][1] = 1 - in[0]; out[2][0][2] = -in[0];
85  out[3][0][0] = in[1] + in[2]; out[3][0][1] = in[0]; out[3][0][2] = in[0];
86 
87  }
88 
89  out[4][0][0] = 0; out[4][0][1] = 0; out[4][0][2] = 1;
90  }
91 
93  void partial (const std::array<unsigned int, 3>& order,
94  const typename Traits::DomainType& in, // position
95  std::vector<typename Traits::RangeType>& out) const // return value
96  {
97  auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
98  if (totalOrder == 0) {
99  evaluateFunction(in, out);
100  } else if (totalOrder == 1) {
101  out.resize(size());
102 
103  auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
104  if (in[0] > in[1])
105  {
106  switch (direction) {
107  case 0:
108  out[0] = -1 + in[1];
109  out[1] = 1 - in[1];
110  out[2] = -in[1];
111  out[3] = in[1];
112  out[4] = 0;
113  break;
114  case 1:
115  out[0] = -1 + in[0] + in[2];
116  out[1] = -in[0] - in[2];
117  out[2] = 1 - in[0] - in[2];
118  out[3] = in[0]+in[2];
119  out[4] = 0;
120  break;
121  case 2:
122  out[0] = -1 + in[1];
123  out[1] = -in[1];
124  out[2] = -in[1];
125  out[3] = in[1];
126  out[4] = 1;
127  break;
128  default:
129  DUNE_THROW(RangeError, "Component out of range.");
130  }
131  }
132  else /* (in[0] <= in[1]) */
133  {
134  switch (direction) {
135  case 0:
136  out[0] = -1 + in[1] + in[2];
137  out[1] = 1 - in[1] - in[2];
138  out[2] = -in[1] - in[2];
139  out[3] = in[1] + in[2];
140  out[4] = 0;
141  break;
142  case 1:
143  out[0] = -1 + in[0];
144  out[1] = -in[0];
145  out[2] = 1 - in[0];
146  out[3] = in[0];
147  out[4] = 0;
148  break;
149  case 2:
150  out[0] = -1 + in[0];
151  out[1] = -in[0];
152  out[2] = -in[0];
153  out[3] = in[0];
154  out[4] = 1;
155  break;
156  default:
157  DUNE_THROW(RangeError, "Component out of range.");
158  }
159  }
160  } else if (totalOrder == 2) {
161  out.resize(size());
162 
163  if ((order[0] == 1 && order[1] == 1) ||
164  (order[1] == 1 && order[2] == 1 && in[0] > in[1]) ||
165  (order[0] == 1 && order[2] == 1 && in[0] <=in[1])) {
166  out[0] = 1;
167  out[1] =-1;
168  out[2] =-1;
169  out[3] = 1;
170  out[4] = 0;
171  } else {
172  for (std::size_t i = 0; i < size(); ++i)
173  out[i] = 0;
174  }
175 
176  } else {
177  out.resize(size());
178  for (std::size_t i = 0; i < size(); ++i)
179  out[i] = 0;
180  }
181  }
182 
184  unsigned int order () const
185  {
186  return 1;
187  }
188  };
189 }
190 #endif
A dense n x m matrix.
Definition: fmatrix.hh:68
vector space out of a tensor product of fields.
Definition: fvector.hh:93
Linear Lagrange shape functions on the pyramid.
Definition: pyramidp1localbasis.hh:27
void partial(const std::array< unsigned int, 3 > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of all shape functions.
Definition: pyramidp1localbasis.hh:93
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: pyramidp1localbasis.hh:68
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: pyramidp1localbasis.hh:40
LocalBasisTraits< D, 3, Dune::FieldVector< D, 3 >, R, 1, Dune::FieldVector< R, 1 >, Dune::FieldMatrix< R, 1, 3 > > Traits
export type traits for function signature
Definition: pyramidp1localbasis.hh:31
unsigned int order() const
Polynomial order of the shape functions.
Definition: pyramidp1localbasis.hh:184
unsigned int size() const
number of shape functions
Definition: pyramidp1localbasis.hh:34
Default exception class for range errors.
Definition: exceptions.hh:252
Implements a matrix constructed from a given type representing a field and compile-time given number ...
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:331
Dune namespace.
Definition: alignedallocator.hh:10
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:32
D DomainType
domain type
Definition: localbasis.hh:43
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 27, 22:29, 2024)