Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
balos1 committed Jun 17, 2024
1 parent f97e71b commit a030d57
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
12 changes: 11 additions & 1 deletion include/sundials/sundials_stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
extern "C" {
#endif

typedef _SUNDIALS_STRUCT_ SUNStepper_s* SUNStepper;
typedef int (*SUNJacFn)(sunrealtype t, N_Vector y, N_Vector fy, SUNMatrix Jac,
void* user_data, N_Vector tmp1, N_Vector tmp2,
N_Vector tmp3);

typedef int (*SUNJacTimesFn)(N_Vector v, N_Vector Jv, sunrealtype t, N_Vector y,
N_Vector fy, void* user_data, N_Vector tmp);

typedef _SUNDIALS_STRUCT_ SUNStepper_* SUNStepper;

typedef int (*SUNStepperAdvanceFn)(SUNStepper stepper, sunrealtype t0,
sunrealtype tout, N_Vector y,
Expand Down Expand Up @@ -87,6 +94,9 @@ SUNErrCode SUNStepper_TryStep(SUNStepper stepper, sunrealtype t0,
sunrealtype tout, N_Vector y, sunrealtype* tret,
int* stop_reason);

SUNDIALS_EXPORT
SUNErrCode SUNStepper_Reset(SUNStepper stepper, sunrealtype tR, N_Vector yR);

#ifdef __cplusplus
}
#endif
Expand Down
38 changes: 28 additions & 10 deletions src/sundials/sundials_stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,35 @@
#include "sundials/sundials_nvector.h"
#include "sundials_stepper_impl.h"

SUNErrCode SUNStepper_Create(SUNContext sunctx, SUNStepper* stepper)
SUNErrCode SUNStepper_Create(SUNContext sunctx, SUNStepper* stepper_ptr)
{
SUNFunctionBegin(sunctx);

*stepper = NULL;
*stepper = (SUNStepper)malloc(sizeof(**stepper));
SUNStepper stepper = NULL;
stepper = malloc(sizeof(*stepper));
SUNAssert(stepper, SUN_ERR_MALLOC_FAIL);

memset(*stepper, 0, sizeof(**stepper));
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)->ops = (SUNStepper_Ops)malloc(sizeof(*((*stepper)->ops)));
SUNAssert((*stepper)->ops, SUN_ERR_MALLOC_FAIL);
stepper->ops = malloc(sizeof(*(stepper->ops)));
SUNAssert(stepper->ops, SUN_ERR_MALLOC_FAIL);

memset((*stepper)->ops, 0, sizeof(*((*stepper)->ops)));
stepper->ops->advance = NULL;
stepper->ops->onestep = NULL;
stepper->ops->trystep = NULL;
stepper->ops->fullrhs = NULL;
stepper->ops->reset = NULL;

/* initialize stepper data */
(*stepper)->last_flag = SUN_SUCCESS;
(*stepper)->sunctx = sunctx;
*stepper_ptr = stepper;

return SUN_SUCCESS;
}
Expand Down Expand Up @@ -87,6 +98,13 @@ SUNErrCode SUNStepper_TryStep(SUNStepper stepper, sunrealtype t0,
return SUN_ERR_NOT_IMPLEMENTED;
}

SUNErrCode SUNStepper_Reset(SUNStepper stepper, sunrealtype tR, N_Vector yR)
{
SUNFunctionBegin(stepper->sunctx);
if (stepper->ops->advance) { return stepper->ops->reset(stepper, tR, yR); }
return SUN_ERR_NOT_IMPLEMENTED;
}

SUNErrCode SUNStepper_SetContent(SUNStepper stepper, void* content)
{
SUNFunctionBegin(stepper->sunctx);
Expand Down
6 changes: 3 additions & 3 deletions src/sundials/sundials_stepper_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
extern "C" {
#endif

typedef struct SUNStepper_Ops_s* SUNStepper_Ops;
typedef struct SUNStepper_Ops_* SUNStepper_Ops;

struct SUNStepper_Ops_s
struct SUNStepper_Ops_
{
SUNStepperAdvanceFn advance;
SUNStepperOneStepFn onestep;
Expand All @@ -31,7 +31,7 @@ struct SUNStepper_Ops_s
SUNStepperResetFn reset;
};

struct SUNStepper_s
struct SUNStepper_
{
/* stepper specific content and operations */
void* content;
Expand Down

0 comments on commit a030d57

Please sign in to comment.