dune-localfunctions  2.11
enriched/cubeq1bubble/localinterpolation.hh
Go to the documentation of this file.
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 {
32  template<class LB>
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:
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
Definition: bdfmcube.hh:17
static constexpr void interpolate(const F &f, std::vector< C > &out)
Local interpolation of the function f.
Definition: enriched/cubeq1bubble/localinterpolation.hh:52
Interpolation into the CubeQ1BubbleLocalBasis.
Definition: enriched/cubeq1bubble/localinterpolation.hh:33