dune-localfunctions  2.2.1
brezzidouglasmarini1q2dlocalinterpolation.hh
Go to the documentation of this file.
1 #ifndef DUNE_LOCALFUNCTIONS_BREZZIDOUGLASMARINI1Q2DLOCALINTERPOLATION_HH
2 #define DUNE_LOCALFUNCTIONS_BREZZIDOUGLASMARINI1Q2DLOCALINTERPOLATION_HH
3 
4 #include <vector>
5 
6 #include <dune/geometry/quadraturerules.hh>
7 
8 namespace Dune
9 {
10 
19  template<class LB>
21  {
22 
23 public:
26  {
27  sign0 = sign1 = sign2 = sign3 = 1.0;
28  }
29 
35  BDM1Q2DLocalInterpolation (unsigned int s)
36  {
37  sign0 = sign1 = sign2 = sign3 = 1.0;
38  if (s & 1)
39  {
40  sign0 = -1.0;
41  }
42  if (s & 2)
43  {
44  sign1 = -1.0;
45  }
46  if (s & 4)
47  {
48  sign2 = -1.0;
49  }
50  if (s & 8)
51  {
52  sign3 = -1.0;
53  }
54 
55  n0[0] = -1.0;
56  n0[1] = 0.0;
57  n1[0] = 1.0;
58  n1[1] = 0.0;
59  n2[0] = 0.0;
60  n2[1] = -1.0;
61  n3[0] = 0.0;
62  n3[1] = 1.0;
63  }
64 
73  template<typename F, typename C>
74  void interpolate (const F& f, std::vector<C>& out) const
75  {
76  // f gives v*outer normal at a point on the edge!
77  typedef typename LB::Traits::RangeFieldType Scalar;
78  typedef typename LB::Traits::DomainFieldType Vector;
79  typename F::Traits::RangeType y;
80 
81  out.resize(8);
82  fill(out.begin(), out.end(), 0.0);
83 
84  const int qOrder = 4;
85  const QuadratureRule<Scalar,1>& rule = QuadratureRules<Scalar,1>::rule(GeometryType(GeometryType::cube,1), qOrder);
86 
87  for (typename QuadratureRule<Scalar,1>::const_iterator it = rule.begin();
88  it != rule.end(); ++it)
89  {
90  Scalar qPos = it->position();
91  typename LB::Traits::DomainType localPos;
92 
93  localPos[0] = 0.0;
94  localPos[1] = qPos;
95  f.evaluate(localPos, y);
96  out[0] += (y[0]*n0[0] + y[1]*n0[1])*it->weight()*sign0;
97  out[1] += (y[0]*n0[0] + y[1]*n0[1])*(2.0*qPos - 1.0)*it->weight();
98 
99  localPos[0] = 1.0;
100  localPos[1] = qPos;
101  f.evaluate(localPos, y);
102  out[2] += (y[0]*n1[0] + y[1]*n1[1])*it->weight()*sign1;
103  out[3] += (y[0]*n1[0] + y[1]*n1[1])*(1.0 - 2.0*qPos)*it->weight();
104 
105  localPos[0] = qPos;
106  localPos[1] = 0.0;
107  f.evaluate(localPos, y);
108  out[4] += (y[0]*n2[0] + y[1]*n2[1])*it->weight()*sign2;
109  out[5] += (y[0]*n2[0] + y[1]*n2[1])*(1.0 - 2.0*qPos)*it->weight();
110 
111  localPos[0] = qPos;
112  localPos[1] = 1.0;
113  f.evaluate(localPos, y);
114  out[6] += (y[0]*n3[0] + y[1]*n3[1])*it->weight()*sign3;
115  out[7] += (y[0]*n3[0] + y[1]*n3[1])*(2.0*qPos - 1.0)*it->weight();
116  }
117  }
118 
119 private:
120  typename LB::Traits::RangeFieldType sign0, sign1, sign2, sign3;
121  typename LB::Traits::DomainType n0, n1, n2, n3;
122  };
123 }
124 #endif // DUNE_LOCALFUNCTIONS_BREZZIDOUGLASMARINI1Q2DLOCALINTERPOLATION_HH