diff --git a/.github/workflows/build-ci-containers-e4s.yml b/.github/workflows/build-ci-containers-e4s.yml index ad6cb16a2f..ee7c931f8d 100644 --- a/.github/workflows/build-ci-containers-e4s.yml +++ b/.github/workflows/build-ci-containers-e4s.yml @@ -26,7 +26,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push Docker images - uses: docker/build-push-action@v6.7.0 + uses: docker/build-push-action@v6.10.0 with: context: "./docker/sundials-ci/e4s-base" build-args: e4s_version=22.05 @@ -56,7 +56,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push Docker images - uses: docker/build-push-action@v6.7.0 + uses: docker/build-push-action@v6.10.0 with: context: "./docker/sundials-ci/e4s-quarterly" build-args: spack_yaml=./int${{ matrix.indexsize }}-${{ matrix.precision }}/spack.yaml diff --git a/.github/workflows/build-ci-containers-nightly.yml b/.github/workflows/build-ci-containers-nightly.yml index 5045a62a3b..176b3a3d88 100644 --- a/.github/workflows/build-ci-containers-nightly.yml +++ b/.github/workflows/build-ci-containers-nightly.yml @@ -32,7 +32,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push Docker images - uses: docker/build-push-action@v6.7.0 + uses: docker/build-push-action@v6.10.0 with: context: "./docker/sundials-ci/spack-nightly" build-args: spack_yaml=./int${{ matrix.indexsize }}-${{ matrix.precision }}/spack.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b1e20b242..85b69748cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ ### New Features and Enhancements +Added the `SUNStepper` base class to represent a generic solution procedure for +IVPs. A SUNStepper can be created from an ARKODE memory block with the new +function `ARKodeCreateSUNStepper`. To enable interoperability with +`MRIStepInnerStepper`, the function `MRIStepInnerStepper_CreateFromSUNStepper` +was added. + The following DIRK schemes now have coefficients accurate to quad precision: * `ARKODE_BILLINGTON_3_3_2` * `ARKODE_KVAERNO_4_2_3` @@ -65,6 +71,10 @@ support. Fixed a CMake configuration issue related to aliasing an `ALIAS` target when using `ENABLE_KLU=ON` in combination with a static-only build of SuiteSparse. +Fixed a CMake issue which caused third-party CMake variables to be unset. +Users may see more options in the CMake GUI now as a result of the fix. +See details in GitHub Issue [#538](https://github.com/LLNL/sundials/issues/538). + ### Deprecation Notices The ARKODE stepper specific functions to retrieve the number of right-hand side diff --git a/cmake/SundialsTPLOptions.cmake b/cmake/SundialsTPLOptions.cmake index 291709c8a8..765dcb4120 100644 --- a/cmake/SundialsTPLOptions.cmake +++ b/cmake/SundialsTPLOptions.cmake @@ -70,12 +70,11 @@ sundials_option( sundials_option(ENABLE_LAPACK BOOL "Enable Lapack support" OFF) sundials_option(LAPACK_LIBRARIES STRING "Lapack and Blas libraries" - "${LAPACK_LIBRARIES}" DEPENDS_ON ENABLE_LAPACK) + "${LAPACK_LIBRARIES}") sundials_option( LAPACK_WORKS BOOL "Set to ON to force CMake to accept a given LAPACK configuration" OFF - DEPENDS_ON ENABLE_LAPACK ADVANCED) # --------------------------------------------------------------- @@ -84,7 +83,7 @@ sundials_option( sundials_option(ENABLE_GINKGO BOOL "Enable Ginkgo support" OFF) sundials_option(Ginkgo_DIR PATH "Path to the root of a Ginkgo installation" - "${Ginkgo_DIR}" DEPENDS_ON ENABLE_GINKGO) + "${Ginkgo_DIR}") sundials_option( SUNDIALS_GINKGO_BACKENDS @@ -96,7 +95,6 @@ sundials_option( sundials_option( GINKGO_WORKS BOOL "Set to ON to force CMake to accept a given Ginkgo configuration" OFF - DEPENDS_ON ENABLE_GINKGO ADVANCED) # --------------------------------------------------------------- @@ -105,7 +103,7 @@ sundials_option( sundials_option(ENABLE_MAGMA BOOL "Enable MAGMA support" OFF) sundials_option(MAGMA_DIR PATH "Path to the root of a MAGMA installation" - "${MAGMA_DIR}" DEPENDS_ON ENABLE_MAGMA) + "${MAGMA_DIR}") sundials_option( SUNDIALS_MAGMA_BACKENDS STRING @@ -116,9 +114,7 @@ sundials_option( sundials_option( MAGMA_WORKS BOOL - "Set to ON to force CMake to accept a given MAGMA configuration" OFF - DEPENDS_ON ENABLE_MAGMA - ADVANCED) + "Set to ON to force CMake to accept a given MAGMA configuration" OFF ADVANCED) # --------------------------------------------------------------- # Enable SuperLU_DIST support? @@ -127,30 +123,24 @@ sundials_option(ENABLE_SUPERLUDIST BOOL "Enable SuperLU_DIST support" OFF) sundials_option( SUPERLUDIST_DIR PATH "Path to the root of the SuperLU_DIST installation" - "${SUPERLUDIST_DIR}" DEPENDS_ON ENABLE_SUPERLUDIST) + "${SUPERLUDIST_DIR}") sundials_option( SUPERLUDIST_INCLUDE_DIRS PATH "SuperLU_DIST include directories" - "${SUPERLUDIST_INCLUDE_DIRS}" - DEPENDS_ON ENABLE_SUPERLUDIST - ADVANCED) + "${SUPERLUDIST_INCLUDE_DIRS}" ADVANCED) sundials_option( SUPERLUDIST_LIBRARIES STRING "Semi-colon separated list of libraries needed for SuperLU_DIST." - "${SUPERLUDIST_LIBRARIES}" - DEPENDS_ON ENABLE_SUPERLUDIST - ADVANCED) + "${SUPERLUDIST_LIBRARIES}" ADVANCED) sundials_option( SUPERLUDIST_OpenMP BOOL - "Enable SUNDIALS support for SuperLU_DIST OpenMP on-node parallelism" OFF - DEPENDS_ON ENABLE_SUPERLUDIST) + "Enable SUNDIALS support for SuperLU_DIST OpenMP on-node parallelism" OFF) sundials_option( SUPERLUDIST_WORKS BOOL "Set to ON to force CMake to accept a given SuperLU_DIST configuration" OFF - DEPENDS_ON ENABLE_SUPERLUDIST ADVANCED) # --------------------------------------------------------------- @@ -159,24 +149,22 @@ sundials_option( sundials_option(ENABLE_SUPERLUMT BOOL "Enable SuperLU_MT support" OFF) sundials_option(SUPERLUMT_INCLUDE_DIR PATH "SuperLU_MT include directory" - "${SUPERLUMT_INCLUDE_DIR}" DEPENDS_ON ENABLE_SUPERLUMT) + "${SUPERLUMT_INCLUDE_DIR}") sundials_option(SUPERLUMT_LIBRARY_DIR PATH "SuperLU_MT library directory" - "${SUPERLUMT_LIBRARY_DIR}" DEPENDS_ON ENABLE_SUPERLUMT) + "${SUPERLUMT_LIBRARY_DIR}") sundials_option( SUPERLUMT_LIBRARIES STRING "Semi-colon separated list of additional libraries needed for SuperLU_MT." - "${SUPERLUMT_LIBRARIES}" DEPENDS_ON ENABLE_SUPERLUMT) + "${SUPERLUMT_LIBRARIES}") -sundials_option( - SUPERLUMT_THREAD_TYPE STRING "SuperLU_MT threading type: OPENMP or PTHREAD" - "PTHREAD" DEPENDS_ON ENABLE_SUPERLUMT) +sundials_option(SUPERLUMT_THREAD_TYPE STRING + "SuperLU_MT threading type: OPENMP or PTHREAD" "PTHREAD") sundials_option( SUPERLUMT_WORKS BOOL "Set to ON to force CMake to accept a given SUPERLUMT configuration" OFF - DEPENDS_ON ENABLE_SUPERLUMT ADVANCED) # --------------------------------------------------------------- @@ -185,36 +173,31 @@ sundials_option( sundials_option(ENABLE_KLU BOOL "Enable KLU support" OFF) sundials_option(KLU_INCLUDE_DIR PATH "KLU include directory" - "${KLU_INCLUDE_DIR}" DEPENDS_ON ENABLE_KLU) + "${KLU_INCLUDE_DIR}") sundials_option(KLU_LIBRARY_DIR PATH "KLU library directory" - "${KLU_LIBRARY_DIR}" DEPENDS_ON ENABLE_KLU) + "${KLU_LIBRARY_DIR}") sundials_option( KLU_WORKS BOOL "Set to ON to force CMake to accept a given KLU configuration" - OFF - DEPENDS_ON ENABLE_KLU - ADVANCED) + OFF ADVANCED) # --------------------------------------------------------------- # Enable hypre support? # --------------------------------------------------------------- sundials_option(ENABLE_HYPRE BOOL "Enable hypre support" OFF) -sundials_option(HYPRE_DIR PATH "Path to hypre installation" "${HYPRE_DIR}" - DEPENDS_ON ENABLE_HYPRE) +sundials_option(HYPRE_DIR PATH "Path to hypre installation" "${HYPRE_DIR}") sundials_option(HYPRE_INCLUDE_DIR PATH "HYPRE include directory" - "${HYPRE_INCLUDE_DIR}" DEPENDS_ON ENABLE_HYPRE) + "${HYPRE_INCLUDE_DIR}") sundials_option(HYPRE_LIBRARY_DIR PATH "HYPRE library directory" - "${HYPRE_LIBRARY_DIR}" DEPENDS_ON ENABLE_HYPRE) + "${HYPRE_LIBRARY_DIR}") sundials_option( HYPRE_WORKS BOOL - "Set to ON to force CMake to accept a given hypre configuration" OFF - DEPENDS_ON ENABLE_HYPRE - ADVANCED) + "Set to ON to force CMake to accept a given hypre configuration" OFF ADVANCED) # --------------------------------------------------------------- # Enable PETSc support? @@ -223,36 +206,30 @@ sundials_option( sundials_option(ENABLE_PETSC BOOL "Enable PETSc support" OFF) sundials_option(PETSC_DIR PATH "Path to the root of a PETSc installation" - "${PETSC_DIR}" DEPENDS_ON ENABLE_PETSC) + "${PETSC_DIR}") sundials_option(PETSC_ARCH STRING "PETSc architecture (optional)" - "${PETSC_ARCH}" DEPENDS_ON ENABLE_PETSC) + "${PETSC_ARCH}") sundials_option( PETSC_LIBRARIES STRING "Semi-colon separated list of PETSc link libraries" - "${PETSC_LIBRARIES}" - DEPENDS_ON ENABLE_PETSC - ADVANCED) + "${PETSC_LIBRARIES}" ADVANCED) sundials_option( - PETSC_INCLUDES STRING "Semi-colon separated list of PETSc include directories" - "${PETSC_INCLUDES}" - DEPENDS_ON ENABLE_PETSC + PETSC_INCLUDES STRING + "Semi-colon separated list of PETSc include directories" "${PETSC_INCLUDES}" ADVANCED) sundials_option( PETSC_WORKS BOOL - "Set to ON to force CMake to accept a given PETSc configuration" OFF - DEPENDS_ON ENABLE_PETSC - ADVANCED) + "Set to ON to force CMake to accept a given PETSc configuration" OFF ADVANCED) # ------------------------------------------------------------- # Enable RAJA support? # ------------------------------------------------------------- sundials_option(ENABLE_RAJA BOOL "Enable RAJA support" OFF) -sundials_option(RAJA_DIR PATH "Path to root of RAJA installation" "${RAJA_DIR}" - DEPENDS_ON ENABLE_RAJA) +sundials_option(RAJA_DIR PATH "Path to root of RAJA installation" "${RAJA_DIR}") sundials_option( SUNDIALS_RAJA_BACKENDS STRING @@ -276,24 +253,20 @@ sundials_option(Trilinos_DIR PATH "Path to root of Trilinos installation" sundials_option(ENABLE_XBRAID BOOL "Enable XBraid support" OFF) sundials_option(XBRAID_DIR PATH "Path to the root of an XBraid installation" - "${XBRAID_DIR}" DEPENDS_ON ENABLE_XBRAID) + "${XBRAID_DIR}") sundials_option( XBRAID_LIBRARIES STRING "Semi-colon separated list of XBraid link libraries" - "${XBRAID_LIBRARIES}" - DEPENDS_ON ENABLE_XBRAID - ADVANCED) + "${XBRAID_LIBRARIES}" ADVANCED) sundials_option( XBRAID_INCLUDES STRING - "Semi-colon separated list of XBraid include directories" "${XBRAID_INCLUDES}" - DEPENDS_ON ENABLE_XBRAID - ADVANCED) + "Semi-colon separated list of XBraid include directories" + "${XBRAID_INCLUDES}" ADVANCED) sundials_option( XBRAID_WORKS BOOL "Set to ON to force CMake to accept a given XBraid configuration" OFF - DEPENDS_ON ENABLE_XBRAID ADVANCED) # ------------------------------------------------------------- @@ -303,12 +276,11 @@ sundials_option( sundials_option(ENABLE_ONEMKL BOOL "Enable oneMKL support" OFF) sundials_option(ONEMKL_DIR PATH "Path to root of oneMKL installation" - "${ONEMKL_DIR}" DEPENDS_ON ENABLE_ONEMKL) + "${ONEMKL_DIR}") sundials_option( ONEMKL_WORKS BOOL "Set to ON to force CMake to accept a given oneMKL configuration" OFF - DEPENDS_ON ENABLE_ONEMKL ADVANCED) sundials_option( @@ -331,12 +303,11 @@ sundials_option(ENABLE_CALIPER BOOL "Enable CALIPER support" OFF DEPENDS_ON SUNDIALS_BUILD_WITH_PROFILING) sundials_option(CALIPER_DIR PATH "Path to the root of an CALIPER installation" - "${CALIPER_DIR}" DEPENDS_ON ENABLE_CALIPER) + "${CALIPER_DIR}") sundials_option( CALIPER_WORKS BOOL "Set to ON to force CMake to accept a given CALIPER configuration" OFF - DEPENDS_ON ENABLE_CALIPER ADVANCED) # --------------------------------------------------------------- @@ -347,7 +318,7 @@ sundials_option(ENABLE_ADIAK BOOL "Enable Adiak support" OFF DEPENDS_ON SUNDIALS_BUILD_WITH_PROFILING) sundials_option(adiak_DIR PATH "Path to the root of an Adiak installation" - "${ADIAK_DIR}" DEPENDS_ON ENABLE_ADIAK) + "${ADIAK_DIR}") # --------------------------------------------------------------- # Enable Kokkos support? @@ -361,7 +332,6 @@ sundials_option(Kokkos_DIR PATH "Path to the root of a Kokkos installation" sundials_option( KOKKOS_WORKS BOOL "Set to ON to force CMake to accept a given Kokkos configuration" OFF - DEPENDS_ON ENABLE_KOKKOS ADVANCED) # --------------------------------------------------------------- @@ -377,5 +347,4 @@ sundials_option( sundials_option( KOKKOS_KERNELS_WORKS BOOL "Set to ON to force CMake to accept a given Kokkos configuration" OFF - DEPENDS_ON ENABLE_KOKKOS ENABLE_KOKKOS_KERNELS ADVANCED) diff --git a/doc/arkode/guide/source/Constants.rst b/doc/arkode/guide/source/Constants.rst index 695a517ee5..fc300c802a 100644 --- a/doc/arkode/guide/source/Constants.rst +++ b/doc/arkode/guide/source/Constants.rst @@ -563,6 +563,8 @@ contains the ARKODE output constants. | :index:`ARK_MAX_STAGE_LIMIT_FAIL` | -50 | Stepper failed to achieve stable results. Either reduce | | | | the step size or increase the stage_max_limit | +-------------------------------------+------+------------------------------------------------------------+ + | :index:`ARK_SUNSTEPPER_ERR` | -51 | An error occurred in the SUNStepper module. | + +-------------------------------------+------+------------------------------------------------------------+ | :index:`ARK_UNRECOGNIZED_ERROR` | -99 | An unknown error was encountered. | +-------------------------------------+------+------------------------------------------------------------+ | | diff --git a/doc/arkode/guide/source/Usage/ARKStep/User_callable.rst b/doc/arkode/guide/source/Usage/ARKStep/User_callable.rst index 8f929ab4b7..e004611e58 100644 --- a/doc/arkode/guide/source/Usage/ARKStep/User_callable.rst +++ b/doc/arkode/guide/source/Usage/ARKStep/User_callable.rst @@ -35,6 +35,11 @@ ARKStep supports *all categories*: * non-identity mass matrices * relaxation Runge--Kutta methods +ARKStep also has forcing function support when converted to a +:c:type:`SUNStepper` or :c:type:`MRIStepInnerStepper`. See +:c:func:`ARKodeCreateSUNStepper` and :c:func:`ARKStepCreateMRIStepInnerStepper` +for additional details. + .. _ARKODE.Usage.ARKStep.Initialization: diff --git a/doc/arkode/guide/source/Usage/ERKStep/User_callable.rst b/doc/arkode/guide/source/Usage/ERKStep/User_callable.rst index 38441b733e..2e15e816fa 100644 --- a/doc/arkode/guide/source/Usage/ERKStep/User_callable.rst +++ b/doc/arkode/guide/source/Usage/ERKStep/User_callable.rst @@ -33,6 +33,10 @@ ERKStep supports the following categories: * temporal adaptivity * relaxation Runge--Kutta methods +ERKStep does not have forcing function support when converted to a +:c:type:`SUNStepper` or :c:type:`MRIStepInnerStepper`. See +:c:func:`ARKodeCreateSUNStepper` and :c:func:`ARKStepCreateMRIStepInnerStepper` +for additional details. .. _ARKODE.Usage.ERKStep.Initialization: diff --git a/doc/arkode/guide/source/Usage/MRIStep/Custom_Inner_Stepper/Description.rst b/doc/arkode/guide/source/Usage/MRIStep/Custom_Inner_Stepper/Description.rst index 523bd8a7be..f327d5a76c 100644 --- a/doc/arkode/guide/source/Usage/MRIStep/Custom_Inner_Stepper/Description.rst +++ b/doc/arkode/guide/source/Usage/MRIStep/Custom_Inner_Stepper/Description.rst @@ -79,6 +79,32 @@ Creating and Destroying an Object for details on how to attach member data and method function pointers. +.. c:function:: int MRIStepInnerStepper_CreateFromSUNStepper(SUNStepper sunstepper, MRIStepInnerStepper* stepper) + + This utility function wraps a :c:type:`SUNStepper` as an + :c:type:`MRIStepInnerStepper`. + + :param sunctx: the SUNDIALS simulation context. + :param sunstepper: the c:type:`SUNStepper` to wrap. + :param stepper: a pointer to an MRI inner stepper object. + + :retval ARK_SUCCESS: if successful + :retval ARK_MEM_FAIL: if a memory allocation error occurs + + **Example usage:** + + .. code-block:: C + + SUNStepper sunstepper = NULL; + SUNStepper_Create(ctx, &sunstepper); + /* Attach content and functions to the SUNStepper... */ + + MRIStepInnerStepper inner_stepper = NULL; + flag = MRIStepInnerStepper_CreateFromSUNStepper(sunstepper, &inner_stepper); + + .. versionadded:: x.y.z + + .. c:function:: int MRIStepInnerStepper_Free(MRIStepInnerStepper *stepper) This function destroys an :c:type:`MRIStepInnerStepper` object. diff --git a/doc/arkode/guide/source/Usage/MRIStep/User_callable.rst b/doc/arkode/guide/source/Usage/MRIStep/User_callable.rst index 5b9d0baebf..6fe35f5045 100644 --- a/doc/arkode/guide/source/Usage/MRIStep/User_callable.rst +++ b/doc/arkode/guide/source/Usage/MRIStep/User_callable.rst @@ -33,6 +33,10 @@ MRIStep supports the following categories: * implicit nonlinear and/or linear solvers +MRIStep does not have forcing function support when converted to a +:c:type:`SUNStepper` or :c:type:`MRIStepInnerStepper`. See +:c:func:`ARKodeCreateSUNStepper` and :c:func:`ARKStepCreateMRIStepInnerStepper` +for additional details. .. _ARKODE.Usage.MRIStep.Initialization: diff --git a/doc/arkode/guide/source/Usage/SPRKStep/User_callable.rst b/doc/arkode/guide/source/Usage/SPRKStep/User_callable.rst index fe5a43ddfb..6ea553ef30 100644 --- a/doc/arkode/guide/source/Usage/SPRKStep/User_callable.rst +++ b/doc/arkode/guide/source/Usage/SPRKStep/User_callable.rst @@ -30,6 +30,11 @@ SPRKStep supports only the basic set of user-callable functions, and does not support any of the restricted groups (time adaptivity, implicit solvers, etc.). +SPRKStep does not have forcing function support when converted to a +:c:type:`SUNStepper` or :c:type:`MRIStepInnerStepper`. See +:c:func:`ARKodeCreateSUNStepper` and :c:func:`ARKStepCreateMRIStepInnerStepper` +for additional details. + .. _ARKODE.Usage.SPRKStep.Initialization: diff --git a/doc/arkode/guide/source/Usage/User_callable.rst b/doc/arkode/guide/source/Usage/User_callable.rst index 1e66661976..3242368579 100644 --- a/doc/arkode/guide/source/Usage/User_callable.rst +++ b/doc/arkode/guide/source/Usage/User_callable.rst @@ -4725,3 +4725,31 @@ rescale the upcoming time step by the specified factor. If a value * ``examples/arkode/C_serial/ark_heat1D_adapt.c`` .. versionadded:: 6.1.0 + + + +.. _ARKODE.Usage.SUNStepperInterface: + +Using an ARKODE solver as a SUNStepper +-------------------------------------- + +The utility function :c:func:`ARKodeCreateSUNStepper` wraps an ARKODE memory +block as a :c:type:`SUNStepper`. + +.. c:function:: int ARKodeCreateSUNStepper(void *inner_arkode_mem, SUNStepper *stepper) + + Wraps an ARKODE integrator as a :c:type:`SUNStepper`. + + :param arkode_mem: pointer to the ARKODE memory block. + :param stepper: the :c:type:`SUNStepper` object. + + :retval ARK_SUCCESS: the function exited successfully. + :retval ARK_MEM_FAIL: a memory allocation failed. + :retval ARK_SUNSTEPPER_ERR: the :c:type:`SUNStepper` initialization failed. + + .. warning:: + Currently, ``stepper`` will be equipped with an implementation for the + :c:func:`SUNStepper_SetForcing` function only if ``inner_arkode_mem`` is + an ARKStep integrator. + + .. versionadded:: x.y.z diff --git a/doc/arkode/guide/source/index.rst b/doc/arkode/guide/source/index.rst index e809010fd0..edb093b943 100644 --- a/doc/arkode/guide/source/index.rst +++ b/doc/arkode/guide/source/index.rst @@ -65,6 +65,7 @@ with support by the `US Department of Energy `_, sunlinsol/index.rst sunnonlinsol/index.rst sunadaptcontroller/index.rst + sunstepper/index.rst sunmemory/index.rst sundials/Install_link.rst Constants diff --git a/doc/arkode/guide/source/sunstepper/SUNStepper_links.rst b/doc/arkode/guide/source/sunstepper/SUNStepper_links.rst new file mode 100644 index 0000000000..938c5f5d9d --- /dev/null +++ b/doc/arkode/guide/source/sunstepper/SUNStepper_links.rst @@ -0,0 +1,14 @@ +.. ---------------------------------------------------------------- + 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 + ---------------------------------------------------------------- + +.. include:: ../../../../shared/sunstepper/SUNStepper_Description.rst +.. include:: ../../../../shared/sunstepper/SUNStepper_Implementing.rst diff --git a/doc/arkode/guide/source/sunstepper/index.rst b/doc/arkode/guide/source/sunstepper/index.rst new file mode 100644 index 0000000000..86e89bd4c0 --- /dev/null +++ b/doc/arkode/guide/source/sunstepper/index.rst @@ -0,0 +1,20 @@ +.. ---------------------------------------------------------------- + Programmer(s): Steven B. Roberts @ LLNL + ---------------------------------------------------------------- + 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 + ---------------------------------------------------------------- + +.. include:: ../../../../shared/sunstepper/SUNStepper_Structure.rst + +.. toctree:: + :maxdepth: 1 + + SUNStepper_links.rst diff --git a/doc/shared/RecentChanges.rst b/doc/shared/RecentChanges.rst index 731ffbfb7a..01ac3994ae 100644 --- a/doc/shared/RecentChanges.rst +++ b/doc/shared/RecentChanges.rst @@ -2,6 +2,12 @@ **New Features and Enhancements** +Added the :c:type:`SUNStepper` base class to represent a generic solution +procedure for IVPs. A SUNStepper can be created from an ARKODE memory block with +the new function :c:func:`ARKodeCreateSUNStepper`. To enable interoperability +with :c:type:`MRIStepInnerStepper`, the function +:c:func:`MRIStepInnerStepper_CreateFromSUNStepper` was added. + The following DIRK schemes now have coefficients accurate to quad precision: * ``ARKODE_BILLINGTON_3_3_2`` @@ -68,6 +74,10 @@ support. Fixed a CMake configuration issue related to aliasing an ``ALIAS`` target when using ``ENABLE_KLU=ON`` in combination with a static-only build of SuiteSparse. +Fixed a CMake issue which caused third-party CMake variables to be unset. +Users may see more options in the CMake GUI now as a result of the fix. +See details in GitHub Issue `#538 `__. + **Deprecation Notices** The ARKODE stepper specific functions to retrieve the number of right-hand side diff --git a/doc/shared/sunstepper/SUNStepper_Description.rst b/doc/shared/sunstepper/SUNStepper_Description.rst new file mode 100644 index 0000000000..cb4b62d962 --- /dev/null +++ b/doc/shared/sunstepper/SUNStepper_Description.rst @@ -0,0 +1,395 @@ +.. ---------------------------------------------------------------- + Programmer(s): Steven B. Roberts @LLNL + David J. Gardner @ LLNL + ---------------------------------------------------------------- + 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 + ---------------------------------------------------------------- + +.. _SUNStepper.Description: + +The SUNStepper API +================== + +.. versionadded:: x.y.z + +As with other SUNDIALS classes, the :c:type:`SUNStepper` abstract base class is +implemented using a C structure containing a ``content`` pointer to the derived +class member data and a structure of function pointers to the derived class +implementations of the virtual methods. + +.. c:type:: SUNStepper + + An object for solving the IVP :eq:`SUNStepper_IVP`. + + The actual definition of the ``SUNStepper`` structure is kept private to + allow for the object internals to change without impacting user code. The + following sections describe the base class methods and the virtual methods + that a must be provided by a derived class. + +.. _SUNStepper.Description.BaseMethods: + +Base Class Methods +------------------ + +This section describes methods provided by the :c:type:`SUNStepper` abstract +base class that aid the user in implementing derived classes. This includes +functions for creating and destroying a generic base class object, attaching and +retrieving the derived class ``content`` pointer, and setting function pointers +to derived class method implementations. + +.. _SUNStepper.Description.BaseMethods.CreateDestroy: + +Creating and Destroying an Object +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In addition to creating an empty :c:type:`SUNStepper` using +:c:func:`SUNStepper_Create` described below, there is the +:c:func:`ARKodeCreateSUNStepper` function to construct a :c:type:`SUNStepper` +from an ARKODE integrator. + +.. c:function:: SUNErrCode SUNStepper_Create(SUNContext sunctx, SUNStepper *stepper) + + This function creates a :c:type:`SUNStepper` object to which a user should + attach the member data (content) pointer and method function pointers. + + :param sunctx: the SUNDIALS simulation context. + :param stepper: a pointer to a stepper object. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + **Example usage:** + + .. code-block:: C + + /* create an instance of the base class */ + SUNStepper stepper = NULL; + SUNErrCode err = SUNStepper_Create(sunctx, &stepper); + + .. note:: + + See :numref:`SUNStepper.Description.BaseMethods.Content` and + :numref:`SUNStepper.Description.BaseMethods.AttachFunctions` + for details on how to attach member data and method function pointers. + + +.. c:function:: SUNErrCode SUNStepper_Destroy(SUNStepper *stepper) + + This function frees memory allocated by the :c:type:`SUNStepper` base class + and uses the function pointer optionally specified with + :c:func:`SUNStepper_SetDestroyFn` to free the content. + + :param stepper: a pointer to a stepper object. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + .. note:: + + This function only frees memory allocated within the base class and the + base class structure itself. The user is responsible for freeing any + memory allocated for the member data (content). + + +.. _SUNStepper.Description.BaseMethods.SteppingFunctions: + +Stepping Functions +^^^^^^^^^^^^^^^^^^ + +.. c:function:: SUNErrCode SUNStepper_Evolve(SUNStepper stepper, sunrealtype tout, N_Vector vret, sunrealtype* tret) + + This function evolves the ODE :eq:`SUNStepper_IVP` towards the time ``tout`` + and stores the solution at time ``tret`` in ``vret``. + + :param stepper: the stepper object. + :param tout: the time to evolve towards. + :param vret: on output, the state at time ``tret``. + :param tret: the time corresponding to the output value ``vret``. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_OneStep(SUNStepper stepper, sunrealtype tout, N_Vector vret, sunrealtype* tret) + + This function evolves the ODE :eq:`SUNStepper_IVP` *one timestep* towards + the time ``tout`` and stores the solution at time ``tret`` in ``vret``. + + :param stepper: the stepper object. + :param tout: the time to evolve towards. + :param vret: on output, the state at time ``tret``. + :param tret: the time corresponding to the output value ``vret``. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_FullRhs(SUNStepper stepper, sunrealtype t, N_Vector v, N_Vector f, SUNFullRhsMode mode) + + This function computes the full right-hand side function of the ODE, + :math:`f(t, v) + r(t)` in :eq:`SUNStepper_IVP` for a given value of the + independent variable ``t`` and state vector ``v``. + + :param stepper: the stepper object. + :param t: the current value of the independent variable. + :param v: the current value of the dependent variable vector. + :param f: the output vector for the ODE right-hand side, + :math:`f(t, v) + r(t)`, in :eq:`SUNStepper_IVP`. + :param mode: the purpose of the right-hand side evaluation. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_Reset(SUNStepper stepper, sunrealtype tR, N_Vector vR) + + This function resets the stepper state to the provided independent variable + value and dependent variable vector. + + :param stepper: the stepper object. + :param tR: the value of the independent variable :math:`t_R`. + :param vR: the value of the dependent variable vector :math:`v(t_R)`. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_SetStopTime(SUNStepper stepper, sunrealtype tstop) + + This function specifies the value of the independent variable :math:`t` past + which the solution is not to proceed. + + :param stepper: the stepper object. + :param tstop: stopping time for the stepper. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_SetForcing(SUNStepper stepper, sunrealtype tshift, sunrealtype tscale, N_Vector* forcing, int nforcing) + + This function sets the data necessary to compute the forcing term + :eq:`SUNStepper_forcing`. This includes the shift and scaling factors for the + normalized time :math:`\frac{t - t_{\text{shift}}}{t_{\text{scale}}}` and the + array of polynomial coefficient vectors :math:`\widehat{f}_k`. + + :param stepper: a stepper object. + :param tshift: the time shift to apply to the current time when computing + the forcing, :math:`t_{\text{shift}}`. + :param tscale: the time scaling to apply to the current time when computing + the forcing, :math:`t_{\text{scale}}`. + :param forcing: a pointer to an array of forcing vectors, + :math:`\widehat{f}_k`. + :param nforcing: the number of forcing vectors, :math:`n_{\text{forcing}}`. A + value of 0 effectively eliminates the forcing term. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + .. note:: + + When integrating the ODE :eq:`SUNStepper_IVP` the :c:type:`SUNStepper` is + responsible for evaluating ODE right-hand side function :math:`f(t, v)` as + well as computing and applying the forcing term :eq:`SUNStepper_forcing` + to obtain the full right-hand side of the ODE :eq:`SUNStepper_IVP`. + + +.. _SUNStepper.Description.BaseMethods.RhsMode: + +The Right-Hand Side Evaluation Mode +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. c:enum:: SUNFullRhsMode + + A flag indicating the purpose of a right-hand side function evaluation. + + .. c:enumerator:: SUN_FULLRHS_START + + Evaluate at the beginning of the simulation. + + .. c:enumerator:: SUN_FULLRHS_END + + Evaluate at the end of a successful step. + + .. c:enumerator:: SUN_FULLRHS_OTHER + + Evaluate elsewhere, e.g., for dense output. + + +.. _SUNStepper.Description.BaseMethods.Content: + +Attaching and Accessing the Content Pointer +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. c:function:: SUNErrCode SUNStepper_SetContent(SUNStepper stepper, void *content) + + This function attaches a member data (content) pointer to a + :c:type:`SUNStepper` object. + + :param stepper: a stepper object. + :param content: a pointer to the stepper member data. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_GetContent(SUNStepper stepper, void **content) + + This function retrieves the member data (content) pointer from a + :c:type:`SUNStepper` object. + + :param stepper: a stepper object. + :param content: a pointer to set to the stepper member data pointer. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +Handling Warnings and Errors +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +An implementation of a :c:type:`SUNStepper` may have a system of warning and error +handling that cannot be encoded as a :c:type:`SUNErrCode` which is the return +type of all :c:type:`SUNStepper` functions. Therefore, we provide the following +function to get and set a separate flag associated with a stepper. + +.. c:function:: SUNErrCode SUNStepper_SetLastFlag(SUNStepper stepper, int last_flag) + + This function sets a flag that can be used by :c:type:`SUNStepper` implementations to + indicate warnings or errors that occurred during an operation, e.g., + :c:func:`SUNStepper_Evolve`. + + :param stepper: the stepper object. + :param last_flag: the flag value. + :return: A :c:type:`SUNErrCode` indicating success or failure. + +.. c:function:: SUNErrCode SUNStepper_GetLastFlag(SUNStepper stepper, int *last_flag) + + This function provides the last value of the flag used by the :c:type:`SUNStepper` + implementation to indicate warnings or errors that occurred during an + operation, e.g., :c:func:`SUNStepper_Evolve`. + + :param stepper: the stepper object. + :param last_flag: A pointer to where the flag value will be written. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. _SUNStepper.Description.BaseMethods.AttachFunctions: + +Setting Member Functions +^^^^^^^^^^^^^^^^^^^^^^^^ + +The functions in this section are used to specify how each operation on a +:c:type:`SUNStepper` implementation is performed. Technically, all of these +functions are optional to call; the functions that need to be attached are +determined by the "consumer" of the :c:type:`SUNStepper`. + +.. c:function:: SUNErrCode SUNStepper_SetEvolveFn(SUNStepper stepper, SUNStepperEvolveFn fn) + + This function attaches a :c:type:`SUNStepperEvolveFn` function to a + :c:type:`SUNStepper` object. + + :param stepper: a stepper object. + :param fn: the :c:type:`SUNStepperEvolveFn` function to attach. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_SetOneStepFn(SUNStepper stepper, SUNStepperOneStepFn fn) + + This function attaches a :c:type:`SUNStepperOneStepFn` function to a + :c:type:`SUNStepper` object. + + :param stepper: a stepper object. + :param fn: the :c:type:`SUNStepperOneStepFn` function to attach. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_SetFullRhsFn(SUNStepper stepper, SUNStepperFullRhsFn fn) + + This function attaches a :c:type:`SUNStepperFullRhsFn` function to a + :c:type:`SUNStepper` object. + + :param stepper: a stepper object. + :param fn: the :c:type:`SUNStepperFullRhsFn` function to attach. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_SetResetFn(SUNStepper stepper, SUNStepperResetFn fn) + + This function attaches a :c:type:`SUNStepperResetFn` function to a + :c:type:`SUNStepper` object. + + :param stepper: a stepper object. + :param fn: the :c:type:`SUNStepperResetFn` function to attach. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_SetStopTimeFn(SUNStepper stepper, SUNStepperSetStopTimeFn fn) + + This function attaches a :c:type:`SUNStepperSetStopTimeFn` function to a + :c:type:`SUNStepper` object. + + :param stepper: a stepper object. + :param fn: the :c:type:`SUNStepperSetStopTimeFn` function to attach. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_SetForcingFn(SUNStepper stepper, SUNStepperSetForcingFn fn) + + This function attaches a :c:type:`SUNStepperSetForcingFn` function to a + :c:type:`SUNStepper` object. + + :param stepper: a stepper object. + :param fn: the :c:type:`SUNStepperSetForcingFn` function to attach. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. c:function:: SUNErrCode SUNStepper_SetDestroyFn(SUNStepper stepper, SUNStepperDestroyFn fn) + + This function attaches a :c:type:`SUNStepperDestroyFn` function to a + :c:type:`SUNStepper`. The provided function is responsible for freeing any + memory allocated for the :c:type:`SUNStepper` content. + + :param stepper: a stepper object. + :param fn: the :c:type:`SUNStepperDestroyFn` function to attach. + :return: A :c:type:`SUNErrCode` indicating success or failure. + + +.. _SUNStepper.Description.ImplMethods: + +Implementation Specific Methods +------------------------------- + +This section describes the virtual methods defined by the :c:type:`SUNStepper` +abstract base class. + + +.. c:type:: SUNErrCode (*SUNStepperEvolveFn)(SUNStepper stepper, sunrealtype tout, N_Vector vret, sunrealtype* tret) + + This type represents a function with the signature of + :c:func:`SUNStepper_Evolve`. + + +.. c:type:: SUNErrCode (*SUNStepperOneStepFn)(SUNStepper stepper, sunrealtype tout, N_Vector vret, sunrealtype* tret) + + This type represents a function with the signature of + :c:func:`SUNStepper_OneStep`. + + +.. c:type:: SUNErrCode (*SUNStepperFullRhsFn)(SUNStepper stepper, sunrealtype t, N_Vector v, N_Vector f, SUNFullRhsMode mode) + + This type represents a function with the signature of + :c:func:`SUNStepper_FullRhs`. + + +.. c:type:: SUNErrCode (*SUNStepperResetFn)(SUNStepper stepper, sunrealtype tR, N_Vector vR) + + This type represents a function with the signature of + :c:func:`SUNStepper_Reset`. + + +.. c:type:: SUNErrCode (*SUNStepperSetStopTimeFn)(SUNStepper stepper, sunrealtype tstop) + + This type represents a function with the signature of + :c:func:`SUNStepper_SetStopTime`. + + +.. c:type:: SUNErrCode (*SUNStepperSetForcingFn)(SUNStepper stepper, sunrealtype tshift, sunrealtype tscale, N_Vector* forcing, int nforcing) + + This type represents a function with the signature of + :c:func:`SUNStepper_SetForcing`. + + +.. c:type:: SUNErrCode (*SUNStepperDestroyFn)(SUNStepper stepper) + + This type represents a function with the signature similar to + :c:func:`SUNStepper_Destroy` for freeing the content associated with a + :c:type:`SUNStepper`. diff --git a/doc/shared/sunstepper/SUNStepper_Implementing.rst b/doc/shared/sunstepper/SUNStepper_Implementing.rst new file mode 100644 index 0000000000..1f57de65de --- /dev/null +++ b/doc/shared/sunstepper/SUNStepper_Implementing.rst @@ -0,0 +1,54 @@ +.. ---------------------------------------------------------------- + Programmer(s): David J. Gardner @ LLNL + Steven B. Roberts @ LLNL + ---------------------------------------------------------------- + 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 + ---------------------------------------------------------------- + +.. _SUNStepper.Implementing: + +Implementing a SUNStepper +========================= + +To create a SUNStepper implementation: + +#. Define the stepper-specific content. + + This is typically a user-defined structure in C codes, a user-defined class + or structure in C++ codes, or a user-defined module in Fortran codes. This + content should hold any data necessary to perform the operations defined by + the :c:type:`SUNStepper` member functions. + +#. Define implementations of the required member functions (see + :numref:`SUNStepper.Description.ImplMethods`). + + These are typically user-defined functions in C, member functions of the + user-defined structure or class in C++, or functions contained in the + user-defined module in Fortran. + + Note that all member functions are passed the :c:type:`SUNStepper` object and + the stepper-specific content can, if necessary, be retrieved using + :c:func:`SUNStepper_GetContent`. Stepper-specific warnings and errors can be + recorded with :c:func:`SUNStepper_SetLastFlag`. + +#. In the user code, before creating the outer memory structure that uses the + :c:type:`SUNStepper`, do the following: + + #. Create a :c:type:`SUNStepper` object with :c:func:`SUNStepper_Create`. + + #. Attach a pointer to the stepper content to the :c:type:`SUNStepper` object + with :c:func:`SUNStepper_SetContent` if necessary, e.g., when the content + is a C structure. + + #. Attach the member function implementations using the functions described + in :numref:`SUNStepper.Description.BaseMethods.AttachFunctions`. + +#. Attach the :c:type:`SUNStepper` object to the outer memory structure. diff --git a/doc/shared/sunstepper/SUNStepper_Structure.rst b/doc/shared/sunstepper/SUNStepper_Structure.rst new file mode 100644 index 0000000000..bce90f5c57 --- /dev/null +++ b/doc/shared/sunstepper/SUNStepper_Structure.rst @@ -0,0 +1,39 @@ +.. ---------------------------------------------------------------- + Programmer(s): Steven B. Roberts @ LLNL + ---------------------------------------------------------------- + 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 + ---------------------------------------------------------------- + +.. _SUNStepper: + +##################################### +Stepper Data Structure +##################################### + +This section presents the :c:type:`SUNStepper` base class which represents a +generic solution procedure for IVPs of the form + +.. math:: + \dot{v}(t) = f(t, v) + r(t), \qquad v(t_0) = v_0, + :label: SUNStepper_IVP + +on an interval :math:`t \in [t_0, t_f]`. The time dependent forcing term, +:math:`r_i(t)`, is given by + +.. math:: + r(t) = \sum_{k = 0}^{n_{\text{forcing}}-1} + \left( \frac{t - t_{\text{shift}}}{t_{\text{scale}}} \right)^{k} \widehat{f}_k. + :label: SUNStepper_forcing + +:c:type:`SUNStepper` provides an abstraction over SUNDIALS integrators, custom +integrators, exact solution procedures, or other approaches for solving +:eq:`SUNStepper_IVP`. These are used, for example, in operator splitting and +forcing methods to solve inner IVPs in a flexible way. diff --git a/doc/superbuild/source/index.rst b/doc/superbuild/source/index.rst index e61162c884..d597a82a0c 100644 --- a/doc/superbuild/source/index.rst +++ b/doc/superbuild/source/index.rst @@ -174,6 +174,7 @@ SUNDIALS License and Notices sunlinsol/index.rst sunnonlinsol/index.rst sunadaptcontroller/index.rst + sunstepper/index.rst sunmemory/index.rst History_link.rst Changelog_link.rst diff --git a/doc/superbuild/source/sunstepper/SUNStepper_links.rst b/doc/superbuild/source/sunstepper/SUNStepper_links.rst new file mode 100644 index 0000000000..925278111c --- /dev/null +++ b/doc/superbuild/source/sunstepper/SUNStepper_links.rst @@ -0,0 +1,14 @@ +.. ---------------------------------------------------------------- + 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 + ---------------------------------------------------------------- + +.. include:: ../../../shared/sunstepper/SUNStepper_Description.rst +.. include:: ../../../shared/sunstepper/SUNStepper_Implementing.rst diff --git a/doc/superbuild/source/sunstepper/index.rst b/doc/superbuild/source/sunstepper/index.rst new file mode 100644 index 0000000000..37c94c70d7 --- /dev/null +++ b/doc/superbuild/source/sunstepper/index.rst @@ -0,0 +1,20 @@ +.. ---------------------------------------------------------------- + Programmer(s): Steven B. Roberts @ LLNL + ---------------------------------------------------------------- + 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 + ---------------------------------------------------------------- + +.. include:: ../../../shared/sunstepper/SUNStepper_Structure.rst + +.. toctree:: + :maxdepth: 1 + + SUNStepper_links.rst diff --git a/include/arkode/arkode.h b/include/arkode/arkode.h index 3f934b78af..684e4fadab 100644 --- a/include/arkode/arkode.h +++ b/include/arkode/arkode.h @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { @@ -143,6 +144,8 @@ extern "C" { #define ARK_DOMEIG_FAIL -49 #define ARK_MAX_STAGE_LIMIT_FAIL -50 +#define ARK_SUNSTEPPER_ERR -51 + #define ARK_UNRECOGNIZED_ERROR -99 /* ------------------------------ @@ -417,6 +420,9 @@ SUNDIALS_EXPORT int ARKodeGetNumRelaxSolveFails(void* arkode_mem, SUNDIALS_EXPORT int ARKodeGetNumRelaxSolveIters(void* arkode_mem, long int* iters); +/* SUNStepper functions */ +SUNDIALS_EXPORT int ARKodeCreateSUNStepper(void* arkode_mem, SUNStepper* stepper); + #ifdef __cplusplus } #endif diff --git a/include/arkode/arkode_mristep.h b/include/arkode/arkode_mristep.h index 828272948a..506534b9db 100644 --- a/include/arkode/arkode_mristep.h +++ b/include/arkode/arkode_mristep.h @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { @@ -167,6 +168,10 @@ SUNDIALS_EXPORT int MRIStepGetLastInnerStepFlag(void* arkode_mem, int* flag); /* Custom inner stepper functions */ SUNDIALS_EXPORT int MRIStepInnerStepper_Create(SUNContext sunctx, MRIStepInnerStepper* stepper); + +SUNDIALS_EXPORT int MRIStepInnerStepper_CreateFromSUNStepper( + SUNStepper sunstepper, MRIStepInnerStepper* stepper); + SUNDIALS_EXPORT int MRIStepInnerStepper_Free(MRIStepInnerStepper* stepper); SUNDIALS_EXPORT int MRIStepInnerStepper_SetContent(MRIStepInnerStepper stepper, void* content); diff --git a/include/sundials/sundials_stepper.h b/include/sundials/sundials_stepper.h new file mode 100644 index 0000000000..e735792e89 --- /dev/null +++ b/include/sundials/sundials_stepper.h @@ -0,0 +1,129 @@ +/* ----------------------------------------------------------------- + * 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 + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_STEPPER_H +#define _SUNDIALS_STEPPER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum +{ + SUN_FULLRHS_START, + SUN_FULLRHS_END, + SUN_FULLRHS_OTHER +} SUNFullRhsMode; + +typedef int (*SUNRhsJacFn)(sunrealtype t, N_Vector y, N_Vector fy, + SUNMatrix Jac, void* user_data, N_Vector tmp1, + N_Vector tmp2, N_Vector tmp3); + +typedef int (*SUNRhsJacTimesFn)(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 SUNErrCode (*SUNStepperEvolveFn)(SUNStepper stepper, sunrealtype tout, + N_Vector vret, sunrealtype* tret); + +typedef SUNErrCode (*SUNStepperOneStepFn)(SUNStepper stepper, sunrealtype tout, + N_Vector vret, sunrealtype* tret); + +typedef SUNErrCode (*SUNStepperFullRhsFn)(SUNStepper stepper, sunrealtype t, + N_Vector v, N_Vector f, + SUNFullRhsMode mode); + +typedef SUNErrCode (*SUNStepperResetFn)(SUNStepper stepper, sunrealtype tR, + N_Vector vR); + +typedef SUNErrCode (*SUNStepperSetStopTimeFn)(SUNStepper stepper, + sunrealtype tstop); + +typedef SUNErrCode (*SUNStepperSetForcingFn)(SUNStepper stepper, + sunrealtype tshift, + sunrealtype tscale, + N_Vector* forcing, int nforcing); + +typedef SUNErrCode (*SUNStepperDestroyFn)(SUNStepper stepper); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_Create(SUNContext sunctx, SUNStepper* stepper); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_Destroy(SUNStepper* stepper); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_Evolve(SUNStepper stepper, sunrealtype tout, + N_Vector vret, sunrealtype* tret); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_OneStep(SUNStepper stepper, sunrealtype tout, + N_Vector vret, sunrealtype* tret); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_FullRhs(SUNStepper stepper, sunrealtype t, N_Vector v, + N_Vector f, SUNFullRhsMode mode); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_Reset(SUNStepper stepper, sunrealtype tR, N_Vector vR); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_SetStopTime(SUNStepper stepper, sunrealtype tstop); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_SetForcing(SUNStepper stepper, sunrealtype tshift, + sunrealtype tscale, N_Vector* forcing, + int nforcing); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_SetContent(SUNStepper stepper, void* content); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_GetContent(SUNStepper stepper, void** content); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_SetLastFlag(SUNStepper stepper, int last_flag); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_GetLastFlag(SUNStepper stepper, int* last_flag); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_SetEvolveFn(SUNStepper stepper, SUNStepperEvolveFn fn); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_SetOneStepFn(SUNStepper stepper, SUNStepperOneStepFn fn); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_SetFullRhsFn(SUNStepper stepper, SUNStepperFullRhsFn fn); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_SetResetFn(SUNStepper stepper, SUNStepperResetFn fn); + +SUNDIALS_EXPORT +SUNErrCode SUNStepper_SetStopTimeFn(SUNStepper stepper, + SUNStepperSetStopTimeFn fn); + +SUNDIALS_EXPORT SUNErrCode SUNStepper_SetForcingFn(SUNStepper stepper, + SUNStepperSetForcingFn fn); + +SUNDIALS_EXPORT SUNErrCode SUNStepper_SetDestroyFn(SUNStepper stepper, + SUNStepperDestroyFn fn); + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNDIALS_STEPPER_H */ diff --git a/src/arkode/CMakeLists.txt b/src/arkode/CMakeLists.txt index 45386c0d87..f5019337f9 100644 --- a/src/arkode/CMakeLists.txt +++ b/src/arkode/CMakeLists.txt @@ -43,6 +43,7 @@ set(arkode_SOURCES arkode_sprkstep_io.c arkode_sprkstep.c arkode_sprk.c + arkode_sunstepper.c arkode_user_controller.c arkode.c) diff --git a/src/arkode/arkode.c b/src/arkode/arkode.c index 7c3e8b68ce..101781d036 100644 --- a/src/arkode/arkode.c +++ b/src/arkode/arkode.c @@ -1473,6 +1473,7 @@ ARKodeMem arkCreate(SUNContext sunctx) ark_mem->step_getnumnonlinsolviters = NULL; ark_mem->step_getnumnonlinsolvconvfails = NULL; ark_mem->step_getnonlinsolvstats = NULL; + ark_mem->step_setforcing = NULL; ark_mem->step_mem = NULL; ark_mem->step_supports_adaptive = SUNFALSE; ark_mem->step_supports_implicit = SUNFALSE; @@ -2714,6 +2715,10 @@ int arkHandleFailure(ARKodeMem ark_mem, int flag) arkProcessError(ark_mem, ARK_MAX_STAGE_LIMIT_FAIL, __LINE__, __func__, __FILE__, "The max stage limit failed unrecoverably"); break; + case ARK_SUNSTEPPER_ERR: + arkProcessError(ark_mem, ARK_SUNSTEPPER_ERR, __LINE__, __func__, __FILE__, + "An inner SUNStepper error occurred"); + break; default: /* This return should never happen */ arkProcessError(ark_mem, ARK_UNRECOGNIZED_ERROR, __LINE__, __func__, __FILE__, diff --git a/src/arkode/arkode_arkstep.c b/src/arkode/arkode_arkstep.c index d19bbf9935..a6ddccf89b 100644 --- a/src/arkode/arkode_arkstep.c +++ b/src/arkode/arkode_arkstep.c @@ -21,10 +21,12 @@ #include #include +#include "arkode/arkode.h" #include "arkode/arkode_butcher.h" #include "arkode_arkstep_impl.h" #include "arkode_impl.h" #include "arkode_interp_impl.h" +#include "sundials/sundials_types.h" #define FIXED_LIN_TOL @@ -139,6 +141,7 @@ void* ARKStepCreate(ARKRhsFn fe, ARKRhsFn fi, sunrealtype t0, N_Vector y0, ark_mem->step_getnumnonlinsolviters = arkStep_GetNumNonlinSolvIters; ark_mem->step_getnumnonlinsolvconvfails = arkStep_GetNumNonlinSolvConvFails; ark_mem->step_getnonlinsolvstats = arkStep_GetNonlinSolvStats; + ark_mem->step_setforcing = arkStep_SetInnerForcing; ark_mem->step_supports_adaptive = SUNTRUE; ark_mem->step_supports_implicit = SUNTRUE; ark_mem->step_supports_massmatrix = SUNTRUE; @@ -3340,16 +3343,19 @@ void arkStep_ApplyForcing(ARKodeARKStepMem step_mem, sunrealtype* stage_times, methods). ----------------------------------------------------------------------------*/ -int arkStep_SetInnerForcing(void* arkode_mem, sunrealtype tshift, +int arkStep_SetInnerForcing(ARKodeMem ark_mem, sunrealtype tshift, sunrealtype tscale, N_Vector* forcing, int nvecs) { - ARKodeMem ark_mem; ARKodeARKStepMem step_mem; - int retval; - /* access ARKodeMem and ARKodeARKStepMem structures */ - retval = arkStep_AccessARKODEStepMem(arkode_mem, __func__, &ark_mem, &step_mem); - if (retval != ARK_SUCCESS) { return (retval); } + /* access ARKodeARKStepMem structure */ + if (ark_mem->step_mem == NULL) + { + arkProcessError(ark_mem, ARK_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_ARKSTEP_NO_MEM); + return ARK_MEM_NULL; + } + step_mem = (ARKodeARKStepMem)ark_mem->step_mem; if (nvecs > 0) { diff --git a/src/arkode/arkode_arkstep_impl.h b/src/arkode/arkode_arkstep_impl.h index 806101a98b..21e0231a89 100644 --- a/src/arkode/arkode_arkstep_impl.h +++ b/src/arkode/arkode_arkstep_impl.h @@ -271,7 +271,7 @@ int arkStep_NlsConvTest(SUNNonlinearSolver NLS, N_Vector y, N_Vector del, sunrealtype tol, N_Vector ewt, void* arkode_mem); /* private functions for interfacing with MRIStep */ -int arkStep_SetInnerForcing(void* arkode_mem, sunrealtype tshift, +int arkStep_SetInnerForcing(ARKodeMem arkode_mem, sunrealtype tshift, sunrealtype tscale, N_Vector* f, int nvecs); int arkStep_MRIStepInnerEvolve(MRIStepInnerStepper stepper, sunrealtype t0, sunrealtype tout, N_Vector y); diff --git a/src/arkode/arkode_impl.h b/src/arkode/arkode_impl.h index 4e03a9ff59..a79f3e0d91 100644 --- a/src/arkode/arkode_impl.h +++ b/src/arkode/arkode_impl.h @@ -35,6 +35,7 @@ #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 */ extern "C" { @@ -290,6 +291,11 @@ typedef int (*ARKTimestepAttachMasssolFn)( typedef void (*ARKTimestepDisableMSetup)(ARKodeMem ark_mem); typedef void* (*ARKTimestepGetMassMemFn)(ARKodeMem ark_mem); +/* time stepper interface functions -- forcing */ +typedef int (*ARKTimestepSetForcingFn)(ARKodeMem ark_mem, sunrealtype tshift, + sunrealtype tscale, N_Vector* f, + int nvecs); + /*=============================================================== ARKODE interpolation module definition ===============================================================*/ @@ -455,6 +461,9 @@ struct ARKodeMemRec ARKTimestepGetMassMemFn step_getmassmem; ARKMassMultFn step_mmult; + /* Time stepper module -- forcing */ + ARKTimestepSetForcingFn step_setforcing; + /* N_Vector storage */ N_Vector ewt; /* error weight vector */ N_Vector rwt; /* residual weight vector */ diff --git a/src/arkode/arkode_io.c b/src/arkode/arkode_io.c index 1ae4e4c1a7..2ae790ed86 100644 --- a/src/arkode/arkode_io.c +++ b/src/arkode/arkode_io.c @@ -2903,6 +2903,7 @@ char* ARKodeGetReturnFlagName(long int flag) case ARK_MAX_STAGE_LIMIT_FAIL: sprintf(name, "ARK_MAX_STAGE_LIMIT_FAIL"); break; + case ARK_SUNSTEPPER_ERR: sprintf(name, "ARK_SUNSTEPPER_ERR"); break; case ARK_UNRECOGNIZED_ERROR: sprintf(name, "ARK_UNRECOGNIZED_ERROR"); break; default: sprintf(name, "NONE"); } diff --git a/src/arkode/arkode_mristep.c b/src/arkode/arkode_mristep.c index 3d86f50973..09f144ba6b 100644 --- a/src/arkode/arkode_mristep.c +++ b/src/arkode/arkode_mristep.c @@ -16,12 +16,15 @@ * This is the implementation file for ARKODE's MRI time stepper module. * ---------------------------------------------------------------------------*/ +#include "arkode/arkode_mristep.h" + #include #include #include #include #include +#include "arkode/arkode.h" #include "arkode_impl.h" #include "arkode_interp_impl.h" #include "arkode_mristep_impl.h" @@ -2547,9 +2550,9 @@ int mriStep_StageSetup(ARKodeMem ark_mem) return (ARK_SUCCESS); } -/*=============================================================== +/*--------------------------------------------------------------- User-callable functions for a custom inner integrator - ===============================================================*/ + ---------------------------------------------------------------*/ int MRIStepInnerStepper_Create(SUNContext sunctx, MRIStepInnerStepper* stepper) { @@ -2582,6 +2585,30 @@ int MRIStepInnerStepper_Create(SUNContext sunctx, MRIStepInnerStepper* stepper) return (ARK_SUCCESS); } +int MRIStepInnerStepper_CreateFromSUNStepper(SUNStepper sunstepper, + MRIStepInnerStepper* stepper) +{ + int retval = MRIStepInnerStepper_Create(sunstepper->sunctx, stepper); + if (retval != ARK_SUCCESS) { return retval; } + + retval = MRIStepInnerStepper_SetContent(*stepper, sunstepper); + if (retval != ARK_SUCCESS) { return retval; } + + retval = MRIStepInnerStepper_SetEvolveFn(*stepper, + mriStepInnerStepper_EvolveSUNStepper); + if (retval != ARK_SUCCESS) { return retval; } + + retval = MRIStepInnerStepper_SetFullRhsFn(*stepper, + mriStepInnerStepper_FullRhsSUNStepper); + if (retval != ARK_SUCCESS) { return retval; } + + retval = MRIStepInnerStepper_SetResetFn(*stepper, + mriStepInnerStepper_ResetSUNStepper); + if (retval != ARK_SUCCESS) { return retval; } + + return ARK_SUCCESS; +} + int MRIStepInnerStepper_Free(MRIStepInnerStepper* stepper) { if (*stepper == NULL) { return ARK_SUCCESS; } @@ -2743,9 +2770,9 @@ int MRIStepInnerStepper_GetForcingData(MRIStepInnerStepper stepper, return ARK_SUCCESS; } -/*=============================================================== - Private inner integrator functions - ===============================================================*/ +/*--------------------------------------------------------------- + Internal inner integrator functions + ---------------------------------------------------------------*/ /* Check for required operations */ int mriStepInnerStepper_HasRequiredOps(MRIStepInnerStepper stepper) @@ -2770,6 +2797,27 @@ int mriStepInnerStepper_Evolve(MRIStepInnerStepper stepper, sunrealtype t0, return stepper->last_flag; } +int mriStepInnerStepper_EvolveSUNStepper(MRIStepInnerStepper stepper, + SUNDIALS_MAYBE_UNUSED sunrealtype t0, + sunrealtype tout, N_Vector y) +{ + SUNStepper sunstepper = (SUNStepper)stepper->content; + sunrealtype tret; + + SUNErrCode err = sunstepper->ops->setstoptime(sunstepper, tout); + if (err != SUN_SUCCESS) + { + stepper->last_flag = sunstepper->last_flag; + return ARK_SUNSTEPPER_ERR; + } + + err = sunstepper->ops->evolve(sunstepper, tout, y, &tret); + stepper->last_flag = sunstepper->last_flag; + if (err != SUN_SUCCESS) { return ARK_SUNSTEPPER_ERR; } + + return ARK_SUCCESS; +} + /* 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. */ @@ -2784,6 +2832,26 @@ 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 ark_mode) +{ + SUNStepper sunstepper = (SUNStepper)stepper->content; + + SUNFullRhsMode mode; + switch (ark_mode) + { + case ARK_FULLRHS_START: mode = SUN_FULLRHS_START; break; + case ARK_FULLRHS_END: mode = SUN_FULLRHS_END; break; + default: mode = SUN_FULLRHS_OTHER; break; + } + + SUNErrCode err = sunstepper->ops->fullrhs(sunstepper, t, y, f, mode); + stepper->last_flag = sunstepper->last_flag; + if (err != SUN_SUCCESS) { return ARK_SUNSTEPPER_ERR; } + return ARK_SUCCESS; +} + /* Reset the inner (fast) stepper state */ int mriStepInnerStepper_Reset(MRIStepInnerStepper stepper, sunrealtype tR, N_Vector yR) @@ -2805,6 +2873,16 @@ int mriStepInnerStepper_Reset(MRIStepInnerStepper stepper, sunrealtype tR, } } +int mriStepInnerStepper_ResetSUNStepper(MRIStepInnerStepper stepper, + sunrealtype tR, N_Vector yR) +{ + SUNStepper sunstepper = (SUNStepper)stepper->content; + SUNErrCode err = sunstepper->ops->reset(sunstepper, tR, yR); + stepper->last_flag = sunstepper->last_flag; + if (err != SUN_SUCCESS) { return ARK_SUNSTEPPER_ERR; } + return ARK_SUCCESS; +} + /* Allocate MRI forcing and fused op workspace vectors if necessary */ int mriStepInnerStepper_AllocVecs(MRIStepInnerStepper stepper, int count, N_Vector tmpl) @@ -2847,7 +2925,7 @@ int mriStepInnerStepper_AllocVecs(MRIStepInnerStepper stepper, int count, /* Allocate fused operation workspace arrays */ if (stepper->vecs == NULL) { - stepper->vecs = (N_Vector*)calloc(count + 1, sizeof(*stepper->vecs)); + stepper->vecs = (N_Vector*)calloc(count + 1, sizeof(N_Vector)); if (stepper->vecs == NULL) { mriStepInnerStepper_FreeVecs(stepper); @@ -2857,7 +2935,7 @@ int mriStepInnerStepper_AllocVecs(MRIStepInnerStepper stepper, int count, if (stepper->vals == NULL) { - stepper->vals = (sunrealtype*)calloc(count + 1, sizeof(*stepper->vals)); + stepper->vals = (sunrealtype*)calloc(count + 1, sizeof(sunrealtype)); if (stepper->vals == NULL) { mriStepInnerStepper_FreeVecs(stepper); diff --git a/src/arkode/arkode_mristep_impl.h b/src/arkode/arkode_mristep_impl.h index f631307e07..3ae944b12d 100644 --- a/src/arkode/arkode_mristep_impl.h +++ b/src/arkode/arkode_mristep_impl.h @@ -272,10 +272,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, diff --git a/src/arkode/arkode_sunstepper.c b/src/arkode/arkode_sunstepper.c new file mode 100644 index 0000000000..261379bf2a --- /dev/null +++ b/src/arkode/arkode_sunstepper.c @@ -0,0 +1,214 @@ +/*--------------------------------------------------------------- + * Programmer(s): Steven B. Roberts @ LLNL + Cody J. Balos @ LLNL + *--------------------------------------------------------------- + * 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 + *--------------------------------------------------------------- + * This is the implementation file for ARKODE's interfacing with + * SUNStepper + *--------------------------------------------------------------*/ + +#include +#include +#include "arkode_impl.h" +#include "sundials_macros.h" + +static SUNErrCode arkSUNStepperEvolveHelper(SUNStepper stepper, + sunrealtype tout, N_Vector y, + sunrealtype* tret, int mode) +{ + SUNFunctionBegin(stepper->sunctx); + /* extract the ARKODE memory struct */ + void* arkode_mem; + SUNCheckCall(SUNStepper_GetContent(stepper, &arkode_mem)); + + /* evolve inner ODE */ + stepper->last_flag = ARKodeEvolve(arkode_mem, tout, y, tret, mode); + if (stepper->last_flag < 0) { return SUN_ERR_OP_FAIL; } + + return SUN_SUCCESS; +} + +static SUNErrCode arkSUNStepperEvolve(SUNStepper stepper, sunrealtype tout, + N_Vector y, sunrealtype* tret) +{ + return arkSUNStepperEvolveHelper(stepper, tout, y, tret, ARK_NORMAL); +} + +static SUNErrCode arkSUNStepperOneStep(SUNStepper stepper, sunrealtype tout, + N_Vector y, sunrealtype* tret) +{ + return arkSUNStepperEvolveHelper(stepper, tout, y, tret, ARK_ONE_STEP); +} + +/*------------------------------------------------------------------------------ + Implementation of SUNStepperFullRhsFn to compute the full inner + (fast) ODE IVP RHS. + ----------------------------------------------------------------------------*/ + +static SUNErrCode arkSUNStepperFullRhs(SUNStepper stepper, sunrealtype t, + N_Vector y, N_Vector f, + SUNFullRhsMode mode) +{ + SUNFunctionBegin(stepper->sunctx); + /* extract the ARKODE memory struct */ + void* arkode_mem; + SUNCheckCall(SUNStepper_GetContent(stepper, &arkode_mem)); + ARKodeMem ark_mem = (ARKodeMem)arkode_mem; + + int ark_mode; + switch (mode) + { + case SUN_FULLRHS_START: ark_mode = ARK_FULLRHS_START; break; + case SUN_FULLRHS_END: ark_mode = ARK_FULLRHS_END; break; + case SUN_FULLRHS_OTHER: ark_mode = ARK_FULLRHS_OTHER; break; + default: ark_mode = -1; break; + } + + stepper->last_flag = ark_mem->step_fullrhs(ark_mem, t, y, f, ark_mode); + if (stepper->last_flag != ARK_SUCCESS) { return SUN_ERR_OP_FAIL; } + + return SUN_SUCCESS; +} + +/*------------------------------------------------------------------------------ + Implementation of SUNStepperResetFn to reset the inner (fast) stepper + state. + ----------------------------------------------------------------------------*/ + +static SUNErrCode arkSUNStepperReset(SUNStepper stepper, sunrealtype tR, + N_Vector yR) +{ + SUNFunctionBegin(stepper->sunctx); + /* extract the ARKODE memory struct */ + void* arkode_mem; + SUNCheckCall(SUNStepper_GetContent(stepper, &arkode_mem)); + + stepper->last_flag = ARKodeReset(arkode_mem, tR, yR); + if (stepper->last_flag != ARK_SUCCESS) { return SUN_ERR_OP_FAIL; } + + return SUN_SUCCESS; +} + +/*------------------------------------------------------------------------------ + Implementation of SUNStepperStopTimeFn to set the tstop time + ----------------------------------------------------------------------------*/ + +static SUNErrCode arkSUNStepperSetStopTime(SUNStepper stepper, sunrealtype tstop) +{ + SUNFunctionBegin(stepper->sunctx); + /* extract the ARKODE memory struct */ + void* arkode_mem; + SUNCheckCall(SUNStepper_GetContent(stepper, &arkode_mem)); + + stepper->last_flag = ARKodeSetStopTime(arkode_mem, tstop); + if (stepper->last_flag != ARK_SUCCESS) { return SUN_ERR_OP_FAIL; } + + return SUN_SUCCESS; +} + +static SUNErrCode arkSUNStepperSetForcing(SUNStepper stepper, sunrealtype tshift, + sunrealtype tscale, N_Vector* forcing, + int nforcing) +{ + SUNFunctionBegin(stepper->sunctx); + /* extract the ARKODE memory struct */ + void* arkode_mem; + SUNCheckCall(SUNStepper_GetContent(stepper, &arkode_mem)); + ARKodeMem ark_mem = (ARKodeMem)arkode_mem; + + stepper->last_flag = ark_mem->step_setforcing(ark_mem, tshift, tscale, + forcing, nforcing); + if (stepper->last_flag != ARK_SUCCESS) { return SUN_ERR_OP_FAIL; } + + return SUN_SUCCESS; +} + +int ARKodeCreateSUNStepper(void* arkode_mem, SUNStepper* stepper) +{ + /* unpack ark_mem */ + if (arkode_mem == NULL) + { + arkProcessError(NULL, ARK_MEM_NULL, __LINE__, __func__, __FILE__, + MSG_ARK_NO_MEM); + return ARK_MEM_NULL; + } + ARKodeMem ark_mem = (ARKodeMem)arkode_mem; + + SUNErrCode err = SUNStepper_Create(ark_mem->sunctx, stepper); + if (err != SUN_SUCCESS) + { + arkProcessError(ark_mem, ARK_SUNSTEPPER_ERR, __LINE__, __func__, __FILE__, + "Failed to create SUNStepper"); + return ARK_SUNSTEPPER_ERR; + } + + err = SUNStepper_SetContent(*stepper, arkode_mem); + if (err != SUN_SUCCESS) + { + arkProcessError(ark_mem, ARK_SUNSTEPPER_ERR, __LINE__, __func__, __FILE__, + "Failed to set SUNStepper content"); + return ARK_SUNSTEPPER_ERR; + } + + err = SUNStepper_SetEvolveFn(*stepper, arkSUNStepperEvolve); + if (err != SUN_SUCCESS) + { + arkProcessError(ark_mem, ARK_SUNSTEPPER_ERR, __LINE__, __func__, __FILE__, + "Failed to set SUNStepper evolve function"); + return ARK_SUNSTEPPER_ERR; + } + + err = SUNStepper_SetOneStepFn(*stepper, arkSUNStepperOneStep); + if (err != SUN_SUCCESS) + { + arkProcessError(ark_mem, ARK_SUNSTEPPER_ERR, __LINE__, __func__, __FILE__, + "Failed to set SUNStepper one step function"); + return ARK_SUNSTEPPER_ERR; + } + + err = SUNStepper_SetFullRhsFn(*stepper, arkSUNStepperFullRhs); + if (err != SUN_SUCCESS) + { + arkProcessError(ark_mem, ARK_SUNSTEPPER_ERR, __LINE__, __func__, __FILE__, + "Failed to set SUNStepper full RHS function"); + return ARK_SUNSTEPPER_ERR; + } + + err = SUNStepper_SetResetFn(*stepper, arkSUNStepperReset); + if (err != SUN_SUCCESS) + { + arkProcessError(ark_mem, ARK_SUNSTEPPER_ERR, __LINE__, __func__, __FILE__, + "Failed to set SUNStepper reset function"); + return ARK_SUNSTEPPER_ERR; + } + + err = SUNStepper_SetStopTimeFn(*stepper, arkSUNStepperSetStopTime); + if (err != SUN_SUCCESS) + { + arkProcessError(ark_mem, ARK_SUNSTEPPER_ERR, __LINE__, __func__, __FILE__, + "Failed to set SUNStepper stop time function"); + return ARK_SUNSTEPPER_ERR; + } + + if (ark_mem->step_setforcing != NULL) + { + err = SUNStepper_SetForcingFn(*stepper, arkSUNStepperSetForcing); + if (err != SUN_SUCCESS) + { + arkProcessError(ark_mem, ARK_SUNSTEPPER_ERR, __LINE__, __func__, __FILE__, + "Failed to set SUNStepper forcing function"); + return ARK_SUNSTEPPER_ERR; + } + } + + return ARK_SUCCESS; +} diff --git a/src/arkode/fmod_int32/farkode_mod.c b/src/arkode/fmod_int32/farkode_mod.c index 52f187e8c4..4bfdf17364 100644 --- a/src/arkode/fmod_int32/farkode_mod.c +++ b/src/arkode/fmod_int32/farkode_mod.c @@ -2253,6 +2253,20 @@ SWIGEXPORT int _wrap_FARKodeGetNumRelaxSolveIters(void *farg1, long *farg2) { } +SWIGEXPORT int _wrap_FARKodeCreateSUNStepper(void *farg1, void *farg2) { + int fresult ; + void *arg1 = (void *) 0 ; + SUNStepper *arg2 = (SUNStepper *) 0 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (SUNStepper *)(farg2); + result = (int)ARKodeCreateSUNStepper(arg1,arg2); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FARKBandPrecInit(void *farg1, int32_t const *farg2, int32_t const *farg3, int32_t const *farg4) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/arkode/fmod_int32/farkode_mod.f90 b/src/arkode/fmod_int32/farkode_mod.f90 index 5dca9b3b38..3cd700fa7e 100644 --- a/src/arkode/fmod_int32/farkode_mod.f90 +++ b/src/arkode/fmod_int32/farkode_mod.f90 @@ -96,6 +96,7 @@ module farkode_mod integer(C_INT), parameter, public :: ARK_STEPPER_UNSUPPORTED = -48_C_INT integer(C_INT), parameter, public :: ARK_DOMEIG_FAIL = -49_C_INT integer(C_INT), parameter, public :: ARK_MAX_STAGE_LIMIT_FAIL = -50_C_INT + integer(C_INT), parameter, public :: ARK_SUNSTEPPER_ERR = -51_C_INT integer(C_INT), parameter, public :: ARK_UNRECOGNIZED_ERROR = -99_C_INT ! typedef enum ARKRelaxSolver enum, bind(c) @@ -243,6 +244,7 @@ module farkode_mod public :: FARKodeGetNumRelaxBoundFails public :: FARKodeGetNumRelaxSolveFails public :: FARKodeGetNumRelaxSolveIters + public :: FARKodeCreateSUNStepper public :: FARKBandPrecInit public :: FARKBandPrecGetWorkSpace public :: FARKBandPrecGetNumRhsEvals @@ -1706,6 +1708,15 @@ function swigc_FARKodeGetNumRelaxSolveIters(farg1, farg2) & integer(C_INT) :: fresult end function +function swigc_FARKodeCreateSUNStepper(farg1, farg2) & +bind(C, name="_wrap_FARKodeCreateSUNStepper") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + function swigc_FARKBandPrecInit(farg1, farg2, farg3, farg4) & bind(C, name="_wrap_FARKBandPrecInit") & result(fresult) @@ -4631,6 +4642,22 @@ function FARKodeGetNumRelaxSolveIters(arkode_mem, iters) & swig_result = fresult end function +function FARKodeCreateSUNStepper(arkode_mem, stepper) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: arkode_mem +type(C_PTR), target, intent(inout) :: stepper +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = arkode_mem +farg2 = c_loc(stepper) +fresult = swigc_FARKodeCreateSUNStepper(farg1, farg2) +swig_result = fresult +end function + function FARKBandPrecInit(arkode_mem, n, mu, ml) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/arkode/fmod_int32/farkode_mristep_mod.c b/src/arkode/fmod_int32/farkode_mristep_mod.c index 8b6a72b660..b454003c6d 100644 --- a/src/arkode/fmod_int32/farkode_mristep_mod.c +++ b/src/arkode/fmod_int32/farkode_mristep_mod.c @@ -755,6 +755,20 @@ SWIGEXPORT int _wrap_FMRIStepInnerStepper_Create(void *farg1, void *farg2) { } +SWIGEXPORT int _wrap_FMRIStepInnerStepper_CreateFromSUNStepper(void *farg1, void *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + MRIStepInnerStepper *arg2 = (MRIStepInnerStepper *) 0 ; + int result; + + arg1 = (SUNStepper)(farg1); + arg2 = (MRIStepInnerStepper *)(farg2); + result = (int)MRIStepInnerStepper_CreateFromSUNStepper(arg1,arg2); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FMRIStepInnerStepper_Free(void *farg1) { int fresult ; MRIStepInnerStepper *arg1 = (MRIStepInnerStepper *) 0 ; diff --git a/src/arkode/fmod_int32/farkode_mristep_mod.f90 b/src/arkode/fmod_int32/farkode_mristep_mod.f90 index ecba398b89..9505d486cb 100644 --- a/src/arkode/fmod_int32/farkode_mristep_mod.f90 +++ b/src/arkode/fmod_int32/farkode_mristep_mod.f90 @@ -132,6 +132,7 @@ module farkode_mristep_mod public :: FMRIStepGetCurrentCoupling public :: FMRIStepGetLastInnerStepFlag public :: FMRIStepInnerStepper_Create + public :: FMRIStepInnerStepper_CreateFromSUNStepper public :: FMRIStepInnerStepper_Free public :: FMRIStepInnerStepper_SetContent public :: FMRIStepInnerStepper_GetContent @@ -530,6 +531,15 @@ function swigc_FMRIStepInnerStepper_Create(farg1, farg2) & integer(C_INT) :: fresult end function +function swigc_FMRIStepInnerStepper_CreateFromSUNStepper(farg1, farg2) & +bind(C, name="_wrap_FMRIStepInnerStepper_CreateFromSUNStepper") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + function swigc_FMRIStepInnerStepper_Free(farg1) & bind(C, name="_wrap_FMRIStepInnerStepper_Free") & result(fresult) @@ -1931,6 +1941,22 @@ function FMRIStepInnerStepper_Create(sunctx, stepper) & swig_result = fresult end function +function FMRIStepInnerStepper_CreateFromSUNStepper(sunstepper, stepper) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: sunstepper +type(C_PTR), target, intent(inout) :: stepper +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = sunstepper +farg2 = c_loc(stepper) +fresult = swigc_FMRIStepInnerStepper_CreateFromSUNStepper(farg1, farg2) +swig_result = fresult +end function + function FMRIStepInnerStepper_Free(stepper) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/arkode/fmod_int64/farkode_mod.c b/src/arkode/fmod_int64/farkode_mod.c index b092ee9d57..5a63d50210 100644 --- a/src/arkode/fmod_int64/farkode_mod.c +++ b/src/arkode/fmod_int64/farkode_mod.c @@ -2253,6 +2253,20 @@ SWIGEXPORT int _wrap_FARKodeGetNumRelaxSolveIters(void *farg1, long *farg2) { } +SWIGEXPORT int _wrap_FARKodeCreateSUNStepper(void *farg1, void *farg2) { + int fresult ; + void *arg1 = (void *) 0 ; + SUNStepper *arg2 = (SUNStepper *) 0 ; + int result; + + arg1 = (void *)(farg1); + arg2 = (SUNStepper *)(farg2); + result = (int)ARKodeCreateSUNStepper(arg1,arg2); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FARKBandPrecInit(void *farg1, int64_t const *farg2, int64_t const *farg3, int64_t const *farg4) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/arkode/fmod_int64/farkode_mod.f90 b/src/arkode/fmod_int64/farkode_mod.f90 index f2239fc011..3b255deb0d 100644 --- a/src/arkode/fmod_int64/farkode_mod.f90 +++ b/src/arkode/fmod_int64/farkode_mod.f90 @@ -96,6 +96,7 @@ module farkode_mod integer(C_INT), parameter, public :: ARK_STEPPER_UNSUPPORTED = -48_C_INT integer(C_INT), parameter, public :: ARK_DOMEIG_FAIL = -49_C_INT integer(C_INT), parameter, public :: ARK_MAX_STAGE_LIMIT_FAIL = -50_C_INT + integer(C_INT), parameter, public :: ARK_SUNSTEPPER_ERR = -51_C_INT integer(C_INT), parameter, public :: ARK_UNRECOGNIZED_ERROR = -99_C_INT ! typedef enum ARKRelaxSolver enum, bind(c) @@ -243,6 +244,7 @@ module farkode_mod public :: FARKodeGetNumRelaxBoundFails public :: FARKodeGetNumRelaxSolveFails public :: FARKodeGetNumRelaxSolveIters + public :: FARKodeCreateSUNStepper public :: FARKBandPrecInit public :: FARKBandPrecGetWorkSpace public :: FARKBandPrecGetNumRhsEvals @@ -1706,6 +1708,15 @@ function swigc_FARKodeGetNumRelaxSolveIters(farg1, farg2) & integer(C_INT) :: fresult end function +function swigc_FARKodeCreateSUNStepper(farg1, farg2) & +bind(C, name="_wrap_FARKodeCreateSUNStepper") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + function swigc_FARKBandPrecInit(farg1, farg2, farg3, farg4) & bind(C, name="_wrap_FARKBandPrecInit") & result(fresult) @@ -4631,6 +4642,22 @@ function FARKodeGetNumRelaxSolveIters(arkode_mem, iters) & swig_result = fresult end function +function FARKodeCreateSUNStepper(arkode_mem, stepper) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: arkode_mem +type(C_PTR), target, intent(inout) :: stepper +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = arkode_mem +farg2 = c_loc(stepper) +fresult = swigc_FARKodeCreateSUNStepper(farg1, farg2) +swig_result = fresult +end function + function FARKBandPrecInit(arkode_mem, n, mu, ml) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/arkode/fmod_int64/farkode_mristep_mod.c b/src/arkode/fmod_int64/farkode_mristep_mod.c index 5ddb7d077a..d5597bea4f 100644 --- a/src/arkode/fmod_int64/farkode_mristep_mod.c +++ b/src/arkode/fmod_int64/farkode_mristep_mod.c @@ -755,6 +755,20 @@ SWIGEXPORT int _wrap_FMRIStepInnerStepper_Create(void *farg1, void *farg2) { } +SWIGEXPORT int _wrap_FMRIStepInnerStepper_CreateFromSUNStepper(void *farg1, void *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + MRIStepInnerStepper *arg2 = (MRIStepInnerStepper *) 0 ; + int result; + + arg1 = (SUNStepper)(farg1); + arg2 = (MRIStepInnerStepper *)(farg2); + result = (int)MRIStepInnerStepper_CreateFromSUNStepper(arg1,arg2); + fresult = (int)(result); + return fresult; +} + + SWIGEXPORT int _wrap_FMRIStepInnerStepper_Free(void *farg1) { int fresult ; MRIStepInnerStepper *arg1 = (MRIStepInnerStepper *) 0 ; diff --git a/src/arkode/fmod_int64/farkode_mristep_mod.f90 b/src/arkode/fmod_int64/farkode_mristep_mod.f90 index be5bb7445a..e2202c73da 100644 --- a/src/arkode/fmod_int64/farkode_mristep_mod.f90 +++ b/src/arkode/fmod_int64/farkode_mristep_mod.f90 @@ -132,6 +132,7 @@ module farkode_mristep_mod public :: FMRIStepGetCurrentCoupling public :: FMRIStepGetLastInnerStepFlag public :: FMRIStepInnerStepper_Create + public :: FMRIStepInnerStepper_CreateFromSUNStepper public :: FMRIStepInnerStepper_Free public :: FMRIStepInnerStepper_SetContent public :: FMRIStepInnerStepper_GetContent @@ -530,6 +531,15 @@ function swigc_FMRIStepInnerStepper_Create(farg1, farg2) & integer(C_INT) :: fresult end function +function swigc_FMRIStepInnerStepper_CreateFromSUNStepper(farg1, farg2) & +bind(C, name="_wrap_FMRIStepInnerStepper_CreateFromSUNStepper") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + function swigc_FMRIStepInnerStepper_Free(farg1) & bind(C, name="_wrap_FMRIStepInnerStepper_Free") & result(fresult) @@ -1931,6 +1941,22 @@ function FMRIStepInnerStepper_Create(sunctx, stepper) & swig_result = fresult end function +function FMRIStepInnerStepper_CreateFromSUNStepper(sunstepper, stepper) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: sunstepper +type(C_PTR), target, intent(inout) :: stepper +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = sunstepper +farg2 = c_loc(stepper) +fresult = swigc_FMRIStepInnerStepper_CreateFromSUNStepper(farg1, farg2) +swig_result = fresult +end function + function FMRIStepInnerStepper_Free(stepper) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/sundials/CMakeLists.txt b/src/sundials/CMakeLists.txt index cf31cb497e..e3d82d88a3 100644 --- a/src/sundials/CMakeLists.txt +++ b/src/sundials/CMakeLists.txt @@ -49,6 +49,7 @@ set(sundials_HEADERS sundials_nvector.hpp sundials_profiler.h sundials_profiler.hpp + sundials_stepper.h sundials_types_deprecated.h sundials_types.h sundials_version.h) @@ -95,6 +96,7 @@ set(sundials_SOURCES sundials_nonlinearsolver.c sundials_nvector_senswrapper.c sundials_nvector.c + sundials_stepper.c sundials_profiler.c sundials_version.c) diff --git a/src/sundials/fmod_int32/fsundials_core_mod.c b/src/sundials/fmod_int32/fsundials_core_mod.c index 62e0215249..9cec8422c8 100644 --- a/src/sundials/fmod_int32/fsundials_core_mod.c +++ b/src/sundials/fmod_int32/fsundials_core_mod.c @@ -291,6 +291,9 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { #include "sundials/sundials_adaptcontroller.h" + +#include "sundials/sundials_stepper.h" + SWIGEXPORT void _wrap_FSUNLogErrHandlerFn(int const *farg1, SwigArrayWrapper *farg2, SwigArrayWrapper *farg3, SwigArrayWrapper *farg4, int const *farg5, void *farg6, void *farg7) { int arg1 ; char *arg2 = (char *) 0 ; @@ -2641,4 +2644,290 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Space(SUNAdaptController farg1, long *f } +SWIGEXPORT int _wrap_FSUNStepper_Create(void *farg1, void *farg2) { + int fresult ; + SUNContext arg1 = (SUNContext) 0 ; + SUNStepper *arg2 = (SUNStepper *) 0 ; + SUNErrCode result; + + arg1 = (SUNContext)(farg1); + arg2 = (SUNStepper *)(farg2); + result = (SUNErrCode)SUNStepper_Create(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_Destroy(void *farg1) { + int fresult ; + SUNStepper *arg1 = (SUNStepper *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper *)(farg1); + result = (SUNErrCode)SUNStepper_Destroy(arg1); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_Evolve(void *farg1, double const *farg2, N_Vector farg3, double *farg4) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + N_Vector arg3 = (N_Vector) 0 ; + sunrealtype *arg4 = (sunrealtype *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (N_Vector)(farg3); + arg4 = (sunrealtype *)(farg4); + result = (SUNErrCode)SUNStepper_Evolve(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_OneStep(void *farg1, double const *farg2, N_Vector farg3, double *farg4) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + N_Vector arg3 = (N_Vector) 0 ; + sunrealtype *arg4 = (sunrealtype *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (N_Vector)(farg3); + arg4 = (sunrealtype *)(farg4); + result = (SUNErrCode)SUNStepper_OneStep(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_FullRhs(void *farg1, double const *farg2, N_Vector farg3, N_Vector farg4, int const *farg5) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + N_Vector arg3 = (N_Vector) 0 ; + N_Vector arg4 = (N_Vector) 0 ; + SUNFullRhsMode arg5 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (N_Vector)(farg3); + arg4 = (N_Vector)(farg4); + arg5 = (SUNFullRhsMode)(*farg5); + result = (SUNErrCode)SUNStepper_FullRhs(arg1,arg2,arg3,arg4,arg5); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_Reset(void *farg1, double const *farg2, N_Vector farg3) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + N_Vector arg3 = (N_Vector) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (N_Vector)(farg3); + result = (SUNErrCode)SUNStepper_Reset(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetStopTime(void *farg1, double const *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + result = (SUNErrCode)SUNStepper_SetStopTime(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetForcing(void *farg1, double const *farg2, double const *farg3, void *farg4, int const *farg5) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + sunrealtype arg3 ; + N_Vector *arg4 = (N_Vector *) 0 ; + int arg5 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (sunrealtype)(*farg3); + arg4 = (N_Vector *)(farg4); + arg5 = (int)(*farg5); + result = (SUNErrCode)SUNStepper_SetForcing(arg1,arg2,arg3,arg4,arg5); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetContent(void *farg1, void *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + void *arg2 = (void *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (void *)(farg2); + result = (SUNErrCode)SUNStepper_SetContent(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_GetContent(void *farg1, void *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + void **arg2 = (void **) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (void **)(farg2); + result = (SUNErrCode)SUNStepper_GetContent(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetLastFlag(void *farg1, int const *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + int arg2 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (int)(*farg2); + result = (SUNErrCode)SUNStepper_SetLastFlag(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_GetLastFlag(void *farg1, int *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + int *arg2 = (int *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (int *)(farg2); + result = (SUNErrCode)SUNStepper_GetLastFlag(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetEvolveFn(void *farg1, SUNStepperEvolveFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperEvolveFn arg2 = (SUNStepperEvolveFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperEvolveFn)(farg2); + result = (SUNErrCode)SUNStepper_SetEvolveFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetOneStepFn(void *farg1, SUNStepperOneStepFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperOneStepFn arg2 = (SUNStepperOneStepFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperOneStepFn)(farg2); + result = (SUNErrCode)SUNStepper_SetOneStepFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetFullRhsFn(void *farg1, SUNStepperFullRhsFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperFullRhsFn arg2 = (SUNStepperFullRhsFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperFullRhsFn)(farg2); + result = (SUNErrCode)SUNStepper_SetFullRhsFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetResetFn(void *farg1, SUNStepperResetFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperResetFn arg2 = (SUNStepperResetFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperResetFn)(farg2); + result = (SUNErrCode)SUNStepper_SetResetFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetStopTimeFn(void *farg1, SUNStepperSetStopTimeFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperSetStopTimeFn arg2 = (SUNStepperSetStopTimeFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperSetStopTimeFn)(farg2); + result = (SUNErrCode)SUNStepper_SetStopTimeFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetForcingFn(void *farg1, SUNStepperSetForcingFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperSetForcingFn arg2 = (SUNStepperSetForcingFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperSetForcingFn)(farg2); + result = (SUNErrCode)SUNStepper_SetForcingFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetDestroyFn(void *farg1, SUNStepperDestroyFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperDestroyFn arg2 = (SUNStepperDestroyFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperDestroyFn)(farg2); + result = (SUNErrCode)SUNStepper_SetDestroyFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + diff --git a/src/sundials/fmod_int32/fsundials_core_mod.f90 b/src/sundials/fmod_int32/fsundials_core_mod.f90 index 2bda4cb0fe..0b95e5c880 100644 --- a/src/sundials/fmod_int32/fsundials_core_mod.f90 +++ b/src/sundials/fmod_int32/fsundials_core_mod.f90 @@ -543,6 +543,33 @@ module fsundials_core_mod public :: FSUNAdaptController_SetErrorBias public :: FSUNAdaptController_UpdateH public :: FSUNAdaptController_Space + ! typedef enum SUNFullRhsMode + enum, bind(c) + enumerator :: SUN_FULLRHS_START + enumerator :: SUN_FULLRHS_END + enumerator :: SUN_FULLRHS_OTHER + end enum + integer, parameter, public :: SUNFullRhsMode = kind(SUN_FULLRHS_START) + public :: SUN_FULLRHS_START, SUN_FULLRHS_END, SUN_FULLRHS_OTHER + public :: FSUNStepper_Create + public :: FSUNStepper_Destroy + public :: FSUNStepper_Evolve + public :: FSUNStepper_OneStep + public :: FSUNStepper_FullRhs + public :: FSUNStepper_Reset + public :: FSUNStepper_SetStopTime + public :: FSUNStepper_SetForcing + public :: FSUNStepper_SetContent + public :: FSUNStepper_GetContent + public :: FSUNStepper_SetLastFlag + public :: FSUNStepper_GetLastFlag + public :: FSUNStepper_SetEvolveFn + public :: FSUNStepper_SetOneStepFn + public :: FSUNStepper_SetFullRhsFn + public :: FSUNStepper_SetResetFn + public :: FSUNStepper_SetStopTimeFn + public :: FSUNStepper_SetForcingFn + public :: FSUNStepper_SetDestroyFn ! WRAPPER DECLARATIONS interface @@ -2041,6 +2068,187 @@ function swigc_FSUNAdaptController_Space(farg1, farg2, farg3) & integer(C_INT) :: fresult end function +function swigc_FSUNStepper_Create(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_Create") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_Destroy(farg1) & +bind(C, name="_wrap_FSUNStepper_Destroy") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_Evolve(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNStepper_Evolve") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +type(C_PTR), value :: farg3 +type(C_PTR), value :: farg4 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_OneStep(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNStepper_OneStep") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +type(C_PTR), value :: farg3 +type(C_PTR), value :: farg4 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_FullRhs(farg1, farg2, farg3, farg4, farg5) & +bind(C, name="_wrap_FSUNStepper_FullRhs") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +type(C_PTR), value :: farg3 +type(C_PTR), value :: farg4 +integer(C_INT), intent(in) :: farg5 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_Reset(farg1, farg2, farg3) & +bind(C, name="_wrap_FSUNStepper_Reset") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +type(C_PTR), value :: farg3 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetStopTime(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetStopTime") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetForcing(farg1, farg2, farg3, farg4, farg5) & +bind(C, name="_wrap_FSUNStepper_SetForcing") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +real(C_DOUBLE), intent(in) :: farg3 +type(C_PTR), value :: farg4 +integer(C_INT), intent(in) :: farg5 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetContent(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetContent") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_GetContent(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_GetContent") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetLastFlag(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetLastFlag") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +integer(C_INT), intent(in) :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_GetLastFlag(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_GetLastFlag") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetEvolveFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetEvolveFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetOneStepFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetOneStepFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetFullRhsFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetFullRhsFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetResetFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetResetFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetStopTimeFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetStopTimeFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetForcingFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetForcingFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetDestroyFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetDestroyFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + end interface @@ -4782,5 +4990,339 @@ function FSUNAdaptController_Space(c, lenrw, leniw) & swig_result = fresult end function +function FSUNStepper_Create(sunctx, stepper) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: sunctx +type(C_PTR), target, intent(inout) :: stepper +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = sunctx +farg2 = c_loc(stepper) +fresult = swigc_FSUNStepper_Create(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_Destroy(stepper) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR), target, intent(inout) :: stepper +integer(C_INT) :: fresult +type(C_PTR) :: farg1 + +farg1 = c_loc(stepper) +fresult = swigc_FSUNStepper_Destroy(farg1) +swig_result = fresult +end function + +function FSUNStepper_Evolve(stepper, tout, vret, tret) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tout +type(N_Vector), target, intent(inout) :: vret +real(C_DOUBLE), dimension(*), target, intent(inout) :: tret +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +type(C_PTR) :: farg3 +type(C_PTR) :: farg4 + +farg1 = stepper +farg2 = tout +farg3 = c_loc(vret) +farg4 = c_loc(tret(1)) +fresult = swigc_FSUNStepper_Evolve(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + +function FSUNStepper_OneStep(stepper, tout, vret, tret) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tout +type(N_Vector), target, intent(inout) :: vret +real(C_DOUBLE), dimension(*), target, intent(inout) :: tret +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +type(C_PTR) :: farg3 +type(C_PTR) :: farg4 + +farg1 = stepper +farg2 = tout +farg3 = c_loc(vret) +farg4 = c_loc(tret(1)) +fresult = swigc_FSUNStepper_OneStep(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + +function FSUNStepper_FullRhs(stepper, t, v, f, mode) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: t +type(N_Vector), target, intent(inout) :: v +type(N_Vector), target, intent(inout) :: f +integer(SUNFullRhsMode), intent(in) :: mode +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +type(C_PTR) :: farg3 +type(C_PTR) :: farg4 +integer(C_INT) :: farg5 + +farg1 = stepper +farg2 = t +farg3 = c_loc(v) +farg4 = c_loc(f) +farg5 = mode +fresult = swigc_FSUNStepper_FullRhs(farg1, farg2, farg3, farg4, farg5) +swig_result = fresult +end function + +function FSUNStepper_Reset(stepper, tr, vr) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tr +type(N_Vector), target, intent(inout) :: vr +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +type(C_PTR) :: farg3 + +farg1 = stepper +farg2 = tr +farg3 = c_loc(vr) +fresult = swigc_FSUNStepper_Reset(farg1, farg2, farg3) +swig_result = fresult +end function + +function FSUNStepper_SetStopTime(stepper, tstop) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tstop +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 + +farg1 = stepper +farg2 = tstop +fresult = swigc_FSUNStepper_SetStopTime(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetForcing(stepper, tshift, tscale, forcing, nforcing) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tshift +real(C_DOUBLE), intent(in) :: tscale +type(C_PTR) :: forcing +integer(C_INT), intent(in) :: nforcing +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +real(C_DOUBLE) :: farg3 +type(C_PTR) :: farg4 +integer(C_INT) :: farg5 + +farg1 = stepper +farg2 = tshift +farg3 = tscale +farg4 = forcing +farg5 = nforcing +fresult = swigc_FSUNStepper_SetForcing(farg1, farg2, farg3, farg4, farg5) +swig_result = fresult +end function + +function FSUNStepper_SetContent(stepper, content) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_PTR) :: content +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = stepper +farg2 = content +fresult = swigc_FSUNStepper_SetContent(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_GetContent(stepper, content) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_PTR), target, intent(inout) :: content +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = stepper +farg2 = c_loc(content) +fresult = swigc_FSUNStepper_GetContent(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetLastFlag(stepper, last_flag) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +integer(C_INT), intent(in) :: last_flag +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +integer(C_INT) :: farg2 + +farg1 = stepper +farg2 = last_flag +fresult = swigc_FSUNStepper_SetLastFlag(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_GetLastFlag(stepper, last_flag) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +integer(C_INT), dimension(*), target, intent(inout) :: last_flag +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = stepper +farg2 = c_loc(last_flag(1)) +fresult = swigc_FSUNStepper_GetLastFlag(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetEvolveFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetEvolveFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetOneStepFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetOneStepFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetFullRhsFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetFullRhsFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetResetFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetResetFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetStopTimeFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetStopTimeFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetForcingFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetForcingFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetDestroyFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetDestroyFn(farg1, farg2) +swig_result = fresult +end function + end module diff --git a/src/sundials/fmod_int64/fsundials_core_mod.c b/src/sundials/fmod_int64/fsundials_core_mod.c index 2478b92d68..b1f96d2b55 100644 --- a/src/sundials/fmod_int64/fsundials_core_mod.c +++ b/src/sundials/fmod_int64/fsundials_core_mod.c @@ -291,6 +291,9 @@ SWIGINTERN SwigArrayWrapper SwigArrayWrapper_uninitialized() { #include "sundials/sundials_adaptcontroller.h" + +#include "sundials/sundials_stepper.h" + SWIGEXPORT void _wrap_FSUNLogErrHandlerFn(int const *farg1, SwigArrayWrapper *farg2, SwigArrayWrapper *farg3, SwigArrayWrapper *farg4, int const *farg5, void *farg6, void *farg7) { int arg1 ; char *arg2 = (char *) 0 ; @@ -2641,4 +2644,290 @@ SWIGEXPORT int _wrap_FSUNAdaptController_Space(SUNAdaptController farg1, long *f } +SWIGEXPORT int _wrap_FSUNStepper_Create(void *farg1, void *farg2) { + int fresult ; + SUNContext arg1 = (SUNContext) 0 ; + SUNStepper *arg2 = (SUNStepper *) 0 ; + SUNErrCode result; + + arg1 = (SUNContext)(farg1); + arg2 = (SUNStepper *)(farg2); + result = (SUNErrCode)SUNStepper_Create(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_Destroy(void *farg1) { + int fresult ; + SUNStepper *arg1 = (SUNStepper *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper *)(farg1); + result = (SUNErrCode)SUNStepper_Destroy(arg1); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_Evolve(void *farg1, double const *farg2, N_Vector farg3, double *farg4) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + N_Vector arg3 = (N_Vector) 0 ; + sunrealtype *arg4 = (sunrealtype *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (N_Vector)(farg3); + arg4 = (sunrealtype *)(farg4); + result = (SUNErrCode)SUNStepper_Evolve(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_OneStep(void *farg1, double const *farg2, N_Vector farg3, double *farg4) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + N_Vector arg3 = (N_Vector) 0 ; + sunrealtype *arg4 = (sunrealtype *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (N_Vector)(farg3); + arg4 = (sunrealtype *)(farg4); + result = (SUNErrCode)SUNStepper_OneStep(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_FullRhs(void *farg1, double const *farg2, N_Vector farg3, N_Vector farg4, int const *farg5) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + N_Vector arg3 = (N_Vector) 0 ; + N_Vector arg4 = (N_Vector) 0 ; + SUNFullRhsMode arg5 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (N_Vector)(farg3); + arg4 = (N_Vector)(farg4); + arg5 = (SUNFullRhsMode)(*farg5); + result = (SUNErrCode)SUNStepper_FullRhs(arg1,arg2,arg3,arg4,arg5); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_Reset(void *farg1, double const *farg2, N_Vector farg3) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + N_Vector arg3 = (N_Vector) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (N_Vector)(farg3); + result = (SUNErrCode)SUNStepper_Reset(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetStopTime(void *farg1, double const *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + result = (SUNErrCode)SUNStepper_SetStopTime(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetForcing(void *farg1, double const *farg2, double const *farg3, void *farg4, int const *farg5) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + sunrealtype arg2 ; + sunrealtype arg3 ; + N_Vector *arg4 = (N_Vector *) 0 ; + int arg5 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (sunrealtype)(*farg2); + arg3 = (sunrealtype)(*farg3); + arg4 = (N_Vector *)(farg4); + arg5 = (int)(*farg5); + result = (SUNErrCode)SUNStepper_SetForcing(arg1,arg2,arg3,arg4,arg5); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetContent(void *farg1, void *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + void *arg2 = (void *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (void *)(farg2); + result = (SUNErrCode)SUNStepper_SetContent(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_GetContent(void *farg1, void *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + void **arg2 = (void **) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (void **)(farg2); + result = (SUNErrCode)SUNStepper_GetContent(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetLastFlag(void *farg1, int const *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + int arg2 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (int)(*farg2); + result = (SUNErrCode)SUNStepper_SetLastFlag(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_GetLastFlag(void *farg1, int *farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + int *arg2 = (int *) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (int *)(farg2); + result = (SUNErrCode)SUNStepper_GetLastFlag(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetEvolveFn(void *farg1, SUNStepperEvolveFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperEvolveFn arg2 = (SUNStepperEvolveFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperEvolveFn)(farg2); + result = (SUNErrCode)SUNStepper_SetEvolveFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetOneStepFn(void *farg1, SUNStepperOneStepFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperOneStepFn arg2 = (SUNStepperOneStepFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperOneStepFn)(farg2); + result = (SUNErrCode)SUNStepper_SetOneStepFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetFullRhsFn(void *farg1, SUNStepperFullRhsFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperFullRhsFn arg2 = (SUNStepperFullRhsFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperFullRhsFn)(farg2); + result = (SUNErrCode)SUNStepper_SetFullRhsFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetResetFn(void *farg1, SUNStepperResetFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperResetFn arg2 = (SUNStepperResetFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperResetFn)(farg2); + result = (SUNErrCode)SUNStepper_SetResetFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetStopTimeFn(void *farg1, SUNStepperSetStopTimeFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperSetStopTimeFn arg2 = (SUNStepperSetStopTimeFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperSetStopTimeFn)(farg2); + result = (SUNErrCode)SUNStepper_SetStopTimeFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetForcingFn(void *farg1, SUNStepperSetForcingFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperSetForcingFn arg2 = (SUNStepperSetForcingFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperSetForcingFn)(farg2); + result = (SUNErrCode)SUNStepper_SetForcingFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + +SWIGEXPORT int _wrap_FSUNStepper_SetDestroyFn(void *farg1, SUNStepperDestroyFn farg2) { + int fresult ; + SUNStepper arg1 = (SUNStepper) 0 ; + SUNStepperDestroyFn arg2 = (SUNStepperDestroyFn) 0 ; + SUNErrCode result; + + arg1 = (SUNStepper)(farg1); + arg2 = (SUNStepperDestroyFn)(farg2); + result = (SUNErrCode)SUNStepper_SetDestroyFn(arg1,arg2); + fresult = (SUNErrCode)(result); + return fresult; +} + + diff --git a/src/sundials/fmod_int64/fsundials_core_mod.f90 b/src/sundials/fmod_int64/fsundials_core_mod.f90 index 7096d0c6ce..13be2c2a2a 100644 --- a/src/sundials/fmod_int64/fsundials_core_mod.f90 +++ b/src/sundials/fmod_int64/fsundials_core_mod.f90 @@ -543,6 +543,33 @@ module fsundials_core_mod public :: FSUNAdaptController_SetErrorBias public :: FSUNAdaptController_UpdateH public :: FSUNAdaptController_Space + ! typedef enum SUNFullRhsMode + enum, bind(c) + enumerator :: SUN_FULLRHS_START + enumerator :: SUN_FULLRHS_END + enumerator :: SUN_FULLRHS_OTHER + end enum + integer, parameter, public :: SUNFullRhsMode = kind(SUN_FULLRHS_START) + public :: SUN_FULLRHS_START, SUN_FULLRHS_END, SUN_FULLRHS_OTHER + public :: FSUNStepper_Create + public :: FSUNStepper_Destroy + public :: FSUNStepper_Evolve + public :: FSUNStepper_OneStep + public :: FSUNStepper_FullRhs + public :: FSUNStepper_Reset + public :: FSUNStepper_SetStopTime + public :: FSUNStepper_SetForcing + public :: FSUNStepper_SetContent + public :: FSUNStepper_GetContent + public :: FSUNStepper_SetLastFlag + public :: FSUNStepper_GetLastFlag + public :: FSUNStepper_SetEvolveFn + public :: FSUNStepper_SetOneStepFn + public :: FSUNStepper_SetFullRhsFn + public :: FSUNStepper_SetResetFn + public :: FSUNStepper_SetStopTimeFn + public :: FSUNStepper_SetForcingFn + public :: FSUNStepper_SetDestroyFn ! WRAPPER DECLARATIONS interface @@ -2041,6 +2068,187 @@ function swigc_FSUNAdaptController_Space(farg1, farg2, farg3) & integer(C_INT) :: fresult end function +function swigc_FSUNStepper_Create(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_Create") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_Destroy(farg1) & +bind(C, name="_wrap_FSUNStepper_Destroy") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_Evolve(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNStepper_Evolve") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +type(C_PTR), value :: farg3 +type(C_PTR), value :: farg4 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_OneStep(farg1, farg2, farg3, farg4) & +bind(C, name="_wrap_FSUNStepper_OneStep") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +type(C_PTR), value :: farg3 +type(C_PTR), value :: farg4 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_FullRhs(farg1, farg2, farg3, farg4, farg5) & +bind(C, name="_wrap_FSUNStepper_FullRhs") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +type(C_PTR), value :: farg3 +type(C_PTR), value :: farg4 +integer(C_INT), intent(in) :: farg5 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_Reset(farg1, farg2, farg3) & +bind(C, name="_wrap_FSUNStepper_Reset") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +type(C_PTR), value :: farg3 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetStopTime(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetStopTime") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetForcing(farg1, farg2, farg3, farg4, farg5) & +bind(C, name="_wrap_FSUNStepper_SetForcing") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +real(C_DOUBLE), intent(in) :: farg2 +real(C_DOUBLE), intent(in) :: farg3 +type(C_PTR), value :: farg4 +integer(C_INT), intent(in) :: farg5 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetContent(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetContent") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_GetContent(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_GetContent") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetLastFlag(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetLastFlag") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +integer(C_INT), intent(in) :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_GetLastFlag(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_GetLastFlag") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_PTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetEvolveFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetEvolveFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetOneStepFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetOneStepFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetFullRhsFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetFullRhsFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetResetFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetResetFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetStopTimeFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetStopTimeFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetForcingFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetForcingFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + +function swigc_FSUNStepper_SetDestroyFn(farg1, farg2) & +bind(C, name="_wrap_FSUNStepper_SetDestroyFn") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +type(C_FUNPTR), value :: farg2 +integer(C_INT) :: fresult +end function + end interface @@ -4782,5 +4990,339 @@ function FSUNAdaptController_Space(c, lenrw, leniw) & swig_result = fresult end function +function FSUNStepper_Create(sunctx, stepper) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: sunctx +type(C_PTR), target, intent(inout) :: stepper +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = sunctx +farg2 = c_loc(stepper) +fresult = swigc_FSUNStepper_Create(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_Destroy(stepper) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR), target, intent(inout) :: stepper +integer(C_INT) :: fresult +type(C_PTR) :: farg1 + +farg1 = c_loc(stepper) +fresult = swigc_FSUNStepper_Destroy(farg1) +swig_result = fresult +end function + +function FSUNStepper_Evolve(stepper, tout, vret, tret) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tout +type(N_Vector), target, intent(inout) :: vret +real(C_DOUBLE), dimension(*), target, intent(inout) :: tret +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +type(C_PTR) :: farg3 +type(C_PTR) :: farg4 + +farg1 = stepper +farg2 = tout +farg3 = c_loc(vret) +farg4 = c_loc(tret(1)) +fresult = swigc_FSUNStepper_Evolve(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + +function FSUNStepper_OneStep(stepper, tout, vret, tret) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tout +type(N_Vector), target, intent(inout) :: vret +real(C_DOUBLE), dimension(*), target, intent(inout) :: tret +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +type(C_PTR) :: farg3 +type(C_PTR) :: farg4 + +farg1 = stepper +farg2 = tout +farg3 = c_loc(vret) +farg4 = c_loc(tret(1)) +fresult = swigc_FSUNStepper_OneStep(farg1, farg2, farg3, farg4) +swig_result = fresult +end function + +function FSUNStepper_FullRhs(stepper, t, v, f, mode) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: t +type(N_Vector), target, intent(inout) :: v +type(N_Vector), target, intent(inout) :: f +integer(SUNFullRhsMode), intent(in) :: mode +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +type(C_PTR) :: farg3 +type(C_PTR) :: farg4 +integer(C_INT) :: farg5 + +farg1 = stepper +farg2 = t +farg3 = c_loc(v) +farg4 = c_loc(f) +farg5 = mode +fresult = swigc_FSUNStepper_FullRhs(farg1, farg2, farg3, farg4, farg5) +swig_result = fresult +end function + +function FSUNStepper_Reset(stepper, tr, vr) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tr +type(N_Vector), target, intent(inout) :: vr +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +type(C_PTR) :: farg3 + +farg1 = stepper +farg2 = tr +farg3 = c_loc(vr) +fresult = swigc_FSUNStepper_Reset(farg1, farg2, farg3) +swig_result = fresult +end function + +function FSUNStepper_SetStopTime(stepper, tstop) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tstop +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 + +farg1 = stepper +farg2 = tstop +fresult = swigc_FSUNStepper_SetStopTime(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetForcing(stepper, tshift, tscale, forcing, nforcing) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +real(C_DOUBLE), intent(in) :: tshift +real(C_DOUBLE), intent(in) :: tscale +type(C_PTR) :: forcing +integer(C_INT), intent(in) :: nforcing +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +real(C_DOUBLE) :: farg2 +real(C_DOUBLE) :: farg3 +type(C_PTR) :: farg4 +integer(C_INT) :: farg5 + +farg1 = stepper +farg2 = tshift +farg3 = tscale +farg4 = forcing +farg5 = nforcing +fresult = swigc_FSUNStepper_SetForcing(farg1, farg2, farg3, farg4, farg5) +swig_result = fresult +end function + +function FSUNStepper_SetContent(stepper, content) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_PTR) :: content +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = stepper +farg2 = content +fresult = swigc_FSUNStepper_SetContent(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_GetContent(stepper, content) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_PTR), target, intent(inout) :: content +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = stepper +farg2 = c_loc(content) +fresult = swigc_FSUNStepper_GetContent(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetLastFlag(stepper, last_flag) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +integer(C_INT), intent(in) :: last_flag +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +integer(C_INT) :: farg2 + +farg1 = stepper +farg2 = last_flag +fresult = swigc_FSUNStepper_SetLastFlag(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_GetLastFlag(stepper, last_flag) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +integer(C_INT), dimension(*), target, intent(inout) :: last_flag +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_PTR) :: farg2 + +farg1 = stepper +farg2 = c_loc(last_flag(1)) +fresult = swigc_FSUNStepper_GetLastFlag(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetEvolveFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetEvolveFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetOneStepFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetOneStepFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetFullRhsFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetFullRhsFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetResetFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetResetFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetStopTimeFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetStopTimeFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetForcingFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetForcingFn(farg1, farg2) +swig_result = fresult +end function + +function FSUNStepper_SetDestroyFn(stepper, fn) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT) :: swig_result +type(C_PTR) :: stepper +type(C_FUNPTR), intent(in), value :: fn +integer(C_INT) :: fresult +type(C_PTR) :: farg1 +type(C_FUNPTR) :: farg2 + +farg1 = stepper +farg2 = fn +fresult = swigc_FSUNStepper_SetDestroyFn(farg1, farg2) +swig_result = fresult +end function + end module diff --git a/src/sundials/sundials_stepper.c b/src/sundials/sundials_stepper.c new file mode 100644 index 0000000000..def6592823 --- /dev/null +++ b/src/sundials/sundials_stepper.c @@ -0,0 +1,202 @@ +/* ----------------------------------------------------------------- + * 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 + * -----------------------------------------------------------------*/ + +#include +#include +#include +#include + +#include "sundials/sundials_errors.h" +#include "sundials/sundials_nvector.h" +#include "sundials/sundials_types.h" +#include "sundials_stepper_impl.h" + +SUNErrCode SUNStepper_Create(SUNContext sunctx, SUNStepper* stepper_ptr) +{ + SUNFunctionBegin(sunctx); + SUNCheck(stepper_ptr, SUN_ERR_ARG_CORRUPT); + + SUNStepper stepper = malloc(sizeof(*stepper)); + SUNAssert(stepper, SUN_ERR_MALLOC_FAIL); + + stepper->content = NULL; + stepper->sunctx = sunctx; + stepper->last_flag = SUN_SUCCESS; + + stepper->ops = malloc(sizeof(*(stepper->ops))); + SUNAssert(stepper->ops, SUN_ERR_MALLOC_FAIL); + + stepper->ops->evolve = NULL; + stepper->ops->onestep = NULL; + stepper->ops->fullrhs = NULL; + stepper->ops->reset = NULL; + stepper->ops->setstoptime = NULL; + stepper->ops->setforcing = NULL; + stepper->ops->destroy = NULL; + + *stepper_ptr = stepper; + + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_Destroy(SUNStepper* stepper_ptr) +{ + if (stepper_ptr != NULL) + { + const SUNStepper_Ops ops = (*stepper_ptr)->ops; + if (ops && ops->destroy) { ops->destroy(*stepper_ptr); } + free(ops); + free(*stepper_ptr); + *stepper_ptr = NULL; + } + + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_Evolve(SUNStepper stepper, sunrealtype tout, N_Vector y, + sunrealtype* tret) +{ + SUNFunctionBegin(stepper->sunctx); + if (stepper->ops->evolve) + { + return stepper->ops->evolve(stepper, tout, y, tret); + } + return SUN_ERR_NOT_IMPLEMENTED; +} + +SUNErrCode SUNStepper_OneStep(SUNStepper stepper, sunrealtype tout, N_Vector y, + sunrealtype* tret) +{ + SUNFunctionBegin(stepper->sunctx); + if (stepper->ops->onestep) + { + return stepper->ops->onestep(stepper, tout, y, tret); + } + return SUN_ERR_NOT_IMPLEMENTED; +} + +SUNErrCode SUNStepper_FullRhs(SUNStepper stepper, sunrealtype t, N_Vector v, + N_Vector f, SUNFullRhsMode mode) +{ + SUNFunctionBegin(stepper->sunctx); + if (stepper->ops->fullrhs) + { + return stepper->ops->fullrhs(stepper, t, v, f, mode); + } + return SUN_ERR_NOT_IMPLEMENTED; +} + +SUNErrCode SUNStepper_Reset(SUNStepper stepper, sunrealtype tR, N_Vector yR) +{ + SUNFunctionBegin(stepper->sunctx); + if (stepper->ops->reset) { return stepper->ops->reset(stepper, tR, yR); } + return SUN_ERR_NOT_IMPLEMENTED; +} + +SUNErrCode SUNStepper_SetStopTime(SUNStepper stepper, sunrealtype tstop) +{ + SUNFunctionBegin(stepper->sunctx); + if (stepper->ops->setstoptime) + { + return stepper->ops->setstoptime(stepper, tstop); + } + return SUN_ERR_NOT_IMPLEMENTED; +} + +SUNErrCode SUNStepper_SetForcing(SUNStepper stepper, sunrealtype tshift, + sunrealtype tscale, N_Vector* forcing, + int nforcing) +{ + SUNFunctionBegin(stepper->sunctx); + if (stepper->ops->setforcing) + { + return stepper->ops->setforcing(stepper, tshift, tscale, forcing, nforcing); + } + return SUN_ERR_NOT_IMPLEMENTED; +} + +SUNErrCode SUNStepper_SetContent(SUNStepper stepper, void* content) +{ + SUNFunctionBegin(stepper->sunctx); + stepper->content = content; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_GetContent(SUNStepper stepper, void** content) +{ + SUNFunctionBegin(stepper->sunctx); + *content = stepper->content; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_SetLastFlag(SUNStepper stepper, int last_flag) +{ + SUNFunctionBegin(stepper->sunctx); + stepper->last_flag = last_flag; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_GetLastFlag(SUNStepper stepper, int* last_flag) +{ + SUNFunctionBegin(stepper->sunctx); + *last_flag = stepper->last_flag; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_SetEvolveFn(SUNStepper stepper, SUNStepperEvolveFn fn) +{ + SUNFunctionBegin(stepper->sunctx); + stepper->ops->evolve = fn; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_SetOneStepFn(SUNStepper stepper, SUNStepperOneStepFn fn) +{ + SUNFunctionBegin(stepper->sunctx); + stepper->ops->onestep = fn; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_SetFullRhsFn(SUNStepper stepper, SUNStepperFullRhsFn fn) +{ + SUNFunctionBegin(stepper->sunctx); + stepper->ops->fullrhs = fn; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_SetResetFn(SUNStepper stepper, SUNStepperResetFn fn) +{ + SUNFunctionBegin(stepper->sunctx); + stepper->ops->reset = fn; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_SetStopTimeFn(SUNStepper stepper, SUNStepperSetStopTimeFn fn) +{ + SUNFunctionBegin(stepper->sunctx); + stepper->ops->setstoptime = fn; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_SetForcingFn(SUNStepper stepper, SUNStepperSetForcingFn fn) +{ + SUNFunctionBegin(stepper->sunctx); + stepper->ops->setforcing = fn; + return SUN_SUCCESS; +} + +SUNErrCode SUNStepper_SetDestroyFn(SUNStepper stepper, SUNStepperDestroyFn fn) +{ + SUNFunctionBegin(stepper->sunctx); + stepper->ops->destroy = fn; + return SUN_SUCCESS; +} diff --git a/src/sundials/sundials_stepper_impl.h b/src/sundials/sundials_stepper_impl.h new file mode 100644 index 0000000000..ab3b763c51 --- /dev/null +++ b/src/sundials/sundials_stepper_impl.h @@ -0,0 +1,53 @@ +/* ----------------------------------------------------------------- + * 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 + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_STEPPER_IMPL_H +#define _SUNDIALS_STEPPER_IMPL_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct SUNStepper_Ops_* SUNStepper_Ops; + +struct SUNStepper_Ops_ +{ + SUNStepperEvolveFn evolve; + SUNStepperOneStepFn onestep; + SUNStepperFullRhsFn fullrhs; + SUNStepperResetFn reset; + SUNStepperSetStopTimeFn setstoptime; + SUNStepperSetForcingFn setforcing; + SUNStepperDestroyFn destroy; +}; + +struct SUNStepper_ +{ + /* stepper specific content and operations */ + void* content; + SUNStepper_Ops ops; + + /* stepper context */ + SUNContext sunctx; + + /* last stepper return flag */ + int last_flag; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNDIALS_STEPPER_IMPL_H */ diff --git a/swig/sundials/fsundials_core_mod.i b/swig/sundials/fsundials_core_mod.i index 344f9372bb..930e55c702 100644 --- a/swig/sundials/fsundials_core_mod.i +++ b/swig/sundials/fsundials_core_mod.i @@ -25,4 +25,5 @@ %include "fsundials_linearsolver.i" %include "fsundials_nonlinearsolver.i" %include "fsundials_adaptcontroller.i" +%include "fsundials_stepper.i" %include "fcopyright.i" diff --git a/swig/sundials/fsundials_stepper.i b/swig/sundials/fsundials_stepper.i new file mode 100644 index 0000000000..c72ea64546 --- /dev/null +++ b/swig/sundials/fsundials_stepper.i @@ -0,0 +1,25 @@ +// --------------------------------------------------------------- +// Programmer: Steven B. Roberts @ LLNL +// --------------------------------------------------------------- +// 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 +// --------------------------------------------------------------- +// Swig interface file +// --------------------------------------------------------------- + +%{ +#include "sundials/sundials_stepper.h" +%} + +%apply void* { SUNStepper }; + +// Process and wrap functions in the following files +%include "sundials/sundials_stepper.h" +