Dune Core Modules (2.8.0)

monomiallocalinterpolation.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_LOCALFUNCTIONS_MONOMIAL_MONOMIALLOCALINTERPOLATION_HH
4#define DUNE_LOCALFUNCTIONS_MONOMIAL_MONOMIALLOCALINTERPOLATION_HH
5
6#include <vector>
7
10
11#include <dune/geometry/type.hh>
13#include <dune/localfunctions/common/localinterpolation.hh>
14
15namespace Dune
16{
17
18 template<class LB, unsigned int size>
19 class MonomialLocalInterpolation
20 {
21 typedef typename LB::Traits::DomainType D;
22 typedef typename LB::Traits::DomainFieldType DF;
23 static const int dimD=LB::Traits::dimDomain;
24 typedef typename LB::Traits::RangeType R;
25 typedef typename LB::Traits::RangeFieldType RF;
26
27 typedef QuadratureRule<DF,dimD> QR;
28 typedef typename QR::iterator QRiterator;
29
30 public:
31 MonomialLocalInterpolation (const GeometryType &gt_,
32 const LB &lb_)
33 : gt(gt_), lb(lb_), Minv(0)
34 , qr(QuadratureRules<DF,dimD>::rule(gt, 2*lb.order()))
35 {
36 // Compute inverse of the mass matrix of the local basis, and store it in Minv
37 if(size != lb.size())
38 DUNE_THROW(Exception, "size template parameter does not match size of "
39 "local basis");
40
41 const QRiterator qrend = qr.end();
42 for(QRiterator qrit = qr.begin(); qrit != qrend; ++qrit) {
43 std::vector<R> base;
44 lb.evaluateFunction(qrit->position(),base);
45
46 for(unsigned int i = 0; i < size; ++i)
47 for(unsigned int j = 0; j < size; ++j)
48 Minv[i][j] += qrit->weight() * base[i] * base[j];
49 }
50 Minv.invert();
51 }
52
60 template<typename F, typename C>
61 void interpolate (const F& ff, std::vector<C>& out) const
62 {
63 using DomainType = std::decay_t<decltype(qr.begin()->position())>;
64
65 auto&& f = Impl::makeFunctionWithCallOperator<DomainType>(ff);
66
67 out.clear();
68 out.resize(size, 0);
69
70 const QRiterator qrend = qr.end();
71 for(QRiterator qrit = qr.begin(); qrit != qrend; ++qrit) {
72 //TODO: mass matrix
73 R y = f(qrit->position());
74
75 std::vector<R> base;
76 lb.evaluateFunction(qrit->position(),base);
77
78 for(unsigned int i = 0; i < size; ++i)
79 for(unsigned int j = 0; j < size; ++j)
80 out[i] += Minv[i][j] * qrit->weight() * y * base[j];
81 }
82 }
83
84 private:
86 const LB &lb;
87 FieldMatrix<RF, size, size> Minv;
88 const QR &qr;
89 };
90
91}
92
93#endif //DUNE_LOCALFUNCTIONS_MONOMIAL_MONOMIALLOCALINTERPOLATION_HH
std::vector< QuadraturePoint< ct, dim > >::const_iterator iterator
Definition: quadraturerules.hh:183
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
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
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:156
Dune namespace.
Definition: alignedallocator.hh:11
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 22, 23:33, 2024)