This source file includes following definitions.
- clone
- clone
- clone
- assemble_RHS
- evaluate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #ifndef SECORD_OP_RHS_IMPL_H
22 #define SECORD_OP_RHS_IMPL_H
23
24 #include <functional>
25 #include <config.h>
26 #include <dune/fem/quadrature/cachingquadrature.hh>
27 #include "grid.h"
28 #include "secOrd_op_rhs.h"
29
30
31 namespace Esfem{
32
33 namespace Impl{
34
35 class Rhs_fun
36 :public Dune::Fem::Function
37 <Esfem::Grid::Grid_and_time::Function_space, Rhs_fun>
38 {
39 public:
40
41 using Base = Esfem::Grid::Grid_and_time::Function_space;
42
43 using Domain = Base::DomainType;
44
45 using Range = Base::RangeType;
46
47 static_assert(Domain::dimension == 3, "Bad Domain dimension");
48 static_assert(Range::dimension == 1, "Bad Range dimension");
49
50
51
52 Rhs_fun(const Dune::Fem::TimeProviderBase&,
53 const Growth);
54
55 Rhs_fun(const Rhs_fun&) = delete;
56
57 Rhs_fun& operator=(const Rhs_fun&) = delete;
58
59
60 void evaluate(const Domain&, Range&) const;
61
62 Range operator()(const Domain&) const;
63 private:
64
65 const Dune::Fem::TimeProviderBase& tp;
66
67 std::function<void(const Domain&,Range&)> fun_impl;
68
69 void dassert(const bool assertion, const std::string& msg);
70 };
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 class Vec_rhs_fun
98 :public Dune::Fem::Function
99 <Esfem::Grid::Grid_and_time::Vec_Function_space, Vec_rhs_fun>
100 {
101 public:
102
103 using Base = Esfem::Grid::Grid_and_time::Vec_Function_space;
104
105 using Domain = Base::DomainType;
106
107 using Range = Base::RangeType;
108
109 static_assert(Domain::dimension == 3, "Bad Domain dimension");
110 static_assert(Range::dimension == 3, "Bad Range dimension");
111
112
113
114 explicit Vec_rhs_fun(const Dune::Fem::TimeProviderBase&);
115
116 Vec_rhs_fun(const Vec_rhs_fun&) = delete;
117
118 Vec_rhs_fun& operator=(const Vec_rhs_fun&) = delete;
119
120
121 void evaluate(const Domain&, Range&) const;
122
123 Range operator()(const Domain&) const;
124 private:
125
126 const Dune::Fem::TimeProviderBase& tp;
127
128 double alpha;
129
130 double epsilon;
131
132 double r_start;
133
134 double r_end;
135
136 double k;
137
138 double delta;
139
140 mutable double cache[4];
141
142
143
144
145
146
147
148
149
150
151 void update_cache() const;
152 };
153
154
155
156
157
158 struct sls_rhs
159 : Dune::Fem::Function
160 <Esfem::Grid::Grid_and_time::Vec_Function_space, sls_rhs>,
161 SecOrd_op::vRhs{
162
163 using dBase = Esfem::Grid::Grid_and_time::Vec_Function_space;
164
165 using dom = dBase::DomainType;
166
167 using ran = dBase::RangeType;
168
169 using Range = ran;
170
171
172
173 sls_rhs(const Grid::Grid_and_time&);
174 sls_rhs* clone() override{ return new sls_rhs {*this}; }
175 void addScaled_to(Grid::Vec_FEfun& rhs) override;
176
177 ran operator()(const dom&) const;
178 private:
179
180 static constexpr int dim {2};
181
182 const Dune::Fem::TimeProviderBase& tp;
183
184 Esfem::Grid::Vec_FEfun::Dune_FEfun lvec;
185
186 double rA;
187
188 double rE;
189
190 double a;
191
192 double e;
193
194 double k;
195
196 double delta;
197 };
198
199
200
201
202 struct sd_rhs
203 : Dune::Fem::Function
204 <Esfem::Grid::Grid_and_time::Vec_Function_space, sd_rhs>,
205 SecOrd_op::vRhs{
206
207 using dBase = Esfem::Grid::Grid_and_time::Vec_Function_space;
208
209 using dom = dBase::DomainType;
210
211 using ran = dBase::RangeType;
212
213 using Range = ran;
214
215
216
217 sd_rhs(const Grid::Grid_and_time&);
218 sd_rhs* clone() override{ return new sd_rhs {*this}; }
219 void addScaled_to(Grid::Vec_FEfun& rhs) override;
220
221 ran operator()(const dom&) const;
222 private:
223
224 static constexpr int dim {2};
225
226 const Dune::Fem::TimeProviderBase& tp;
227
228 Esfem::Grid::Vec_FEfun::Dune_FEfun lvec;
229
230 double a;
231
232 double e;
233 };
234
235
236
237
238
239 struct sdp_u_rhs
240 : Dune::Fem::Function
241 <Esfem::Grid::Grid_and_time::Function_space, sdp_u_rhs>,
242 SecOrd_op::sRhs{
243
244 using dBase = Esfem::Grid::Grid_and_time::Function_space;
245
246 using dom = dBase::DomainType;
247
248 using ran = dBase::RangeType;
249
250 using Range = ran;
251
252
253
254 sdp_u_rhs(const Grid::Grid_and_time&);
255 sdp_u_rhs* clone() override{ return new sdp_u_rhs {*this}; }
256 void addScaled_to(Grid::Scal_FEfun& rhs) override;
257
258 ran operator()(const dom&) const;
259 private:
260
261 static constexpr int dim {2};
262
263 const Dune::Fem::TimeProviderBase& tp;
264
265 Esfem::Grid::Scal_FEfun::Dune_FEfun lscal;
266
267 double rA;
268
269 double rE;
270
271 double k;
272 };
273
274
275
276
277
278
279 template<typename Rhs, typename Fef>
280 void assemble_RHS(const Rhs& rhs, Fef& fef);
281 }
282
283
284 struct SecOrd_op::Rhs::Data{
285
286 const Dune::Fem::TimeProviderBase& tp;
287
288 Impl::Rhs_fun rhs;
289
290 Esfem::Grid::Scal_FEfun::Dune_FEfun load_vector;
291
292
293 Data(const Grid::Grid_and_time&, const Growth);
294 };
295
296
297 struct SecOrd_op::Vec_rhs::Data{
298
299 const Dune::Fem::TimeProviderBase& tp;
300
301 Impl::Vec_rhs_fun rhs;
302
303 Esfem::Grid::Vec_FEfun::Dune_FEfun load_vector;
304
305
306 Data(const Grid::Grid_and_time&);
307 };
308 }
309
310
311
312
313 template<typename Rhs, typename Fef>
314 void Esfem::Impl::assemble_RHS(const Rhs& rhs, Fef& fef){
315 using Range = typename Rhs::Range;
316 using Grid_part = typename Fef::GridPartType;
317 using Quadrature = Dune::Fem::CachingQuadrature<Grid_part, 0>;
318
319 fef.clear();
320 const auto& df_space = fef.space();
321 for(const auto& entity : df_space){
322 const auto& geometry = entity.geometry();
323 const Quadrature quad {entity, 2 * df_space.order() + 1};
324 auto fef_local = fef.localFunction(entity);
325 for(std::size_t pt = 0; pt < quad.nop(); ++pt){
326 const auto& x = quad.point(pt);
327 Range fx {rhs(geometry.global(x))};
328
329 fx *= quad.weight(pt) * geometry.integrationElement(x);
330 fef_local.axpy(quad[pt], fx);
331 }
332 }
333 fef.communicate();
334 }
335
336
337
338
339 inline void Esfem::Impl::Rhs_fun::evaluate(const Domain& d, Range& r) const{
340 fun_impl(d,r);
341 }
342 inline Esfem::Impl::Rhs_fun::Range
343 Esfem::Impl::Rhs_fun::operator()(const Domain& d) const{
344 Range r {0};
345 evaluate(d,r);
346 return r;
347 }
348
349 #endif