From 15b29de21df21765da632091981f979385e524d2 Mon Sep 17 00:00:00 2001 From: Simon Sticko Date: Fri, 29 Apr 2022 13:20:24 +0200 Subject: [PATCH] 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. --- include/deal.II/base/time_stepping.h | 4 ++++ include/deal.II/base/time_stepping.templates.h | 12 ++++++++++++ 2 files changed, 16 insertions(+) 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.; -- 2.39.5