AdaptInfo.hpp 17.1 KB
Newer Older
1
2
3
#pragma once

// std c++ headers
4
#include <algorithm>
5
#include <cmath>
6
#include <limits>
7
#include <map>
8
#include <string>
9
#include <utility>
10
11

// AMDiS includes
12
#include <amdis/Output.hpp>
13
#include <amdis/common/ConceptsBase.hpp>
14
#include <amdis/common/Math.hpp>
15
#include <amdis/utility/TreePath.hpp>
16
17
18
19
20
21
22
23

namespace AMDiS
{

  /**
   * \ingroup Adaption
   *
   * \brief
24
   * Holds adapt parameters and infos about the problem.
25
26
27
   */
  class AdaptInfo
  {
28
29
30
  public:
    using Key = std::string;

31
32
33
34
35
36
37
38
39
  protected:
    /** \brief
     * Stores adapt infos for a scalar problem or for one component of a
     * vector valued problem.
     */
    class ScalContent
    {
    public:
      /// Constructor.
40
      explicit ScalContent(std::string const& prefix);
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

      /// Sum of all error estimates
      double est_sum = 0.0;

      /// Sum of all time error estimates
      double est_t_sum = 0.0;

      /// maximal local error estimate.
      double est_max = 0.0;

      /// Maximum of all time error estimates
      double est_t_max = 0.0;

      /// factors to combine max and integral time estimate
      double fac_max = 0.0, fac_sum = 1.0;

      /// Tolerance for the (absolute or relative) error
      double spaceTolerance = 0.0;

      /// Time tolerance.
      double timeTolerance = 0.0;

      /// Relative time tolerance
      double timeRelativeTolerance = 0.0;

      /// Lower bound for the time error.
      double timeErrLow = 0.0;

      /// true if coarsening is allowed, false otherwise.
      int coarsenAllowed = 0;

      /// true if refinement is allowed, false otherwise.
      int refinementAllowed = 1;
    };

  public:
    /// Constructor.
78
    explicit AdaptInfo(std::string const& name);
79
80

    /// Destructor.
81
    virtual ~AdaptInfo() = default;
82
83
84
85
86
87
88

    /// Resets all variables to zero (or something equivalent)
    void reset();

    /// Returns whether space tolerance is reached.
    virtual bool spaceToleranceReached() const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
89
      for (auto const& scalContent : scalContents_)      {
90
        if (!(scalContent.second.est_sum < scalContent.second.spaceTolerance))
91
92
93
94
95
96
          return false;
      }

      return true;
    }

97
    /// Returns whether space tolerance of component associated with key is reached.
98
    virtual bool spaceToleranceReached(Key key) const
99
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
100
      if (!(scalContent(key).est_sum < scalContent(key).spaceTolerance))
101
102
103
104
105
        return false;
      else
        return true;
    }

106
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
107
    bool spaceToleranceReached(const TP& tp) const
108
109
110
111
    {
      return spaceToleranceReached(to_string(tp));
    }

112
113
114
    /// Returns whether time tolerance is reached.
    virtual bool timeToleranceReached() const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
115
116
      for (auto const& scalContent : scalContents_)
        if (!(timeEstCombined(scalContent.first) < scalContent.second.timeTolerance))
117
118
119
120
121
          return false;

      return true;
    }

122
    /// Returns whether time tolerance of component associated with key is reached.
123
    virtual bool timeToleranceReached(Key key) const
124
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
125
      if (!(timeEstCombined(key) < scalContent(key).timeTolerance))
126
127
128
129
130
        return false;
      else
        return true;
    }

131
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
132
    bool timeToleranceReached(const TP& tp) const
133
134
135
136
    {
      return timeToleranceReached(to_string(tp));
    }

137
138
139
    /// Returns whether time error is under its lower bound.
    virtual bool timeErrorLow() const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
140
141
      for (auto const& scalContent : scalContents_)
        if (!(timeEstCombined(scalContent.first) < scalContent.second.timeErrLow))
142
143
144
145
          return false;

      return true;
    }
146

147
148
    /// Returns the time estimation as a combination
    /// of maximal and integral time error
Praetorius, Simon's avatar
Praetorius, Simon committed
149
    double timeEstCombined(Key key) const
150
151
    {
      return
Praetorius, Simon's avatar
Praetorius, Simon committed
152
153
        scalContent(key).est_t_max * scalContent(key).fac_max +
        scalContent(key).est_t_sum * scalContent(key).fac_sum;
154
155
    }

156
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
157
    double timeEstCombined(const TP& tp) const
158
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
159
      return tTimeEstCombined(to_string(tp));
160
    }
161
162
163
164

    /// Print debug information about time error and its bound.
    void printTimeErrorLowInfo() const;

Praetorius, Simon's avatar
Praetorius, Simon committed
165
166
    /// Returns \ref spaceIteration_.
    int spaceIteration() const
167
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
168
      return spaceIteration_;
169
170
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
171
    /// Sets \ref spaceIteration_.
172
173
    void setSpaceIteration(int it)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
174
      spaceIteration_ = it;
175
176
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
177
178
    /// Returns \ref maxSpaceIteration_.
    int maxSpaceIteration() const
179
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
180
      return maxSpaceIteration_;
181
182
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
183
184
    /// Sets \ref maxSpaceIteration_.
    void maxSpaceIteration(int it)
185
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
186
      maxSpaceIteration_ = it;
187
188
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
189
    /// Increments \ref spaceIteration_ by 1;
190
191
    void incSpaceIteration()
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
192
      spaceIteration_++;
193
194
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
195
    /// Sets \ref timestepIteration_.
196
197
    void setTimestepIteration(int it)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
198
      timestepIteration_ = it;
199
200
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
201
202
    /// Returns \ref timestepIteration_.
    int timestepIteration() const
203
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
204
      return timestepIteration_;
205
206
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
207
    /// Increments \ref timestepIteration_ by 1;
208
209
    void incTimestepIteration()
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
210
      timestepIteration_++;
211
212
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
213
214
    /// Returns \ref maxTimestepIteration_.
    int maxTimestepIteration() const
215
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
216
      return maxTimestepIteration_;
217
218
219
220
221
    }

    /// Sets \ref maxTimestepIteration.
    void setMaxTimestepIteration(int it)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
222
      maxTimestepIteration_ = it;
223
224
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
225
    /// Sets \ref timeIteration_.
226
227
    void setTimeIteration(int it)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
228
      timeIteration_ = it;
229
230
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
231
232
    /// Returns \ref timeIteration_.
    int timeIteration() const
233
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
234
      return timeIteration_;
235
236
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
237
    /// Increments \ref timesIteration_ by 1;
238
239
    void incTimeIteration()
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
240
      timeIteration_++;
241
242
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
243
244
    /// Returns \ref maxTimeIteration_.
    int maxTimeIteration() const
245
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
246
      return maxTimeIteration_;
247
248
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
249
    /// Sets \ref maxTimeIteration_.
250
251
    void setMaxTimeIteration(int it)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
252
      maxTimeIteration_ = it;
253
254
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
255
256
    /// Returns \ref timestepNumber_.
    int timestepNumber() const
257
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
258
      return timestepNumber_;
259
260
261
262
263
    }

    /// Sets \ref timestepNumber.
    void setTimestepNumber(int num)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
264
      timestepNumber_ = std::min(nTimesteps_, num);
265
266
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
267
268
    /// Returns \ref nTimesteps_.
    int numberOfTimesteps() const
269
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
270
      return nTimesteps_;
271
272
273
274
275
    }

    /// Sets \ref nTimesteps.
    void setNumberOfTimesteps(int num)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
276
      nTimesteps_ = std::max(0, num);
277
278
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
279
    /// Increments \ref timestepNumber_ by 1;
280
281
    void incTimestepNumber()
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
282
      timestepNumber_++;
283
284
285
    }

    /// Sets \ref est_sum.
286
    void setEstSum(double e, Key key)
287
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
288
      scalContent(key).est_sum = e;
289
290
    }

291
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
292
    void setEstSum(double e, const TP& tp)
293
294
295
296
    {
      setEstSum(e, to_string(tp));
    }

297
    /// Sets \ref est_max.
298
    void setEstMax(double e, Key key)
299
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
300
      scalContent(key).est_max = e;
301
302
    }

303
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
304
    void setEstMax(double e, const TP& tp)
305
306
307
308
    {
      setEstMax(e, to_string(tp));
    }

309
    /// Sets \ref est_max.
310
    void setTimeEstMax(double e, Key key)
311
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
312
      scalContent(key).est_t_max = e;
313
314
    }

315
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
316
    void setTimeEstMax(double e, const TP& tp)
317
318
319
320
    {
      setTimeEstMax(e, to_string(tp));
    }

321
    /// Sets \ref est_t_sum.
322
    void setTimeEstSum(double e, Key key)
323
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
324
      scalContent(key).est_t_sum = e;
325
326
    }

327
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
328
    void setTimeEstSum(double e, const TP& tp)
329
330
331
332
    {
      setTimeEstSum(e, to_string(tp));
    }

333
    /// Returns \ref est_sum.
Praetorius, Simon's avatar
Praetorius, Simon committed
334
    double estSum(Key key) const
335
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
336
      return scalContent(key).est_sum;
337
338
    }

339
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
340
    double estSum(const TP& tp)
341
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
342
      return estSum(to_string(tp));
343
344
    }

345
    /// Returns \ref est_t_sum.
Praetorius, Simon's avatar
Praetorius, Simon committed
346
    double estTSum(Key key) const
347
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
348
      return scalContent(key).est_t_sum;
349
350
    }

351
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
352
    double estTSum(const TP& tp)
353
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
354
      return estTSum(to_string(tp));
355
356
    }

357
    /// Returns \ref est_max.
Praetorius, Simon's avatar
Praetorius, Simon committed
358
    double estMax(Key key) const
359
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
360
      return scalContent(key).est_max;
361
362
    }

363
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
364
    double estMax(const TP& tp)
365
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
366
      return estMax(to_string(tp));
367
368
    }

369
    /// Returns \ref est_max.
Praetorius, Simon's avatar
Praetorius, Simon committed
370
    double timeEstMax(Key key) const
371
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
372
      return scalContent(key).est_t_max;
373
374
    }

375
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
376
    double timeEstmax(const TP& tp)
377
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
378
      return timeEstMax(to_string(tp));
379
380
    }

381
    /// Returns \ref est_t_sum.
Praetorius, Simon's avatar
Praetorius, Simon committed
382
    double timeEstSum(Key key) const
383
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
384
      return scalContent(key).est_t_sum;
385
386
    }

387
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
388
    double timeEstSum(const TP& tp)
389
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
390
      return timeEstSum(to_string(tp));
391
392
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
393
394
    /// Returns \ref timeEst_ the estimated overall time error
    double timeEst() const
395
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
396
      return timeEst_;
397
398
399
400
    }

    void setTimeEst(double value)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
401
      timeEst_ = value;
402
403
404
    }

    /// Returns \ref spaceTolerance.
Praetorius, Simon's avatar
Praetorius, Simon committed
405
    double spaceTolerance(Key key) const
406
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
407
      return scalContent(key).spaceTolerance;
408
409
    }

410
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
411
    double spaceTolerance(const TP& tp)
412
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
413
      return spaceTolerance(to_string(tp));
414
415
    }

416
    /// Sets \ref spaceTolerance.
417
    void setSpaceTolerance(Key key, double tol)
418
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
419
      scalContent(key).spaceTolerance = tol;
420
421
    }

422
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
423
    void setSpaceTolerance(const TP& tp, double tol)
424
425
426
427
    {
      return setSpaceTolerance(to_string(tp), tol);
    }

428
    /// Returns \ref timeTolerance.
Praetorius, Simon's avatar
Praetorius, Simon committed
429
    double timeTolerance(Key key) const
430
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
431
      return scalContent(key).timeTolerance;
432
433
    }

434
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
435
    double timeTolerance(const TP& tp)
436
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
437
      return timeTolerance(to_string(tp));
438
439
    }

440
    /// Returns \ref timeRelativeTolerance.
Praetorius, Simon's avatar
Praetorius, Simon committed
441
    double timeRelativeTolerance(Key key) const
442
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
443
      return scalContent(key).timeRelativeTolerance;
444
445
    }

446
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
447
    double timeRelativeTolerance(const TP& tp)
448
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
449
      return timeRelativeTolerance(to_string(tp));
450
451
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
452
    /// Sets \ref time_
453
454
    double setTime(double t)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
455
456
457
458
459
      time_ = t;
      if (time_ > endTime_)
        time_ = endTime_;
      if (time_ < startTime_)
        time_ = startTime_;
460

Praetorius, Simon's avatar
Praetorius, Simon committed
461
      return time_;
462
463
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
464
465
    /// Gets \ref time_
    double const& time() const
466
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
467
      return time_;
468
469
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
470
    /// Sets \ref timestep_
471
472
    double setTimestep(double t)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
473
474
475
476
477
478
479
      timestep_ = t;
      if (timestep_ > maxTimestep_)
        timestep_ = maxTimestep_;
      if (timestep_ < minTimestep_)
        timestep_ = minTimestep_;
      if (time_ + timestep_ > endTime_)
        timestep_ = endTime_ - time_;
480

Praetorius, Simon's avatar
Praetorius, Simon committed
481
      return timestep_;
482
    }
Praetorius, Simon's avatar
Praetorius, Simon committed
483
484
    /// Gets \ref timestep_
    double const& timestep() const
485
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
486
      return timestep_;
487
488
489
490
    }

    void setLastProcessedTimestep(double t)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
491
      lastProcessedTimestep_ = t;
492
493
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
494
    double lastProcessedTimestep() const
495
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
496
      return lastProcessedTimestep_;
497
498
499
500
501
502
    }

    /// Returns true, if the end time is reached and no more timestep
    /// computations must be done.
    bool reachedEndTime() const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
503
504
      if (nTimesteps_ > 0)
        return !(timestepNumber_ < nTimesteps_);
505

Praetorius, Simon's avatar
Praetorius, Simon committed
506
      return !(std::abs(time_ - endTime_) > std::numeric_limits<double>::epsilon());
507
508
509
    }


Praetorius, Simon's avatar
Praetorius, Simon committed
510
    /// Sets \ref minTimestep_
511
512
    void setMinTimestep(double t)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
513
      minTimestep_ = t;
514
515
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
516
517
    /// Gets \ref minTimestep_
    double minTimestep() const
518
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
519
      return minTimestep_;
520
521
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
522
523
    /// Sets \ref maxTimestep_
    void maxTimestep(double t)
524
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
525
      maxTimestep_ = t;
526
527
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
528
529
    /// Gets \ref maxTimestep_
    double maxTimestep() const
530
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
531
      return maxTimestep_;
532
533
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
534
    /// Sets \ref startTime_ = time
535
536
    void setStartTime(double time)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
537
      startTime_ = time;
538
539
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
540
    /// Sets \ref endTime_ = time
541
542
    void setEndTime(double time)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
543
      endTime_ = time;
544
545
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
546
547
    /// Returns \ref startTime_
    double startTime() const
548
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
549
      return startTime_;
550
551
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
552
553
    /// Returns \ref endTime_
    double endTime() const
554
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
555
      return endTime_;
556
557
558
    }

    /// Returns \ref timeErrLow.
Praetorius, Simon's avatar
Praetorius, Simon committed
559
    double timeErrLow(Key key) const
560
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
561
      return scalContent(key).timeErrLow;
562
563
    }

564
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
Praetorius, Simon's avatar
Praetorius, Simon committed
565
    double timeErrLow(const TP& tp)
566
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
567
      return timeErrLow(to_string(tp));
568
569
    }

570
    /// Returns whether coarsening is allowed or not.
571
    bool isCoarseningAllowed(Key key) const
572
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
573
      return (scalContent(key).coarsenAllowed == 1);
574
575
    }

576
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
577
    bool isCoarseningAllowed(const TP& tp)
578
579
580
581
    {
      return isCoarseningAllowed(to_string(tp));
    }

582
    /// Returns whether coarsening is allowed or not.
583
    bool isRefinementAllowed(Key key) const
584
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
585
      return (scalContent(key).refinementAllowed == 1);
586
587
    }

588
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
589
    bool isRefinementAllowed(const TP& tp)
590
591
592
593
    {
      return isRefinementAllowed(to_string(tp));
    }

594
    ///
595
    void allowRefinement(bool allow, Key key)
596
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
597
      scalContent(key).refinementAllowed = allow;
598
599
    }

600
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
601
    void allowRefinement(bool allow, const TP& tp)
602
603
604
605
    {
      return allowRefinement(allow, to_string(tp));
    }

606
    ///
607
    void allowCoarsening(bool allow, Key key)
608
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
609
      scalContent(key).coarsenAllowed = allow;
610
611
    }

612
    template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
613
    void allowCoarsening(bool allow, const TP& tp)
614
615
616
617
    {
      return allowCoarsening(allow, to_string(tp));
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
618
    int size() const
619
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
620
      return int(scalContents_.size());
621
622
623
624
    }

    void setSolverIterations(int it)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
625
      solverIterations_ = it;
626
627
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
628
    int solverIterations() const
629
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
630
      return solverIterations_;
631
632
633
634
    }

    void setMaxSolverIterations(int it)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
635
      maxSolverIterations_ = it;
636
637
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
638
    int maxSolverIterations() const
639
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
640
      return maxSolverIterations_;
641
642
643
644
    }

    void setSolverTolerance(double tol)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
645
      solverTolerance_ = tol;
646
647
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
648
    double solverTolerance() const
649
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
650
      return solverTolerance_;
651
652
653
654
    }

    void setSolverResidual(double res)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
655
      solverResidual_ = res;
656
657
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
658
    double solverResidual() const
659
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
660
      return solverResidual_;
661
662
663
664
    }

    void setGlobalTimeTolerance(double tol)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
665
      globalTimeTolerance_ = tol;
666
667
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
668
    double globalTimeTolerance() const
669
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
670
      return globalTimeTolerance_;
671
672
673
674
675
676
677
678
679
680
681
    }


    /** \brief
     * Resets timestep, current time and time boundaries without
     * any check. Is used by the parareal algorithm.
     */
    void resetTimeValues(double newTimeStep,
                         double newStartTime,
                         double newEndTime)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
682
683
684
685
686
      time_ = newStartTime;
      startTime_ = newStartTime;
      endTime_ = newEndTime;
      timestep_ = newTimeStep;
      timestepNumber_ = 0;
687
688
    }

689
  private:
Praetorius, Simon's avatar
Praetorius, Simon committed
690
    ScalContent& scalContent(Key key) const
691
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
692
      auto result = scalContents_.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(name_ + "[" + key + "]") );
693
694
695
      return result.first->second;
    }

696
697
  protected:
    /// Name.
698
    std::string name_;
699
700

    /// Current space iteration
Praetorius, Simon's avatar
Praetorius, Simon committed
701
    int spaceIteration_ = -1;
702
703
704
705
706

    /** \brief
     * maximal allowed number of iterations of the adaptive procedure; if
     * maxIteration <= 0, no iteration bound is used
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
707
    int maxSpaceIteration_ = -1;
708
709

    /// Current timestep iteration
Praetorius, Simon's avatar
Praetorius, Simon committed
710
    int timestepIteration_ = 0;
711
712

    /// Maximal number of iterations for choosing a timestep
Praetorius, Simon's avatar
Praetorius, Simon committed
713
    int maxTimestepIteration_ = 30;
714
715

    /// Current time iteration
Praetorius, Simon's avatar
Praetorius, Simon committed
716
    int timeIteration_ = 0;
717
718

    /// Maximal number of time iterations
Praetorius, Simon's avatar
Praetorius, Simon committed
719
    int maxTimeIteration_ = 30;
720
721

    /// Actual time, end of time interval for current time step
Praetorius, Simon's avatar
Praetorius, Simon committed
722
    double time_ = 0.0;
723
724

    /// Initial time
Praetorius, Simon's avatar
Praetorius, Simon committed
725
    double startTime_ = 0.0;
726
727

    /// Final time
Praetorius, Simon's avatar
Praetorius, Simon committed
728
    double endTime_ = 1.0;
729

730
    /// Time step size to be used
Praetorius, Simon's avatar
Praetorius, Simon committed
731
    double timestep_ = 0.0;
732
733

    /// Last processed time step size of finished iteration
Praetorius, Simon's avatar
Praetorius, Simon committed
734
    double lastProcessedTimestep_ = 0.0;
735
736

    /// Minimal step size
Praetorius, Simon's avatar
Praetorius, Simon committed
737
    double minTimestep_ = 0.0;
738
739

    /// Maximal step size
Praetorius, Simon's avatar
Praetorius, Simon committed
740
    double maxTimestep_ = 1.0;
741
742

    /// Number of current time step
Praetorius, Simon's avatar
Praetorius, Simon committed
743
    int timestepNumber_ = 0;
744
745
746
747
748
749

    /** \brief
     * Per default this value is 0 and not used. If it is set to a non-zero value,
     * the computation of the stationary problem is done nTimesteps times with a
     * fixed timestep.
     */
Praetorius, Simon's avatar
Praetorius, Simon committed
750
    int nTimesteps_ = 0;
751
752

    /// number of iterations needed of linear or nonlinear solver
Praetorius, Simon's avatar
Praetorius, Simon committed
753
    int solverIterations_ = 0;
754
755

    /// maximal number of iterations needed of linear or nonlinear solver
Praetorius, Simon's avatar
Praetorius, Simon committed
756
    int maxSolverIterations_ = 0;
757
758

    ///
Praetorius, Simon's avatar
Praetorius, Simon committed
759
    double solverTolerance_ = 1.e-8;
760
761

    ///
Praetorius, Simon's avatar
Praetorius, Simon committed
762
    double solverResidual_ = 0.0;
763
764

    /// tolerance for the overall time error
Praetorius, Simon's avatar
Praetorius, Simon committed
765
    double globalTimeTolerance_ = 1.0;
766

767
    /// Scalar adapt infos
Praetorius, Simon's avatar
Praetorius, Simon committed
768
    mutable std::map<Key, ScalContent> scalContents_;
769
770

    /// overall time error estimate
Praetorius, Simon's avatar
Praetorius, Simon committed
771
    double timeEst_ = 0.0;
772
773
774
  };

} // end namespace AMDiS