From 7669c933c7416a6202c41b4cbd97ffb3be7a4515 Mon Sep 17 00:00:00 2001 From: Steven Roberts Date: Tue, 10 Sep 2024 21:00:16 -0700 Subject: [PATCH] Add more asserts to controllers --- .../imexgus/sunadaptcontroller_imexgus.c | 2 -- .../soderlind/sunadaptcontroller_soderlind.c | 1 - src/sundials/sundials_adaptcontroller.c | 7 +++++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c b/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c index 650ffc52df..0bbcda4b0a 100644 --- a/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c +++ b/src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c @@ -127,8 +127,6 @@ SUNErrCode SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C, { SUNFunctionBegin(C->sunctx); - SUNAssert(hnew, SUN_ERR_ARG_CORRUPT); - /* order parameter to use */ const int ord = p + 1; diff --git a/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c b/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c index 17ef9493dc..ebee48b849 100644 --- a/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c +++ b/src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c @@ -299,7 +299,6 @@ SUNErrCode SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C, sunrealtype* hnew) { SUNFunctionBegin(C->sunctx); - SUNAssert(hnew, SUN_ERR_ARG_CORRUPT); /* order parameter to use */ const int ord = p + 1; diff --git a/src/sundials/sundials_adaptcontroller.c b/src/sundials/sundials_adaptcontroller.c index 39a56480d0..925d3fae50 100644 --- a/src/sundials/sundials_adaptcontroller.c +++ b/src/sundials/sundials_adaptcontroller.c @@ -18,6 +18,7 @@ #include #include +#include #include "sundials/sundials_errors.h" @@ -131,6 +132,9 @@ SUNErrCode SUNAdaptController_EstimateStep(SUNAdaptController C, sunrealtype h, SUNErrCode ier = SUN_SUCCESS; if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } SUNFunctionBegin(C->sunctx); + SUNAssert(isfinite(h), SUN_ERR_ARG_OUTOFRANGE); + SUNAssert(p > 0, SUN_ERR_ARG_OUTOFRANGE); + SUNAssert(dsm >= SUN_RCONST(0.0), SUN_ERR_ARG_OUTOFRANGE); SUNAssert(hnew, SUN_ERR_ARG_CORRUPT); *hnew = h; /* initialize output with identity */ if (C->ops->estimatestep) { ier = C->ops->estimatestep(C, h, p, dsm, hnew); } @@ -170,6 +174,7 @@ SUNErrCode SUNAdaptController_SetErrorBias(SUNAdaptController C, sunrealtype bia SUNErrCode ier = SUN_SUCCESS; if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } SUNFunctionBegin(C->sunctx); + SUNAssert(bias >= SUN_RCONST(1.0), SUN_ERR_ARG_OUTOFRANGE); if (C->ops->seterrorbias) { ier = C->ops->seterrorbias(C, bias); } return (ier); } @@ -180,6 +185,8 @@ SUNErrCode SUNAdaptController_UpdateH(SUNAdaptController C, sunrealtype h, SUNErrCode ier = SUN_SUCCESS; if (C == NULL) { return SUN_ERR_ARG_CORRUPT; } SUNFunctionBegin(C->sunctx); + SUNAssert(isfinite(h), SUN_ERR_ARG_OUTOFRANGE); + SUNAssert(dsm >= SUN_RCONST(0.0), SUN_ERR_ARG_OUTOFRANGE); if (C->ops->updateh) { ier = C->ops->updateh(C, h, dsm); } return (ier); }