dune-localfunctions  2.2.0
meta/power/interpolation.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH
5 #define DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH
6 
7 #include <algorithm>
8 #include <cassert>
9 #include <cstddef>
10 #include <vector>
11 
12 // #include <dune/common/array.hh>
13 // #include <dune/common/geometrytype.hh>
14 #include <dune/common/static_assert.hh>
15 
16 // #include <dune/localfunctions/common/localkey.hh>
17 
18 namespace Dune {
19 
22 
28  template<class Backend, class BasisTraits>
30  dune_static_assert(Backend::Traits::dimRange == 1, "PowerInterpolation "
31  "works only with scalar backends");
32 
33  const Backend *backend;
34 
35  public:
37  typedef BasisTraits Traits;
38 
40 
46  PowerInterpolation(const Backend &backend_) : backend(&backend_) { }
47 
48  private:
49  template<class F>
50  class ComponentEvaluator {
51  const F &f;
52  std::size_t comp;
53 
54  public:
55  ComponentEvaluator(const F &f_, std::size_t comp_) :
56  f(f_), comp(comp_)
57  { }
58 
59  void evaluate(const typename Backend::Traits::DomainLocal &x,
60  typename Backend::Traits::Range &y) const
61  {
62  typename Traits::Range fy;
63  f.evaluate(x, fy);
64  y[0] = fy[comp];
65  }
66  };
67 
68  public:
70 
79  template<typename F, typename C>
80  void interpolate(const F& f, std::vector<C>& out) const {
81  out.clear();
82  std::vector<C> cout;
83  for(std::size_t d = 0; d < Traits::dimRange; ++d) {
84  backend->interpolate(ComponentEvaluator<F>(f, d), cout);
85  if(d == 0)
86  out.resize(cout.size()*Traits::dimRange);
87  // make sure the size of cout does not change surprisingly
88  assert(out.size() == cout.size()*Traits::dimRange);
89  std::copy(cout.begin(), cout.end(), out.begin() + d*cout.size());
90  }
91  }
92  };
93 
94 } // namespace Dune
95 
96 #endif // DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH