Skip to content

Commit

Permalink
bring up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
balos1 committed Aug 20, 2024
1 parent 4be592c commit 1a92308
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 74 deletions.
7 changes: 5 additions & 2 deletions include/sundials/sundials_stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <sundials/sundials_core.h>

#include "sundials/sundials_export.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -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,
Expand Down
79 changes: 19 additions & 60 deletions src/arkode/arkode_arkstep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
===============================================================*/
Expand Down Expand Up @@ -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__,
Expand All @@ -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); }

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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); }
Expand Down Expand Up @@ -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;
}

/*---------------------------------------------------------------
Expand All @@ -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__,
Expand Down Expand Up @@ -3817,19 +3776,19 @@ 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 */
flag = arkSetForcePass(arkode_mem, SUNTRUE);
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);
Expand Down
2 changes: 2 additions & 0 deletions src/arkode/arkode_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 13 additions & 12 deletions src/sundials/sundials_stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1a92308

Please sign in to comment.