Dune Core Modules (2.7.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 #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>
11 #include <dune/localfunctions/common/localinterpolation.hh>
12 
13 namespace 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
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
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: dualq1localinterpolation.hh:19
void interpolate(const F &ff, std::vector< C > &out) const
Local interpolation of a function.
Definition: dualq1localinterpolation.hh:30
A dense n x m matrix.
Definition: fmatrix.hh:69
vector space out of a tensor product of fields.
Definition: fvector.hh:96
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:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)