Dune Core Modules (2.9.0)

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 (C) 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
13
14#include <dune/localfunctions/common/localbasis.hh>
15#include <dune/localfunctions/common/localkey.hh>
16#include <dune/localfunctions/common/localinterpolation.hh>
17
18namespace Dune
19{
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
132 template<class LB>
134 {
135 public:
136
138 RT0Cube2DLocalInterpolation (std::bitset<4> s = 0)
139 {
140 for (int i=0; i<4; i++)
141 sign_[i] = s[i] ? -1.0 : 1.0;
142
143 m0 = {0.0, 0.5};
144 m1 = {1.0, 0.5};
145 m2 = {0.5, 0.0};
146 m3 = {0.5, 1.0};
147
148 n0 = {-1.0, 0.0};
149 n1 = { 1.0, 0.0};
150 n2 = { 0.0, -1.0};
151 n3 = { 0.0, 1.0};
152 }
153
154 template<typename F, typename C>
155 void interpolate (const F& ff, std::vector<C>& out) const
156 {
157 // f gives v*outer normal at a point on the edge!
158 auto&& f = Impl::makeFunctionWithCallOperator<typename LB::Traits::DomainType>(ff);
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
186 {
187 public:
190 {
191 for (std::size_t i=0; i<4; i++)
192 li[i] = LocalKey(i,1,0);
193 }
194
196 std::size_t size () const
197 {
198 return 4;
199 }
200
202 const LocalKey& localKey (std::size_t i) const
203 {
204 return li[i];
205 }
206
207 private:
208 std::vector<LocalKey> li;
209 };
210
211}
212#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:23
Lowest order Raviart-Thomas shape functions on the reference quadrilateral.
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
Layout map for RT0 elements on quadrilaterals.
Definition: raviartthomas0cube2dall.hh:186
RT0Cube2DLocalCoefficients()
Standard constructor.
Definition: raviartthomas0cube2dall.hh:189
std::size_t size() const
number of coefficients
Definition: raviartthomas0cube2dall.hh:196
const LocalKey & localKey(std::size_t i) const
get i'th index
Definition: raviartthomas0cube2dall.hh:202
Lowest order Raviart-Thomas shape functions on the reference quadrilateral.
Definition: raviartthomas0cube2dall.hh:134
RT0Cube2DLocalInterpolation(std::bitset< 4 > s=0)
Constructor with explicitly given edge orientations.
Definition: raviartthomas0cube2dall.hh:138
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:291
Dune namespace.
Definition: alignedallocator.hh:13
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:34
D DomainType
domain type
Definition: localbasis.hh:42
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)