diff --git a/doc/arkode/guide/source/Usage/ARKStep/ASA.rst b/doc/arkode/guide/source/Usage/ARKStep/ASA.rst index bbb58e3aae..19cf1d5776 100644 --- a/doc/arkode/guide/source/Usage/ARKStep/ASA.rst +++ b/doc/arkode/guide/source/Usage/ARKStep/ASA.rst @@ -3,20 +3,53 @@ Adjoint Sensitivity Analysis ============================ +The previous sections discuss using ARKStep for the intergation of forward ODE models. +This section discusses how to use ARKStep for adjoint sensitivity analysis as introduced +in :numref:`ARKODE.Mathematics.ASA`. To use ARKStep for ASA, users simply setup the forward +integration as usual (following :numref:`ARKODE.Usage.Skeleton`) with one exception: +a :c:type:`SUNAdjointCheckpointScheme` object must be provided to the forward ARKStep stepper +creating a :c:type:`SUNAdjointCheckpointScheme` object and then calling +:c:func:`ARKodeSetAdjointCheckpointScheme` before the call to the :c:func:`ARKodeEvolve` +function. After the forward model integration code, a :c:type:`SUNAdjointStepper` object +can be created for the adjoint model integration by calling :c:func:`ARKStepCreateAdjointStepper`. +The code snippet below demonstrates these steps in brief and the example code +``examples/arkode/C_serial/ark_lotka_volterra_asa.c`` demonstrates these steps in detail. + +.. code-block:: C + + // 1. Create a SUNAdjointCheckpointScheme object + + // 2. Setup ARKStep for forward integration + + // 3. Attach the SUNAdjointCheckpointScheme + + // 4. Evolve the forward model + + // 5. Create the SUNAdjointStepper + + // 6. Setup the adjoint model + + // 7. Evolve the adjoint model + + // 8. Cleanup + + + +User Callable Functions +----------------------- + This section describes ARKStep-specific user-callable functions for performing adjoint sensitivity analysis with methods with ARKStep. - .. c:function:: int ARKStepCreateAdjointStepper(void* arkode_mem, N_Vector sf, SUNAdjointStepper* adj_stepper_ptr) - Creates a :c:type:`SUNAdjointStepper` object compatible with the provided ARKStep instance for + Creates a :c:type:`SUNAdjointStepper` object compatible with the provided ARKStep instance for integrating the adjoint sensitivity system :eq:`ARKODE_ADJOINT_ODE`. :param arkode_mem: a pointer to the ARKStep memory block. :param sf: the sensitivity vector holding the adjoint system terminal condition. - This must be an instance of the ManyVector ``N_Vector`` implementation with two subvectors. - The first subvector must hold :math:`\partial g/\partial y |_{t=t_f} \in \mathbb{R}^N` and the second subvector must - hold :math:`\partial g / \partial p |_{t=t_f} \in \mathbb{R}^d`. + This must be an instance of the ManyVector ``N_Vector`` implementation with two subvectors. + The first subvector must hold :math:`\partial g/\partial y |_{t=t_f} \in \mathbb{R}^N` and the second subvector must hold :math:`\partial g / \partial p |_{t=t_f} \in \mathbb{R}^d`. :param adj_stepper_ptr: the newly created :c:type:`SUNAdjointStepper` object. :return: diff --git a/doc/arkode/guide/source/sunadjoint/index.rst b/doc/arkode/guide/source/sunadjoint/index.rst index 12481eb0fc..6259c2de26 100644 --- a/doc/arkode/guide/source/sunadjoint/index.rst +++ b/doc/arkode/guide/source/sunadjoint/index.rst @@ -11,7 +11,7 @@ SUNDIALS Copyright End ---------------------------------------------------------------- -.. _SUNAdaptController: +.. _SUNAdjoint: ########################### Adjoint Sensitivty Analysis @@ -24,6 +24,7 @@ sensitivity analysis (ASA). The API itself does not implement ASA, but it provid interface for ASA capabilties implemented in the SUNDIALS packages. Right now it supports :ref:`the ASA capabilties in ARKODE `, while the ASA capabilities in :ref:`CVODES ` and :ref:`IDAS ` must be used directly. +*Users should read the package specific sections on ASA capabiltiies before this section.* .. toctree:: :maxdepth: 1 diff --git a/doc/shared/sunadjoint/SUNAdjointCheckpointScheme.rst b/doc/shared/sunadjoint/SUNAdjointCheckpointScheme.rst deleted file mode 100644 index ff2669e666..0000000000 --- a/doc/shared/sunadjoint/SUNAdjointCheckpointScheme.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. - ---------------------------------------------------------------- - SUNDIALS Copyright Start - Copyright (c) 2002-2024, Lawrence Livermore National Security - and Southern Methodist University. - All rights reserved. - - See the top-level LICENSE and NOTICE files for details. - - SPDX-License-Identifier: BSD-3-Clause - SUNDIALS Copyright End - ---------------------------------------------------------------- - -.. _SUNAdjoint.CheckpointScheme: - -The SUNAdjointCheckpointScheme API -================================== diff --git a/doc/shared/sunadjoint/SUNAdjointStepper.rst b/doc/shared/sunadjoint/SUNAdjointStepper.rst deleted file mode 100644 index 6ef50ab43b..0000000000 --- a/doc/shared/sunadjoint/SUNAdjointStepper.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. - ---------------------------------------------------------------- - SUNDIALS Copyright Start - Copyright (c) 2002-2024, Lawrence Livermore National Security - and Southern Methodist University. - All rights reserved. - - See the top-level LICENSE and NOTICE files for details. - - SPDX-License-Identifier: BSD-3-Clause - SUNDIALS Copyright End - ---------------------------------------------------------------- - -.. _SUNAdjoint.Solver: - -The SUNAdjointStepper API -======================== diff --git a/doc/shared/sunadjoint/SUNAdjoint_Description.rst b/doc/shared/sunadjoint/SUNAdjoint_Description.rst index b1ac73b464..f1a925db42 100644 --- a/doc/shared/sunadjoint/SUNAdjoint_Description.rst +++ b/doc/shared/sunadjoint/SUNAdjoint_Description.rst @@ -11,4 +11,363 @@ SUNDIALS Copyright End ---------------------------------------------------------------- -.. _SUNAdjoint.Description: +.. _SUNAdjointStepper: + +The SUNAdjointStepper class +=========================== + +The :c:type:`SUNAdjointStepper` class provides a package-agnostic +interface to SUNDIALS ASA capabilties. It currently only supports the discrete +ASA capabilties in the ARKODE package, but in the future this support may be expanded. + +A :c:type:`SUNAdjointStepper` is a pointer to the +:c:struct:`SUNAdjointStepper_` structure: + +.. c:type:: struct SUNAdjointStepper_ *SUNAdjointStepper + +.. c:struct:: SUNAdjointStepper_ + + .. c:member:: SUNStepper adj_sunstepper + + The :c:type:`SUNStepper` object used for backwards time stepping of the adjoint ODE system. + + .. c:member:: SUNStepper fwd_sunstepper + + The :c:type:`SUNStepper` object used for forward time stepping of the original ODE system if any recomputation of missing + state data is required during the backwards integration. + + .. c:member:: sunrealtype tf + + The terminal time of the backwards adjoint ODE. + + .. c:member:: int64_t step_idx + + The index of the current backward integration step with respect to the forward integration. + + .. c:member:: int64_t final_step_idx + + The index of the final step in the forward integration (corresponds to ``tf``). + + .. c:member:: SUNMatrix Jac + + Matrix data for the Jacobian :math:`df/dy`. + + .. c:member:: SUNMatrix JacP + + Matrix data for the Jacobian :math:`df/dp`. + + .. c:member:: SUNJacFn JacFn + + Jacobian function pointer to evaluate :math:`df/dy`. + + .. c:member:: SUNJacFn JacPFn + + Jacobian function pointer to evaluate :math:`df/dp`. + + .. c:member:: SUNJacTimesFn JvpFn + + Jacobian-times-vector function pointer to evaluate :math:`(df/dy)^T v`. + + .. c:member:: SUNJacTimesFn JPvpFn + + Jacobian-times-vector function pointer to evaluate :math:`(df/dp)^T v`. + + .. c:member:: SUNJacTimesFn vJpFn + + Jacobian-times-vector function pointer to evaluate :math:`v^T(df/dy)`. + + .. c:member:: SUNJacTimesFn vJPpFn + + Jacobian-times-vector function pointer to evaluate :math:`v^T(df/dp)`. + + .. c:member:: uint64_t nst + + Holds the count of the number of backwards steps taken. + + .. c:member:: uint64_t njeval + + Holds the count of the number of :math:`df/dy` evaluations. + + .. c:member:: uint64_t njpeval + + Holds the count of the number of :math:`df/dp` evaluations. + + .. c:member:: uint64_t njtimesv + + Holds the count of the number of :math:`(df/dy)^T v` evaluations. + + .. c:member:: uint64_t njptimesv + + Holds the count of the number of :math:`(df/dp)^T v` evaluations. + + .. c:member:: uint64_t nvtimesj + + Holds the count of the number of :math:`v^T(df/dy)` evaluations. + + .. c:member:: uint64_t nvtimesjp + + Holds the count of the number of :math:`v^T(df/dp)` evaluations. + + .. c:member:: uint64_t nrecompute + + .. c:member:: void* user_data + + A pointer that is passed back to user-supplied functions + + .. c:member:: void* content + + Pointer to derived class specific member data + + .. c:member:: SUNContext sunctx + + The SUNDIALS simulation context + + +The :c:type:`SUNAdjointStepper` class has the following functions: + +.. c:function:: SUNErrCode SUNAdjointStepper_Create(SUNStepper fwd_sunstepper, SUNStepper adj_sunstepper, \ + int64_t final_step_idx, N_Vector sf, sunrealtype tf, SUNAdjointCheckpointScheme checkpoint_scheme, \ + SUNContext sunctx, SUNAdjointStepper* adj_stepper) + + + +.. c:function:: SUNErrCode SUNAdjointStepper_ReInit(SUNAdjointStepper adj, N_Vector sf, sunrealtype tf) + + Reinitializes the adjoint stepper to solve a new problem of the same size. + + :param adj_stepper: The adjoint solver object. + :param tf: The time to start integrating the adjoint system from. + :param sf: The terminal condition vector of sensitivity solutions dg/dy0 and dg/dp. + + :return: A :c:type:`SUNErrCode` indicating failure or success. + + +.. c:function:: SUNErrCode SUNAdjointStepper_Evolve(SUNAdjointStepper adj_stepper, sunrealtype tout,\ + N_Vector sens, sunrealtype* tret, int* stop_reason) + + Integrates the adjoint system. + + :param adj_stepper: The adjoint solver object. + :param tout: The time at which the adjoint solution is desired. + :param sens: The vector of sensitivity solutions dg/dy0 and dg/dp. + :param tret: On return, the time reached by the adjoint solver. + :param stop_reason: On return, an integer code that indicates why the adjoint solver stopped. + + :return: A :c:type:`SUNErrCode` indicating failure or success. + + +.. c:function:: SUNErrCode SUNAdjointStepper_OneStep(SUNAdjointStepper adj_stepper, sunrealtype tout,\ + N_Vector sens, sunrealtype* tret, int* stop_reason) + + Evolves the adjoint system backwards one step. + + :param adj_stepper: The adjoint solver object. + :param tout: The time at which the adjoint solution is desired. + :param sens: The vector of sensitivity solutions dg/dy0 and dg/dp. + :param tret: On return, the time reached by the adjoint solver. + :param stop_reason: On return, an integer code that indicates why the adjoint solver stopped. + + :return: A :c:type:`SUNErrCode` indicating failure or success. + + +.. c:function:: SUNErrCode SUNAdjointStepper_RecomputeFwd(SUNAdjointStepper adj_stepper, \ + int64_t start_idx, int64_t stop_idx, \ + sunrealtype t0, sunrealtype tf, N_Vector y0) + + Evolves the forward system in time from start_idx/t0 to stop_idx/tf with dense checkpointing. + + :param adj_stepper: The SUNAdjointStepper object. + :param start_idx: the index of the step, w.r.t. the original forward integration, to begin forward integration from. + :param stop_idx: the index of the step, w.r.t. the original forward integration, to end forward integration. + :param t0: the initial time, w.r.t. the original forward integration, to start forward integration from. + :param tf: the final time, w.r.t. the original forward integration, to stop forward integration. + :param y0: the initial state, w.r.t. the original forward integration, to start forward integration. + + :return: A :c:type:`SUNErrCode` indicating failure or success. + + +.. c:function:: SUNErrCode SUNAdjointStepper_SetJacFn(SUNAdjointStepper adj_stepper, SUNJacFn JacFn, \ + SUNMatrix Jac, SUNJacFn JacPFn, SUNMatrix JacP) + + Sets the function pointers and matrices needed to evluate and store :math:`df/dy` and + :math:`df/dp`. ``Jac`` should have dimensions ``neq x neq`` where ``neq`` is the number of states + in the forward problem. ``JacP`` should have dimensions ``nparams x neq`` where ``nparams`` is the + number of parameters in the model to get sensitivities for. + + :param adj_stepper: The SUNAdjointStepper object. + :param JacFn: the function that evaluates :math:`df/dy`. + :param Jac: a :c:type:`SUNMatrix` that will hold :math:`df/dy`. + :param JacPFn: the function that evaluates :math:`df/dp`. + :param JacP: a :c:type:`SUNMatrix` that will hold :math:`df/dp`. + + :return: A :c:type:`SUNErrCode` indicating failure or success. + +.. c:function:: SUNErrCode SUNAdjointStepper_SetJacTimesVecFn(SUNAdjointStepper adj_stepper, SUNJacTimesFn Jvp, SUNJacTimesFn JPvp) + + + Sets the function pointers to evaluate :math:`(df/dy)^T v` and :math:`(df/dp)^T v` + + :param adj_stepper: The SUNAdjointStepper object. + :param Jvp: function that evaluates :math:`(df/dy)^T v`. + :param JPvp: function that evaluates :math:`(df/dp)^T v`. + + :return: A :c:type:`SUNErrCode` indicating failure or success. + + +.. c:function:: SUNErrCode SUNAdjointStepper_SetJacTimesVecFn(SUNAdjointStepper adj_stepper, SUNJacTimesFn Jvp, SUNJacTimesFn JPvp) + + + Sets the function pointers to evaluate :math:`v^T (df/dy)` and :math:`v^T (df/dp)` + + :param adj_stepper: The SUNAdjointStepper object. + :param Jvp: function that evaluates :math:`v^T (df/dy)`. + :param JPvp: function that evaluates :math:`v^T (df/dp)`. + + :return: A :c:type:`SUNErrCode` indicating failure or success. + + +.. c:function:: SUNErrCode SUNAdjointStepper_SetUserData(SUNAdjointStepper adj_stepper, void* user_data) + + Sets the user data pointer. + + :param adj_stepper: The SUNAdjointStepper object. + :param user_data: the user data pointer that will be passed back to user-supplied callback functions. + + :return: A :c:type:`SUNErrCode` indicating failure or success. + + +.. c:function:: SUNErrCode SUNAdjointStepper_PrintAllStats(SUNAdjointStepper adj_stepper, \ + FILE* outfile, SUNOutputFormat fmt) + + Prints the adjoint stepper statistics/counters in a human-readable table format or CSV format. + + :param adj_stepper: The SUNAdjointStepper object. + :param outfile: A file to write the output to. + :param fmt: the format to write in (:c:type:`SUN_OUTPUTFORMAT_TABLE` or :c:type:`SUN_OUTPUTFORMAT_CSV`). + + :return: A :c:type:`SUNErrCode` indicating failure or success. + + +.. _SUNAdjointCheckpointScheme: + +The SUNAdjointCheckpointScheme Class +==================================== + +The :c:type:`SUNAdjointCheckpointScheme` base class provides an inteface for checkpointing +states during forward integration and accessing them as needed during the backwards integration +of the adjoint model. + +A :c:type:`SUNAdjointCheckpointScheme` is a pointer to the +:c:struct:`SUNAdjointCheckpointScheme_` structure: + +.. c:type:: struct SUNAdjointCheckpointScheme_ *SUNAdjointCheckpointScheme + +.. c:struct:: SUNAdjointCheckpointScheme_ + + .. c:member:: SUNAdjointCheckpointScheme_Ops ops + + The ops structure holds the vtable of function pointers for the base class. + + .. c:member:: void* content + + Pointer to derived class specific member data. + + .. c:member:: SUNContext sunctx + + The SUNDIALS simulation context. + + +.. c:function:: SUNErrCode SUNAdjointCheckpointScheme_NewEmpty(SUNContext sunctx, \ + SUNAdjointCheckpointScheme* cs_ptr) + + Allocates a new object but without any content. + + :param sunctx: The SUNDIALS simulation context + :param cs_ptr: on output, the pointer to the new :c:type:`SUNAdjointCheckpointScheme` object + + :return: A :c:type:`SUNErrCode` indicating failure or success. + +.. c:function:: SUNErrCode SUNAdjointCheckpointScheme_ShouldWeSave(SUNAdjointCheckpointScheme cs, \ + sunindextype step_num, sunindextype stage_num, sunrealtype t, sunbooleantype* yes_or_no) + + Determines if the (step_num, stage_num) should be checkpointed or not. + + :param cs: The :c:type:`SUNAdjointCheckpointScheme` object + :param step_num: the step number of the checkpoint + :param stage_num: the stage number of the checkpoint + :param t: the time of the checkpoint + :param yes_or_no: boolean indicating if the checkpoint should be saved or not + + :return: A :c:type:`SUNErrCode` indicating failure or success. + +.. c:function:: SUNErrCode SUNAdjointCheckpointScheme_ShouldWeDelete(SUNAdjointCheckpointScheme cs, \ + sunindextype step_num, sunindextype stage_num, sunbooleantype* yes_or_no) + + Determines if the (step_num, stage_num) checkpoint should be deleted or not. + + :param cs: The :c:type:`SUNAdjointCheckpointScheme` object + :param step_num: the step number of the checkpoint + :param stage_num: the stage number of the checkpoint + :param t: the time of the checkpoint + :param yes_or_no: boolean indicating if the checkpoint should be deleted or not + + :return: A :c:type:`SUNErrCode` indicating failure or success. + +.. c:function:: SUNErrCode SUNAdjointCheckpointScheme_InsertVector(SUNAdjointCheckpointScheme cs, \ + sunindextype step_num, sunindextype stage_num, sunrealtype t, N_Vector state) + + Inserts the vector as the checkpoint for (step_num, stage_num). + + :param cs: The :c:type:`SUNAdjointCheckpointScheme` object + :param step_num: the step number of the checkpoint + :param stage_num: the stage number of the checkpoint + :param t: the time of the checkpoint + :param state: the state vector to checkpoint + + :return: A :c:type:`SUNErrCode` indicating failure or success. + +.. c:function:: SUNErrCode SUNAdjointCheckpointScheme_LoadVector(SUNAdjointCheckpointScheme cs, \ + sunindextype step_num, sunindextype stage_num, sunbooleantype peek, N_Vector* out, sunrealtype* tout) + + Loads the checkpointed vector for (step_num, stage_num). + + :param cs: The :c:type:`SUNAdjointCheckpointScheme` object + :param step_num: the step number of the checkpoint + :param stage_num: the stage number of the checkpoint + :param peek: if true, then the checkpoint will be loaded but not deleted regardless + of other implementation-specific settings. If false, then the checkpoint may be + deleted depending on the implementation. + :param out: the loaded state vector + :param tout: on output, the time of the checkpoint + + :return: A :c:type:`SUNErrCode` indicating failure or success. + +.. c:function:: SUNErrCode SUNAdjointCheckpointScheme_RemoveVector(SUNAdjointCheckpointScheme cs, \ + sunindextype step_num, sunindextype stage_num, N_Vector* out) + + Removes the checkpointed vector for (step_num, stage_num). + + :param cs: The :c:type:`SUNAdjointCheckpointScheme` object + :param step_num: the step number of the checkpoint + :param stage_num: the stage number of the checkpoint + :param out: the loaded state vector + + :return: A :c:type:`SUNErrCode` indicating failure or success. + +.. c:function:: SUNErrCode SUNAdjointCheckpointScheme_EnableDense(SUNAdjointCheckpointScheme cs, \ + sunbooleantype on_or_off) + + Enables or disables dense checkpointing (checkpointing every step/stage). + + :param cs: The :c:type:`SUNAdjointCheckpointScheme` object + :param on_or_off: if true, dense checkpointing will be turned on, ifalse it will be turned off. + + :return: A :c:type:`SUNErrCode` indicating failure or success. + +.. c:function:: SUNErrCode SUNAdjointCheckpointScheme_Destroy(SUNAdjointCheckpointScheme* cs_ptr) + + Destroys (deallocates) the SUNAdjointCheckpointScheme object. + + :param cs_ptr: pointer to a :c:type:`SUNAdjointCheckpointScheme` object + + :return: A :c:type:`SUNErrCode` indicating failure or success. \ No newline at end of file diff --git a/doc/superbuild/source/sunadjoint/SUNAdjoint_links.rst b/doc/superbuild/source/sunadjoint/SUNAdjoint_links.rst index 417eb7e5de..45253a3419 100644 --- a/doc/superbuild/source/sunadjoint/SUNAdjoint_links.rst +++ b/doc/superbuild/source/sunadjoint/SUNAdjoint_links.rst @@ -10,5 +10,4 @@ SUNDIALS Copyright End ---------------------------------------------------------------- -.. include:: ../../../shared/sunadjoint/SUNAdjointCheckpointScheme.rst -.. include:: ../../../shared/sunadjoint/SUNAdjointStepper.rst +.. include:: ../../../shared/sunadjoint/SUNAdjoint_Description.rst diff --git a/include/sunadjoint/sunadjoint_checkpointscheme.h b/include/sunadjoint/sunadjoint_checkpointscheme.h index 29a876bb3c..126c136ccb 100644 --- a/include/sunadjoint/sunadjoint_checkpointscheme.h +++ b/include/sunadjoint/sunadjoint_checkpointscheme.h @@ -47,12 +47,6 @@ struct SUNAdjointCheckpointScheme_Ops_ SUNErrCode (*removeVector)(SUNAdjointCheckpointScheme, sunindextype step_num, sunindextype stage_num, N_Vector* out); - SUNErrCode (*removeRange)(SUNAdjointCheckpointScheme, - sunindextype step_num_start, - sunindextype step_num_end, - sunindextype stage_num_start, - sunindextype stage_num_end); - SUNErrCode (*destroy)(SUNAdjointCheckpointScheme*); SUNErrCode (*enableDense)(SUNAdjointCheckpointScheme, sunbooleantype on_or_off); @@ -98,13 +92,6 @@ SUNErrCode SUNAdjointCheckpointScheme_RemoveVector(SUNAdjointCheckpointScheme, sunindextype stage_num, N_Vector* out); -SUNDIALS_EXPORT -SUNErrCode SUNAdjointCheckpointScheme_RemoveRange(SUNAdjointCheckpointScheme, - sunindextype step_num_start, - sunindextype step_num_end, - sunindextype stage_num_start, - sunindextype stage_num_end); - SUNDIALS_EXPORT SUNErrCode SUNAdjointCheckpointScheme_Destroy(SUNAdjointCheckpointScheme*); diff --git a/include/sunadjoint/sunadjoint_checkpointscheme_basic.h b/include/sunadjoint/sunadjoint_checkpointscheme_basic.h index 0d8aa61df1..4e499fcf70 100644 --- a/include/sunadjoint/sunadjoint_checkpointscheme_basic.h +++ b/include/sunadjoint/sunadjoint_checkpointscheme_basic.h @@ -146,19 +146,6 @@ SUNErrCode SUNAdjointCheckpointScheme_RemoveVector_Basic( SUNAdjointCheckpointScheme check_scheme, sunindextype step_num, sunindextype stage_num, N_Vector* out); -/** - This function removes multiple checkpoints. - - :param check_scheme: the SUNAdjointCheckpointScheme object - - :returns: a :c:type:`SUNErrCode` indicating success or failure - */ -SUNDIALS_EXPORT -SUNErrCode SUNAdjointCheckpointScheme_RemoveRange_Basic( - SUNAdjointCheckpointScheme check_scheme, sunindextype step_num_start, - sunindextype step_num_end, sunindextype stage_num_start, - sunindextype stage_num_end); - /** This function loads a checkpoint state (represented as a N_Vector). diff --git a/include/sunadjoint/sunadjoint_stepper.h b/include/sunadjoint/sunadjoint_stepper.h index e081d9f8a3..c92485c339 100644 --- a/include/sunadjoint/sunadjoint_stepper.h +++ b/include/sunadjoint/sunadjoint_stepper.h @@ -40,6 +40,7 @@ struct SUNAdjointStepper_ nrecompute; void* user_data; + void* content; SUNContext sunctx; }; @@ -58,11 +59,11 @@ SUNErrCode SUNAdjointStepper_Create( /* Reinitializes the adjoint stepper to solve a new problem of the same size. - :param adj_stepper: The adjoint solver object. + :param adj_stepper: The SUNAdjointStepper object. :param tf: The time to start integrating the adjoint system from. :param sf: The terminal condition vector of sensitivity solutions dg/dy0 and dg/dp. - :returns: A SUNErrCode indicating failure or success. + :return: A SUNErrCode indicating failure or success. */ SUNDIALS_EXPORT SUNErrCode SUNAdjointStepper_ReInit(SUNAdjointStepper adj, N_Vector sf, @@ -71,13 +72,13 @@ SUNErrCode SUNAdjointStepper_ReInit(SUNAdjointStepper adj, N_Vector sf, /* Integrates the adjoint system. - :param adj_stepper: The adjoint solver object. + :param adj_stepper: The SUNAdjointStepper object. :param tout: The time at which the adjoint solution is desired. :param sens: The vector of sensitivity solutions dg/dy0 and dg/dp. :param tret: On return, the time reached by the adjoint solver. :param stop_reason: On return, an integer code that indicates why the adjoint solver stopped. - :returns: A SUNErrCode indicating failure or success. + :return: A SUNErrCode indicating failure or success. */ SUNDIALS_EXPORT SUNErrCode SUNAdjointStepper_Evolve(SUNAdjointStepper adj_stepper, @@ -87,19 +88,31 @@ SUNErrCode SUNAdjointStepper_Evolve(SUNAdjointStepper adj_stepper, /* Evolves the adjoint system backwards one step. - :param adj_stepper: The adjoint solver object. + :param adj_stepper: The SUNAdjointStepper object. :param tout: The time at which the adjoint solution is desired. :param sens: The vector of sensitivity solutions dg/dy0 and dg/dp. :param tret: On return, the time reached by the adjoint solver. :param stop_reason: On return, an integer code that indicates why the adjoint solver stopped. - :returns: A SUNErrCode indicating failure or success. + :return: A SUNErrCode indicating failure or success. */ SUNDIALS_EXPORT SUNErrCode SUNAdjointStepper_OneStep(SUNAdjointStepper adj_stepper, sunrealtype tout, N_Vector sens, sunrealtype* tret, int* stop_reason); +/* + Evolves the forward system in time from start_idx/t0 to stop_idx/tf with dense checkpointing. + + :param adj_stepper: The SUNAdjointStepper object. + :param start_idx: the index of the step, w.r.t. the original forward integration, to begin forward integration from. + :param stop_idx: the index of the step, w.r.t. the original forward integration, to end forward integration. + :param t0: the initial time, w.r.t. the original forward integration, to start forward integration from. + :param tf: the final time, w.r.t. the original forward integration, to stop forward integration. + :param y0: the initial state, w.r.t. the original forward integration, to start forward integration. + + :return: A SUNErrCode indicating failure or success. +*/ SUNDIALS_EXPORT SUNErrCode SUNAdjointStepper_RecomputeFwd(SUNAdjointStepper adj_stepper, int64_t start_idx, int64_t stop_idx, diff --git a/src/sunadjoint/sunadjoint_checkpointscheme.c b/src/sunadjoint/sunadjoint_checkpointscheme.c index 62c001207b..fd82ea193c 100644 --- a/src/sunadjoint/sunadjoint_checkpointscheme.c +++ b/src/sunadjoint/sunadjoint_checkpointscheme.c @@ -42,7 +42,6 @@ SUNErrCode SUNAdjointCheckpointScheme_NewEmpty( ops->insertVector = NULL; ops->loadVector = NULL; ops->removeVector = NULL; - ops->removeRange = NULL; ops->enableDense = NULL; ops->destroy = NULL;