Skip to content

Commit

Permalink
Added no-op SUNAdaptController implementation, to be used with fixed …
Browse files Browse the repository at this point in the history
…stepsize runs
  • Loading branch information
drreynolds committed Oct 18, 2023
1 parent e6bfc92 commit f94e99b
Show file tree
Hide file tree
Showing 11 changed files with 519 additions and 12 deletions.
44 changes: 44 additions & 0 deletions include/sunadaptcontroller/sunadaptcontroller_noop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* -----------------------------------------------------------------
* Programmer(s): Daniel R. Reynolds @ SMU
* -----------------------------------------------------------------
* SUNDIALS Copyright Start
* Copyright (c) 2002-2023, 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 header file for the SUNAdaptController_NOOP module.
* -----------------------------------------------------------------*/

#ifndef _SUNADAPTCONTROLLER_NOOP_H
#define _SUNADAPTCONTROLLER_NOOP_H

#include <stdio.h>
#include <sundials/sundials_adaptcontroller.h>

#ifdef __cplusplus /* wrapper to enable C++ usage */
extern "C" {
#endif

/* ------------------------------------------
* No-op implementation of SUNAdaptController
* ------------------------------------------ */

/* ------------------
* Exported Functions
* ------------------ */

SUNDIALS_EXPORT
SUNAdaptController SUNAdaptController_NoOp(SUNContext sunctx);
SUNDIALS_EXPORT
SUNAdaptController_Type SUNAdaptController_GetType_NoOp(SUNAdaptController C);

#ifdef __cplusplus
}
#endif

#endif /* _SUNADAPTCONTROLLER_PID_H */
1 change: 1 addition & 0 deletions src/arkode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ sundials_add_library(sundials_arkode
sundials_sunadaptcontrollerimpgus_obj
sundials_sunadaptcontrollerpi_obj
sundials_sunadaptcontrollerimexgus_obj
sundials_sunadaptcontrollernoop_obj
sundials_sunmatrixband_obj
sundials_sunmatrixdense_obj
sundials_sunmatrixsparse_obj
Expand Down
26 changes: 17 additions & 9 deletions src/arkode/arkode_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <sunadaptcontroller/sunadaptcontroller_expgus.h>
#include <sunadaptcontroller/sunadaptcontroller_impgus.h>
#include <sunadaptcontroller/sunadaptcontroller_imexgus.h>
#include <sunadaptcontroller/sunadaptcontroller_noop.h>


/*===============================================================
Expand Down Expand Up @@ -671,25 +672,32 @@ int arkSetFixedStep(void *arkode_mem, realtype hfixed)
ark_mem->hadapt_mem->hcontroller = NULL;

/* If re-enabling time adaptivity, create default PID controller
and attach object to ARKODE */
and attach object to ARKODE.
Otherwise, create No-op controller and attach to ARKODE. */
SUNAdaptController C = NULL;
if (hfixed == ZERO)
{
C = SUNAdaptController_PID(ark_mem->sunctx);
if (C == NULL) {
arkProcessError(ark_mem, ARK_MEM_FAIL, "ARKODE", "arkSetFixedStep",
"SUNAdaptControllerPID allocation failure");
"SUNAdaptController_PID allocation failure");
return(ARK_MEM_FAIL);
}

retval = SUNAdaptController_Space(C, &lenrw, &leniw);
if (retval == SUNADAPTCONTROLLER_SUCCESS) {
ark_mem->liw += leniw;
ark_mem->lrw += lenrw;
} else {
C = SUNAdaptController_NoOp(ark_mem->sunctx);
if (C == NULL) {
arkProcessError(ark_mem, ARK_MEM_FAIL, "ARKODE", "arkSetFixedStep",
"SUNAdaptController_NoOp allocation failure");
return(ARK_MEM_FAIL);
}
ark_mem->hadapt_mem->hcontroller = C;
ark_mem->hadapt_mem->owncontroller = SUNTRUE;
}
retval = SUNAdaptController_Space(C, &lenrw, &leniw);
if (retval == SUNADAPTCONTROLLER_SUCCESS) {
ark_mem->liw += leniw;
ark_mem->lrw += lenrw;
}
ark_mem->hadapt_mem->hcontroller = C;
ark_mem->hadapt_mem->owncontroller = SUNTRUE;

/* re-attach internal error weight functions if necessary */
if ((hfixed == ZERO) && (!ark_mem->user_efun)) {
Expand Down
1 change: 1 addition & 0 deletions src/sunadaptcontroller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ add_subdirectory(expgus)
add_subdirectory(i)
add_subdirectory(imexgus)
add_subdirectory(impgus)
add_subdirectory(noop)
add_subdirectory(pi)
add_subdirectory(pid)
29 changes: 29 additions & 0 deletions src/sunadaptcontroller/noop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ---------------------------------------------------------------
# Programmer(s): Daniel R. Reynolds @ SMU
# ---------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2023, 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
# ---------------------------------------------------------------

# Create a library out of the generic sundials modules
sundials_add_library(sundials_sunadaptcontrollernoop
SOURCES
sunadaptcontroller_noop.c
HEADERS
${SUNDIALS_SOURCE_DIR}/include/sunadaptcontroller/sunadaptcontroller_noop.h
INCLUDE_SUBDIR
sunadaptcontroller
OBJECT_LIB_ONLY
)

# Add F2003 module if the interface is enabled
if(BUILD_FORTRAN_MODULE_INTERFACE)
add_subdirectory(fmod)
endif()
25 changes: 25 additions & 0 deletions src/sunadaptcontroller/noop/fmod/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ---------------------------------------------------------------
# Programmer(s): Daniel R. Reynolds @ SMU
# ---------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2023, 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
# ---------------------------------------------------------------

sundials_add_f2003_library(sundials_fsunadaptcontrollernoop_mod
SOURCES
fsunadaptcontroller_noop_mod.f90 fsunadaptcontroller_noop_mod.c
OBJECT_LIBRARIES
sundials_fgeneric_mod_obj
OUTPUT_NAME
sundials_fsunadaptcontrollernoop_mod
OBJECT_LIB_ONLY
)

message(STATUS "Added SUNAdaptController_NOOP F2003 interface")
Loading

0 comments on commit f94e99b

Please sign in to comment.