Dune Core Modules (2.9.1)

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