Dune Core Modules (2.8.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#include <dune/localfunctions/common/localinterpolation.hh>
12
13namespace Dune {
14
17
23 template<class Backend, class BasisTraits>
25 static_assert(Backend::Traits::dimRange == 1,
26 "PowerInterpolation works only with scalar backends");
27
28 const Backend *backend;
29
30 public:
32 typedef BasisTraits Traits;
33
35
41 PowerInterpolation(const Backend &backend_) : backend(&backend_) { }
42
43 private:
44 template<class F>
45 class ComponentEvaluator
46 {
47 const F &f;
48 std::size_t comp;
49
50 public:
51 ComponentEvaluator(const F &f_, std::size_t comp_) :
52 f(f_), comp(comp_)
53 { }
54
55 typename Backend::Traits::Range operator()(const typename Backend::Traits::DomainLocal &x) const
56 {
57 typename Traits::Range fy = f(x);
58 typename Backend::Traits::Range y;
59 y[0] = fy[comp];
60 return y;
61 }
62 };
63
64 public:
66
75 template<typename F, typename C>
76 void interpolate(const F& ff, std::vector<C>& out) const {
77
78 auto&& f = Impl::makeFunctionWithCallOperator<typename Backend::Traits::DomainLocal>(ff);
79
80
81 out.clear();
82 std::vector<C> cout;
83 for(std::size_t d = 0; d < Traits::dimRange; ++d) {
84 // When dropping support for `evaluate()` we can simply use a lambda
85 // instead of ComponentEvaluator. But changing this now would break
86 // PowerInterpolation for FE-implementation outside of dune-localfunctions
87 // which may not have been adjusted so far.
88 backend->interpolate(ComponentEvaluator<std::decay_t<decltype(f)>>(f, d), cout);
89 if(d == 0)
90 out.resize(cout.size()*Traits::dimRange);
91 // make sure the size of cout does not change surprisingly
92 assert(out.size() == cout.size()*Traits::dimRange);
93 std::copy(cout.begin(), cout.end(), out.begin() + d*cout.size());
94 }
95 }
96 };
97
98} // namespace Dune
99
100#endif // DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH
Meta-interpolation turning a scalar interpolation into vector-valued interpolation.
Definition: interpolation.hh:24
void interpolate(const F &ff, std::vector< C > &out) const
Determine coefficients interpolating a given function.
Definition: interpolation.hh:76
BasisTraits Traits
Export basis traits.
Definition: interpolation.hh:32
PowerInterpolation(const Backend &backend_)
Construct a PowerInterpolation.
Definition: interpolation.hh:41
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)