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_META_POWER_BASIS_HH
5#define DUNE_LOCALFUNCTIONS_META_POWER_BASIS_HH
6
7#include <numeric>
8#include <cstddef>
9#include <vector>
10
13
14namespace Dune {
15
17
23 template<class Backend, std::size_t dimR>
24 class PowerBasis {
25 static_assert(Backend::Traits::dimRange == 1,
26 "PowerBasis works only with scalar backends");
27
28 // don't use a reference here so this class stays copyable
29 const Backend *backend;
30
31 public:
33 struct Traits : public Backend::Traits
34 {
36 static const std::size_t dimRange = dimR;
39
41
45 typedef FieldMatrix<typename Traits::RangeField, dimR,
46 Traits::dimDomainGlobal> Jacobian;
47 };
48
50
56 PowerBasis(const Backend &backend_) : backend(&backend_) { }
57
59 std::size_t size () const { return backend->size()*dimR; }
61 std::size_t order () const { return backend->order(); }
62
64 void evaluateFunction(const typename Traits::DomainLocal& in,
65 std::vector<typename Traits::Range>& out) const
66 {
67 std::vector<typename Backend::Traits::Range> backendValues;
68 backend->evaluateFunction(in, backendValues);
69 out.assign(size(), typename Traits::Range(0));
70 for(std::size_t d = 0; d < dimR; ++d)
71 for(std::size_t i = 0; i < backend->size(); ++i)
72 out[d*backend->size()+i][d] = backendValues[i][0];
73 }
74
76 void evaluateJacobian(const typename Traits::DomainLocal& in,
77 std::vector<typename Traits::Jacobian>& out) const
78 {
79 std::vector<typename Backend::Traits::Jacobian> backendValues;
80 backend->evaluateJacobian(in, backendValues);
81 out.assign(size(), typename Traits::Jacobian(0));
82 for(std::size_t d = 0; d < dimR; ++d)
83 for(std::size_t i = 0; i < backend->size(); ++i)
84 out[d*backend->size()+i][d] = backendValues[i][0];
85 }
86
88 void partial (const std::array<unsigned int, Backend::Traits::dimDomainGlobal>& order,
89 const typename Traits::DomainLocal& in, // position
90 std::vector<typename Traits::Range>& out) const // return value
91 {
92 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
93 if (totalOrder == 0) {
94 evaluateFunction(in, out);
95 } else {
96 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
97 }
98 }
99 };
100
101} // namespace Dune
102
103#endif // DUNE_LOCALFUNCTIONS_META_POWER_BASIS_HH
A dense n x m matrix.
Definition: fmatrix.hh:69
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Default exception for dummy implementations.
Definition: exceptions.hh:261
Meta-basis turning a scalar basis into vector-valued basis.
Definition: basis.hh:24
PowerBasis(const Backend &backend_)
Construct a PowerBasis.
Definition: basis.hh:56
std::size_t size() const
Number of shape functions.
Definition: basis.hh:59
void partial(const std::array< unsigned int, Backend::Traits::dimDomainGlobal > &order, const typename Traits::DomainLocal &in, std::vector< typename Traits::Range > &out) const
Evaluate partial derivatives of all shape functions.
Definition: basis.hh:88
void evaluateJacobian(const typename Traits::DomainLocal &in, std::vector< typename Traits::Jacobian > &out) const
Evaluate Jacobian of all shape functions at given position.
Definition: basis.hh:76
void evaluateFunction(const typename Traits::DomainLocal &in, std::vector< typename Traits::Range > &out) const
Evaluate all shape functions at given position.
Definition: basis.hh:64
std::size_t order() const
Polynomial order of the shape functions for quadrature.
Definition: basis.hh:61
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
types of domain and range
Definition: basis.hh:34
FieldMatrix< typename Traits::RangeField, dimR, Traits::dimDomainGlobal > Jacobian
Jacobian properties.
Definition: basis.hh:46
FieldVector< typename Traits::RangeField, dimR > Range
Type used for range values.
Definition: basis.hh:38
static const std::size_t dimRange
Dimension of the range values.
Definition: basis.hh:36
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)