Dune Core Modules (unstable)

raviartthomas0cube2dall.hh
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 #ifndef DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_CUBE2D_ALL_HH
6 #define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_CUBE2D_ALL_HH
7 
8 #include <cstddef>
9 #include <numeric>
10 #include <vector>
11 
12 #include <dune/common/fmatrix.hh>
13 
14 #include <dune/localfunctions/common/localbasis.hh>
15 #include <dune/localfunctions/common/localkey.hh>
16 
17 namespace Dune
18 {
28  template<class D, class R>
30  {
31  public:
34 
36  RT0Cube2DLocalBasis (std::bitset<4> s = 0)
37  {
38  for (int i=0; i<4; i++)
39  sign_[i] = s[i] ? -1.0 : 1.0;
40  }
41 
43  unsigned int size () const
44  {
45  return 4;
46  }
47 
49  inline void evaluateFunction (const typename Traits::DomainType& in,
50  std::vector<typename Traits::RangeType>& out) const
51  {
52  out.resize(4);
53  out[0] = {sign_[0]*(in[0]-1.0), 0.0};
54  out[1] = {sign_[1]*(in[0]), 0.0};
55  out[2] = {0.0, sign_[2]*(in[1]-1.0)};
56  out[3] = {0.0, sign_[3]*(in[1])};
57  }
58 
60  inline void
61  evaluateJacobian (const typename Traits::DomainType& in, // position
62  std::vector<typename Traits::JacobianType>& out) const // return value
63  {
64  out.resize(4);
65  out[0][0] = {sign_[0], 0};
66  out[0][1] = {0, 0};
67 
68  out[1][0] = {sign_[1], 0};
69  out[1][1] = {0, 0};
70 
71  out[2][0] = {0, 0};
72  out[2][1] = {0, sign_[2]};
73 
74  out[3][0] = {0, 0};
75  out[3][1] = {0, sign_[3]};
76  }
77 
79  void partial (const std::array<unsigned int, 2>& order,
80  const typename Traits::DomainType& in, // position
81  std::vector<typename Traits::RangeType>& out) const // return value
82  {
83  auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
84  if (totalOrder == 0) {
85  evaluateFunction(in, out);
86  } else if (totalOrder == 1) {
87  auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
88  out.resize(size());
89 
90  for (std::size_t i = 0; i < size(); ++i)
91  out[i] = {0, 0};
92 
93  switch (direction) {
94  case 0:
95  out[0][0] = sign_[0];
96  out[1][0] = sign_[1];
97  break;
98  case 1:
99  out[2][1] = sign_[2];
100  out[3][1] = sign_[3];
101  break;
102  default:
103  DUNE_THROW(RangeError, "Component out of range.");
104  }
105  } else {
106  out.resize(size());
107  for (std::size_t i = 0; i < size(); ++i)
108  for (std::size_t j = 0; j < 2; ++j)
109  out[i][j] = 0;
110  }
111 
112  }
113 
115  unsigned int order () const
116  {
117  return 1;
118  }
119 
120  private:
121  std::array<R,4> sign_;
122  };
123 
124 
133  template<class LB>
135  {
136  public:
137 
139  RT0Cube2DLocalInterpolation (std::bitset<4> s = 0)
140  {
141  for (int i=0; i<4; i++)
142  sign_[i] = s[i] ? -1.0 : 1.0;
143 
144  m0 = {0.0, 0.5};
145  m1 = {1.0, 0.5};
146  m2 = {0.5, 0.0};
147  m3 = {0.5, 1.0};
148 
149  n0 = {-1.0, 0.0};
150  n1 = { 1.0, 0.0};
151  n2 = { 0.0, -1.0};
152  n3 = { 0.0, 1.0};
153  }
154 
155  template<typename F, typename C>
156  void interpolate (const F& f, std::vector<C>& out) const
157  {
158  // f gives v*outer normal at a point on the edge!
159 
160  out.resize(4);
161 
162  // Evaluate the normal components at the edge midpoints
163  auto y = f(m0); out[0] = (y[0]*n0[0]+y[1]*n0[1])*sign_[0];
164  y = f(m1); out[1] = (y[0]*n1[0]+y[1]*n1[1])*sign_[1];
165  y = f(m2); out[2] = (y[0]*n2[0]+y[1]*n2[1])*sign_[2];
166  y = f(m3); out[3] = (y[0]*n3[0]+y[1]*n3[1])*sign_[3];
167  }
168 
169  private:
170  std::array<typename LB::Traits::RangeFieldType,4> sign_;
171 
172  // The four edge midpoints of the reference quadrilateral
173  typename LB::Traits::DomainType m0,m1,m2,m3;
174 
175  // The four edge normals of the reference quadrilateral
176  typename LB::Traits::DomainType n0,n1,n2,n3;
177  };
178 
187  {
188  public:
191  {
192  for (std::size_t i=0; i<4; i++)
193  li[i] = LocalKey(i,1,0);
194  }
195 
197  std::size_t size () const
198  {
199  return 4;
200  }
201 
203  const LocalKey& localKey (std::size_t i) const
204  {
205  return li[i];
206  }
207 
208  private:
209  std::vector<LocalKey> li;
210  };
211 
212 }
213 #endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_CUBE2D_ALL_HH
A dense n x m matrix.
Definition: fmatrix.hh:117
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Describe position of one degree of freedom.
Definition: localkey.hh:24
Definition: raviartthomas0cube2dall.hh:30
RT0Cube2DLocalBasis(std::bitset< 4 > s=0)
Constructor with a set of edge orientations.
Definition: raviartthomas0cube2dall.hh:36
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: raviartthomas0cube2dall.hh:49
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: raviartthomas0cube2dall.hh:79
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: raviartthomas0cube2dall.hh:61
unsigned int order() const
Polynomial order of the shape functions.
Definition: raviartthomas0cube2dall.hh:115
unsigned int size() const
number of shape functions
Definition: raviartthomas0cube2dall.hh:43
Definition: raviartthomas0cube2dall.hh:187
const LocalKey & localKey(std::size_t i) const
get i'th index
Definition: raviartthomas0cube2dall.hh:203
RT0Cube2DLocalCoefficients()
Standard constructor.
Definition: raviartthomas0cube2dall.hh:190
std::size_t size() const
number of coefficients
Definition: raviartthomas0cube2dall.hh:197
Definition: raviartthomas0cube2dall.hh:135
RT0Cube2DLocalInterpolation(std::bitset< 4 > s=0)
Constructor with explicitly given edge orientations.
Definition: raviartthomas0cube2dall.hh:139
Default exception class for range errors.
Definition: exceptions.hh:254
Implements a matrix constructed from a given type representing a field and compile-time given number ...
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:279
Dune namespace.
Definition: alignedallocator.hh:13
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:35
D DomainType
domain type
Definition: localbasis.hh:43
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 1, 22:29, 2024)