]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added AssertIDA macro.
authorLuca Heltai <luca.heltai@sissa.it>
Wed, 6 Sep 2017 11:32:56 +0000 (13:32 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Fri, 15 Sep 2017 12:39:43 +0000 (14:39 +0200)
include/deal.II/sundials/ida_interface.h
source/sundials/ida_interface.cc

index fb3728cd9b02601710299c27374bf04e6487e7ec..d96650138d5ffa614baeb2807893711dcc9f99cc 100644 (file)
@@ -42,6 +42,9 @@
 
 DEAL_II_NAMESPACE_OPEN
 
+// Shorthand notation for IDA error codes.
+#define AssertIDA(code) Assert(code >= 0, ExcIDAError(code))
+
 namespace SUNDIALS
 {
 
@@ -306,6 +309,14 @@ namespace SUNDIALS
      */
     void set_initial_time(const double &t);
 
+    /**
+     * Handle IDA exceptions.
+     */
+    DeclException1(ExcIDAError, int, << "One of the SUNDIALS IDA internal functions "
+                   << " returned a negative error code: "
+                   << arg1 << ". Please consult SUNDIALS manual.");
+
+
   private:
 
     /**
index 54f69d1f6bc49d29a1b0353e7d42cd62162dd7b0..d3e61177df8c51c51ee9291a4fbc4339ce2df07c 100644 (file)
@@ -428,6 +428,7 @@ namespace SUNDIALS
     copy(diff_id, differential_components());
 
     status = IDAInit(ida_mem, t_dae_residual<VectorType>, current_time, yy, yp);
+    AssertIDA(status);
 
     if (use_local_tolerances)
       {
@@ -439,16 +440,24 @@ namespace SUNDIALS
         status += IDASStolerances(ida_mem, rel_tol, abs_tol);
       }
 
-    status += IDASetInitStep(ida_mem, current_time_step);
-    status += IDASetUserData(ida_mem, (void *) this);
+    status = IDASetInitStep(ida_mem, current_time_step);
+    AssertIDA(status);
 
-    status += IDASetId(ida_mem, diff_id);
-    status += IDASetSuppressAlg(ida_mem, ignore_algebraic_terms_for_errors);
+    status = IDASetUserData(ida_mem, (void *) this);
+    AssertIDA(status);
 
-//  status += IDASetMaxNumSteps(ida_mem, max_steps);
-    status += IDASetStopTime(ida_mem, final_time);
+    status = IDASetId(ida_mem, diff_id);
+    AssertIDA(status);
 
-    status += IDASetMaxNonlinIters(ida_mem, max_non_linear_iterations);
+    status = IDASetSuppressAlg(ida_mem, ignore_algebraic_terms_for_errors);
+    AssertIDA(status);
+
+//  status = IDASetMaxNumSteps(ida_mem, max_steps);
+    status = IDASetStopTime(ida_mem, final_time);
+    AssertIDA(status);
+
+    status = IDASetMaxNonlinIters(ida_mem, max_non_linear_iterations);
+    AssertIDA(status);
 
     // Initialize solver
     IDAMem IDA_mem;
@@ -458,9 +467,8 @@ namespace SUNDIALS
     IDA_mem->ida_lsolve = t_dae_solve<VectorType>;
     IDA_mem->ida_setupNonNull = true;
 
-    status += IDASetMaxOrd(ida_mem, max_order);
-
-    AssertThrow(status == 0, ExcMessage("Error initializing IDA."));
+    status = IDASetMaxOrd(ida_mem, max_order);
+    AssertIDA(status);
 
     std::string type;
     if (first_step)
@@ -479,16 +487,22 @@ namespace SUNDIALS
     if (type == "use_y_dot")
       {
         // (re)initialization of the vectors
-        IDACalcIC(ida_mem, IDA_Y_INIT, current_time+current_time_step);
-        IDAGetConsistentIC(ida_mem, yy, yp);
+        status = IDACalcIC(ida_mem, IDA_Y_INIT, current_time+current_time_step);
+        AssertIDA(status);
+
+        status = IDAGetConsistentIC(ida_mem, yy, yp);
+        AssertIDA(status);
 
         copy(solution, yy);
         copy(solution_dot, yp);
       }
     else if (type == "use_y_diff")
       {
-        IDACalcIC(ida_mem, IDA_YA_YDP_INIT, current_time+current_time_step);
-        IDAGetConsistentIC(ida_mem, yy, yp);
+        status = IDACalcIC(ida_mem, IDA_YA_YDP_INIT, current_time+current_time_step);
+        AssertIDA(status);
+
+        status = IDAGetConsistentIC(ida_mem, yy, yp);
+        AssertIDA(status);
 
         copy(solution, yy);
         copy(solution_dot, yp);

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.