Dune Core Modules (2.9.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// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5
6#ifndef DUNE_LOCALFUNCTIONS_META_POWER_BASIS_HH
7#define DUNE_LOCALFUNCTIONS_META_POWER_BASIS_HH
8
9#include <numeric>
10#include <cstddef>
11#include <vector>
12
15
16namespace Dune {
17
19
25 template<class Backend, std::size_t dimR>
26 class PowerBasis {
27 static_assert(Backend::Traits::dimRange == 1,
28 "PowerBasis works only with scalar backends");
29
30 // don't use a reference here so this class stays copyable
31 const Backend *backend;
32
33 public:
35 struct Traits : public Backend::Traits
36 {
38 static const std::size_t dimRange = dimR;
41
43
47 typedef FieldMatrix<typename Traits::RangeField, dimR,
48 Traits::dimDomainGlobal> Jacobian;
49 };
50
52
58 PowerBasis(const Backend &backend_) : backend(&backend_) { }
59
61 std::size_t size () const { return backend->size()*dimR; }
63 std::size_t order () const { return backend->order(); }
64
66 void evaluateFunction(const typename Traits::DomainLocal& in,
67 std::vector<typename Traits::Range>& out) const
68 {
69 std::vector<typename Backend::Traits::Range> backendValues;
70 backend->evaluateFunction(in, backendValues);
71 out.assign(size(), typename Traits::Range(0));
72 for(std::size_t d = 0; d < dimR; ++d)
73 for(std::size_t i = 0; i < backend->size(); ++i)
74 out[d*backend->size()+i][d] = backendValues[i][0];
75 }
76
78 void evaluateJacobian(const typename Traits::DomainLocal& in,
79 std::vector<typename Traits::Jacobian>& out) const
80 {
81 std::vector<typename Backend::Traits::Jacobian> backendValues;
82 backend->evaluateJacobian(in, backendValues);
83 out.assign(size(), typename Traits::Jacobian(0));
84 for(std::size_t d = 0; d < dimR; ++d)
85 for(std::size_t i = 0; i < backend->size(); ++i)
86 out[d*backend->size()+i][d] = backendValues[i][0];
87 }
88
90 void partial (const std::array<unsigned int, Backend::Traits::dimDomainGlobal>& order,
91 const typename Traits::DomainLocal& in, // position
92 std::vector<typename Traits::Range>& out) const // return value
93 {
94 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
95 if (totalOrder == 0) {
96 evaluateFunction(in, out);
97 } else {
98 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
99 }
100 }
101 };
102
103} // namespace Dune
104
105#endif // DUNE_LOCALFUNCTIONS_META_POWER_BASIS_HH
A dense n x m matrix.
Definition: fmatrix.hh:117
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Default exception for dummy implementations.
Definition: exceptions.hh:263
Meta-basis turning a scalar basis into vector-valued basis.
Definition: basis.hh:26
PowerBasis(const Backend &backend_)
Construct a PowerBasis.
Definition: basis.hh:58
std::size_t size() const
Number of shape functions.
Definition: basis.hh:61
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:90
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:78
void evaluateFunction(const typename Traits::DomainLocal &in, std::vector< typename Traits::Range > &out) const
Evaluate all shape functions at given position.
Definition: basis.hh:66
std::size_t order() const
Polynomial order of the shape functions for quadrature.
Definition: basis.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:218
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:291
Dune namespace.
Definition: alignedallocator.hh:13
types of domain and range
Definition: basis.hh:36
FieldMatrix< typename Traits::RangeField, dimR, Traits::dimDomainGlobal > Jacobian
Jacobian properties.
Definition: basis.hh:48
FieldVector< typename Traits::RangeField, dimR > Range
Type used for range values.
Definition: basis.hh:40
static const std::size_t dimRange
Dimension of the range values.
Definition: basis.hh:38
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)