DUNE PDELab (2.7)

interpolationhelper.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 GENERIC_INTERPOLATIONHELPER_HH
4#define GENERIC_INTERPOLATIONHELPER_HH
5
6#include <vector>
7
10#include <dune/localfunctions/utility/field.hh>
11#include <dune/localfunctions/common/localinterpolation.hh>
12
13namespace Dune
14{
15 // A small helper class to avoid having to
16 // write the interpolation twice (once for function
17 // and once for a basis)
18 template< class F, unsigned int dimension >
19 struct InterpolationHelper
20 {
21 template <class Func,class Container, bool type>
22 struct Helper;
23 };
24 template <class F,unsigned int d>
25 template <class Func,class Vector>
26 struct InterpolationHelper<F,d>::Helper<Func,Vector,true>
27 // Func is of Function type
28 {
29 typedef std::vector< Dune::FieldVector<F,d> > Result;
30 Helper(const Func & func, Vector &vec)
31 : func_(func),
32 vec_(vec),
33 tmp_(1)
34 {}
35 const typename Vector::value_type &operator()(unsigned int row,unsigned int col)
36 {
37 return vec_[row];
38 }
39 template <class Fy>
40 void set(unsigned int row,unsigned int col,
41 const Fy &val)
42 {
43 assert(col==0);
44 assert(row<vec_.size());
45 field_cast( val, vec_[row] );
46 }
47 template <class Fy>
48 void add(unsigned int row,unsigned int col,
49 const Fy &val)
50 {
51 assert(col==0);
52 assert(row<vec_.size());
53 vec_[row] += field_cast<typename Vector::value_type>(val);
54 }
55 template <class DomainVector,
56 std::enable_if_t<models<Impl::FunctionWithCallOperator<DomainVector>, Func>(), int> = 0>
57 const Result &evaluate(const DomainVector &x) const
58 {
59 field_cast(func_(x), tmp_[0] );
60 return tmp_;
61 }
62 template <class DomainVector,
63 std::enable_if_t<not models<Impl::FunctionWithCallOperator<DomainVector>, Func>(), int> = 0>
64 const Result &evaluate(const DomainVector &x) const
65 {
66 typename Func::DomainType xx ;
67 typename Func::RangeType ff ;
68 field_cast(x,xx);
69 func_.evaluate(xx,ff);
70 field_cast(ff, tmp_[0] );
71 return tmp_;
72 }
73 unsigned int size() const
74 {
75 return 1;
76 }
77 const Func &func_;
78 Vector &vec_;
79 mutable Result tmp_;
80 };
81 template <class F,unsigned int d>
82 template <class Basis,class Matrix>
83 struct InterpolationHelper<F,d>::Helper<Basis,Matrix,false>
84 // Func is of Basis type
85 {
86 typedef std::vector< Dune::FieldVector<F,d> > Result;
87 Helper(const Basis & basis, Matrix &matrix)
88 : basis_(basis),
89 matrix_(matrix),
90 tmp_(basis.size()) {}
91 const F &operator()(unsigned int row,unsigned int col) const
92 {
93 return matrix_(row,col);
94 }
95 F &operator()(unsigned int row,unsigned int col)
96 {
97 return matrix_(row,col);
98 }
99 template <class Fy>
100 void set(unsigned int row,unsigned int col,
101 const Fy &val)
102 {
103 assert(col<matrix_.cols());
104 assert(row<matrix_.rows());
105 field_cast(val,matrix_(row,col));
106 }
107 template <class Fy>
108 void add(unsigned int row,unsigned int col,
109 const Fy &val)
110 {
111 assert(col<matrix_.cols());
112 assert(row<matrix_.rows());
113 matrix_(row,col) += val;
114 }
115 template <class DomainVector>
116 const Result &evaluate(const DomainVector &x) const
117 {
118 basis_.template evaluate<0>(x,tmp_);
119 return tmp_;
120 }
121 unsigned int size() const
122 {
123 return basis_.size();
124 }
125
126 const Basis &basis_;
127 Matrix &matrix_;
128 mutable Result tmp_;
129 };
130}
131#endif // GENERIC_INTERPOLATIONHELPER_HH
Infrastructure for concepts.
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:14
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:157
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)