DUNE PDELab (git)

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 © 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
14namespace Dune {
15
18
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& f, std::vector<C>& out) const {
79 out.clear();
80 std::vector<C> cout;
81 for(std::size_t d = 0; d < Traits::dimRange; ++d) {
82 // When dropping support for `evaluate()` we can simply use a lambda
83 // instead of ComponentEvaluator. But changing this now would break
84 // PowerInterpolation for FE-implementation outside of dune-localfunctions
85 // which may not have been adjusted so far.
86 backend->interpolate(ComponentEvaluator<std::decay_t<decltype(f)>>(f, d), cout);
87 if(d == 0)
88 out.resize(cout.size()*Traits::dimRange);
89 // make sure the size of cout does not change surprisingly
90 assert(out.size() == cout.size()*Traits::dimRange);
91 std::copy(cout.begin(), cout.end(), out.begin() + d*cout.size());
92 }
93 }
94 };
95
96} // namespace Dune
97
98#endif // DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH
Meta-interpolation turning a scalar interpolation into vector-valued interpolation.
Definition: interpolation.hh:26
BasisTraits Traits
Export basis traits.
Definition: interpolation.hh:34
void interpolate(const F &f, std::vector< C > &out) const
Determine coefficients interpolating a given function.
Definition: interpolation.hh:78
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 (Nov 13, 23:29, 2024)