7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_INTERPOLATETEST_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_INTERPOLATETEST_HH
13#include <dune/common/test/testsuite.hh>
14#include <dune/common/typetraits.hh>
15#include <dune/common/hybridutilities.hh>
17#include <dune/functions/gridfunctions/discreteglobalbasisfunction.hh>
18#include <dune/functions/functionspacebases/interpolate.hh>
21double infinityDiff(
const double& x,
const double& y)
23 return std::fabs(x-y);
26double infinityDiff(
const bool& x,
const bool& y)
28 return std::fabs(x-y);
31template<
class X,
class Y>
32double infinityDiff(
const X& x,
const Y& y)
34 if (x.size() != y.size())
37 Dune::Hybrid::forEach(Dune::range(Dune::Hybrid::size(x)), [&](
auto i) {
38 auto&& xi = Dune::Hybrid::elementAt(x, i);
39 auto&& yi = Dune::Hybrid::elementAt(y, i);
40 diff = std::max(diff, infinityDiff(xi, yi));
45template<
class Range,
class Basis,
class C>
46Dune::TestSuite checkInterpolateConsistency(Basis basis, C&& x)
48 using Coefficients = std::decay_t<C>;
50 Dune::TestSuite suite(
"interpolate consistency check");
51 double coeffTol = 1e-10;
54 auto fGridFunction = Dune::Functions::makeDiscreteGlobalBasisFunction<Range>(basis, x);
58 const auto& f = fGridFunction;
60 Dune::Functions::interpolate(basis, y, f);
62 suite.check(infinityDiff(x, y) < coeffTol)
63 <<
"Interpolation of DiscreteGlobalBasisFunction via local operator() differs from original coefficient vector" << std::endl;