Dune Core Modules (2.6.0)

interpolation.hh
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 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 namespace Dune {
13 
16 
22  template<class Backend, class BasisTraits>
24  static_assert(Backend::Traits::dimRange == 1,
25  "PowerInterpolation works only with scalar backends");
26 
27  const Backend *backend;
28 
29  public:
31  typedef BasisTraits Traits;
32 
34 
40  PowerInterpolation(const Backend &backend_) : backend(&backend_) { }
41 
42  private:
43  template<class F>
44  class ComponentEvaluator {
45  const F &f;
46  std::size_t comp;
47 
48  public:
49  ComponentEvaluator(const F &f_, std::size_t comp_) :
50  f(f_), comp(comp_)
51  { }
52 
53  void evaluate(const typename Backend::Traits::DomainLocal &x,
54  typename Backend::Traits::Range &y) const
55  {
56  typename Traits::Range fy;
57  f.evaluate(x, fy);
58  y[0] = fy[comp];
59  }
60  };
61 
62  public:
64 
73  template<typename F, typename C>
74  void interpolate(const F& f, std::vector<C>& out) const {
75  out.clear();
76  std::vector<C> cout;
77  for(std::size_t d = 0; d < Traits::dimRange; ++d) {
78  backend->interpolate(ComponentEvaluator<F>(f, d), cout);
79  if(d == 0)
80  out.resize(cout.size()*Traits::dimRange);
81  // make sure the size of cout does not change surprisingly
82  assert(out.size() == cout.size()*Traits::dimRange);
83  std::copy(cout.begin(), cout.end(), out.begin() + d*cout.size());
84  }
85  }
86  };
87 
88 } // namespace Dune
89 
90 #endif // DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH
Meta-interpolation turning a scalar interpolation into vector-valued interpolation.
Definition: interpolation.hh:23
BasisTraits Traits
Export basis traits.
Definition: interpolation.hh:31
void interpolate(const F &f, std::vector< C > &out) const
Determine coefficients interpolating a given function.
Definition: interpolation.hh:74
PowerInterpolation(const Backend &backend_)
Construct a PowerInterpolation.
Definition: interpolation.hh:40
Dune namespace.
Definition: alignedallocator.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 3, 22:32, 2024)