Dune Core Modules (2.6.0)

q1localbasis.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_Q1_LOCALBASIS_HH
4#define DUNE_Q1_LOCALBASIS_HH
5
6#include <numeric>
7
9
10#include <dune/localfunctions/common/localbasis.hh>
11
12namespace Dune
13{
25 template<class D, class R, int dim>
27 {
28 public:
31
33 unsigned int size () const
34 {
35 return 1<<dim;
36 }
37
39 inline void evaluateFunction (const typename Traits::DomainType& in,
40 std::vector<typename Traits::RangeType>& out) const
41 {
42 out.resize(size());
43
44 for (size_t i=0; i<size(); i++) {
45
46 out[i] = 1;
47
48 for (int j=0; j<dim; j++)
49 // if j-th bit of i is set multiply with in[j], else with 1-in[j]
50 out[i] *= (i & (1<<j)) ? in[j] : 1-in[j];
51
52 }
53
54 }
55
57 inline void
58 evaluateJacobian (const typename Traits::DomainType& in, // position
59 std::vector<typename Traits::JacobianType>& out) const // return value
60 {
61 out.resize(size());
62
63 // Loop over all shape functions
64 for (size_t i=0; i<size(); i++) {
65
66 // Loop over all coordinate directions
67 for (int j=0; j<dim; j++) {
68
69 // Initialize: the overall expression is a product
70 // if j-th bit of i is set to -1, else 1
71 out[i][0][j] = (i & (1<<j)) ? 1 : -1;
72
73 for (int k=0; k<dim; k++) {
74
75 if (j!=k)
76 // if k-th bit of i is set multiply with in[j], else with 1-in[j]
77 out[i][0][j] *= (i & (1<<k)) ? in[k] : 1-in[k];
78
79 }
80
81 }
82
83 }
84
85 }
86
92 void partial(const std::array<unsigned int,dim>& order,
93 const typename Traits::DomainType& in,
94 std::vector<typename Traits::RangeType>& out) const
95 {
96 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
97
98 if (totalOrder == 0) {
99 evaluateFunction(in, out);
100 }
101 else if (totalOrder == 1) {
102 out.resize(size());
103
104 auto direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
105 if (direction >= dim) {
106 DUNE_THROW(RangeError, "Direction of partial derivative not found!");
107 }
108
109 // Loop over all shape functions
110 for (std::size_t i = 0; i < size(); ++i) {
111
112 // Initialize: the overall expression is a product
113 // if j-th bit of i is set to -1, else 1
114 out[i] = (i & (1<<direction)) ? 1 : -1;
115
116 for (int k = 0; k < dim; ++k) {
117 if (direction != k)
118 // if k-th bit of i is set multiply with in[j], else with 1-in[j]
119 out[i] *= (i & (1<<k)) ? in[k] : 1-in[k];
120 }
121
122 }
123 }
124 else
125 {
126 DUNE_THROW(NotImplemented, "To be implemented!");
127 }
128 }
129
131 unsigned int order () const
132 {
133 return 1;
134 }
135 };
136}
137#endif
A dense n x m matrix.
Definition: fmatrix.hh:68
vector space out of a tensor product of fields.
Definition: fvector.hh:93
Default exception for dummy implementations.
Definition: exceptions.hh:261
Lagrange shape functions of order 1 on the reference cube.
Definition: q1localbasis.hh:27
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: q1localbasis.hh:58
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: q1localbasis.hh:39
unsigned int order() const
Polynomial order of the shape functions.
Definition: q1localbasis.hh:131
unsigned int size() const
number of shape functions
Definition: q1localbasis.hh:33
void partial(const std::array< unsigned int, dim > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of any order of all shape functions.
Definition: q1localbasis.hh:92
Default exception class for range errors.
Definition: exceptions.hh:252
Implements a matrix constructed from a given type representing a field and compile-time given number ...
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:331
Dune namespace.
Definition: alignedallocator.hh:10
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:32
D DomainType
domain type
Definition: localbasis.hh:43
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)