Skip to content

Commit

Permalink
wrap SUNStepper as MRIStepInnerStepper
Browse files Browse the repository at this point in the history
  • Loading branch information
balos1 committed May 6, 2024
1 parent 536c14b commit 9cc9567
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/arkode/arkode_mristep.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ SUNDIALS_EXPORT int MRIStepInnerStepper_Create(SUNContext sunctx,
MRIStepInnerStepper* stepper);

SUNDIALS_EXPORT int MRIStepInnerStepper_CreateFromSUNStepper(
SUNContext sunctx, SUNStepper sunstepper, MRIStepInnerStepper* stepper);
SUNStepper sunstepper, MRIStepInnerStepper* stepper);

SUNDIALS_EXPORT int MRIStepInnerStepper_Free(MRIStepInnerStepper* stepper);

Expand Down
41 changes: 41 additions & 0 deletions src/arkode/arkode_mristep.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
* This is the implementation file for ARKODE's MRI time stepper module.
* ---------------------------------------------------------------------------*/

#include "arkode/arkode_mristep.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sundials/sundials_math.h>
#include <sunnonlinsol/sunnonlinsol_newton.h>

#include "arkode/arkode.h"
#include "arkode_impl.h"
#include "arkode_interp_impl.h"
#include "arkode_mristep_impl.h"
Expand Down Expand Up @@ -2721,6 +2724,18 @@ int MRIStepInnerStepper_Create(SUNContext sunctx, MRIStepInnerStepper* stepper)
return (ARK_SUCCESS);
}

int MRIStepInnerStepper_CreateFromSUNStepper(SUNStepper sunstepper,
MRIStepInnerStepper* stepper)
{
MRIStepInnerStepper_Create(sunstepper->sunctx, stepper);
MRIStepInnerStepper_SetContent(*stepper, sunstepper);
MRIStepInnerStepper_SetEvolveFn(*stepper, mriStepInnerStepper_EvolveSUNStepper);
MRIStepInnerStepper_SetFullRhsFn(*stepper,
mriStepInnerStepper_FullRhsSUNStepper);
MRIStepInnerStepper_SetResetFn(*stepper, mriStepInnerStepper_ResetSUNStepper);
return (ARK_SUCCESS);
}

int MRIStepInnerStepper_Free(MRIStepInnerStepper* stepper)
{
if (*stepper == NULL) { return ARK_SUCCESS; }
Expand Down Expand Up @@ -2921,6 +2936,15 @@ int mriStepInnerStepper_Evolve(MRIStepInnerStepper stepper, sunrealtype t0,
return stepper->last_flag;
}

int mriStepInnerStepper_EvolveSUNStepper(MRIStepInnerStepper stepper,
sunrealtype t0, sunrealtype tout,
N_Vector y)
{
SUNStepper sunstepper = (SUNStepper)stepper->content;
stepper->last_flag = sunstepper->ops->advance(sunstepper, t0, tout, y);
return stepper->last_flag;
}

/* Compute the full RHS for inner (fast) time scale TODO(DJG): This function can
be made optional when fullrhs is not called unconditionally by the ARKODE
infrastructure e.g., in arkInitialSetup, arkYddNorm, and arkCompleteStep. */
Expand All @@ -2935,6 +2959,15 @@ int mriStepInnerStepper_FullRhs(MRIStepInnerStepper stepper, sunrealtype t,
return stepper->last_flag;
}

int mriStepInnerStepper_FullRhsSUNStepper(MRIStepInnerStepper stepper,
sunrealtype t, N_Vector y, N_Vector f,
int mode)
{
SUNStepper sunstepper = (SUNStepper)stepper->content;
stepper->last_flag = sunstepper->ops->fullrhs(sunstepper, t, y, f, mode);
return stepper->last_flag;
}

/* Reset the inner (fast) stepper state */
int mriStepInnerStepper_Reset(MRIStepInnerStepper stepper, sunrealtype tR,
N_Vector yR)
Expand All @@ -2960,6 +2993,14 @@ int mriStepInnerStepper_Reset(MRIStepInnerStepper stepper, sunrealtype tR,
}
}

int mriStepInnerStepper_ResetSUNStepper(MRIStepInnerStepper stepper,
sunrealtype tR, N_Vector yR)
{
SUNStepper sunstepper = (SUNStepper)stepper->content;
stepper->last_flag = sunstepper->ops->reset(sunstepper, tR, yR);
return stepper->last_flag;
}

/* Allocate MRI forcing and fused op workspace vectors if necessary */
int mriStepInnerStepper_AllocVecs(MRIStepInnerStepper stepper, int count,
N_Vector tmpl)
Expand Down
8 changes: 8 additions & 0 deletions src/arkode/arkode_mristep_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,18 @@ int mriStep_NlsConvTest(SUNNonlinearSolver NLS, N_Vector y, N_Vector del,
int mriStepInnerStepper_HasRequiredOps(MRIStepInnerStepper stepper);
int mriStepInnerStepper_Evolve(MRIStepInnerStepper stepper, sunrealtype t0,
sunrealtype tout, N_Vector y);
int mriStepInnerStepper_EvolveSUNStepper(MRIStepInnerStepper stepper,
sunrealtype t0, sunrealtype tout,
N_Vector y);
int mriStepInnerStepper_FullRhs(MRIStepInnerStepper stepper, sunrealtype t,
N_Vector y, N_Vector f, int mode);
int mriStepInnerStepper_FullRhsSUNStepper(MRIStepInnerStepper stepper,
sunrealtype t, N_Vector y, N_Vector f,
int mode);
int mriStepInnerStepper_Reset(MRIStepInnerStepper stepper, sunrealtype tR,
N_Vector yR);
int mriStepInnerStepper_ResetSUNStepper(MRIStepInnerStepper stepper,
sunrealtype tR, N_Vector yR);
int mriStepInnerStepper_AllocVecs(MRIStepInnerStepper stepper, int count,
N_Vector tmpl);
int mriStepInnerStepper_Resize(MRIStepInnerStepper stepper, ARKVecResizeFn resize,
Expand Down

0 comments on commit 9cc9567

Please sign in to comment.