diff --git a/include/sundials/sundials_stepper.h b/include/sundials/sundials_stepper.h index 859aa78240..ef4d5477d5 100644 --- a/include/sundials/sundials_stepper.h +++ b/include/sundials/sundials_stepper.h @@ -15,6 +15,8 @@ #include +#include "sundials/sundials_export.h" + #ifdef __cplusplus extern "C" { #endif @@ -86,8 +88,9 @@ SUNErrCode SUNStepper_Advance(SUNStepper stepper, sunrealtype t0, int* stop_reason); SUNDIALS_EXPORT -SUNErrCode SUNStepper_Step(SUNStepper stepper, sunrealtype t0, sunrealtype tout, - N_Vector y, sunrealtype* tret, int* stop_reason); +SUNErrCode SUNStepper_OneStep(SUNStepper stepper, sunrealtype t0, + sunrealtype tout, N_Vector y, sunrealtype* tret, + int* stop_reason); SUNDIALS_EXPORT SUNErrCode SUNStepper_TryStep(SUNStepper stepper, sunrealtype t0, diff --git a/src/arkode/arkode_arkstep.c b/src/arkode/arkode_arkstep.c index ea18cb2c83..a68936ab1b 100644 --- a/src/arkode/arkode_arkstep.c +++ b/src/arkode/arkode_arkstep.c @@ -348,47 +348,6 @@ int ARKStepReInit(void* arkode_mem, ARKRhsFn fe, ARKRhsFn fi, sunrealtype t0, return (ARK_SUCCESS); } -/*------------------------------------------------------------------------------ - ARKStepCreateMRIStepInnerStepper - - Wraps an ARKStep memory structure as an MRIStep inner stepper. - ----------------------------------------------------------------------------*/ -int ARKStepCreateMRIStepInnerStepper(void* inner_arkode_mem, - MRIStepInnerStepper* stepper) -{ - int retval; - ARKodeMem ark_mem; - ARKodeARKStepMem step_mem; - - retval = arkStep_AccessARKODEStepMem(inner_arkode_mem, - "ARKStepCreateMRIStepInnerStepper", - &ark_mem, &step_mem); - if (retval) - { - arkProcessError(NULL, ARK_ILL_INPUT, __LINE__, __func__, __FILE__, - "The ARKStep memory pointer is NULL"); - return ARK_ILL_INPUT; - } - - retval = MRIStepInnerStepper_Create(ark_mem->sunctx, stepper); - if (retval != ARK_SUCCESS) { return (retval); } - - retval = MRIStepInnerStepper_SetContent(*stepper, inner_arkode_mem); - if (retval != ARK_SUCCESS) { return (retval); } - - retval = MRIStepInnerStepper_SetEvolveFn(*stepper, arkStep_MRIStepInnerEvolve); - if (retval != ARK_SUCCESS) { return (retval); } - - retval = MRIStepInnerStepper_SetFullRhsFn(*stepper, - arkStep_MRIStepInnerFullRhs); - if (retval != ARK_SUCCESS) { return (retval); } - - retval = MRIStepInnerStepper_SetResetFn(*stepper, arkStep_MRIStepInnerReset); - if (retval != ARK_SUCCESS) { return (retval); } - - return (ARK_SUCCESS); -} - /*=============================================================== Interface routines supplied to ARKODE ===============================================================*/ @@ -3172,11 +3131,11 @@ int arkStep_ComputeSolutions_MassFixed(ARKodeMem ark_mem, sunrealtype* dsmPtr) int ARKStepCreateSUNStepper(void* inner_arkode_mem, SUNStepper* stepper) { int retval; - ARKodeMem ark_mem; + ARKodeMem ark_mem = (ARKodeMem)inner_arkode_mem; ARKodeARKStepMem step_mem; retval = arkStep_AccessStepMem(inner_arkode_mem, "ARKStepCreateSUNStepper", - &ark_mem, &step_mem); + &step_mem); if (retval) { arkProcessError(NULL, ARK_ILL_INPUT, __LINE__, __func__, __FILE__, @@ -3193,6 +3152,12 @@ int ARKStepCreateSUNStepper(void* inner_arkode_mem, SUNStepper* stepper) retval = SUNStepper_SetAdvanceFn(*stepper, arkStep_SUNStepperAdvance); if (retval != ARK_SUCCESS) { return (retval); } + retval = SUNStepper_SetOneStepFn(*stepper, arkStep_SUNStepperOneStep); + if (retval != ARK_SUCCESS) { return (retval); } + + retval = SUNStepper_SetTryStepFn(*stepper, arkStep_SUNStepperTryStep); + if (retval != ARK_SUCCESS) { return (retval); } + retval = SUNStepper_SetFullRhsFn(*stepper, arkStep_SUNStepperFullRhs); if (retval != ARK_SUCCESS) { return (retval); } @@ -3233,11 +3198,11 @@ int arkStep_SUNStepperAdvance(SUNStepper stepper, sunrealtype t0, if (retval != ARK_SUCCESS) { return (retval); } /* set the stop time */ - retval = ARKStepSetStopTime(arkode_mem, tout); + retval = ARKodeSetStopTime(arkode_mem, tout); if (retval != ARK_SUCCESS) { return (retval); } /* evolve inner ODE */ - *stop_reason = ARKStepEvolve(arkode_mem, tout, y, tret, ARK_NORMAL); + *stop_reason = ARKodeEvolve(arkode_mem, tout, y, tret, ARK_NORMAL); if (*stop_reason < 0) { return (*stop_reason); } /* disable inner forcing */ @@ -3270,12 +3235,8 @@ int arkStep_SUNStepperOneStep(SUNStepper stepper, sunrealtype t0, retval = arkStep_SetInnerForcing(arkode_mem, tshift, tscale, forcing, nforcing); if (retval != ARK_SUCCESS) { return (retval); } - /* set the stop time */ - retval = ARKStepSetStopTime(arkode_mem, tout); - if (retval != ARK_SUCCESS) { return (retval); } - /* evolve inner ODE */ - *stop_reason = ARKStepEvolve(arkode_mem, tout, y, tret, ARK_ONE_STEP); + *stop_reason = ARKodeEvolve(arkode_mem, tout, y, tret, ARK_ONE_STEP); if (*stop_reason < 0) { return (*stop_reason); } /* disable inner forcing */ @@ -3308,10 +3269,6 @@ int arkStep_SUNStepperTryStep(SUNStepper stepper, sunrealtype t0, retval = arkStep_SetInnerForcing(arkode_mem, tshift, tscale, forcing, nforcing); if (retval != ARK_SUCCESS) { return (retval); } - /* set the stop time */ - retval = ARKStepSetStopTime(arkode_mem, tout); - if (retval != ARK_SUCCESS) { return (retval); } - /* try to evolve inner ODE */ retval = arkStep_TryStep(arkode_mem, t0, tout, y, tret, stop_reason); if (retval != ARK_SUCCESS) { return (retval); } @@ -3359,7 +3316,10 @@ int arkStep_SUNStepperReset(SUNStepper stepper, sunrealtype tR, N_Vector yR) retval = SUNStepper_GetContent(stepper, &arkode_mem); if (retval != ARK_SUCCESS) { return (retval); } - return (ARKStepReset(arkode_mem, tR, yR)); + retval = ARKodeReset(arkode_mem, tR, yR); + if (retval != ARK_SUCCESS) { return (retval); } + + return retval; } /*--------------------------------------------------------------- @@ -3380,8 +3340,7 @@ int ARKStepCreateMRIStepInnerStepper(void* inner_arkode_mem, ARKodeARKStepMem step_mem; retval = arkStep_AccessStepMem(inner_arkode_mem, - "ARKStepCreateMRIStepInnerStepper", &ark_mem, - &step_mem); + "ARKStepCreateMRIStepInnerStepper", &step_mem); if (retval) { arkProcessError(NULL, ARK_ILL_INPUT, __LINE__, __func__, __FILE__, @@ -3817,11 +3776,11 @@ int arkStep_TryStep(void* arkode_mem, sunrealtype tstart, sunrealtype tstop, if (y == NULL) { return ARK_ILL_INPUT; } /* Reset ARKStep state */ - flag = ARKStepReset(arkode_mem, tstart, y); + flag = ARKodeReset(arkode_mem, tstart, y); if (flag != ARK_SUCCESS) { return flag; } /* Set the time step size */ - flag = ARKStepSetInitStep(arkode_mem, tstop - tstart); + flag = ARKodeSetInitStep(arkode_mem, tstop - tstart); if (flag != ARK_SUCCESS) { return flag; } /* Ignore temporal error test result and force step to pass */ @@ -3829,7 +3788,7 @@ int arkStep_TryStep(void* arkode_mem, sunrealtype tstart, sunrealtype tstop, if (flag != ARK_SUCCESS) { return flag; } /* Take step, check flag below */ - tmp_flag = ARKStepEvolve(arkode_mem, tstop, y, tret, ARK_ONE_STEP); + tmp_flag = ARKodeEvolve(arkode_mem, tstop, y, tret, ARK_ONE_STEP); /* Re-enable temporal error test check */ flag = arkSetForcePass(arkode_mem, SUNFALSE); diff --git a/src/arkode/arkode_impl.h b/src/arkode/arkode_impl.h index b94e9a2ff2..daed0b1532 100644 --- a/src/arkode/arkode_impl.h +++ b/src/arkode/arkode_impl.h @@ -34,6 +34,7 @@ #include "arkode_root_impl.h" #include "arkode_types_impl.h" #include "sundials_logger_impl.h" +#include "sundials_macros.h" #include "sundials_stepper_impl.h" #ifdef __cplusplus /* wrapper to enable C++ usage */ @@ -638,6 +639,7 @@ int arkAccessHAdaptMem(void* arkode_mem, const char* fname, ARKodeMem* ark_mem, int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq, sunrealtype adapt_params[3]); +int arkSetAdaptivityFn(void* arkode_mem, ARKAdaptFn hfun, void* h_data); int arkAllocSUNStepperForcing(SUNStepper stepper, int count, N_Vector tmpl); int arkFreeSUNStepperForcing(SUNStepper stepper); diff --git a/src/sundials/sundials_stepper.c b/src/sundials/sundials_stepper.c index 8bb2cbadac..e543c93ca5 100644 --- a/src/sundials/sundials_stepper.c +++ b/src/sundials/sundials_stepper.c @@ -14,19 +14,19 @@ SUNErrCode SUNStepper_Create(SUNContext sunctx, SUNStepper* stepper_ptr) SUNFunctionBegin(sunctx); SUNStepper stepper = NULL; - stepper = malloc(sizeof(*stepper)); + stepper = malloc(sizeof(*stepper)); SUNAssert(stepper, SUN_ERR_MALLOC_FAIL); - stepper->content = NULL; - stepper->sunctx = sunctx; - stepper->last_flag = SUN_SUCCESS; - stepper->forcing = NULL; - stepper->nforcing = 0; + stepper->content = NULL; + stepper->sunctx = sunctx; + stepper->last_flag = SUN_SUCCESS; + stepper->forcing = NULL; + stepper->nforcing = 0; stepper->nforcing_allocated = 0; - stepper->tshift = SUN_RCONST(0.0); - stepper->tscale = SUN_RCONST(0.0); - stepper->fused_scalars = NULL; - stepper->fused_vectors = NULL; + stepper->tshift = SUN_RCONST(0.0); + stepper->tscale = SUN_RCONST(0.0); + stepper->fused_scalars = NULL; + stepper->fused_vectors = NULL; stepper->ops = malloc(sizeof(*(stepper->ops))); SUNAssert(stepper->ops, SUN_ERR_MALLOC_FAIL); @@ -75,8 +75,9 @@ SUNErrCode SUNStepper_Advance(SUNStepper stepper, sunrealtype t0, return SUN_ERR_NOT_IMPLEMENTED; } -SUNErrCode SUNStepper_Step(SUNStepper stepper, sunrealtype t0, sunrealtype tout, - N_Vector y, sunrealtype* tret, int* stop_reason) +SUNErrCode SUNStepper_OneStep(SUNStepper stepper, sunrealtype t0, + sunrealtype tout, N_Vector y, sunrealtype* tret, + int* stop_reason) { SUNFunctionBegin(stepper->sunctx); if (stepper->ops->onestep)