Dune Core Modules (2.6.0)

pk1dlocalbasis.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_Pk1DLOCALBASIS_HH
4#define DUNE_Pk1DLOCALBASIS_HH
5
7
8#include <dune/localfunctions/common/localbasis.hh>
9
10namespace Dune
11{
24 template<class D, class R, unsigned int k>
26 {
27 public:
28
30 enum {N = k+1};
31
33 enum {O = k};
34
35 typedef LocalBasisTraits<D,
36 1,
38 R,
39 1,
42 > Traits;
43
46 {
47 for (unsigned int i=0; i<=k; i++)
48 pos[i] = (1.0*i)/std::max(k,(unsigned int)1);
49 }
50
52 unsigned int size () const
53 {
54 return N;
55 }
56
58 inline void evaluateFunction (const typename Traits::DomainType& x,
59 std::vector<typename Traits::RangeType>& out) const
60 {
61 out.resize(N);
62
63 for (unsigned int i=0; i<N; i++)
64 {
65 out[i] = 1.0;
66 for (unsigned int alpha=0; alpha<i; alpha++)
67 out[i] *= (x[0]-pos[alpha])/(pos[i]-pos[alpha]);
68 for (unsigned int gamma=i+1; gamma<=k; gamma++)
69 out[i] *= (x[0]-pos[gamma])/(pos[i]-pos[gamma]);
70 }
71 }
72
74 inline void
75 evaluateJacobian (const typename Traits::DomainType& x, // position
76 std::vector<typename Traits::JacobianType>& out) const // return value
77 {
78 out.resize(N);
79
80 for (unsigned int i=0; i<=k; i++) {
81
82 // x_0 derivative
83 out[i][0][0] = 0.0;
84 R factor=1.0;
85 for (unsigned int a=0; a<i; a++)
86 {
87 R product=factor;
88 for (unsigned int alpha=0; alpha<i; alpha++)
89 product *= (alpha==a) ? 1.0/(pos[i]-pos[alpha])
90 : (x[0]-pos[alpha])/(pos[i]-pos[alpha]);
91 for (unsigned int gamma=i+1; gamma<=k; gamma++)
92 product *= (pos[gamma]-x[0])/(pos[gamma]-pos[i]);
93 out[i][0][0] += product;
94 }
95 for (unsigned int c=i+1; c<=k; c++)
96 {
97 R product=factor;
98 for (unsigned int alpha=0; alpha<i; alpha++)
99 product *= (x[0]-pos[alpha])/(pos[i]-pos[alpha]);
100 for (unsigned int gamma=i+1; gamma<=k; gamma++)
101 product *= (gamma==c) ? -1.0/(pos[gamma]-pos[i])
102 : (pos[gamma]-x[0])/(pos[gamma]-pos[i]);
103 out[i][0][0] += product;
104 }
105 }
106
107 }
108
114 void partial(const std::array<unsigned int,1>& order,
115 const typename Traits::DomainType& in,
116 std::vector<typename Traits::RangeType>& out) const
117 {
118 switch (order[0])
119 {
120 case 0:
121 evaluateFunction(in,out);
122 break;
123 default:
124 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
125 }
126 }
128 unsigned int order () const
129 {
130 return k;
131 }
132
133 private:
134 R pos[k+1]; // positions on the interval
135 };
136
137}
138#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 arbitrary order on the 1D reference triangle.
Definition: pk1dlocalbasis.hh:26
unsigned int order() const
Polynomial order of the shape functions.
Definition: pk1dlocalbasis.hh:128
unsigned int size() const
number of shape functions
Definition: pk1dlocalbasis.hh:52
void evaluateFunction(const typename Traits::DomainType &x, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: pk1dlocalbasis.hh:58
void partial(const std::array< unsigned int, 1 > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of any order of all shape functions.
Definition: pk1dlocalbasis.hh:114
void evaluateJacobian(const typename Traits::DomainType &x, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: pk1dlocalbasis.hh:75
Pk1DLocalBasis()
Standard constructor.
Definition: pk1dlocalbasis.hh:45
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
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 (Nov 24, 23:30, 2024)