DUNE PDELab (git)

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 © 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
16namespace Dune
17{
18
22 template<class LB, unsigned int size>
23 class MonomialLocalInterpolation
24 {
25 typedef typename LB::Traits::DomainType D;
26 typedef typename LB::Traits::DomainFieldType DF;
27 static const int dimD=LB::Traits::dimDomain;
28 typedef typename LB::Traits::RangeType R;
29 typedef typename LB::Traits::RangeFieldType RF;
30
31 typedef QuadratureRule<DF,dimD> QR;
32 typedef typename QR::iterator QRiterator;
33
34 public:
35 MonomialLocalInterpolation (const GeometryType &gt_,
36 const LB &lb_)
37 : gt(gt_), lb(lb_), Minv(0)
38 , qr(QuadratureRules<DF,dimD>::rule(gt, 2*lb.order()))
39 {
40 // Compute inverse of the mass matrix of the local basis, and store it in Minv
41 if(size != lb.size())
42 DUNE_THROW(Exception, "size template parameter does not match size of "
43 "local basis");
44
45 const QRiterator qrend = qr.end();
46 for(QRiterator qrit = qr.begin(); qrit != qrend; ++qrit) {
47 std::vector<R> base;
48 lb.evaluateFunction(qrit->position(),base);
49
50 for(unsigned int i = 0; i < size; ++i)
51 for(unsigned int j = 0; j < size; ++j)
52 Minv[i][j] += qrit->weight() * base[i] * base[j];
53 }
54 Minv.invert();
55 }
56
64 template<typename F, typename C>
65 void interpolate (const F& f, std::vector<C>& out) const
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:245
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
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
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 24, 23:30, 2024)