DUNE PDELab (git)

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>
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;
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
A Simple helper class to organize your test suite.
Definition: testsuite.hh:31
Traits for type conversions and type information.
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
constexpr decltype(auto) elementAt(Container &&c, Index &&i)
Get element at given position from container.
Definition: hybridutilities.hh:126
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)