Dune Core Modules (2.9.1)

dualq1localinterpolation.hh
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 (C) 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_Q1_LOCALINTERPOLATION_HH
6#define DUNE_DUAL_Q1_LOCALINTERPOLATION_HH
7
8#include <array>
9#include <vector>
10
13#include <dune/localfunctions/common/localinterpolation.hh>
14
15namespace Dune
16{
17
19 template<int dim, class LB>
21 {
22 public:
23
24 void setCoefficients(const std::array<Dune::FieldVector<typename LB::Traits::RangeFieldType, (1<<dim)> ,(1<<dim)>& coefficients)
25 {
26 coefficients_ = coefficients;
27 }
28
29
31 template<typename F, typename C>
32 void interpolate (const F& ff, std::vector<C>& out) const
33 {
34 typename LB::Traits::DomainType x;
35
36 auto&& f = Impl::makeFunctionWithCallOperator<decltype(x)>(ff);
37
38 const int size = 1<<dim;
39
40 // compute Q1 interpolation coefficients
41 Dune::FieldVector<C,size> q1Coefficients;
42
43 for (int i=0; i< (1<<dim); i++) {
44
45 // Generate coordinate of the i-th corner of the reference cube
46 // We could use the ReferenceElement for this as well, but it is
47 // still not clear how dune-localfunctions should have access to them.
48 for (int j=0; j<dim; j++)
49 x[j] = (i & (1<<j)) ? 1.0 : 0.0;
50
51 q1Coefficients[i] = f(x);
52
53 }
54
55 out.resize(size);
56
57 // solve a linear system to compute the dual coefficients
59
60 for (int i=0; i<size; i++)
61 for (int j=0; j<size; j++)
62 mat[i][j] = coefficients_[j][i];
63
64 // now solve for the weights
66
67 mat.solve(sol,q1Coefficients);
68
69 // write result in out vector
70 for (int i=0; i<size; i++)
71 out[i] = sol[i];
72 }
73
74 private:
75 std::array<Dune::FieldVector<typename LB::Traits::RangeFieldType, (1<<dim)> ,(1<<dim)> coefficients_;
76 };
77
78}
79
80#endif
Definition: dualq1localinterpolation.hh:21
void interpolate(const F &ff, std::vector< C > &out) const
Local interpolation of a function.
Definition: dualq1localinterpolation.hh:32
A dense n x m matrix.
Definition: fmatrix.hh:117
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)