Dune Core Modules (2.6.0)

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