Dune Core Modules (2.8.0)

basis.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_LOCALFUNCTIONS_WHITNEY_EDGES0_5_BASIS_HH
5#define DUNE_LOCALFUNCTIONS_WHITNEY_EDGES0_5_BASIS_HH
6
7#include <cstddef>
8#include <vector>
9
12
13#include <dune/localfunctions/common/localtoglobaladaptors.hh>
14#include <dune/localfunctions/lagrange/lagrangesimplex.hh>
15#include <dune/localfunctions/whitney/edges0.5/common.hh>
16
17namespace Dune {
18
20 //
21 // Basis
22 //
23
25
33 template<class Geometry, class RF>
35 private EdgeS0_5Common<Geometry::mydimension, typename Geometry::ctype>
36 {
37 public:
39 struct Traits {
40 typedef typename Geometry::ctype DomainField;
41 static const std::size_t dimDomainLocal = Geometry::mydimension;
42 static const std::size_t dimDomainGlobal = Geometry::coorddimension;
45
46 typedef RF RangeField;
47 static const std::size_t dimRange = dimDomainLocal;
49
51 };
52
53 private:
54 typedef Dune::Impl::LagrangeSimplexLocalBasis<typename Traits::DomainField,
55 typename Traits::RangeField,
56 Traits::dimDomainLocal,
57 1 // Polynomial order
58 > P1LocalBasis;
60
61 static const P1LocalBasis& p1LocalBasis;
62 static const std::size_t dim = Traits::dimDomainLocal;
63
65 using Base::refelem;
66 using Base::s;
67
68 // global values of the Jacobians (gradients) of the p1 basis
69 std::vector<typename P1Basis::Traits::Jacobian> p1j;
70 // edge sizes and orientations
71 std::vector<typename Traits::DomainField> edgel;
72
73 public:
75
81 template<typename VertexOrder>
82 EdgeS0_5Basis(const Geometry& geo, const VertexOrder& vertexOrder) :
83 p1j(s, typename P1Basis::Traits::Jacobian(0)), edgel(s)
84 {
85 // use some arbitrary position to evaluate jacobians, they are constant
86 static const typename Traits::DomainLocal xl(0);
87
88 // precompute Jacobian (gradients) of the p1 element
89 P1Basis(p1LocalBasis, geo).evaluateJacobian(xl, p1j);
90
91 // calculate edge sizes and orientations
92 for(std::size_t i = 0; i < s; ++i) {
93 edgel[i] = (geo.corner(refelem.subEntity(i,dim-1,0,dim))-
94 geo.corner(refelem.subEntity(i,dim-1,1,dim))
95 ).two_norm();
96 const typename VertexOrder::iterator& edgeVertexOrder =
97 vertexOrder.begin(dim-1, i);
98 if(edgeVertexOrder[0] > edgeVertexOrder[1])
99 edgel[i] *= -1;
100 }
101 }
102
104 std::size_t size () const { return s; }
105
107 void evaluateFunction(const typename Traits::DomainLocal& xl,
108 std::vector<typename Traits::Range>& out) const
109 {
110 out.assign(s, typename Traits::Range(0));
111
112 // compute p1 values -- use the local basis directly for that, local and
113 // global values are identical for scalars
114 std::vector<typename P1LocalBasis::Traits::RangeType> p1v;
115 p1LocalBasis.evaluateFunction(xl, p1v);
116
117 for(std::size_t i = 0; i < s; i++) {
118 const std::size_t i0 = refelem.subEntity(i,dim-1,0,dim);
119 const std::size_t i1 = refelem.subEntity(i,dim-1,1,dim);
120 out[i].axpy( p1v[i0], p1j[i1][0]);
121 out[i].axpy(-p1v[i1], p1j[i0][0]);
122 out[i] *= edgel[i];
123 }
124 }
125
128 std::vector<typename Traits::Jacobian>& out) const
129 {
130 out.resize(s);
131
132 for(std::size_t i = 0; i < s; i++) {
133 const std::size_t i0 = refelem.subEntity(i,dim-1,0,dim);
134 const std::size_t i1 = refelem.subEntity(i,dim-1,1,dim);
135 for(std::size_t j = 0; j < dim; j++)
136 for(std::size_t k = 0; k < dim; k++)
137 out[i][j][k] = edgel[i] *
138 (p1j[i0][0][k]*p1j[i1][0][j]-p1j[i1][0][k]*p1j[i0][0][j]);
139 }
140 }
141
143 void partial (const std::array<unsigned int, dim>& order,
144 const typename Traits::DomainLocal& in, // position
145 std::vector<typename Traits::Range>& out) const // return value
146 {
147 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
148 if (totalOrder == 0) {
149 evaluateFunction(in, out);
150 } else if (totalOrder==1) {
151 auto const k = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
152 out.resize(size());
153
154 for (std::size_t i = 0; i < s; i++)
155 {
156 const std::size_t i0 = refelem.subEntity(i,dim-1,0,dim);
157 const std::size_t i1 = refelem.subEntity(i,dim-1,1,dim);
158 for(std::size_t j = 0; j < dim; j++)
159 out[i][j] = edgel[i] *
160 (p1j[i0][0][k]*p1j[i1][0][j] - p1j[i1][0][k]*p1j[i0][0][j]);
161 }
162 } else {
163 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
164 }
165 }
166
168 std::size_t order () const { return 1; }
169 };
170
171 template<class Geometry, class RF>
172 const typename EdgeS0_5Basis<Geometry, RF>::P1LocalBasis&
173 EdgeS0_5Basis<Geometry, RF>::p1LocalBasis = P1LocalBasis();
174
175} // namespace Dune
176
177#endif // DUNE_LOCALFUNCTIONS_WHITNEY_EDGES0_5_BASIS_HH
Basis for order 0.5 (lowest order) edge elements on simplices.
Definition: basis.hh:36
EdgeS0_5Basis(const Geometry &geo, const VertexOrder &vertexOrder)
Construct an EdgeS0_5Basis.
Definition: basis.hh:82
void evaluateJacobian(const typename Traits::DomainLocal &, std::vector< typename Traits::Jacobian > &out) const
Evaluate all Jacobians.
Definition: basis.hh:127
void evaluateFunction(const typename Traits::DomainLocal &xl, std::vector< typename Traits::Range > &out) const
Evaluate all shape functions.
Definition: basis.hh:107
std::size_t size() const
number of shape functions
Definition: basis.hh:104
void partial(const std::array< unsigned int, dim > &order, const typename Traits::DomainLocal &in, std::vector< typename Traits::Range > &out) const
Evaluate partial derivatives of all shape functions.
Definition: basis.hh:143
std::size_t order() const
Polynomial order of the shape functions.
Definition: basis.hh:168
A dense n x m matrix.
Definition: fmatrix.hh:69
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Wrapper class for geometries.
Definition: geometry.hh:67
@ coorddimension
Definition: geometry.hh:92
GlobalCoordinate corner(int i) const
Obtain a corner of the geometry.
Definition: geometry.hh:156
GridImp::ctype ctype
define type used for coordinates in grid module
Definition: geometry.hh:95
@ mydimension
Definition: geometry.hh:90
Default exception for dummy implementations.
Definition: exceptions.hh:261
Convert a simple scalar local basis into a global basis.
Definition: localtoglobaladaptors.hh:63
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.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:289
Dune namespace.
Definition: alignedallocator.hh:11
export type traits for function signature
Definition: basis.hh:39
Common base class for edge elements.
Definition: common.hh:17
RefElem refelem
The reference element for this edge element.
Definition: common.hh:24
std::size_t s
The number of base functions.
Definition: common.hh:32
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)