DiFfRG
Loading...
Searching...
No Matches
PI.hh
Go to the documentation of this file.
1#pragma once
2
3// DiFfRG
6
7namespace DiFfRG
8{
16 template <typename NEWT> class TC_PI : public TC_Default<NEWT>
17 {
18 public:
20 TC_PI(NEWT &newton_, unsigned int alg_order_, double t_, double max_t_, double dt_, double min_dt_, double max_dt_,
21 double output_dt_)
22 : Base(newton_, alg_order_, t_, max_t_, dt_, min_dt_, max_dt_, output_dt_)
23 {
24 // these are magic numbers, inspired by the implementation of the PI controller in DifferentialEquations.jl,
25 // although a tad more conservative (i.e. cautious when increasing dt)
26 beta1 = 7. / (10. * alg_order);
27 beta2 = 2. / (5. * alg_order);
28 qmin = 0.2;
29 qmax = 10.;
30 qsteady_min = 0.99;
31 qsteady_max = 1.2;
32 qoldinit = 1e-4;
33 qold = qoldinit;
34 gamma = 0.9;
35 }
36
37 protected:
39
43 void get_q()
44 {
45 const double EEst = newton.get_error();
46 q11 = std::pow(EEst, beta1);
47 q = q11 / std::pow(qold, beta2);
48 q = std::max(1. / qmax, std::min(1. / qmin, q / gamma));
49 }
50
54 virtual void step_success() override
55 {
56 t += cur_dt;
57
58 const double EEst = newton.get_error();
59 get_q();
60
62 qold = std::max(EEst, qoldinit);
63
64 sug_dt = cur_dt / q;
65 }
66
70 virtual void step_fail(const std::exception &) override
71 {
72 get_q();
73 sug_dt /= std::min(1. / qmin, q11 / gamma);
74 }
75
77 };
78} // namespace DiFfRG
This is a default time controller implementation which should be used as a base class for any other t...
Definition default.hh:21
unsigned int alg_order
Definition default.hh:126
double sug_dt
Definition default.hh:127
double cur_dt
Definition default.hh:127
NEWT & newton
Definition default.hh:125
double t
Definition default.hh:127
A simple PI controller which adjusts time steps in a smooth fashion depending on how well the solver ...
Definition PI.hh:17
TC_PI(NEWT &newton_, unsigned int alg_order_, double t_, double max_t_, double dt_, double min_dt_, double max_dt_, double output_dt_)
Definition PI.hh:20
unsigned int alg_order
Definition default.hh:126
virtual void step_success() override
Increment t and suggest a dt based on current error and previous error.
Definition PI.hh:54
double beta2
Definition PI.hh:76
double qsteady_min
Definition PI.hh:76
double qmin
Definition PI.hh:76
double qsteady_max
Definition PI.hh:76
virtual void step_fail(const std::exception &) override
On a fail, decrease the timestep.
Definition PI.hh:70
double q
Definition PI.hh:76
double sug_dt
Definition default.hh:127
double qold
Definition PI.hh:76
double cur_dt
Definition default.hh:127
double q11
Definition PI.hh:76
void get_q()
This method just updates q for the calculation of the next sug_dt.
Definition PI.hh:43
double qmax
Definition PI.hh:76
double beta1
Definition PI.hh:76
double gamma
Definition PI.hh:76
NEWT & newton
Definition default.hh:125
double t
Definition default.hh:127
double qoldinit
Definition PI.hh:76
Definition complex_math.hh:14