DUNE PDELab (2.8)

functionwrappers.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_PDELAB_COMMON_FUNCTIONWRAPPERS_HH
5#define DUNE_PDELAB_COMMON_FUNCTIONWRAPPERS_HH
6
7#include <vector>
8#include <tuple>
9
10#include <dune/typetree/nodetags.hh>
11
12#include "function.hh"
13
14namespace Dune {
15 namespace PDELab {
16
19
21 //
22 // PointwiseGridFunctionAdapter
23 //
24
27
32 template<typename Engine, typename F0, typename... Functions>
34 public GridFunctionBase<
35 typename F0::Traits,
36 PointwiseGridFunctionAdapter<Engine, F0, Functions...> >
37 {
38 public:
39 typedef typename F0::Traits Traits;
40
41 private:
42 const Engine& engine;
43 std::tuple<const F0*, const Functions*...> storage;
44
46
54 template<unsigned int I, unsigned int N>
55 void evaluate(
56 const typename Traits::ElementType& e,
57 const typename Traits::DomainType& x,
58 std::vector<typename Traits::RangeType>& y,
59 std::integral_constant<unsigned int, I>,
60 std::integral_constant<unsigned int, N>,
61 std::integral_constant<bool, true>) const {
62 std::get<I>(storage)->evaluate(e, x, y[I]);
63 evaluate(e,x,y,
64 std::integral_constant<unsigned int, I+1>(),
65 std::integral_constant<unsigned int, N>(),
66 std::integral_constant<bool, (I+1<N)>()
67 );
68 }
69
71 template<unsigned int I>
72 void evaluate(
73 const typename Traits::ElementType& e,
74 const typename Traits::DomainType& x,
75 std::vector<typename Traits::RangeType>& y,
76 std::integral_constant<unsigned int, I>,
77 std::integral_constant<unsigned int, I>,
78 std::integral_constant<bool, false>) const
79 {}
80
81 public:
83
93 template<typename... F>
94 PointwiseGridFunctionAdapter(const Engine& engine_, const F&... functions)
95 : engine(engine_), storage(&functions...)
96 {}
97
98 inline void evaluate (const typename Traits::ElementType& e,
99 const typename Traits::DomainType& x,
100 typename Traits::RangeType& y) const
101 {
102 static const unsigned int N = sizeof...(Functions)+1;
103 std::vector<typename Traits::RangeType> in(N);
104 evaluate(e, x, in,
105 std::integral_constant<unsigned int, 0>(),
106 std::integral_constant<unsigned int, N>(),
107 std::integral_constant<bool, true>()
108 );
109 engine.evaluate(y, in);
110 }
111
112 inline const typename Traits::GridViewType& getGridView () const
113 {
114 return std::get<0>(storage)->getGridView();
115 }
116
117 };
118
121 template<typename Engine, typename... Functions>
122 PointwiseGridFunctionAdapter<Engine, Functions...>
123 makePointwiseGridFunctionAdapter(const Engine& engine, const Functions&... f)
124 {
125 return PointwiseGridFunctionAdapter
126 <Engine,Functions...>
127 (engine,f...);
128 }
129
131 //
132 // AdapterEngines
133 //
134
137 {
138 public:
139
141
148 template<typename Domain, typename Range>
149 void evaluate(Range& out,
150 const std::vector<Domain>& in) const;
151 };
152
154
159 template<typename S>
161 {
162 S scale;
163
164 public:
165
167
171 : scale(scale_)
172 {}
173
175 template<typename Domain, typename Range>
176 void evaluate(Range& out,
177 const std::vector<Domain>& in) const {
178 assert(in.size() == 1);
179 out = in[0];
180 out *= scale;
181 }
182 };
184
187 template<typename S>
188 PointwiseScaleAdapterEngine<S>
190 return PointwiseScaleAdapterEngine<S>(scale);
191 }
192
194
200 {
201 public:
202
204 template<typename Domain, typename Range>
205 void evaluate(Range& out,
206 const std::vector<Domain>& in) const {
207 out = 0;
208 for(unsigned i = 0; i < in.size(); ++i)
209 out += in[i];
210 }
211 };
212
214
215 } // namespace PDELab
216} // namespace Dune
217
218#endif // DUNE_PDELAB_COMMON_FUNCTIONWRAPPERS_HH
leaf of a function tree
Definition: function.hh:302
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Evaluate the GridFunction at given position.
Definition: function.hh:208
Interface of a pointwise adapter engine.
Definition: functionwrappers.hh:137
void evaluate(Range &out, const std::vector< Domain > &in) const
calculate the adapted value from a set of input values
Definition: functionwrappers.hh:37
PointwiseGridFunctionAdapter(const Engine &engine_, const F &... functions)
construct a PointwiseGridFunctionAdapter
Definition: functionwrappers.hh:94
Scale the output value.
Definition: functionwrappers.hh:161
PointwiseScaleAdapterEngine(const S scale_)
create a PointwiseScaleAdapterEngine
Definition: functionwrappers.hh:170
void evaluate(Range &out, const std::vector< Domain > &in) const
calculate the adapted value from a set of input values
Definition: functionwrappers.hh:176
PointwiseScaleAdapterEngine< S > makePointwiseScaleAdapterEngine(const S scale)
syntactic sugar to create a PointwiseScaleAdapterEngine
Definition: functionwrappers.hh:189
Sum all terms.
Definition: functionwrappers.hh:200
void evaluate(Range &out, const std::vector< Domain > &in) const
calculate the adapted value from a set of input values
Definition: functionwrappers.hh:205
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)