DUNE PDELab (2.7)

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