dune-localfunctions  2.2.1
monomlocalinterpolation.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil -*-
2 #ifndef DUNE_MONOMLOCALINTERPOLATION_HH
3 #define DUNE_MONOMLOCALINTERPOLATION_HH
4 
5 #include <vector>
6 
7 #include <dune/common/deprecated.hh>
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::BasicType &bt_,
48  const LB &lb_) DUNE_DEPRECATED
49  : gt(bt_, dimD), lb(lb_), Minv(0)
50  , qr(QuadratureRules<DF,dimD>::rule(gt, 2*lb.order()))
51  { init(); }
52 
53  MonomLocalInterpolation (const GeometryType &gt_,
54  const LB &lb_)
55  : gt(gt_), lb(lb_), Minv(0)
56  , qr(QuadratureRules<DF,dimD>::rule(gt, 2*lb.order()))
57  { init(); }
58 
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