Dune Core Modules (2.9.1)

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