From 1b18e8c0ef2833fed53194a118ad8552170aff6d Mon Sep 17 00:00:00 2001 From: "Balos, Cody, J" Date: Fri, 1 Nov 2024 16:53:31 -0700 Subject: [PATCH] check error codes --- include/arkode/arkode.h | 3 +- src/arkode/arkode_arkstep.c | 66 ++++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/include/arkode/arkode.h b/include/arkode/arkode.h index 1124c37f93..ac14bd78f8 100644 --- a/include/arkode/arkode.h +++ b/include/arkode/arkode.h @@ -143,7 +143,8 @@ extern "C" { #define ARK_STEPPER_UNSUPPORTED -48 #define ARK_SUNSTEPPER_ERR -49 -#define ARK_ADJ_RECOMPUTE_FAIL -50 +#define ARK_ADJ_CHECKPOINT_FAIL -50 +#define ARK_ADJ_RECOMPUTE_FAIL -51 #define ARK_UNRECOGNIZED_ERROR -99 diff --git a/src/arkode/arkode_arkstep.c b/src/arkode/arkode_arkstep.c index 229f7b1b17..920b15b0c7 100644 --- a/src/arkode/arkode_arkstep.c +++ b/src/arkode/arkode_arkstep.c @@ -1740,14 +1740,32 @@ int arkStep_TakeStep_Z(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr) if (ark_mem->checkpoint_scheme) { sunbooleantype do_save; - SUNAdjointCheckpointScheme_ShouldWeSave(ark_mem->checkpoint_scheme, - ark_mem->checkpoint_step_idx, 0, - ark_mem->tcur, &do_save); + SUNErrCode errcode = + SUNAdjointCheckpointScheme_ShouldWeSave(ark_mem->checkpoint_scheme, + ark_mem->checkpoint_step_idx, 0, + ark_mem->tcur, &do_save); + if (errcode) + { + arkProcessError(ark_mem, ARK_ADJ_CHECKPOINT_FAIL, __LINE__, __func__, + __FILE__, + "SUNAdjointCheckpointScheme_ShouldWeSave returned %d", + errcode); + } + if (do_save) { - SUNAdjointCheckpointScheme_InsertVector(ark_mem->checkpoint_scheme, - ark_mem->checkpoint_step_idx, 0, - ark_mem->tcur, ark_mem->ycur); + errcode = + SUNAdjointCheckpointScheme_InsertVector(ark_mem->checkpoint_scheme, + ark_mem->checkpoint_step_idx, 0, + ark_mem->tcur, ark_mem->ycur); + + if (errcode) + { + arkProcessError(ark_mem, ARK_ADJ_CHECKPOINT_FAIL, __LINE__, __func__, + __FILE__, + "SUNAdjointCheckpointScheme_InsertVector returned %d", + errcode); + } } } } @@ -2022,14 +2040,31 @@ int arkStep_TakeStep_Z(ARKodeMem ark_mem, sunrealtype* dsmPtr, int* nflagPtr) if (ark_mem->checkpoint_scheme) { sunbooleantype do_save; - SUNAdjointCheckpointScheme_ShouldWeSave(ark_mem->checkpoint_scheme, - ark_mem->checkpoint_step_idx, is, - ark_mem->tcur, &do_save); + SUNErrCode errcode = + SUNAdjointCheckpointScheme_ShouldWeSave(ark_mem->checkpoint_scheme, + ark_mem->checkpoint_step_idx, + is, ark_mem->tcur, &do_save); + if (errcode) + { + arkProcessError(ark_mem, ARK_ADJ_CHECKPOINT_FAIL, __LINE__, __func__, + __FILE__, + "SUNAdjointCheckpointScheme_ShouldWeSave returned %d", + errcode); + } + if (do_save) { SUNAdjointCheckpointScheme_InsertVector(ark_mem->checkpoint_scheme, ark_mem->checkpoint_step_idx, is, ark_mem->tcur, ark_mem->ycur); + + if (errcode) + { + arkProcessError(ark_mem, ARK_ADJ_CHECKPOINT_FAIL, __LINE__, __func__, + __FILE__, + "SUNAdjointCheckpointScheme_InsertVector returned %d", + errcode); + } } } @@ -2314,9 +2349,16 @@ int arkStep_TakeStep_ERK_Adjoint(ARKodeMem ark_mem, sunrealtype* dsmPtr, /* Throw away the step solution */ sunrealtype checkpoint_t = 0.0; N_Vector checkpoint = N_VGetSubvector_ManyVector(ark_mem->tempv2, 0); - SUNAdjointCheckpointScheme_LoadVector(ark_mem->checkpoint_scheme, - adj_stepper->step_idx, 0, 0, - &checkpoint, &checkpoint_t); + SUNErrCode errcode = + SUNAdjointCheckpointScheme_LoadVector(ark_mem->checkpoint_scheme, + adj_stepper->step_idx, 0, 0, + &checkpoint, &checkpoint_t); + if (errcode) + { + arkProcessError(ark_mem, ARK_ADJ_CHECKPOINT_FAIL, __LINE__, __func__, + __FILE__, + "SUNAdjointCheckpointScheme_LoadVector returned %d", errcode); + } /* Now compute the time step solution. We cannot use arkStep_ComputeSolutions because the adjoint calculation for the time step solution is different than the forward case. */