]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Assert that a method was choosen in the time stepping methods. 13658/head
authorSimon Sticko <simon@sticko.se>
Fri, 29 Apr 2022 11:20:24 +0000 (13:20 +0200)
committerSimon Sticko <simon@sticko.se>
Fri, 29 Apr 2022 11:20:24 +0000 (13:20 +0200)
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
include/deal.II/base/time_stepping.templates.h

index d3a5d9fd23e0b7a30f61efd291f3810a683fe2ac..d09e6881e7878469212bf96e0ba81a155e1d8b19 100644 (file)
@@ -767,6 +767,10 @@ namespace TimeStepping
      */
     struct Status : public TimeStepping<VectorType>::Status
     {
+      Status()
+        : method(invalid)
+      {}
+
       runge_kutta_method             method;
       embedded_runge_kutta_time_step exit_delta_t;
       unsigned int                   n_iterations;
index cfc0ff43f1b16e5d68cf9e9cdd03a99bd37877ea..65d73a6ef4fae65867a618b62accec1421303f66 100644 (file)
@@ -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<VectorType> 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<VectorType> 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.;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.