DUNE-FUNCTIONS (unstable)

interpolatetest.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// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_INTERPOLATETEST_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_INTERPOLATETEST_HH
9
10#include <tuple>
11#include <utility>
12
13#include <dune/common/test/testsuite.hh>
14#include <dune/common/typetraits.hh>
15#include <dune/common/hybridutilities.hh>
16
17#include <dune/functions/gridfunctions/discreteglobalbasisfunction.hh>
18#include <dune/functions/functionspacebases/interpolate.hh>
19
20
21double infinityDiff(const double& x, const double& y)
22{
23 return std::fabs(x-y);
24}
25
26double infinityDiff(const bool& x, const bool& y)
27{
28 return std::fabs(x-y);
29}
30
31template<class X, class Y>
32double infinityDiff(const X& x, const Y& y)
33{
34 if (x.size() != y.size())
35 return false;
36 double diff = 0;
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));
41 });
42 return diff;
43}
44
45template<class Range, class Basis, class C>
46Dune::TestSuite checkInterpolateConsistency(Basis basis, C&& x)
47{
48 using Coefficients = std::decay_t<C>;
49
50 Dune::TestSuite suite("interpolate consistency check");
51 double coeffTol = 1e-10;
52
53 // generate a discrete function
54 auto fGridFunction = Dune::Functions::makeDiscreteGlobalBasisFunction<Range>(basis, x);
55
56 // Check both functions
57 {
58 const auto& f = fGridFunction;
59 Coefficients y;
60 Dune::Functions::interpolate(basis, y, f);
61
62 suite.check(infinityDiff(x, y) < coeffTol)
63 << "Interpolation of DiscreteGlobalBasisFunction via local operator() differs from original coefficient vector" << std::endl;
64 }
65
66 return suite;
67}
68
69
70
71#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_INTERPOLATETEST_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 14, 22:29, 2024)