dune-localfunctions  2.5.1
interpolationhelper.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 GENERIC_INTERPOLATIONHELPER_HH
4 #define GENERIC_INTERPOLATIONHELPER_HH
5 
6 #include <vector>
7 
8 #include <dune/common/fvector.hh>
10 
11 namespace Dune
12 {
13  // A small helper class to avoid having to
14  // write the interpolation twice (once for function
15  // and once for a basis)
16  template< class F, unsigned int dimension >
18  {
19  template <class Func,class Container, bool type>
20  struct Helper;
21  };
22  template <class F,unsigned int d>
23  template <class Func,class Vector>
24  struct InterpolationHelper<F,d>::Helper<Func,Vector,true>
25  // Func is of Function type
26  {
27  typedef std::vector< Dune::FieldVector<F,d> > Result;
28  Helper(const Func & func, Vector &vec)
29  : func_(func),
30  vec_(vec),
31  tmp_(1)
32  {}
33  const typename Vector::value_type &operator()(unsigned int row,unsigned int col)
34  {
35  return vec_[row];
36  }
37  template <class Fy>
38  void set(unsigned int row,unsigned int col,
39  const Fy &val)
40  {
41  assert(col==0);
42  assert(row<vec_.size());
43  field_cast( val, vec_[row] );
44  }
45  template <class Fy>
46  void add(unsigned int row,unsigned int col,
47  const Fy &val)
48  {
49  assert(col==0);
50  assert(row<vec_.size());
51  vec_[row] += field_cast<typename Vector::value_type>(val);
52  }
53  template <class DomainVector>
54  const Result &evaluate(const DomainVector &x) const
55  {
56  typename Func::DomainType xx ;
57  typename Func::RangeType ff ;
58  field_cast(x,xx);
59  func_.evaluate(xx,ff);
60  field_cast(ff, tmp_[0] );
61  return tmp_;
62  }
63  unsigned int size() const
64  {
65  return 1;
66  }
67  const Func &func_;
68  Vector &vec_;
69  mutable Result tmp_;
70  };
71  template <class F,unsigned int d>
72  template <class Basis,class Matrix>
73  struct InterpolationHelper<F,d>::Helper<Basis,Matrix,false>
74  // Func is of Basis type
75  {
76  typedef std::vector< Dune::FieldVector<F,d> > Result;
77  Helper(const Basis & basis, Matrix &matrix)
78  : basis_(basis),
79  matrix_(matrix),
80  tmp_(basis.size()) {}
81  const F &operator()(unsigned int row,unsigned int col) const
82  {
83  return matrix_(row,col);
84  }
85  F &operator()(unsigned int row,unsigned int col)
86  {
87  return matrix_(row,col);
88  }
89  template <class Fy>
90  void set(unsigned int row,unsigned int col,
91  const Fy &val)
92  {
93  assert(col<matrix_.cols());
94  assert(row<matrix_.rows());
95  field_cast(val,matrix_(row,col));
96  }
97  template <class Fy>
98  void add(unsigned int row,unsigned int col,
99  const Fy &val)
100  {
101  assert(col<matrix_.cols());
102  assert(row<matrix_.rows());
103  matrix_(row,col) += val;
104  }
105  template <class DomainVector>
106  const Result &evaluate(const DomainVector &x) const
107  {
108  basis_.template evaluate<0>(x,tmp_);
109  return tmp_;
110  }
111  unsigned int size() const
112  {
113  return basis_.size();
114  }
115 
116  const Basis &basis_;
117  Matrix &matrix_;
118  mutable Result tmp_;
119  };
120 }
121 #endif // GENERIC_INTERPOLATIONHELPER_HH
Result tmp_
Definition: interpolationhelper.hh:69
unsigned int size() const
Definition: interpolationhelper.hh:63
Result tmp_
Definition: interpolationhelper.hh:118
const F & operator()(unsigned int row, unsigned int col) const
Definition: interpolationhelper.hh:81
Matrix & matrix_
Definition: interpolationhelper.hh:117
Definition: brezzidouglasmarini1cube2dlocalbasis.hh:15
Definition: interpolationhelper.hh:17
const Result & evaluate(const DomainVector &x) const
Definition: interpolationhelper.hh:54
std::vector< Dune::FieldVector< F, d > > Result
Definition: interpolationhelper.hh:27
Vector & vec_
Definition: interpolationhelper.hh:68
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:157
const Vector::value_type & operator()(unsigned int row, unsigned int col)
Definition: interpolationhelper.hh:33
unsigned int size() const
Definition: interpolationhelper.hh:111
Definition: interpolationhelper.hh:20
const Func & func_
Definition: interpolationhelper.hh:67
std::vector< Dune::FieldVector< F, d > > Result
Definition: interpolationhelper.hh:76
void add(unsigned int row, unsigned int col, const Fy &val)
Definition: interpolationhelper.hh:98
Helper(const Func &func, Vector &vec)
Definition: interpolationhelper.hh:28
void add(unsigned int row, unsigned int col, const Fy &val)
Definition: interpolationhelper.hh:46
const Basis & basis_
Definition: interpolationhelper.hh:116
F & operator()(unsigned int row, unsigned int col)
Definition: interpolationhelper.hh:85
const Result & evaluate(const DomainVector &x) const
Definition: interpolationhelper.hh:106
Helper(const Basis &basis, Matrix &matrix)
Definition: interpolationhelper.hh:77