Debian Codegraph @

dune/localfunctions/enriched/cubeq1bubble/localinterpolation.hh

raw
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 #ifndef DUNE_LOCALFUNCTIONS_ENRICHED_CUBEQ1BUBBLE_LOCALINTERPOLATION_HH
6 #define DUNE_LOCALFUNCTIONS_ENRICHED_CUBEQ1BUBBLE_LOCALINTERPOLATION_HH
7
8 #include <type_traits>
9 #include <vector>
10
11 namespace Dune
12 {
13 /**
14 * \ingroup LocalFunctionsImpl
15 * \brief Interpolation into the CubeQ1BubbleLocalBasis
16 *
17 * The coefficients `f_i` associated to the vertex DOFs are computed
18 * by evaluation of the function `f` to interpolate in the vertex
19 * positions `x_i`. The coefficient associated to the bubble function,
20 * `f_b`, is obtains by evaluation `f` in the barycenter `x_b` of the
21 * element minus the linear contributions in that point:
22 *
23 * \f[
24 * f_i = f(x_i), i=0,\ldots,dim+1
25 * f_b = f(x_b) - \sum_{i=0}^{dim+1} f_i * \phi_i(x_b),
26 * \f]
27 *
28 * with \f(\phi_i\f) the local basis functions.
29 *
30 * \nosubgrouping
31 **/
32 template<class LB>
33 class CubeQ1BubbleLocalInterpolation
34 {
35 static const int dim = LB::dimension;
36 static const int numVertices = power(2, dim);
37
38 using DomainType = typename LB::Traits::DomainType;
39 using RangeType = typename LB::Traits::RangeType;
40
41 public:
42 /**
43 * \brief Local interpolation of the function `f`.
44 * \param[in] f A callable `f:D -> R` with domain `D=DomainType` and range
45 * `R` convertible into the coefficient type `C`.
46 * \param[out] out The interpolation coefficients `{f_i...,f_b}` are stored
47 * in this output vector.
48 **/
49 template<class F, class C,
50 class R = std::invoke_result_t<F, DomainType>,
51 std::enable_if_t<std::is_convertible_v<R, C>, int> = 0>
52 static constexpr void interpolate (const F& f, std::vector<C>& out)
53 {
54 out.resize(numVertices+1);
55
56 // vertices
57 DomainType x(0);
58 for (int i = 0; i < numVertices; ++i)
59 {
60 // Generate coordinate of the i-th corner of the reference cube
61 for (int j = 0; j < dim; ++j)
62 x[j] = (i & (1<<j)) ? 1 : 0;
63
64 out[i] = f(x);
65 }
66
67 // element bubble
68 x = 0.5;
69 R y = f(x);
70
71 // evaluate the other shape functions in x and subtract this value
72 std::vector<RangeType> sfValues;
73 LB::evaluateFunction(x, sfValues);
74
75 out[numVertices] = y;
76 for (int i = 0; i < numVertices; ++i)
77 out[numVertices] -= out[i]*sfValues[i];
78 }
79 };
80
81 } // end namespace Dune
82
83 #endif // DUNE_LOCALFUNCTIONS_ENRICHED_CUBEQ1BUBBLE_LOCALINTERPOLATION_HH