Dune Core Modules (2.6.0)

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