dune-localfunctions 2.12-git
Loading...
Searching...
No Matches
dualq1localinterpolation.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_Q1_LOCALINTERPOLATION_HH
6#define DUNE_DUAL_Q1_LOCALINTERPOLATION_HH
7
8#include <array>
9#include <vector>
10
13
15
16namespace Dune
17{
18
22 template<int dim, class LB>
24 {
25 public:
26
27 void setCoefficients(const std::array<Dune::FieldVector<typename LB::Traits::RangeFieldType, (1<<dim)> ,(1<<dim)>& coefficients)
28 {
29 coefficients_ = coefficients;
30 }
31
32
34 template<typename F, typename C>
35 void interpolate (const F& f, std::vector<C>& out) const
36 {
37 typename LB::Traits::DomainType x;
38
39 const int size = 1<<dim;
40
41 // compute Q1 interpolation coefficients
42 Dune::FieldVector<C,size> q1Coefficients;
43
44 for (int i=0; i< (1<<dim); i++) {
45
46 // Generate coordinate of the i-th corner of the reference cube
47 // We could use the ReferenceElement for this as well, but it is
48 // still not clear how dune-localfunctions should have access to them.
49 for (int j=0; j<dim; j++)
50 x[j] = (i & (1<<j)) ? 1.0 : 0.0;
51
52 q1Coefficients[i] = Impl::rangeCast(f(x));
53
54 }
55
56 out.resize(size);
57
58 // solve a linear system to compute the dual coefficients
60
61 for (int i=0; i<size; i++)
62 for (int j=0; j<size; j++)
63 mat[i][j] = coefficients_[j][i];
64
65 // now solve for the weights
67
68 mat.solve(sol,q1Coefficients);
69
70 // write result in out vector
71 for (int i=0; i<size; i++)
72 out[i] = sol[i];
73 }
74
75 private:
76 std::array<Dune::FieldVector<typename LB::Traits::RangeFieldType, (1<<dim)> ,(1<<dim)> coefficients_;
77 };
78
79}
80
81#endif
int size() const
size_type dim() const
void solve(V1 &x, const V2 &b, bool doPivoting=true) const
Definition dualq1localinterpolation.hh:24
void setCoefficients(const std::array< Dune::FieldVector< typename LB::Traits::RangeFieldType,(1<< dim)>,(1<< dim)> &coefficients)
Definition dualq1localinterpolation.hh:27
void interpolate(const F &f, std::vector< C > &out) const
Local interpolation of a function.
Definition dualq1localinterpolation.hh:35
T resize(T... args)