From: Luca Heltai Date: Wed, 6 Sep 2017 11:32:56 +0000 (+0200) Subject: Added AssertIDA macro. X-Git-Tag: v9.0.0-rc1~1070^2~7 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee5b5706a43259bdefa3aa74d5d1210b6199333e;p=dealii.git Added AssertIDA macro. --- diff --git a/include/deal.II/sundials/ida_interface.h b/include/deal.II/sundials/ida_interface.h index fb3728cd9b..d96650138d 100644 --- a/include/deal.II/sundials/ida_interface.h +++ b/include/deal.II/sundials/ida_interface.h @@ -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: /** diff --git a/source/sundials/ida_interface.cc b/source/sundials/ida_interface.cc index 54f69d1f6b..d3e61177df 100644 --- a/source/sundials/ida_interface.cc +++ b/source/sundials/ida_interface.cc @@ -428,6 +428,7 @@ namespace SUNDIALS copy(diff_id, differential_components()); status = IDAInit(ida_mem, t_dae_residual, 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; 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);