Skip to content

Commit

Permalink
Merge branch 'feature/oo-adaptivity2' of github.com:LLNL/sundials int…
Browse files Browse the repository at this point in the history
…o feature/oo-adaptivity2
  • Loading branch information
drreynolds committed Nov 1, 2023
2 parents 5ae4b42 + 1d4a24f commit a554117
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ implementations.
Added the routines `ARKStepSetAdaptivityAdjustment` and
`ERKStepSetAdaptivityAdjustment`, that allow users to adjust the
value for the method order supplied to the temporal adaptivity controllers.
The ARKODE default for this adjustment has been :math:`-1` since its initial
release, but for some applications a value of :math:`0` is more appropriate.
The ARKODE default for this adjustment has been -1 since its initial
release, but for some applications a value of 0 is more appropriate.
Users who notice that their simulations encounter a large number of
temporal error test failures may want to experiment with adjusting this value.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ note these requirements below. Additionally, we note the behavior of the base SU
Estimates a single-rate step size. This routine is required for controllers
of type ``SUN_ADAPTCONTROLLER_H``. If this is not provided by the
implementation, the base wrapper routine will set ``*hnew = h`` and return.
implementation, the class method will set ``*hnew = h`` and return.
:param C: the :c:type:`SUNAdaptController` object.
:param h: the step size from the previous step attempt.
Expand Down Expand Up @@ -298,7 +298,7 @@ SUNAdaptController functions return one of the following set of error codes:
* ``SUNADAPTCONTROLLER_OPERATION_FAIL`` (-1004) -- catch-all for errors not in the above list.

.. note::
The SUNDIALS time integrators do not rely on these specific return values (only
The SUNDIALS time integrators do not rely on these specific return values and only
on whether the returned values are 0 (successful) or non-zero (failure). Thus,
user-defined implementations are not required to use these specific error codes,
so long as the zero/non-zero convention is followed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ also provides the following additional user-callable routines:
.. math::
h' = h_n \varepsilon_n^{-\hat{k}_1/(p+1)} \left(\frac{\varepsilon_n}{\varepsilon_{n-1}}\right)^{-\hat{k}_2/(p+1)} \left(\frac{h_n}{h_{n-1}}\right).
The inputs to this function correspond to the values of :math:`\hat{k}_1` and :math:`\hat{k}_2`,
which are internally transformed into the Soderlind coeficients :math:`k_1 = \hat{k}_1+\hat{k}_2`,
:math:`k_2 = -\hat{k}_2`, and :math:`k_4=1`.
The inputs to this function correspond to the values of :math:`\hat{k}_1` and :math:`\hat{k}_2`,
which are internally transformed into the Soderlind coeficients :math:`k_1 = \hat{k}_1+\hat{k}_2`,
:math:`k_2 = -\hat{k}_2`, and :math:`k_4=1`.
:param C: the SUNAdaptController_Soderlind object.
:param k1_hat: parameter used within the implicit Gustafsson controller time step estimate.
Expand Down
2 changes: 1 addition & 1 deletion src/arkode/arkode_adapt_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern "C" {
#define SMALL_NEF 2 /* if an error failure occurs and SMALL_NEF <= nef,
then reset eta = MIN(eta, ETAMXF) */
#define PQ 0 /* order to use for controller: 0=embedding,
1=method, -1=min(method,embedding)
1=method, otherwise min(method,embedding)
REMOVE AT SAME TIME AS ARKStepSetAdaptivityMethod */
#define ADJUST -1 /* adjustment to apply within controller to method
order of accuracy */
Expand Down
15 changes: 13 additions & 2 deletions src/arkode/arkode_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ int arkSetAdaptController(void *arkode_mem, SUNAdaptController C)
}
if (ark_mem->hadapt_mem->owncontroller) {
retval = SUNAdaptController_Destroy(ark_mem->hadapt_mem->hcontroller);
ark_mem->hadapt_mem->owncontroller = SUNFALSE;
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
arkProcessError(ark_mem, ARK_MEM_FAIL, "ARKODE", "arkSetAdaptController",
"SUNAdaptController_Destroy failure");
Expand Down Expand Up @@ -658,6 +659,7 @@ int arkSetFixedStep(void *arkode_mem, realtype hfixed)
}
if (ark_mem->hadapt_mem->owncontroller) {
retval = SUNAdaptController_Destroy(ark_mem->hadapt_mem->hcontroller);
ark_mem->hadapt_mem->owncontroller = SUNFALSE;
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
arkProcessError(ark_mem, ARK_MEM_FAIL, "ARKODE", "arkSetFixedStep",
"SUNAdaptController_Destroy failure");
Expand Down Expand Up @@ -703,7 +705,7 @@ int arkSetFixedStep(void *arkode_mem, realtype hfixed)
if (retval != ARK_SUCCESS) return(retval);
}

/* set ark_mem "fixedstep" entry entry */
/* set ark_mem "fixedstep" entry */
if (hfixed != ZERO) {
ark_mem->fixedstep = SUNTRUE;
ark_mem->hin = hfixed;
Expand All @@ -713,6 +715,7 @@ int arkSetFixedStep(void *arkode_mem, realtype hfixed)

/* Notify ARKODE to use hfixed as the initial step size, and return */
retval = arkSetInitStep(arkode_mem, hfixed);

return(ARK_SUCCESS);
}

Expand Down Expand Up @@ -969,6 +972,7 @@ int arkSetAdaptivityMethod(void *arkode_mem, int imethod, int idefault,
}
if (ark_mem->hadapt_mem->owncontroller) {
retval = SUNAdaptController_Destroy(ark_mem->hadapt_mem->hcontroller);
ark_mem->hadapt_mem->owncontroller = SUNFALSE;
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
arkProcessError(ark_mem, ARK_MEM_FAIL, "ARKODE", "arkSetAdaptivityMethod",
"SUNAdaptController_Destroy failure");
Expand Down Expand Up @@ -1000,6 +1004,7 @@ int arkSetAdaptivityMethod(void *arkode_mem, int imethod, int idefault,
if (idefault != 1) {
retval = SUNAdaptController_SetParams_PID(C, k1, -k2, k3);
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
(void) SUNAdaptController_Destroy(C);
arkProcessError(ark_mem, ARK_CONTROLLER_ERR, "ARKODE",
"arkSetAdaptivityMethod", "SUNAdaptController_SetParams_PID failure");
return(ARK_CONTROLLER_ERR);
Expand All @@ -1016,6 +1021,7 @@ int arkSetAdaptivityMethod(void *arkode_mem, int imethod, int idefault,
if (idefault != 1) {
retval = SUNAdaptController_SetParams_PI(C, k1, -k2);
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
(void) SUNAdaptController_Destroy(C);
arkProcessError(ark_mem, ARK_CONTROLLER_ERR, "ARKODE",
"arkSetAdaptivityMethod", "SUNAdaptController_SetParams_PI failure");
return(ARK_CONTROLLER_ERR);
Expand All @@ -1032,6 +1038,7 @@ int arkSetAdaptivityMethod(void *arkode_mem, int imethod, int idefault,
if (idefault != 1) {
retval = SUNAdaptController_SetParams_I(C, k1);
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
(void) SUNAdaptController_Destroy(C);
arkProcessError(ark_mem, ARK_CONTROLLER_ERR, "ARKODE",
"arkSetAdaptivityMethod", "SUNAdaptController_SetParams_I failure");
return(ARK_CONTROLLER_ERR);
Expand All @@ -1048,6 +1055,7 @@ int arkSetAdaptivityMethod(void *arkode_mem, int imethod, int idefault,
if (idefault != 1) {
retval = SUNAdaptController_SetParams_ExpGus(C, k1, k2);
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
(void) SUNAdaptController_Destroy(C);
arkProcessError(ark_mem, ARK_CONTROLLER_ERR, "ARKODE",
"arkSetAdaptivityMethod", "SUNAdaptController_SetParams_ExpGus failure");
return(ARK_CONTROLLER_ERR);
Expand All @@ -1064,6 +1072,7 @@ int arkSetAdaptivityMethod(void *arkode_mem, int imethod, int idefault,
if (idefault != 1) {
retval = SUNAdaptController_SetParams_ImpGus(C, k1, k2);
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
(void) SUNAdaptController_Destroy(C);
arkProcessError(ark_mem, ARK_CONTROLLER_ERR, "ARKODE",
"arkSetAdaptivityMethod", "SUNAdaptController_SetParams_ImpGus failure");
return(ARK_CONTROLLER_ERR);
Expand All @@ -1080,6 +1089,7 @@ int arkSetAdaptivityMethod(void *arkode_mem, int imethod, int idefault,
if (idefault != 1) {
retval = SUNAdaptController_SetParams_ImExGus(C, k1, k2, k3, k3);
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
(void) SUNAdaptController_Destroy(C);
arkProcessError(ark_mem, ARK_CONTROLLER_ERR, "ARKODE",
"arkSetAdaptivityMethod", "SUNAdaptController_SetParams_ImExGus failure");
return(ARK_CONTROLLER_ERR);
Expand Down Expand Up @@ -1138,6 +1148,7 @@ int arkSetAdaptivityFn(void *arkode_mem, ARKAdaptFn hfun, void *h_data)
}
if (ark_mem->hadapt_mem->owncontroller) {
retval = SUNAdaptController_Destroy(ark_mem->hadapt_mem->hcontroller);
ark_mem->hadapt_mem->owncontroller = SUNFALSE;
if (retval != SUNADAPTCONTROLLER_SUCCESS) {
arkProcessError(ark_mem, ARK_MEM_FAIL, "ARKODE", "arkSetAdaptivityFn",
"SUNAdaptController_Destroy failure");
Expand Down Expand Up @@ -1296,7 +1307,7 @@ int arkSetErrorBias(void *arkode_mem, realtype bias)
arkProcessError(ark_mem, ARK_CONTROLLER_ERR, "ARKODE",
"arkSetErrorBias", "SUNAdaptController_SetErrorBias failure");
return(ARK_CONTROLLER_ERR);
}
}
return(ARK_SUCCESS);
}

Expand Down
4 changes: 2 additions & 2 deletions src/arkode/arkode_user_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ SUNAdaptController ARKUserControl(SUNContext sunctx, void* arkode_mem,
SUNAdaptController C;
ARKUserControlContent content;

/* Return with failure if hadapt or arkode_mem are NULL */
if ((hadapt == NULL) || (arkode_mem == NULL)) { return (NULL); }
/* Return with failure if hadapt, arkode_mem, or context are NULL */
if ((hadapt == NULL) || (arkode_mem == NULL) || (sunctx == NULL)) { return (NULL); }

/* Create an empty controller object */
C = NULL;
Expand Down

0 comments on commit a554117

Please sign in to comment.