dune-localfunctions  2.4
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>
13 
14 namespace Dune
15 {
16 
17  template<class LB, unsigned int size>
19  {
20  typedef typename LB::Traits::DomainType D;
21  typedef typename LB::Traits::DomainFieldType DF;
22  static const int dimD=LB::Traits::dimDomain;
23  typedef typename LB::Traits::RangeType R;
24  typedef typename LB::Traits::RangeFieldType RF;
25 
26  typedef QuadratureRule<DF,dimD> QR;
27  typedef typename QR::iterator QRiterator;
28 
29  public:
30  MonomialLocalInterpolation (const GeometryType &gt_,
31  const LB &lb_)
32  : gt(gt_), lb(lb_), Minv(0)
33  , qr(QuadratureRules<DF,dimD>::rule(gt, 2*lb.order()))
34  {
35  // Compute inverse of the mass matrix of the local basis, and store it in Minv
36  if(size != lb.size())
37  DUNE_THROW(Exception, "size template parameter does not match size of "
38  "local basis");
39 
40  const QRiterator qrend = qr.end();
41  for(QRiterator qrit = qr.begin(); qrit != qrend; ++qrit) {
42  std::vector<R> base;
43  lb.evaluateFunction(qrit->position(),base);
44 
45  for(unsigned int i = 0; i < size; ++i)
46  for(unsigned int j = 0; j < size; ++j)
47  Minv[i][j] += qrit->weight() * base[i] * base[j];
48  }
49  Minv.invert();
50  }
51 
59  template<typename F, typename C>
60  void interpolate (const F& f, std::vector<C>& out) const
61  {
62  out.clear();
63  out.resize(size, 0);
64 
65  const QRiterator qrend = qr.end();
66  for(QRiterator qrit = qr.begin(); qrit != qrend; ++qrit) {
67  //TODO: mass matrix
68  R y;
69  f.evaluate(qrit->position(),y);
70 
71  std::vector<R> base;
72  lb.evaluateFunction(qrit->position(),base);
73 
74  for(unsigned int i = 0; i < size; ++i)
75  for(unsigned int j = 0; j < size; ++j)
76  out[i] += Minv[i][j] * qrit->weight() * y * base[j];
77  }
78  }
79 
80  private:
81  GeometryType gt;
82  const LB &lb;
83  FieldMatrix<RF, size, size> Minv;
84  const QR &qr;
85  };
86 
87 }
88 
89 #endif //DUNE_LOCALFUNCTIONS_MONOMIAL_MONOMIALLOCALINTERPOLATION_HH
MonomialLocalInterpolation(const GeometryType &gt_, const LB &lb_)
Definition: monomiallocalinterpolation.hh:30
Definition: brezzidouglasmarini1cube2dlocalbasis.hh:14
Definition: monomiallocalinterpolation.hh:18
void interpolate(const F &f, std::vector< C > &out) const
Determine coefficients interpolating a given function.
Definition: monomiallocalinterpolation.hh:60