Dune Core Modules (2.8.0)

crouzeixraviart.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_CROUZEIXRAVIART_HH
4#define DUNE_LOCALFUNCTIONS_CROUZEIXRAVIART_HH
5
6#include <array>
7#include <numeric>
8
11
12#include <dune/geometry/type.hh>
13#include <dune/geometry/referenceelements.hh>
14
15#include <dune/localfunctions/common/localbasis.hh>
16#include <dune/localfunctions/common/localfiniteelementtraits.hh>
17#include <dune/localfunctions/common/localinterpolation.hh>
18#include <dune/localfunctions/common/localkey.hh>
19
20namespace Dune { namespace Impl
21{
28 template<class D, class R, unsigned int dim>
29 class CrouzeixRaviartLocalBasis
30 {
31 public:
32 using Traits = LocalBasisTraits<D,dim,FieldVector<D,dim>,R,1,FieldVector<R,1>,FieldMatrix<R,1,dim> >;
33
36 static constexpr unsigned int size ()
37 {
38 return dim+1;
39 }
40
42 void evaluateFunction(const typename Traits::DomainType& x,
43 std::vector<typename Traits::RangeType>& out) const
44 {
45 out.resize(size());
46
47 std::fill(out.begin(), out.end()-1, 1.0);
48 out.back() = 1.0-dim;
49
50 for (unsigned int i=0; i<dim; i++)
51 {
52 out[i] -= dim * x[dim-i-1];
53 out.back() += dim*x[i];
54 }
55 }
56
62 void evaluateJacobian(const typename Traits::DomainType& x,
63 std::vector<typename Traits::JacobianType>& out) const
64 {
65 out.resize(size());
66
67 for (unsigned i=0; i<dim; i++)
68 for (unsigned j=0; j<dim; j++)
69 out[i][0][j] = (i==(dim-1-j)) ? -(double)dim : 0;
70
71 std::fill(out.back()[0].begin(), out.back()[0].end(), dim);
72 }
73
80 void partial(const std::array<unsigned int,dim>& order,
81 const typename Traits::DomainType& in,
82 std::vector<typename Traits::RangeType>& out) const
83 {
84 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
85
86 out.resize(size());
87
88 if (totalOrder == 0) {
89 evaluateFunction(in, out);
90 return;
91 }
92
93 if (totalOrder==1)
94 {
95 auto direction = std::find(order.begin(), order.end(), 1)-order.begin();
96
97 for (unsigned int i=0; i<dim; i++)
98 out[i] = (i==(dim-1-direction)) ? -(double)dim : 0.0;
99
100 out.back()[0] = dim;
101 }
102 else // all higher order derivatives are zero
103 std::fill(out.begin(), out.end(), 0);
104 }
105
107 static constexpr unsigned int order ()
108 {
109 return 1;
110 }
111 };
112
117 template<unsigned int dim>
118 class CrouzeixRaviartLocalCoefficients
119 {
120 public:
122 CrouzeixRaviartLocalCoefficients ()
123 : localKeys_(size())
124 {
125 for (std::size_t i=0; i<size(); i++)
126 localKeys_[i] = LocalKey(i,dim-1,0);
127 }
128
130 static constexpr std::size_t size ()
131 {
132 return dim+1;
133 }
134
136 const LocalKey& localKey (std::size_t i) const
137 {
138 return localKeys_[i];
139 }
140
141 private:
142 std::vector<LocalKey> localKeys_;
143 };
144
149 template<class LocalBasis>
150 class CrouzeixRaviartLocalInterpolation
151 {
152 public:
153
161 template<typename F, typename C>
162 void interpolate (const F& ff, std::vector<C>& out) const
163 {
164 constexpr auto dim = LocalBasis::Traits::dimDomain;
165
166 auto&& f = Impl::makeFunctionWithCallOperator<typename LocalBasis::Traits::DomainType>(ff);
167
168 out.resize(LocalBasis::size());
169
170 // Evaluate at the facet midpoints
172 for (int i=0; i<refSimplex.size(1); i++)
173 out[i] = f(refSimplex.template geometry<1>(i).center());
174 }
175 };
176
177} } // namespace Dune::Impl
178
179namespace Dune
180{
187 template<class D, class R, int dim>
189 {
190 public:
194 Impl::CrouzeixRaviartLocalCoefficients<dim>,
195 Impl::CrouzeixRaviartLocalInterpolation<Impl::CrouzeixRaviartLocalBasis<D,R,dim> > >;
196
199 const typename Traits::LocalBasisType& localBasis() const
200 {
201 return basis_;
202 }
203
207 {
208 return coefficients_;
209 }
210
214 {
215 return interpolation_;
216 }
217
219 static constexpr std::size_t size()
220 {
221 return dim+1;
222 }
223
226 static constexpr GeometryType type()
227 {
228 return GeometryTypes::simplex(dim);
229 }
230
231 private:
232 Impl::CrouzeixRaviartLocalBasis<D,R,dim> basis_;
233 Impl::CrouzeixRaviartLocalCoefficients<dim> coefficients_;
234 Impl::CrouzeixRaviartLocalInterpolation<Impl::CrouzeixRaviartLocalBasis<D,R,dim> > interpolation_;
235 };
236
237} // namespace Dune
238
239#endif // DUNE_LOCALFUNCTIONS_CROUZEIXRAVIART_HH
Crouzeix-Raviart finite element.
Definition: crouzeixraviart.hh:189
static constexpr GeometryType type()
The reference element that the local finite element is defined on.
Definition: crouzeixraviart.hh:226
const Traits::LocalCoefficientsType & localCoefficients() const
Returns the assignment of the degrees of freedom to the element subentities.
Definition: crouzeixraviart.hh:206
const Traits::LocalInterpolationType & localInterpolation() const
Returns object that evaluates degrees of freedom.
Definition: crouzeixraviart.hh:213
const Traits::LocalBasisType & localBasis() const
Returns the local basis, i.e., the set of shape functions.
Definition: crouzeixraviart.hh:199
static constexpr std::size_t size()
The number of shape functions.
Definition: crouzeixraviart.hh:219
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
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.
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:461
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:289
Dune namespace.
Definition: alignedallocator.hh:11
static const ReferenceElement & simplex()
get simplex reference elements
Definition: referenceelements.hh:202
D DomainType
domain type
Definition: localbasis.hh:43
traits helper struct
Definition: localfiniteelementtraits.hh:11
LB LocalBasisType
Definition: localfiniteelementtraits.hh:14
LC LocalCoefficientsType
Definition: localfiniteelementtraits.hh:18
LI LocalInterpolationType
Definition: localfiniteelementtraits.hh:22
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)