dune-localfunctions  2.9.0
monomiallocalinterpolation.hh
Go to the documentation of this file.
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 
10 #include <dune/common/fvector.hh>
11 #include <dune/common/fmatrix.hh>
12 
13 #include <dune/geometry/type.hh>
14 #include <dune/geometry/quadraturerules.hh>
16 
17 namespace Dune
18 {
19 
20  template<class LB, unsigned int size>
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:
87  GeometryType gt;
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
Definition: bdfmcube.hh:18
Definition: monomiallocalinterpolation.hh:22
void interpolate(const F &ff, std::vector< C > &out) const
Determine coefficients interpolating a given function.
Definition: monomiallocalinterpolation.hh:63
MonomialLocalInterpolation(const GeometryType &gt_, const LB &lb_)
Definition: monomiallocalinterpolation.hh:33