dune-localfunctions 2.12-git
Loading...
Searching...
No Matches
dualp1localinterpolation.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_DUAL_P1_LOCALINTERPOLATION_HH
6#define DUNE_DUAL_P1_LOCALINTERPOLATION_HH
7
8#include <vector>
9
11
12namespace Dune
13{
17 template<int dim, class LB>
19 {
20 public:
22 template<typename F, typename C>
23 void interpolate (const F& f, std::vector<C>& out) const
24 {
25 typename LB::Traits::DomainType x;
26 // If the dual functions are dual on the faces,
27 // then adjust the interpolation weights
28 const int faceDual(LB::faceDual);
29
30 // compute P1 interpolation coefficients
31 std::vector<C> p1Interpolation(dim+1);
32
33 // vertex 0
34 for (int i=0; i<dim; i++)
35 x[i] = 0;
36 p1Interpolation[0] = Impl::rangeCast(f(x));
37
38 // remaining vertices
39 for (int i=0; i<dim; i++) {
40 for (int j=0; j<dim; j++)
41 x[j] = (i==j);
42
43 p1Interpolation[i+1] = Impl::rangeCast(f(x));
44
45 }
46
47 // compute dual coefficients from the Lagrange ones
48 out.resize(dim+1);
49 for (int i=0; i<dim+1; i++) {
50 out[i] = 2*p1Interpolation[i]/(dim+2-faceDual);
51
52 for (int j=0; j<i; j++)
53 out[i] += p1Interpolation[j]/(dim+2-faceDual);
54
55 for (int j=i+1; j<=dim; j++)
56 out[i] += p1Interpolation[j]/(dim+2-faceDual);
57 }
58 }
59
60 };
61}
62
63#endif
size_type dim() const
Definition dualp1localinterpolation.hh:19
void interpolate(const F &f, std::vector< C > &out) const
Local interpolation of a function.
Definition dualp1localinterpolation.hh:23
T resize(T... args)