From: Simon Sticko Date: Fri, 29 Apr 2022 11:20:24 +0000 (+0200) Subject: Assert that a method was choosen in the time stepping methods. X-Git-Tag: v9.4.0-rc1~294^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15b29de21df21765da632091981f979385e524d2;p=dealii.git Assert that a method was choosen in the time stepping methods. If one does not pass a runge_kutta_method to the constructor of one of the TimeStepping::*RungeKutta classes and forgets to call the initialize(..)-function, the program crashes with a poor error message. Add asserts to get more descriptive error messages. --- diff --git a/include/deal.II/base/time_stepping.h b/include/deal.II/base/time_stepping.h index d3a5d9fd23..d09e6881e7 100644 --- a/include/deal.II/base/time_stepping.h +++ b/include/deal.II/base/time_stepping.h @@ -767,6 +767,10 @@ namespace TimeStepping */ struct Status : public TimeStepping::Status { + Status() + : method(invalid) + {} + runge_kutta_method method; embedded_runge_kutta_time_step exit_delta_t; unsigned int n_iterations; diff --git a/include/deal.II/base/time_stepping.templates.h b/include/deal.II/base/time_stepping.templates.h index cfc0ff43f1..65d73a6ef4 100644 --- a/include/deal.II/base/time_stepping.templates.h +++ b/include/deal.II/base/time_stepping.templates.h @@ -27,6 +27,10 @@ DEAL_II_NAMESPACE_OPEN namespace TimeStepping { + DeclExceptionMsg(ExcNoMethodSelected, + "No method selected. You need to call initialize or pass a " + "runge_kutta_method to the constructor."); + // ---------------------------------------------------------------------- // RungeKutta // ---------------------------------------------------------------------- @@ -198,6 +202,8 @@ namespace TimeStepping double delta_t, VectorType & y) { + Assert(status.method != runge_kutta_method::invalid, ExcNoMethodSelected()); + std::vector f_stages(this->n_stages, y); // Compute the different stages needed. compute_stages(f, t, delta_t, y, f_stages); @@ -390,6 +396,8 @@ namespace TimeStepping VectorType & vec_ri, VectorType & vec_ki) { + Assert(status.method != runge_kutta_method::invalid, ExcNoMethodSelected()); + compute_one_stage(f, t, this->b[0] * delta_t, @@ -566,6 +574,8 @@ namespace TimeStepping double delta_t, VectorType & y) { + Assert(status.method != runge_kutta_method::invalid, ExcNoMethodSelected()); + VectorType old_y(y); std::vector f_stages(this->n_stages, y); // Compute the different stages needed. @@ -996,6 +1006,8 @@ namespace TimeStepping double delta_t, VectorType & y) { + Assert(status.method != runge_kutta_method::invalid, ExcNoMethodSelected()); + bool done = false; unsigned int count = 0; double error_norm = 0.;