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/typetree/TreePath.hpp>
15
16
17
18
19
20
21
22

namespace AMDiS
{

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

30
31
32
33
34
35
36
37
38
  protected:
    /** \brief
     * Stores adapt infos for a scalar problem or for one component of a
     * vector valued problem.
     */
    class ScalContent
    {
    public:
      /// Constructor.
39
      explicit ScalContent(std::string const& prefix);
40
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

      /// 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.
77
    explicit AdaptInfo(std::string const& name);
78
79

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

    /// 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
88
      for (auto const& scalContent : scalContents_)      {
89
        if (!(scalContent.second.est_sum < scalContent.second.spaceTolerance))
90
91
92
93
94
95
          return false;
      }

      return true;
    }

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

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

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

      return true;
    }

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

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

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

      return true;
    }
145

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /// 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
502
503
      if (nTimesteps_ > 0)
        return !(timestepNumber_ < nTimesteps_);
504

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


    /** \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
681
682
683
684
685
      time_ = newStartTime;
      startTime_ = newStartTime;
      endTime_ = newEndTime;
      timestep_ = newTimeStep;
      timestepNumber_ = 0;
686
687
    }

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

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

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

    /** \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
706
    int maxSpaceIteration_ = -1;
707
708

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

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

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

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

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

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

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

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

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

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

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

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

    /** \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
749
    int nTimesteps_ = 0;
750
751

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

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

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

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

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

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

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

} // end namespace AMDiS