Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUNStepper basics based on MRIStepInnerStepper #463

Open
wants to merge 62 commits into
base: develop
Choose a base branch
from

Conversation

balos1
Copy link
Member

@balos1 balos1 commented Apr 29, 2024

I am opening this PR as a draft to gather feedback. This renames/moves MRIStepInnerStepper to SUNStepper so that @Steven-Roberts and I can extend it for other purposes.

src/arkode/arkode.c Outdated Show resolved Hide resolved
src/arkode/arkode_arkstep.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper_impl.h Outdated Show resolved Hide resolved
@balos1
Copy link
Member Author

balos1 commented May 6, 2024

@drreynolds @gardner48 I have made the changes we discussed on Tuesday. Let me know what you think.

@balos1 balos1 changed the title move MRIStepInnerStepper to SUNStepper SUNStepper basics based on MRIStepInnerStepper May 6, 2024
Copy link
Collaborator

@drreynolds drreynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how clean this is now. I noticed a few items for comment (see below).

src/arkode/arkode_arkstep.c Outdated Show resolved Hide resolved
src/arkode/xbraid/arkode_xbraid.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
include/sundials/sundials_stepper.h Show resolved Hide resolved
include/sundials/sundials_stepper.h Outdated Show resolved Hide resolved
include/sundials/sundials_stepper.h Show resolved Hide resolved
include/sundials/sundials_stepper.h Show resolved Hide resolved
src/arkode/arkode_arkstep.c Outdated Show resolved Hide resolved
src/arkode/arkode_arkstep.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
src/arkode/arkode_arkstep.c Outdated Show resolved Hide resolved
include/sundials/sundials_stepper.h Show resolved Hide resolved
src/arkode/arkode_arkstep.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Show resolved Hide resolved
Copy link
Collaborator

@Steven-Roberts Steven-Roberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial pass at latest changes

src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
src/sundials/sundials_stepper_impl.h Show resolved Hide resolved
include/sundials/sundials_stepper.h Outdated Show resolved Hide resolved
src/sundials/sundials_stepper.c Outdated Show resolved Hide resolved
include/sundials/sundials_stepper.h Outdated Show resolved Hide resolved
@Steven-Roberts
Copy link
Collaborator

Steven-Roberts commented Aug 21, 2024

After some more thought and discussion with David on IDA and passing around yp, the primary issue I see is keeping it consistent with y. With operator splitting, for example, y jumps around between calls to evolve, and I don't see how to keep yp consistent. With MRI, the change in the forcing between stages can cause a similar issue. This is not something the outer methods can do and needs to be done in the inner SunStepper integrator.

I'd like to propose the following to make SunStepper self starting (all you need is y to reset then evolve):

  • Remove yp as arguments
  • To support an IDA SunStepper, have a constructor like
int IDACreateSUNStepper(void* inner_ida_mem, ConsistentYPrimeFn f, SUNStepper* stepper)

where there's a function which can be specified by users (we could have a default that uses IDACalcIC) to get yp given y.

src/arkode/arkode_mristep.c Show resolved Hide resolved
sunrealtype* tret);

typedef SUNErrCode (*SUNStepperFullRhsFn)(SUNStepper stepper, sunrealtype t,
N_Vector y, N_Vector f, int mode);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to propose removing the mode argument since it's specific to ARKODE and I don't see any general need for it. Currently, the MRI and operator splitting methods always use ARK_FULLRHS_OTHER mode, and the other modes are unused. Any objections/concerns?

Copy link
Collaborator

@drreynolds drreynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished reviewing the documentation.

CHANGELOG.md Outdated Show resolved Hide resolved
doc/arkode/guide/source/Usage/ARKStep/User_callable.rst Outdated Show resolved Hide resolved
doc/shared/RecentChanges.rst Outdated Show resolved Hide resolved
doc/shared/sunstepper/SUNStepper_Description.rst Outdated Show resolved Hide resolved
doc/shared/sunstepper/SUNStepper_Description.rst Outdated Show resolved Hide resolved
This section describes the virtual methods defined by the :c:type:`SUNStepper`
abstract base class.

An :c:type:`SUNStepper` *must* provide implementations of the following
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
An :c:type:`SUNStepper` *must* provide implementations of the following
A :c:type:`SUNStepper` *must* provide implementations of the following

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are ALL of these functions really "required" for all SUNStepper implementations, or are only some used in various circumstances (in which case a partial implementation could be sufficient)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the docs to indicate they are optional and determined by the "consumer" of the SUNStepper. I'll need to specify the required functionality in the operator splitting PR.

doc/shared/sunstepper/SUNStepper_Description.rst Outdated Show resolved Hide resolved
doc/shared/sunstepper/SUNStepper_Description.rst Outdated Show resolved Hide resolved
doc/shared/sunstepper/SUNStepper_Description.rst Outdated Show resolved Hide resolved
doc/shared/sunstepper/SUNStepper_Description.rst Outdated Show resolved Hide resolved
Copy link
Collaborator

@drreynolds drreynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great.

We may need to be careful with the SUNStepper / MRIStepInnerStepper compatibility since the MRI adaptivity PR #564 adds a couple more routines to the MRIStepInnerStepper, so a "unified" SUNStepper would need those two extra ops to be used in an adaptive MRI sense. I also recommend that in a soon-to-follow release we should consolidate on only the SUNStepper, retaining relevant wrapping as necessary for backwards-compatibility with existing MRIStepInnerStepper objects.

As I mentioned in a comment on the docs, I sincerely doubt that any of the potential "consuming" packages (e.g., SplitStep, ForcingStep, discrete adjoint integration, XBraid, MRIStep) actually require the full set of SUNStepper ops to be implemented. If each consuming package clearly documented their requirements, then all "consumers" could standardize on SUNStepper.

include/arkode/arkode_mristep.h Show resolved Hide resolved
include/sundials/sundials_stepper.h Outdated Show resolved Hide resolved
src/arkode/arkode_io.c Outdated Show resolved Hide resolved
ARKodeMem ark_mem = (ARKodeMem)arkode_mem;

SUNErrCode err = SUNStepper_Create(ark_mem->sunctx, stepper);
if (err != SUN_SUCCESS) { return ARK_SUNSTEPPER_ERR; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this invoke arkProcessError?

swig/sundials/fsundials_stepper.i Outdated Show resolved Hide resolved
SUNStepperFullRhsFn fullrhs;
SUNStepperResetFn reset;
SUNStepperSetStopTimeFn setstoptime;
SUNStepperSetForcingFn setforcing;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: unlike MRIStepInnerStepper, SUNStepper does not include properties for forcing. It defers that to the implementation. This streamlines this struct, removes the need for a forcing "getter," and can reduce storage (saves a N_Vector for ForcingStep over previous version).

.. _SUNStepper.Description.BaseMethods.SteppingFunctions:

Stepping Functions
^^^^^^^^^^^^^^^^^^
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: Unlike MRIStepInnerStepper, the functions in this section are publicly documented. They can be hidden if folks think that's preferable.

Attaching and Accessing the Content Pointer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. c:function:: SUNErrCode SUNStepper_SetContent(SUNStepper stepper, void *content)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: these functions are new to SUNStepper compared to MRIStepInnerStepper. Since the SUNStepper struct is private, I think this is the proper way to access the last_flag.

SUNErrCode SUNStepper_SetOneStepFn(SUNStepper stepper, SUNStepperOneStepFn fn);

SUNDIALS_EXPORT
SUNErrCode SUNStepper_SetFullRhsFn(SUNStepper stepper, SUNStepperFullRhsFn fn);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: there is no analogous SUNStepper_FullRhs. This is following what MRI does where it was presumably excluded because the full RHS functions are private in ARKODE. I can make a public SUNStepper_FullRhs function if folks want.

This section describes the virtual methods defined by the :c:type:`SUNStepper`
abstract base class.

An :c:type:`SUNStepper` *must* provide implementations of the following
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the docs to indicate they are optional and determined by the "consumer" of the SUNStepper. I'll need to specify the required functionality in the operator splitting PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants