DUNE PDELab (git)

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 © 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
14namespace Dune
15{
16
20 template<int dim, class LB>
22 {
23 public:
24
25 void setCoefficients(const std::array<Dune::FieldVector<typename LB::Traits::RangeFieldType, (1<<dim)> ,(1<<dim)>& coefficients)
26 {
27 coefficients_ = coefficients;
28 }
29
30
32 template<typename F, typename C>
33 void interpolate (const F& f, std::vector<C>& out) const
34 {
35 typename LB::Traits::DomainType x;
36
37 const int size = 1<<dim;
38
39 // compute Q1 interpolation coefficients
40 Dune::FieldVector<C,size> q1Coefficients;
41
42 for (int i=0; i< (1<<dim); i++) {
43
44 // Generate coordinate of the i-th corner of the reference cube
45 // We could use the ReferenceElement for this as well, but it is
46 // still not clear how dune-localfunctions should have access to them.
47 for (int j=0; j<dim; j++)
48 x[j] = (i & (1<<j)) ? 1.0 : 0.0;
49
50 q1Coefficients[i] = f(x);
51
52 }
53
54 out.resize(size);
55
56 // solve a linear system to compute the dual coefficients
58
59 for (int i=0; i<size; i++)
60 for (int j=0; j<size; j++)
61 mat[i][j] = coefficients_[j][i];
62
63 // now solve for the weights
65
66 mat.solve(sol,q1Coefficients);
67
68 // write result in out vector
69 for (int i=0; i<size; i++)
70 out[i] = sol[i];
71 }
72
73 private:
74 std::array<Dune::FieldVector<typename LB::Traits::RangeFieldType, (1<<dim)> ,(1<<dim)> coefficients_;
75 };
76
77}
78
79#endif
Definition: dualq1localinterpolation.hh:22
void interpolate(const F &f, std::vector< C > &out) const
Local interpolation of a function.
Definition: dualq1localinterpolation.hh:33
A dense n x m matrix.
Definition: fmatrix.hh:117
vector space out of a tensor product of fields.
Definition: fvector.hh:91
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
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)