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