5#ifndef DUNE_LOCALFUNCTIONS_ENRICHED_CUBEQ1BUBBLE_LOCALBASIS_HH
6#define DUNE_LOCALFUNCTIONS_ENRICHED_CUBEQ1BUBBLE_LOCALBASIS_HH
12#include <dune/common/fvector.hh>
13#include <dune/common/fmatrix.hh>
14#include <dune/common/math.hh>
34 template<
class D,
class R,
int dim>
40 using DomainType = FieldVector<D,dim>;
43 using RangeType = FieldVector<R,1>;
46 using JacobianType = FieldMatrix<R,1,dim>;
48 static constexpr int dimension = dim;
49 static constexpr int numVertices = power(2, dim);
52 static constexpr int scaling = power(2, 2*dim);
59 static constexpr std::size_t
size () noexcept
65 static constexpr void evaluateFunction (
const DomainType& x, std::vector<RangeType>& out)
69 for (
int i = 0; i < numVertices; ++i) {
71 for (
int j = 0; j < dimension; ++j) {
73 out[i] *= (i & (1<<j)) ? x[j] : 1-x[j];
78 for (
int j = 0; j < dimension; ++j) {
79 out.back() *= (1-x[j]) * x[j];
84 static constexpr void evaluateJacobian (
const DomainType& x, std::vector<JacobianType>& out)
89 for (
int i = 0; i < numVertices; ++i) {
91 for (
int j = 0; j < dimension; ++j) {
94 out[i][0][j] = (i & (1<<j)) ? 1 : -1;
96 for (
int k = 0; k < dimension; ++k) {
99 out[i][0][j] *= (i & (1<<k)) ? x[k] : 1-x[k];
104 for (
int j = 0; j < dimension; ++j) {
105 out.back()[0][j] = scaling;
106 for (
int k = 0; k < dimension; ++k)
107 out.back()[0][j] *= (j == k) ? (1-2*x[k]) : (1-x[k])*x[k];
112 static constexpr void partial (
const std::array<unsigned int, dim>&
order,
114 std::vector<RangeType>& out)
116 unsigned int totalOrder = 0;
117 for (
int i = 0; i < dimension; ++i)
118 totalOrder +=
order[i];
120 switch (totalOrder) {
127 for (
int i = 0; i < dimension; ++i)
131 throw std::invalid_argument(
"Direction of partial derivative not found!");
134 for (
int i = 0; i < numVertices; ++i) {
137 out[i] = (i & (1<<d)) ? 1 : -1;
139 for (
int j = 0; j < dimension; ++j) {
142 out[i] *= (i & (1<<j)) ? x[j] : 1-x[j];
146 out.back() = scaling;
147 for (
int k = 0; k < dimension; ++k)
148 out.back() *= (d == k) ? (1-2*x[k]) : (1-x[k])*x[k];
152 throw std::runtime_error(
"Desired derivative order is not implemented");
157 static constexpr unsigned int order () noexcept
Definition bdfmcube.hh:18
Type traits for LocalBasisVirtualInterface.
Definition common/localbasis.hh:35
Q1 basis in dim-d enriched by an (order 2) element bubble function.
Definition enriched/cubeq1bubble/localbasis.hh:36
static constexpr std::size_t size() noexcept
Returns number of shape functions.
Definition enriched/cubeq1bubble/localbasis.hh:59
static constexpr void partial(const std::array< unsigned int, dim > &order, const DomainType &x, std::vector< RangeType > &out)
Evaluate partial derivatives of all shape functions.
Definition enriched/cubeq1bubble/localbasis.hh:112
friend class CubeQ1BubbleLocalInterpolation
Definition enriched/cubeq1bubble/localbasis.hh:37
static constexpr unsigned int order() noexcept
Returns maximal polynomial order of the basis functions.
Definition enriched/cubeq1bubble/localbasis.hh:157
static constexpr void evaluateJacobian(const DomainType &x, std::vector< JacobianType > &out)
Evaluate Jacobian of all shape functions.
Definition enriched/cubeq1bubble/localbasis.hh:84
LocalBasisTraits< D, dim, DomainType, R, 1, RangeType, JacobianType > Traits
Type traits for function signature.
Definition enriched/cubeq1bubble/localbasis.hh:56
static constexpr void evaluateFunction(const DomainType &x, std::vector< RangeType > &out)
Evaluate all shape functions.
Definition enriched/cubeq1bubble/localbasis.hh:65