Dune Core Modules (unstable)

raviartthomas12dlocalbasis.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_RAVIARTTHOMAS12DLOCALBASIS_HH
6#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS12DLOCALBASIS_HH
7
8#include <numeric>
9#include <vector>
10
12
13#include "../../common/localbasis.hh"
14
15namespace Dune
16{
26 template<class D, class R>
28 {
29
30 public:
33
39 RT12DLocalBasis (std::bitset<3> s = 0)
40 {
41 for (size_t i=0; i<3; i++)
42 sign_[i] = (s[i]) ? -1.0 : 1.0;
43 }
44
46 unsigned int size () const
47 {
48 return 8;
49 }
50
57 inline void evaluateFunction (const typename Traits::DomainType& in,
58 std::vector<typename Traits::RangeType>& out) const
59 {
60 out.resize(8);
61 out[0][0] = sign_[0]*(in[0] - 4.0*in[0]*in[1]);
62 out[0][1] = sign_[0]*(-1.0 + 5.0*in[1] - 4.0*in[1]*in[1]);
63 out[1][0] = sign_[1]*(-1.0 + 5.0*in[0] - 4.0*in[0]*in[0]);
64 out[1][1] = sign_[1]*(in[1] - 4.0*in[0]*in[1]);
65 out[2][0] = sign_[2]*(-3.0*in[0] + 4.0*in[0]*in[0] + 4.0*in[1]*in[0]);
66 out[2][1] = sign_[2]*(-3.0*in[1] + 4.0*in[0]*in[1] + 4.0*in[1]*in[1]);
67 out[3][0] = -5.0*in[0] + 8.0*in[0]*in[0] + 4.0*in[1]*in[0];
68 out[3][1] = 3.0 - 6.0*in[0] - 7.0*in[1] + 8.0*in[0]*in[1] + 4.0*in[1]*in[1];
69 out[4][0] = -3.0 + 7.0*in[0] + 6.0*in[1] - 4.0*in[0]*in[0] - 8.0*in[1]*in[0];
70 out[4][1] = 5.0*in[1] - 4.0*in[0]*in[1] - 8.0*in[1]*in[1];
71 out[5][0] = in[0] - 4.0*in[0]*in[0] + 4.0*in[1]*in[0];
72 out[5][1] = -1.0*in[1] - 4.0*in[0]*in[1] + 4.0*in[1]*in[1];
73 out[6][0] = 16.0*in[0] - 16.0*in[0]*in[0] - 8.0*in[1]*in[0];
74 out[6][1] = 8.0*in[1] - 16.0*in[0]*in[1] - 8.0*in[1]*in[1];
75 out[7][0] = 8.0*in[0] - 8.0*in[0]*in[0] - 16.0*in[1]*in[0];
76 out[7][1] = 16.0*in[1] - 8.0*in[0]*in[1] - 16.0*in[1]*in[1];
77 }
78
85 inline void evaluateJacobian (const typename Traits::DomainType& in,
86 std::vector<typename Traits::JacobianType>& out) const
87 {
88 out.resize(8);
89
90 out[0][0][0] = sign_[0]*(1.0 - 4.0*in[1]);
91 out[0][0][1] = sign_[0]*(-4.0*in[0]);
92 out[0][1][0] = 0.0;
93 out[0][1][1] = sign_[0]*(5.0 - 8.0*in[1]);
94
95 out[1][0][0] = sign_[1]*(5.0 - 8.0*in[0]);
96 out[1][0][1] = 0.0;
97 out[1][1][0] = sign_[1]*(-4.0*in[1]);
98 out[1][1][1] = sign_[1]*(1.0 - 4.0*in[0]);
99
100 out[2][0][0] = sign_[2]*(-3.0 + 8.0*in[0] + 4.0*in[1]);
101 out[2][0][1] = sign_[2]*(4.0*in[0]);
102 out[2][1][0] = sign_[2]*(4.0*in[1]);
103 out[2][1][1] = sign_[2]*(-3.0 + 4.0*in[0] + 8.0*in[1]);
104
105 out[3][0][0] = -5.0 + 16.0*in[0] + 4.0*in[1];
106 out[3][0][1] = 4.0*in[0];
107 out[3][1][0] = -6.0 + 8.0*in[1];
108 out[3][1][1] = -7.0 + 8.0*in[0] + 8.0*in[1];
109
110 out[4][0][0] = 7.0 - 8.0*in[0] - 8.0*in[1];
111 out[4][0][1] = 6.0 - 8.0*in[0];
112 out[4][1][0] = -4.0*in[1];
113 out[4][1][1] = 5.0 - 4.0*in[0] - 16.0*in[1];
114
115 out[5][0][0] = 1.0 - 8.0*in[0] + 4*in[1];
116 out[5][0][1] = 4.0*in[0];
117 out[5][1][0] = -4.0*in[1];
118 out[5][1][1] = -1.0 - 4.0*in[0] + 8.0*in[1];
119
120 out[6][0][0] = 16.0 - 32.0*in[0] - 8.0*in[1];
121 out[6][0][1] = -8.0*in[0];
122 out[6][1][0] = -16.0*in[1];
123 out[6][1][1] = 8.0 - 16.0*in[0] - 16.0*in[1];
124
125 out[7][0][0] = 8.0 - 16.0*in[0] - 16.0*in[1];
126 out[7][0][1] = -16.0*in[0];
127 out[7][1][0] = -8.0*in[1];
128 out[7][1][1] = 16.0 - 8.0*in[0] - 32.0*in[1];
129 }
130
132 void partial (const std::array<unsigned int, 2>& order,
133 const typename Traits::DomainType& in, // position
134 std::vector<typename Traits::RangeType>& out) const // return value
135 {
136 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
137 if (totalOrder == 0) {
138 evaluateFunction(in, out);
139 } else if (totalOrder == 1) {
140 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
141 out.resize(size());
142
143 switch (direction) {
144 case 0:
145 out[0][0] = sign_[0]*(1.0 - 4.0*in[1]);
146 out[0][1] = 0.0;
147 out[1][0] = sign_[1]*(5.0 - 8.0*in[0]);
148 out[1][1] = sign_[1]*(-4.0*in[1]);
149 out[2][0] = sign_[2]*(-3.0 + 8.0*in[0] + 4.0*in[1]);
150 out[2][1] = sign_[2]*(4.0*in[1]);
151 out[3][0] = -5.0 + 16.0*in[0] + 4.0*in[1];
152 out[3][1] = -6.0 + 8.0*in[1];
153 out[4][0] = 7.0 - 8.0*in[0] - 8.0*in[1];
154 out[4][1] = -4.0*in[1];
155 out[5][0] = 1.0 - 8.0*in[0] + 4*in[1];
156 out[5][1] = -4.0*in[1];
157 out[6][0] = 16.0 - 32.0*in[0] - 8.0*in[1];
158 out[6][1] = -16.0*in[1];
159 out[7][0] = 8.0 - 16.0*in[0] - 16.0*in[1];
160 out[7][1] = -8.0*in[1];
161 break;
162 case 1:
163 out[2][1] = sign_[2]*(-3.0 + 4.0*in[0] + 8.0*in[1]);
164 out[2][0] = sign_[2]*(4.0*in[0]);
165 out[1][1] = sign_[1]*(1.0 - 4.0*in[0]);
166 out[1][0] = 0.0;
167 out[0][0] = sign_[0]*(-4.0*in[0]);
168 out[0][1] = sign_[0]*(5.0 - 8.0*in[1]);
169 out[3][0] = 4.0*in[0];
170 out[3][1] = -7.0 + 8.0*in[0] + 8.0*in[1];
171 out[4][0] = 6.0 - 8.0*in[0];
172 out[4][1] = 5.0 - 4.0*in[0] - 16.0*in[1];
173 out[5][0] = 4.0*in[0];
174 out[5][1] = -1.0 - 4.0*in[0] + 8.0*in[1];
175 out[6][0] = -8.0*in[0];
176 out[6][1] = 8.0 - 16.0*in[0] - 16.0*in[1];
177 out[7][0] = -16.0*in[0];
178 out[7][1] = 16.0 - 8.0*in[0] - 32.0*in[1];
179 break;
180 default:
181 DUNE_THROW(RangeError, "Component out of range.");
182 }
183 } else {
184 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
185 }
186 }
187
189 unsigned int order () const
190 {
191 return 2;
192 }
193
194 private:
195 std::array<R,3> sign_;
196 };
197}
198#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS12DLOCALBASIS_HH
A dense n x m matrix.
Definition: fmatrix.hh:117
vector space out of a tensor product of fields.
Definition: fvector.hh:92
Default exception for dummy implementations.
Definition: exceptions.hh:355
First order Raviart-Thomas shape functions on the reference triangle.
Definition: raviartthomas12dlocalbasis.hh:28
RT12DLocalBasis(std::bitset< 3 > s=0)
Make set number s, where 0 <= s < 8.
Definition: raviartthomas12dlocalbasis.hh:39
unsigned int size() const
number of shape functions
Definition: raviartthomas12dlocalbasis.hh:46
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: raviartthomas12dlocalbasis.hh:132
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: raviartthomas12dlocalbasis.hh:85
unsigned int order() const
Polynomial order of the shape functions.
Definition: raviartthomas12dlocalbasis.hh:189
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: raviartthomas12dlocalbasis.hh:57
Default exception class for range errors.
Definition: exceptions.hh:346
Implements a matrix constructed from a given type representing a field and compile-time given number ...
#define DUNE_THROW(E,...)
Definition: exceptions.hh:312
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.111.3 (Dec 21, 23:30, 2024)