DUNE-FEM (unstable)

localbasis.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_ENRICHED_SIMPLEXP1BUBBLE_LOCALBASIS_HH
6#define DUNE_LOCALFUNCTIONS_ENRICHED_SIMPLEXP1BUBBLE_LOCALBASIS_HH
7
8#include <numeric>
9#include <stdexcept>
10#include <vector>
11
14#include <dune/common/math.hh>
15
16#include <dune/localfunctions/common/localbasis.hh>
17
18namespace Dune
19{
33 template<class D, class R, int dim>
35 {
36 template<class> friend class SimplexP1BubbleLocalInterpolation;
37
40
43
46
47 static constexpr int dimension = dim;
48 static constexpr int numVertices = dim+1;
49
50 public:
53
55 static constexpr std::size_t size () noexcept
56 {
57 return numVertices+1;
58 }
59
61 static constexpr void evaluateFunction (const DomainType& in,
62 std::vector<RangeType>& out)
63 {
64 out.resize(size());
65 out[0] = 1;
66 out.back() = power(dim+1, dim+1); // normalization of the bubble function
67 for (int i = 0; i < dim; ++i) {
68 out[0] -= in[i];
69 out[i+1] = in[i];
70 out.back() *= in[i];
71 }
72 out.back() *= out[0];
73 }
74
76 static constexpr void evaluateJacobian (const DomainType& in,
77 std::vector<JacobianType>& out)
78 {
79 out.resize(size());
80 RangeType tmp = 1;
81 for (int i = 0; i < dim; ++i) {
82 out[0][0][i] = -1;
83 for (int j = 0; j < dim; ++j)
84 out[j+1][0][i] = (i == j);
85 tmp -= in[i];
86 }
87
88 for (int i = 0; i < dim; ++i) {
89 out.back()[0][i] = power(dim+1, dim+1) * (tmp - in[i]);
90 for (int j = i+1; j < dim+i; ++j)
91 out.back()[0][i] *= in[j % dim];
92 }
93 }
94
96 static constexpr void partial (const std::array<unsigned int, dim>& order,
97 const DomainType& in,
98 std::vector<RangeType>& out)
99 {
100 unsigned int totalOrder = 0;
101 for (int i = 0; i < dim; ++i)
102 totalOrder += order[i];
103
104 switch (totalOrder) {
105 case 0:
106 evaluateFunction(in,out);
107 break;
108 case 1: {
109 out.resize(size());
110 int d = 0; // the direction of differentiation
111 for (int i = 0; i < dim; ++i)
112 d += i * order[i];
113
114 out[0] = -1;
115 RangeType tmp = 1;
116 for (int j = 0; j < dim; ++j) {
117 out[j+1] = (d == j);
118 tmp -= in[j];
119 }
120 out.back() = power(dim+1, dim+1) * (tmp - in[d]);
121 for (int j = d+1; j < dim+d; ++j)
122 out.back() *= in[j % dim];
123 } break;
124 default:
125 throw std::runtime_error("Desired derivative order is not implemented");
126 }
127 }
128
130 static constexpr unsigned int order () noexcept
131 {
132 return dim+1;
133 }
134 };
135
136} // end namespace Dune
137
138#endif // DUNE_LOCALFUNCTIONS_ENRICHED_SIMPLEXP1BUBBLE_LOCALBASIS_HH
A dense n x m matrix.
Definition: fmatrix.hh:117
vector space out of a tensor product of fields.
Definition: fvector.hh:91
P1 basis in dim-d enriched by an (order dim+1) element bubble function.
Definition: localbasis.hh:35
static constexpr void evaluateJacobian(const DomainType &in, std::vector< JacobianType > &out)
Evaluate Jacobian of all shape functions.
Definition: localbasis.hh:76
static constexpr void evaluateFunction(const DomainType &in, std::vector< RangeType > &out)
Evaluate all shape functions.
Definition: localbasis.hh:61
static constexpr void partial(const std::array< unsigned int, dim > &order, const DomainType &in, std::vector< RangeType > &out)
Evaluate partial derivatives of all shape functions.
Definition: localbasis.hh:96
static constexpr unsigned int order() noexcept
Returns maximal polynomial order of the basis functions.
Definition: localbasis.hh:130
static constexpr std::size_t size() noexcept
Returns number of shape functions.
Definition: localbasis.hh:55
Interpolation into the SimplexP1BubbleLocalBasis.
Definition: localinterpolation.hh:34
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr Base power(Base m, Exponent p)
Power method for integer exponents.
Definition: math.hh:75
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:35
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)