dune-pdelab  2.5-dev
prestageengine.hh
Go to the documentation of this file.
1 #ifndef DUNE_PDELAB_GRIDOPERATOR_ONESTEP_PRESTAGEENGINE_HH
2 #define DUNE_PDELAB_GRIDOPERATOR_ONESTEP_PRESTAGEENGINE_HH
3 
5 #include <cmath>
6 #include <vector>
7 
8 namespace Dune{
9  namespace PDELab{
10 
18  template<typename OSLA>
20  : public OneStepLocalAssemblerEngineBase<OSLA,
21  typename OSLA::LocalAssemblerDT0::LocalResidualAssemblerEngine,
22  typename OSLA::LocalAssemblerDT1::LocalResidualAssemblerEngine
23  >
24  {
25 
27  typename OSLA::LocalAssemblerDT0::LocalResidualAssemblerEngine,
28  typename OSLA::LocalAssemblerDT1::LocalResidualAssemblerEngine
29  > BaseT;
30 
31  using BaseT::la;
32  using BaseT::lae0;
33  using BaseT::lae1;
34  using BaseT::implicit;
37 
38  public:
40  typedef OSLA LocalAssembler;
41 
44  typedef typename OSLA::LocalAssemblerDT0 LocalAssemblerDT0;
45  typedef typename OSLA::LocalAssemblerDT1 LocalAssemblerDT1;
46 
47  typedef typename LocalAssemblerDT0::LocalResidualAssemblerEngine ResidualEngineDT0;
48  typedef typename LocalAssemblerDT1::LocalResidualAssemblerEngine ResidualEngineDT1;
50 
52  typedef typename OSLA::Traits::Residual Residual;
53  typedef typename Residual::ElementType ResidualElement;
54 
56  typedef typename OSLA::Traits::Solution Solution;
57  typedef typename Solution::ElementType SolutionElement;
58 
60  typedef typename OSLA::Real Real;
61 
63  typedef std::vector<Solution*> Solutions;
64 
72  : BaseT(la_)
73  , invalid_residual(nullptr)
74  , invalid_solutions(nullptr)
75  , const_residual_0(invalid_residual)
76  , const_residual_1(invalid_residual)
77  , solutions(invalid_solutions)
78  {}
79 
82  bool requireSkeleton() const
83  { return lae0->requireSkeleton() || lae1->requireSkeleton(); }
85 
88  void setSolutions(const Solutions & solutions_)
89  {
90  solutions = &solutions_;
91  }
92 
95  void setConstResiduals(Residual & const_residual_0_, Residual & const_residual_1_)
96  {
97  const_residual_0 = &const_residual_0_;
98  const_residual_1 = &const_residual_1_;
99 
100  // Initialize the engines of the two wrapped local assemblers
101  assert(solutions != invalid_solutions);
102  setLocalAssemblerEngineDT0(la.la0.localResidualAssemblerEngine(*const_residual_0,*((*solutions)[0])));
103  setLocalAssemblerEngineDT1(la.la1.localResidualAssemblerEngine(*const_residual_1,*((*solutions)[0])));
104  }
105 
108  void setConstResidual(Residual & const_residual_)
109  {
110  const_residual_0 = &const_residual_;
111  const_residual_1 = &const_residual_;
112 
113  // Initialize the engines of the two wrapped local assemblers
114  assert(solutions != invalid_solutions);
115  setLocalAssemblerEngineDT0(la.la0.localResidualAssemblerEngine(*const_residual_0,*((*solutions)[0])));
116  setLocalAssemblerEngineDT1(la.la1.localResidualAssemblerEngine(*const_residual_1,*((*solutions)[0])));
117  }
118 
123  template<typename LFSU>
124  void loadCoefficientsLFSUInside(const LFSU & lfsu_s){}
125  template<typename LFSU>
126  void loadCoefficientsLFSUOutside(const LFSU & lfsu_n){}
127  template<typename LFSU>
128  void loadCoefficientsLFSUCoupling(const LFSU & lfsu_c){}
130 
135  {
136  la.la1.setTime(la.time+la.osp_method->d(la.stage)*la.dt);
137  }
138 
141  void preAssembly()
142  {
143  lae0->preAssembly();
144  lae1->preAssembly();
145 
146  *const_residual_0 = 0.0;
147  *const_residual_1 = 0.0;
148 
149  // Extract the coefficients of the time step scheme
150  a.resize(la.stage);
151  b.resize(la.stage);
152  d.resize(la.stage);
153  do0.resize(la.stage);
154  do1.resize(la.stage);
155  for (int i=0; i<la.stage; ++i){
156  a[i] = la.osp_method->a(la.stage,i);
157  b[i] = la.osp_method->b(la.stage,i);
158  d[i] = la.osp_method->d(i);
159  do0[i] = ( std::abs(b[i]) > 1E-6 );
160  do1[i] = ( std::abs(a[i]) > 1E-6 );
161  }
162 
163  // prepare local operators for stage
164  la.la0.preStage(la.time+la.osp_method->d(la.stage)*la.dt,la.stage);
165  la.la1.preStage(la.time+la.osp_method->d(la.stage)*la.dt,la.stage);
166  }
167 
168  template<typename GFSU, typename GFSV>
169  void postAssembly(const GFSU& gfsu, const GFSV& gfsv)
170  {
171  lae0->postAssembly(gfsu,gfsv);
172  lae1->postAssembly(gfsu,gfsv);
173  }
175 
178 
179  template<typename EG, typename LFSU, typename LFSV>
180  void assembleUVVolume(const EG & eg, const LFSU & lfsu, const LFSV & lfsv)
181  {
182  for (int s=0; s<la.stage; ++s){
183  // Reset the time in the local assembler
184  la.la0.setTime(la.time+d[s]*la.dt);
185  la.la1.setTime(la.time+d[s]*la.dt);
186 
187  lae0->setSolution(*((*solutions)[s]));
188  lae1->setSolution(*((*solutions)[s]));
189 
190  lae0->loadCoefficientsLFSUInside(lfsu);
191  lae1->loadCoefficientsLFSUInside(lfsu);
192 
193  if(do0[s]){
194  la.la0.setWeight(b[s]*la.dt_factor0);
195  lae0->assembleUVVolume(eg,lfsu,lfsv);
196  }
197 
198  if(do1[s]){
199  la.la1.setWeight(a[s]*la.dt_factor1);
200  lae1->assembleUVVolume(eg,lfsu,lfsv);
201  }
202  }
203  }
204 
205  template<typename EG, typename LFSV>
206  void assembleVVolume(const EG & eg, const LFSV & lfsv)
207  {
208  for (int s=0; s<la.stage; ++s){
209  // Reset the time in the local assembler
210  la.la0.setTime(la.time+d[s]*la.dt);
211  la.la1.setTime(la.time+d[s]*la.dt);
212 
213  if(do0[s]){
214  la.la0.setWeight(b[s]*la.dt_factor0);
215  lae0->assembleVVolume(eg,lfsv);
216  }
217 
218  if(do1[s]){
219  la.la1.setWeight(a[s]*la.dt_factor1);
220  lae1->assembleVVolume(eg,lfsv);
221  }
222 
223  }
224  }
225 
226  template<typename IG, typename LFSU_S, typename LFSV_S, typename LFSU_N, typename LFSV_N>
227  void assembleUVSkeleton(const IG & ig, const LFSU_S & lfsu_s, const LFSV_S & lfsv_s,
228  const LFSU_N & lfsu_n, const LFSV_N & lfsv_n)
229  {
230  for (int s=0; s<la.stage; ++s){
231  // Reset the time in the local assembler
232  la.la0.setTime(la.time+d[s]*la.dt);
233  la.la1.setTime(la.time+d[s]*la.dt);
234 
235  lae0->setSolution(*((*solutions)[s]));
236  lae1->setSolution(*((*solutions)[s]));
237 
238  lae0->loadCoefficientsLFSUInside(lfsu_s);
239  lae1->loadCoefficientsLFSUInside(lfsu_s);
240  lae0->loadCoefficientsLFSUOutside(lfsu_n);
241  lae1->loadCoefficientsLFSUOutside(lfsu_n);
242 
243  if(do0[s]){
244  la.la0.setWeight(b[s]*la.dt_factor0);
245  lae0->setSolution(*((*solutions)[s]));
246  lae0->assembleUVSkeleton(ig,lfsu_s,lfsv_s,lfsu_n,lfsv_n);
247  }
248 
249  if(do1[s]){
250  la.la1.setWeight(a[s]*la.dt_factor1);
251  lae1->setSolution(*((*solutions)[s]));
252  lae1->assembleUVSkeleton(ig,lfsu_s,lfsv_s,lfsu_n,lfsv_n);
253  }
254  }
255  }
256 
257  template<typename IG, typename LFSV_S, typename LFSV_N>
258  void assembleVSkeleton(const IG & ig, const LFSV_S & lfsv_s, const LFSV_N & lfsv_n)
259  {
260  for (int s=0; s<la.stage; ++s){
261  // Reset the time in the local assembler
262  la.la0.setTime(la.time+d[s]*la.dt);
263  la.la1.setTime(la.time+d[s]*la.dt);
264 
265  if(do0[s]){
266  la.la0.setWeight(b[s]*la.dt_factor0);
267  lae0->assembleVSkeleton(ig,lfsv_s,lfsv_n);
268  }
269 
270  if(do1[s]){
271  la.la1.setWeight(a[s]*la.dt_factor1);
272  lae1->assembleVSkeleton(ig,lfsv_s,lfsv_n);
273  }
274  }
275  }
276 
277  template<typename IG, typename LFSU_S, typename LFSV_S>
278  void assembleUVBoundary(const IG & ig, const LFSU_S & lfsu_s, const LFSV_S & lfsv_s)
279  {
280  for (int s=0; s<la.stage; ++s){
281  // Reset the time in the local assembler
282  la.la0.setTime(la.time+d[s]*la.dt);
283  la.la1.setTime(la.time+d[s]*la.dt);
284 
285  lae0->setSolution(*((*solutions)[s]));
286  lae1->setSolution(*((*solutions)[s]));
287 
288  lae0->loadCoefficientsLFSUInside(lfsu_s);
289  lae1->loadCoefficientsLFSUInside(lfsu_s);
290 
291  if(do0[s]){
292  la.la0.setWeight(b[s]*la.dt_factor0);
293  lae0->assembleUVBoundary(ig,lfsu_s,lfsv_s);
294  }
295 
296  if(do1[s]){
297  la.la1.setWeight(a[s]*la.dt_factor1);
298  lae1->assembleUVBoundary(ig,lfsu_s,lfsv_s);
299  }
300  }
301  }
302 
303  template<typename IG, typename LFSV_S>
304  void assembleVBoundary(const IG & ig, const LFSV_S & lfsv_s)
305  {
306  for (int s=0; s<la.stage; ++s){
307  // Reset the time in the local assembler
308  la.la0.setTime(la.time+d[s]*la.dt);
309  la.la1.setTime(la.time+d[s]*la.dt);
310 
311  if(do0[s]){
312  la.la0.setWeight(b[s]*la.dt_factor0);
313  lae0->assembleVBoundary(ig,lfsv_s);
314  }
315 
316  if(do1[s]){
317  la.la1.setWeight(a[s]*la.dt_factor1);
318  lae1->assembleVBoundary(ig,lfsv_s);
319  }
320  }
321  }
322 
323  template<typename IG, typename LFSU_S, typename LFSV_S>
324  void assembleUVProcessor(const IG & ig, const LFSU_S & lfsu_s, const LFSV_S & lfsv_s)
325  {
326  for (int s=0; s<la.stage; ++s){
327  // Reset the time in the local assembler
328  la.la0.setTime(la.time+d[s]*la.dt);
329  la.la1.setTime(la.time+d[s]*la.dt);
330 
331  lae0->setSolution(*((*solutions)[s]));
332  lae1->setSolution(*((*solutions)[s]));
333 
334  lae0->loadCoefficientsLFSUInside(lfsu_s);
335  lae1->loadCoefficientsLFSUInside(lfsu_s);
336 
337  if(do0[s]){
338  la.la0.setWeight(b[s]*la.dt_factor0);
339  lae0->assembleUVProcessor(ig,lfsu_s,lfsv_s);
340  }
341 
342  if(do1[s]){
343  la.la1.setWeight(a[s]*la.dt_factor1);
344  lae1->assembleUVProcessor(ig,lfsu_s,lfsv_s);
345  }
346  }
347  }
348 
349  template<typename IG, typename LFSV_S>
350  void assembleVProcessor(const IG & ig, const LFSV_S & lfsv_s)
351  {
352  for (int s=0; s<la.stage; ++s){
353  // Reset the time in the local assembler
354  la.la0.setTime(la.time+d[s]*la.dt);
355  la.la1.setTime(la.time+d[s]*la.dt);
356 
357  if(do0[s]){
358  la.la0.setWeight(b[s]*la.dt_factor0);
359  lae0->assembleVProcessor(ig,lfsv_s);
360  }
361 
362  if(do1[s]){
363  la.la1.setWeight(a[s]*la.dt_factor1);
364  lae1->assembleVProcessor(ig,lfsv_s);
365  }
366  }
367  }
368 
369  template<typename IG, typename LFSU_S, typename LFSV_S, typename LFSU_N, typename LFSV_N,
370  typename LFSU_C, typename LFSV_C>
372  const LFSU_S & lfsu_s, const LFSV_S & lfsv_s,
373  const LFSU_N & lfsu_n, const LFSV_N & lfsv_n,
374  const LFSU_C & lfsu_c, const LFSV_C & lfsv_c)
375  {
376  for (int s=0; s<la.stage; ++s){
377  // Reset the time in the local assembler
378  la.la0.setTime(la.time+d[s]*la.dt);
379  la.la1.setTime(la.time+d[s]*la.dt);
380 
381  lae0->setSolution(*((*solutions)[s]));
382  lae1->setSolution(*((*solutions)[s]));
383 
384  lae0->loadCoefficientsLFSUInside(lfsu_s);
385  lae1->loadCoefficientsLFSUInside(lfsu_s);
386 
387  lae0->loadCoefficientsLFSUOutside(lfsu_n);
388  lae1->loadCoefficientsLFSUOutside(lfsu_n);
389 
390  lae0->loadCoefficientsLFSUCoupling(lfsu_c);
391  lae1->loadCoefficientsLFSUCoupling(lfsu_c);
392 
393  if(do0[s]){
394  la.la0.setWeight(b[s]*la.dt_factor0);
395  lae0->assembleUVEnrichedCoupling(ig,lfsu_s,lfsv_s,lfsu_n,lfsv_n,lfsu_c,lfsv_c);
396  }
397 
398  if(do1[s]){
399  la.la1.setWeight(a[s]*la.dt_factor1);
400  lae1->assembleUVEnrichedCoupling(ig,lfsu_s,lfsv_s,lfsu_n,lfsv_n,lfsu_c,lfsv_c);
401  }
402  }
403  }
404 
405  template<typename IG, typename LFSV_S, typename LFSV_N, typename LFSV_C>
406  void assembleVEnrichedCoupling(const IG & ig,
407  const LFSV_S & lfsv_s,
408  const LFSV_N & lfsv_n,
409  const LFSV_C & lfsv_c)
410  {
411  for (int s=0; s<la.stage; ++s){
412  // Reset the time in the local assembler
413  la.la0.setTime(la.time+d[s]*la.dt);
414  la.la1.setTime(la.time+d[s]*la.dt);
415 
416  if(do0[s]){
417  la.la0.setWeight(b[s]*la.dt_factor0);
418  lae0->assembleVEnrichedCoupling(ig,lfsv_s,lfsv_n,lfsv_c);
419  }
420 
421  if(do1[s]){
422  la.la1.setWeight(a[s]*la.dt_factor1);
423  lae1->assembleVEnrichedCoupling(ig,lfsv_s,lfsv_n,lfsv_c);
424  }
425 
426  }
427  }
428 
429  template<typename EG, typename LFSU, typename LFSV>
430  void assembleUVVolumePostSkeleton(const EG & eg, const LFSU & lfsu, const LFSV & lfsv)
431  {
432  for (int s=0; s<la.stage; ++s){
433  // Reset the time in the local assembler
434  la.la0.setTime(la.time+d[s]*la.dt);
435  la.la1.setTime(la.time+d[s]*la.dt);
436 
437  lae0->setSolution(*((*solutions)[s]));
438  lae1->setSolution(*((*solutions)[s]));
439 
440  lae0->loadCoefficientsLFSUInside(lfsu);
441  lae1->loadCoefficientsLFSUInside(lfsu);
442 
443  if(do0[s]){
444  la.la0.setWeight(b[s]*la.dt_factor0);
445  lae0->assembleUVVolumePostSkeleton(eg,lfsu,lfsv);
446  }
447 
448  if(do1[s]){
449  la.la1.setWeight(a[s]*la.dt_factor1);
450  lae1->assembleUVVolumePostSkeleton(eg,lfsu,lfsv);
451  }
452 
453  }
454  }
455 
456  template<typename EG, typename LFSV>
457  void assembleVVolumePostSkeleton(const EG & eg, const LFSV & lfsv)
458  {
459  for (int s=0; s<la.stage; ++s){
460  // Reset the time in the local assembler
461  la.la0.setTime(la.time+d[s]*la.dt);
462  la.la1.setTime(la.time+d[s]*la.dt);
463 
464  if(do0[s]){
465  la.la0.setWeight(b[s]*la.dt_factor0);
466  lae0->assembleVVolumePostSkeleton(eg,lfsv);
467  }
468 
469  if(do1[s]){
470  la.la1.setWeight(a[s]*la.dt_factor1);
471  lae1->assembleVVolumePostSkeleton(eg,lfsv);
472  }
473  }
474  }
476 
477  private:
478 
480  Residual * const invalid_residual;
481 
483  Solutions * const invalid_solutions;
484 
489  Residual * const_residual_0;
490  Residual * const_residual_1;
492 
494  const Solutions * solutions;
495 
497  std::vector<Real> a;
498  std::vector<Real> b;
499  std::vector<Real> d;
500  std::vector<bool> do0;
501  std::vector<bool> do1;
502 
503  }; // End of class OneStepLocalPreStageAssemblerEngine
504 
505  }
506 }
507 #endif // DUNE_PDELAB_GRIDOPERATOR_ONESTEP_PRESTAGEENGINE_HH
void postAssembly(const GFSU &gfsu, const GFSV &gfsv)
Definition: prestageengine.hh:169
Residual::ElementType ResidualElement
Definition: prestageengine.hh:53
const IG & ig
Definition: constraints.hh:148
void setLocalAssemblerEngineDT1(LocalAssemblerEngineDT1 &lae1_)
Definition: enginebase.hh:119
const LocalAssembler & la
Definition: enginebase.hh:454
OSLA::LocalAssemblerDT1 LocalAssemblerDT1
Definition: prestageengine.hh:45
The local assembler engine for UDG sub triangulations which assembles the residual vector...
Definition: enginebase.hh:15
void assembleUVBoundary(const IG &ig, const LFSU_S &lfsu_s, const LFSV_S &lfsv_s)
Definition: prestageengine.hh:278
void loadCoefficientsLFSUOutside(const LFSU &lfsu_n)
Definition: prestageengine.hh:126
const std::string s
Definition: function.hh:830
The local assembler engine for one step methods which assembles the constant part of the residual vec...
Definition: prestageengine.hh:19
void assembleUVVolumePostSkeleton(const EG &eg, const LFSU &lfsu, const LFSV &lfsv)
Definition: prestageengine.hh:430
OSLA::Traits::Solution Solution
The type of the solution vector.
Definition: prestageengine.hh:56
void assembleVProcessor(const IG &ig, const LFSV_S &lfsv_s)
Definition: prestageengine.hh:350
void assembleVBoundary(const IG &ig, const LFSV_S &lfsv_s)
Definition: prestageengine.hh:304
void assembleUVEnrichedCoupling(const IG &ig, const LFSU_S &lfsu_s, const LFSV_S &lfsv_s, const LFSU_N &lfsu_n, const LFSV_N &lfsv_n, const LFSU_C &lfsu_c, const LFSV_C &lfsv_c)
Definition: prestageengine.hh:371
void setLocalAssemblerEngineDT0(LocalAssemblerEngineDT0 &lae0_)
Definition: enginebase.hh:114
void setTimeInLastStage()
Definition: prestageengine.hh:134
void assembleVEnrichedCoupling(const IG &ig, const LFSV_S &lfsv_s, const LFSV_N &lfsv_n, const LFSV_C &lfsv_c)
Definition: prestageengine.hh:406
bool implicit
Definition: enginebase.hh:459
OSLA LocalAssembler
The type of the wrapping local assembler.
Definition: prestageengine.hh:40
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
OneStepLocalPreStageAssemblerEngine(LocalAssembler &la_)
Constructor.
Definition: prestageengine.hh:71
void assembleVSkeleton(const IG &ig, const LFSV_S &lfsv_s, const LFSV_N &lfsv_n)
Definition: prestageengine.hh:258
LocalAssemblerDT1::LocalResidualAssemblerEngine ResidualEngineDT1
Definition: prestageengine.hh:48
void preAssembly()
Definition: prestageengine.hh:141
void loadCoefficientsLFSUInside(const LFSU &lfsu_s)
Definition: prestageengine.hh:124
OSLA::Traits::Residual Residual
The type of the residual vector.
Definition: prestageengine.hh:52
LocalAssemblerEngineDT0 * lae0
Definition: enginebase.hh:456
void assembleUVVolume(const EG &eg, const LFSU &lfsu, const LFSV &lfsv)
Definition: prestageengine.hh:180
LocalAssemblerEngineDT1 * lae1
Definition: enginebase.hh:457
void assembleUVSkeleton(const IG &ig, const LFSU_S &lfsu_s, const LFSV_S &lfsv_s, const LFSU_N &lfsu_n, const LFSV_N &lfsv_n)
Definition: prestageengine.hh:227
void setSolutions(const Solutions &solutions_)
Definition: prestageengine.hh:88
void setConstResidual(Residual &const_residual_)
Definition: prestageengine.hh:108
OSLA::LocalAssemblerDT0 LocalAssemblerDT0
Definition: prestageengine.hh:44
Solution::ElementType SolutionElement
Definition: prestageengine.hh:57
void assembleUVProcessor(const IG &ig, const LFSU_S &lfsu_s, const LFSV_S &lfsv_s)
Definition: prestageengine.hh:324
void assembleVVolume(const EG &eg, const LFSV &lfsv)
Definition: prestageengine.hh:206
std::vector< Solution * > Solutions
The type of the solution container.
Definition: prestageengine.hh:63
bool requireSkeleton() const
Definition: prestageengine.hh:82
void setConstResiduals(Residual &const_residual_0_, Residual &const_residual_1_)
Definition: prestageengine.hh:95
OSLA::Real Real
The type for real numbers.
Definition: prestageengine.hh:60
LocalAssemblerDT0::LocalResidualAssemblerEngine ResidualEngineDT0
Definition: prestageengine.hh:47
void loadCoefficientsLFSUCoupling(const LFSU &lfsu_c)
Definition: prestageengine.hh:128
void assembleVVolumePostSkeleton(const EG &eg, const LFSV &lfsv)
Definition: prestageengine.hh:457