Dune Core Modules (2.6.0)

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#ifndef DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS12DLOCALBASIS_HH
4#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS12DLOCALBASIS_HH
5
6#include <numeric>
7#include <vector>
8
10
11#include "../../common/localbasis.hh"
12
13namespace Dune
14{
24 template<class D, class R>
26 {
27
28 public:
33 {
34 sign0 = sign1 = sign2 = 1.0;
35 }
36
42 RT12DLocalBasis (unsigned int s)
43 {
44 sign0 = sign1 = sign2 = 1.0;
45 if (s & 1)
46 {
47 sign0 = -1.0;
48 }
49 if (s & 2)
50 {
51 sign1 = -1.0;
52 }
53 if (s & 4)
54 {
55 sign2 = -1.0;
56 }
57 }
58
60 unsigned int size () const
61 {
62 return 8;
63 }
64
71 inline void evaluateFunction (const typename Traits::DomainType& in,
72 std::vector<typename Traits::RangeType>& out) const
73 {
74 out.resize(8);
75 out[0][0] = sign0*(in[0] - 4.0*in[0]*in[1]);
76 out[0][1] = sign0*(-1.0 + 5.0*in[1] - 4.0*in[1]*in[1]);
77 out[1][0] = sign1*(-1.0 + 5.0*in[0] - 4.0*in[0]*in[0]);
78 out[1][1] = sign1*(in[1] - 4.0*in[0]*in[1]);
79 out[2][0] = sign2*(-3.0*in[0] + 4.0*in[0]*in[0] + 4.0*in[1]*in[0]);
80 out[2][1] = sign2*(-3.0*in[1] + 4.0*in[0]*in[1] + 4.0*in[1]*in[1]);
81 out[3][0] = -5.0*in[0] + 8.0*in[0]*in[0] + 4.0*in[1]*in[0];
82 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];
83 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];
84 out[4][1] = 5.0*in[1] - 4.0*in[0]*in[1] - 8.0*in[1]*in[1];
85 out[5][0] = in[0] - 4.0*in[0]*in[0] + 4.0*in[1]*in[0];
86 out[5][1] = -1.0*in[1] - 4.0*in[0]*in[1] + 4.0*in[1]*in[1];
87 out[6][0] = 16.0*in[0] - 16.0*in[0]*in[0] - 8.0*in[1]*in[0];
88 out[6][1] = 8.0*in[1] - 16.0*in[0]*in[1] - 8.0*in[1]*in[1];
89 out[7][0] = 8.0*in[0] - 8.0*in[0]*in[0] - 16.0*in[1]*in[0];
90 out[7][1] = 16.0*in[1] - 8.0*in[0]*in[1] - 16.0*in[1]*in[1];
91 }
92
99 inline void evaluateJacobian (const typename Traits::DomainType& in,
100 std::vector<typename Traits::JacobianType>& out) const
101 {
102 out.resize(8);
103
104 out[0][0][0] = sign0*(1.0 - 4.0*in[1]);
105 out[0][0][1] = sign0*(-4.0*in[0]);
106 out[0][1][0] = 0.0;
107 out[0][1][1] = sign0*(5.0 - 8.0*in[1]);
108
109 out[1][0][0] = sign1*(5.0 - 8.0*in[0]);
110 out[1][0][1] = 0.0;
111 out[1][1][0] = sign1*(-4.0*in[1]);
112 out[1][1][1] = sign1*(1.0 - 4.0*in[0]);
113
114 out[2][0][0] = sign2*(-3.0 + 8.0*in[0] + 4.0*in[1]);
115 out[2][0][1] = sign2*(4.0*in[0]);
116 out[2][1][0] = sign2*(4.0*in[1]);
117 out[2][1][1] = sign2*(-3.0 + 4.0*in[0] + 8.0*in[1]);
118
119 out[3][0][0] = -5.0 + 16.0*in[0] + 4.0*in[1];
120 out[3][0][1] = 4.0*in[0];
121 out[3][1][0] = -6.0 + 8.0*in[1];
122 out[3][1][1] = -7.0 + 8.0*in[0] + 8.0*in[1];
123
124 out[4][0][0] = 7.0 - 8.0*in[0] - 8.0*in[1];
125 out[4][0][1] = 6.0 - 8.0*in[0];
126 out[4][1][0] = -4.0*in[1];
127 out[4][1][1] = 5.0 - 4.0*in[0] - 16.0*in[1];
128
129 out[5][0][0] = 1.0 - 8.0*in[0] + 4*in[1];
130 out[5][0][1] = 4.0*in[0];
131 out[5][1][0] = -4.0*in[1];
132 out[5][1][1] = -1.0 - 4.0*in[0] + 8.0*in[1];
133
134 out[6][0][0] = 16.0 - 32.0*in[0] - 8.0*in[1];
135 out[6][0][1] = -8.0*in[0];
136 out[6][1][0] = -16.0*in[1];
137 out[6][1][1] = 8.0 - 16.0*in[0] - 16.0*in[1];
138
139 out[7][0][0] = 8.0 - 16.0*in[0] - 16.0*in[1];
140 out[7][0][1] = -16.0*in[0];
141 out[7][1][0] = -8.0*in[1];
142 out[7][1][1] = 16.0 - 8.0*in[0] - 32.0*in[1];
143 }
144
146 void partial (const std::array<unsigned int, 2>& order,
147 const typename Traits::DomainType& in, // position
148 std::vector<typename Traits::RangeType>& out) const // return value
149 {
150 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
151 if (totalOrder == 0) {
152 evaluateFunction(in, out);
153 } else if (totalOrder == 1) {
154 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
155 out.resize(size());
156
157 switch (direction) {
158 case 0:
159 out[0][0] = sign0*(1.0 - 4.0*in[1]);
160 out[0][1] = 0.0;
161 out[1][0] = sign1*(5.0 - 8.0*in[0]);
162 out[1][1] = sign1*(-4.0*in[1]);
163 out[2][0] = sign2*(-3.0 + 8.0*in[0] + 4.0*in[1]);
164 out[2][1] = sign2*(4.0*in[1]);
165 out[3][0] = -5.0 + 16.0*in[0] + 4.0*in[1];
166 out[3][1] = -6.0 + 8.0*in[1];
167 out[4][0] = 7.0 - 8.0*in[0] - 8.0*in[1];
168 out[4][1] = -4.0*in[1];
169 out[5][0] = 1.0 - 8.0*in[0] + 4*in[1];
170 out[5][1] = -4.0*in[1];
171 out[6][0] = 16.0 - 32.0*in[0] - 8.0*in[1];
172 out[6][1] = -16.0*in[1];
173 out[7][0] = 8.0 - 16.0*in[0] - 16.0*in[1];
174 out[7][1] = -8.0*in[1];
175 break;
176 case 1:
177 out[2][1] = sign2*(-3.0 + 4.0*in[0] + 8.0*in[1]);
178 out[2][0] = sign2*(4.0*in[0]);
179 out[1][1] = sign1*(1.0 - 4.0*in[0]);
180 out[1][0] = 0.0;
181 out[0][0] = sign0*(-4.0*in[0]);
182 out[0][1] = sign0*(5.0 - 8.0*in[1]);
183 out[3][0] = 4.0*in[0];
184 out[3][1] = -7.0 + 8.0*in[0] + 8.0*in[1];
185 out[4][0] = 6.0 - 8.0*in[0];
186 out[4][1] = 5.0 - 4.0*in[0] - 16.0*in[1];
187 out[5][0] = 4.0*in[0];
188 out[5][1] = -1.0 - 4.0*in[0] + 8.0*in[1];
189 out[6][0] = -8.0*in[0];
190 out[6][1] = 8.0 - 16.0*in[0] - 16.0*in[1];
191 out[7][0] = -16.0*in[0];
192 out[7][1] = 16.0 - 8.0*in[0] - 32.0*in[1];
193 break;
194 default:
195 DUNE_THROW(RangeError, "Component out of range.");
196 }
197 } else {
198 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
199 }
200 }
201
203 unsigned int order () const
204 {
205 return 2;
206 }
207
208 private:
209 R sign0, sign1, sign2;
210 };
211}
212#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS12DLOCALBASIS_HH
A dense n x m matrix.
Definition: fmatrix.hh:68
vector space out of a tensor product of fields.
Definition: fvector.hh:93
Default exception for dummy implementations.
Definition: exceptions.hh:261
First order Raviart-Thomas shape functions on the reference triangle.
Definition: raviartthomas12dlocalbasis.hh:26
unsigned int size() const
number of shape functions
Definition: raviartthomas12dlocalbasis.hh:60
RT12DLocalBasis()
Standard constructor.
Definition: raviartthomas12dlocalbasis.hh:32
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:146
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: raviartthomas12dlocalbasis.hh:99
unsigned int order() const
Polynomial order of the shape functions.
Definition: raviartthomas12dlocalbasis.hh:203
RT12DLocalBasis(unsigned int s)
Make set number s, where 0 <= s < 8.
Definition: raviartthomas12dlocalbasis.hh:42
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: raviartthomas12dlocalbasis.hh:71
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.111.3 (Dec 26, 23:30, 2024)