dune-localfunctions  2.3.1-rc1
monomlocalinterpolation.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_MONOMLOCALINTERPOLATION_HH
4 #define DUNE_MONOMLOCALINTERPOLATION_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  void init() {
30  if(size != lb.size())
31  DUNE_THROW(Exception, "size template parameter does not match size of "
32  "local basis");
33 
34  const QRiterator qrend = qr.end();
35  for(QRiterator qrit = qr.begin(); qrit != qrend; ++qrit) {
36  std::vector<R> base;
37  lb.evaluateFunction(qrit->position(),base);
38 
39  for(unsigned int i = 0; i < size; ++i)
40  for(unsigned int j = 0; j < size; ++j)
41  Minv[i][j] += qrit->weight() * base[i] * base[j];
42  }
43  Minv.invert();
44  }
45 
46  public:
47  MonomLocalInterpolation (const GeometryType &gt_,
48  const LB &lb_)
49  : gt(gt_), lb(lb_), Minv(0)
50  , qr(QuadratureRules<DF,dimD>::rule(gt, 2*lb.order()))
51  { init(); }
52 
60  template<typename F, typename C>
61  void interpolate (const F& f, std::vector<C>& out) const
62  {
63  out.clear();
64  out.resize(size, 0);
65 
66  const QRiterator qrend = qr.end();
67  for(QRiterator qrit = qr.begin(); qrit != qrend; ++qrit) {
68  //TODO: mass matrix
69  R y;
70  f.evaluate(qrit->position(),y);
71 
72  std::vector<R> base;
73  lb.evaluateFunction(qrit->position(),base);
74 
75  for(unsigned int i = 0; i < size; ++i)
76  for(unsigned int j = 0; j < size; ++j)
77  out[i] += Minv[i][j] * qrit->weight() * y * base[j];
78  }
79  }
80 
81  private:
82  GeometryType gt;
83  const LB &lb;
84  FieldMatrix<RF, size, size> Minv;
85  const QR &qr;
86  };
87 
88 }
89 
90 #endif //DUNE_MONOMLOCALINTERPOLATION_HH
void interpolate(const F &f, std::vector< C > &out) const
Determine coefficients interpolating a given function.
Definition: monomlocalinterpolation.hh:61
Definition: monomlocalinterpolation.hh:18
MonomLocalInterpolation(const GeometryType &gt_, const LB &lb_)
Definition: monomlocalinterpolation.hh:47