How-to: change tolerances for adaptive time step methods#

Adaptive time step methods provide an error estimator such as:

\[\sum_i \left( \frac{|u^{n+1}_i - \tilde{u}^{n+1}_i|}{a_{tol} + \max(|u^n_i|, |u^{n+1}_i||)} \right)\]

where \(u^n\), \(u^{n+1}\) and \(\tilde{u}^{n+1}\) are respectively the solution at time \(t^n\), time \(t^{n+1}=t^n+\Delta t\) and an other estimation at time \(t^{n+1}=t^n+\Delta t\). We also get two tolerances: the absolute one \(a_{tol}\) and relative one \(r_{tol}\), we can set them with respectively abs_tol and rel_tol member function of algorithm.

34        auto meth = ponio::runge_kutta::rk54_7s().abs_tol( 1e-4 ).rel_tol( 1e-5 );
35        ponio::solve( pb, meth, y0, { 0., 2.0 }, dt, "how_to_tolerance.txt"_fobs );

You can also change the parameters of Newton method in diagonal implicit method, the tolerance and the maximum number of iteration with respectively newton_tol and newton_max_iter member functions.

38        auto meth = ponio::runge_kutta::backward_euler().newton_tol( 1e-3 ).newton_max_iter( 1000 );
39        ponio::solve( pb, meth, y0, { 0., 2.0 }, dt, "how_to_tolerance.txt"_fobs );

See also

The full example can be found in how_to_tolerance.cpp.