Dune Core Modules (2.9.1)

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// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5
6#ifndef DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH
7#define DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH
8
9#include <algorithm>
10#include <cassert>
11#include <cstddef>
12#include <vector>
13#include <dune/localfunctions/common/localinterpolation.hh>
14
15namespace Dune {
16
19
25 template<class Backend, class BasisTraits>
27 static_assert(Backend::Traits::dimRange == 1,
28 "PowerInterpolation works only with scalar backends");
29
30 const Backend *backend;
31
32 public:
34 typedef BasisTraits Traits;
35
37
43 PowerInterpolation(const Backend &backend_) : backend(&backend_) { }
44
45 private:
46 template<class F>
47 class ComponentEvaluator
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 typename Backend::Traits::Range operator()(const typename Backend::Traits::DomainLocal &x) const
58 {
59 typename Traits::Range fy = f(x);
60 typename Backend::Traits::Range y;
61 y[0] = fy[comp];
62 return y;
63 }
64 };
65
66 public:
68
77 template<typename F, typename C>
78 void interpolate(const F& ff, std::vector<C>& out) const {
79
80 auto&& f = Impl::makeFunctionWithCallOperator<typename Backend::Traits::DomainLocal>(ff);
81
82
83 out.clear();
84 std::vector<C> cout;
85 for(std::size_t d = 0; d < Traits::dimRange; ++d) {
86 // When dropping support for `evaluate()` we can simply use a lambda
87 // instead of ComponentEvaluator. But changing this now would break
88 // PowerInterpolation for FE-implementation outside of dune-localfunctions
89 // which may not have been adjusted so far.
90 backend->interpolate(ComponentEvaluator<std::decay_t<decltype(f)>>(f, d), cout);
91 if(d == 0)
92 out.resize(cout.size()*Traits::dimRange);
93 // make sure the size of cout does not change surprisingly
94 assert(out.size() == cout.size()*Traits::dimRange);
95 std::copy(cout.begin(), cout.end(), out.begin() + d*cout.size());
96 }
97 }
98 };
99
100} // namespace Dune
101
102#endif // DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH
Meta-interpolation turning a scalar interpolation into vector-valued interpolation.
Definition: interpolation.hh:26
void interpolate(const F &ff, std::vector< C > &out) const
Determine coefficients interpolating a given function.
Definition: interpolation.hh:78
BasisTraits Traits
Export basis traits.
Definition: interpolation.hh:34
PowerInterpolation(const Backend &backend_)
Construct a PowerInterpolation.
Definition: interpolation.hh:43
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)