dune-localfunctions  2.7.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 #ifndef DUNE_LOCALFUNCTIONS_MONOMIAL_MONOMIALLOCALINTERPOLATION_HH
4 #define DUNE_LOCALFUNCTIONS_MONOMIAL_MONOMIALLOCALINTERPOLATION_HH
5 
6 #include <vector>
7 
8 #include <dune/common/fvector.hh>
9 #include <dune/common/fmatrix.hh>
10 
11 #include <dune/geometry/type.hh>
12 #include <dune/geometry/quadraturerules.hh>
14 
15 namespace Dune
16 {
17 
18  template<class LB, unsigned int size>
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:
85  GeometryType gt;
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
localinterpolation.hh
Dune
Definition: bdfmcube.hh:15
Dune::MonomialLocalInterpolation::MonomialLocalInterpolation
MonomialLocalInterpolation(const GeometryType &gt_, const LB &lb_)
Definition: monomiallocalinterpolation.hh:31
Dune::MonomialLocalInterpolation::interpolate
void interpolate(const F &ff, std::vector< C > &out) const
Determine coefficients interpolating a given function.
Definition: monomiallocalinterpolation.hh:61
Dune::MonomialLocalInterpolation
Definition: monomiallocalinterpolation.hh:19