From dfb08620b47555a3388946aeb226e584727d21b4 Mon Sep 17 00:00:00 2001 From: "Daniel R. Reynolds" Date: Fri, 12 Sep 2025 14:40:01 -0400 Subject: [PATCH 1/4] Fixes for MRI-HTol adaptivity -- added missing scaling to accumulated error, and allowed 'fuzz factor' to also be used when assessing tstop criteria at the start of a step (already used at the end of a step) --- src/arkode/arkode.c | 11 ++++------- src/arkode/arkode_mristep.c | 5 +++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/arkode/arkode.c b/src/arkode/arkode.c index 8ee3920ed7..0e433ac877 100644 --- a/src/arkode/arkode.c +++ b/src/arkode/arkode.c @@ -735,13 +735,10 @@ int ARKodeEvolve(void* arkode_mem, sunrealtype tout, N_Vector yout, } /* perform stopping tests */ - if (!ark_mem->initsetup) + if (arkStopTests(ark_mem, tout, yout, tret, itask, &retval)) { - if (arkStopTests(ark_mem, tout, yout, tret, itask, &retval)) - { - SUNDIALS_MARK_FUNCTION_END(ARK_PROFILER); - return (retval); - } + SUNDIALS_MARK_FUNCTION_END(ARK_PROFILER); + return (retval); } /*-------------------------------------------------- @@ -1999,7 +1996,7 @@ int arkInitialSetup(ARKodeMem ark_mem, sunrealtype tout) if (ark_mem->tstopset) { htmp = (ark_mem->h == ZERO) ? tout - ark_mem->tcur : ark_mem->h; - if ((ark_mem->tstop - ark_mem->tcur) * htmp <= ZERO) + if ((ark_mem->tstop - ark_mem->tcur) * htmp <= -FUZZ_FACTOR * ark_mem->uround) { arkProcessError(ark_mem, ARK_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_ARK_BAD_TSTOP, ark_mem->tstop, ark_mem->tcur); diff --git a/src/arkode/arkode_mristep.c b/src/arkode/arkode_mristep.c index fb80e241fd..ead444c1bf 100644 --- a/src/arkode/arkode_mristep.c +++ b/src/arkode/arkode_mristep.c @@ -3571,6 +3571,11 @@ int mriStep_StageERKFast(ARKodeMem ark_mem, ARKodeMRIStepMem step_mem, __FILE__, "Unable to get accumulated error from the inner stepper"); return (ARK_INNERSTEP_FAIL); } + + /* scale the error estimate by 1/rtol to account for different inner/outer tolerances */ + step_mem->inner_dsm /= ark_mem->reltol; + SUNLogInfo(ARK_LOGGER, "end-fast-steps", "inner_dsm = %e", + step_mem->inner_dsm); } } From 28f4a7d8b33a6ce25339806a09854105678214e0 Mon Sep 17 00:00:00 2001 From: "Daniel R. Reynolds" Date: Fri, 12 Sep 2025 16:13:11 -0400 Subject: [PATCH 2/4] Reverted tstop changes in arkode.c; updated CHANGELOG and recent changes files --- CHANGELOG.md | 4 ++++ doc/shared/RecentChanges.rst | 4 ++++ src/arkode/arkode.c | 11 +++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0d1cebd2c..eb71080845 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ in any order. ### Bug Fixes +Fixed a bug in how MRIStep interacts with an MRIHTol SUNAdaptController object +(the previous version essentially just reverted to a decoupled multirate +controller). + The shared library version numbers for the oneMKL dense linear solver and matrix as well as the PETSc SNES nonlinear solver have been corrected. diff --git a/doc/shared/RecentChanges.rst b/doc/shared/RecentChanges.rst index d3e915851c..365f65234c 100644 --- a/doc/shared/RecentChanges.rst +++ b/doc/shared/RecentChanges.rst @@ -12,6 +12,10 @@ method after :c:func:`KINInit`. Additionally, :c:func:`KINSetMAA` and **Bug Fixes** +Fixed a bug in how MRIStep interacts with an MRIHTol SUNAdaptController object +(the previous version essentially just reverted to a decoupled multirate +controller). + The shared library version numbers for the oneMKL dense linear solver and matrix as well as the PETSc SNES nonlinear solver have been corrected. diff --git a/src/arkode/arkode.c b/src/arkode/arkode.c index 0e433ac877..8ee3920ed7 100644 --- a/src/arkode/arkode.c +++ b/src/arkode/arkode.c @@ -735,10 +735,13 @@ int ARKodeEvolve(void* arkode_mem, sunrealtype tout, N_Vector yout, } /* perform stopping tests */ - if (arkStopTests(ark_mem, tout, yout, tret, itask, &retval)) + if (!ark_mem->initsetup) { - SUNDIALS_MARK_FUNCTION_END(ARK_PROFILER); - return (retval); + if (arkStopTests(ark_mem, tout, yout, tret, itask, &retval)) + { + SUNDIALS_MARK_FUNCTION_END(ARK_PROFILER); + return (retval); + } } /*-------------------------------------------------- @@ -1996,7 +1999,7 @@ int arkInitialSetup(ARKodeMem ark_mem, sunrealtype tout) if (ark_mem->tstopset) { htmp = (ark_mem->h == ZERO) ? tout - ark_mem->tcur : ark_mem->h; - if ((ark_mem->tstop - ark_mem->tcur) * htmp <= -FUZZ_FACTOR * ark_mem->uround) + if ((ark_mem->tstop - ark_mem->tcur) * htmp <= ZERO) { arkProcessError(ark_mem, ARK_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_ARK_BAD_TSTOP, ark_mem->tstop, ark_mem->tcur); From b8da78e1265230d4e4b70752c9a61c35f374e140 Mon Sep 17 00:00:00 2001 From: "Daniel R. Reynolds" Date: Fri, 12 Sep 2025 16:30:43 -0400 Subject: [PATCH 3/4] Removed upper-bound guardrail on user changes to the MRIHTol inner solver tolerance factor --- doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst | 2 +- src/sunadaptcontroller/mrihtol/sunadaptcontroller_mrihtol.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst b/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst index fa9169e6e4..aa69457991 100644 --- a/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst +++ b/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst @@ -153,7 +153,7 @@ also provides the following additional user-callable routines: :param C: the SUNAdaptController_MRIHTol object. :param inner_max_relch: the parameter :math:`relch_{\text{max}}` (must be :math:`\ge 1`). :param inner_min_tolfac: the parameter :math:`\text{tolfac}_{min}` (must be :math:`> 0`). - :param inner_max_tolfac: the parameter :math:`\text{tolfac}_{max}` (must be :math:`> 0` and :math:`\le 1`). + :param inner_max_tolfac: the parameter :math:`\text{tolfac}_{max}` (must be :math:`> 0`). :returns: :c:type:`SUNErrCode` indicating success or failure. diff --git a/src/sunadaptcontroller/mrihtol/sunadaptcontroller_mrihtol.c b/src/sunadaptcontroller/mrihtol/sunadaptcontroller_mrihtol.c index c615f75040..1cdf0c5516 100644 --- a/src/sunadaptcontroller/mrihtol/sunadaptcontroller_mrihtol.c +++ b/src/sunadaptcontroller/mrihtol/sunadaptcontroller_mrihtol.c @@ -236,8 +236,7 @@ SUNErrCode SUNAdaptController_SetParams_MRIHTol(SUNAdaptController C, MRIHTOL_INNER_MIN_TOLFAC(C) = INNER_MIN_TOLFAC; } else { MRIHTOL_INNER_MIN_TOLFAC(C) = inner_min_tolfac; } - if ((inner_max_tolfac <= SUN_RCONST(0.0)) || - (inner_max_tolfac > SUN_RCONST(1.0))) + if (inner_max_tolfac <= SUN_RCONST(0.0)) { MRIHTOL_INNER_MAX_TOLFAC(C) = INNER_MAX_TOLFAC; } From 9ecdf703bfdb3417f93083a55df790bcf71c6216 Mon Sep 17 00:00:00 2001 From: "Daniel R. Reynolds" Date: Tue, 16 Sep 2025 11:12:49 -0400 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: David Gardner --- CHANGELOG.md | 3 ++- doc/shared/RecentChanges.rst | 3 ++- doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst | 5 +++++ src/arkode/arkode_mristep.c | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4e7fc5523..7932d0d00c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,8 @@ in any order. Fixed a bug in how MRIStep interacts with an MRIHTol SUNAdaptController object (the previous version essentially just reverted to a decoupled multirate -controller). +controller). Removed the upper limit on `inner_max_tolfac` in +`SUNAdaptController_SetParams_MRIHTol`. The shared library version numbers for the oneMKL dense linear solver and matrix as well as the PETSc SNES nonlinear solver have been corrected. diff --git a/doc/shared/RecentChanges.rst b/doc/shared/RecentChanges.rst index 7472a102f1..f28f94de12 100644 --- a/doc/shared/RecentChanges.rst +++ b/doc/shared/RecentChanges.rst @@ -23,7 +23,8 @@ method after :c:func:`KINInit`. Additionally, :c:func:`KINSetMAA` and Fixed a bug in how MRIStep interacts with an MRIHTol SUNAdaptController object (the previous version essentially just reverted to a decoupled multirate -controller). +controller). Removed the upper limit on `inner_max_tolfac` in +:c:func:`SUNAdaptController_SetParams_MRIHTol`. The shared library version numbers for the oneMKL dense linear solver and matrix as well as the PETSc SNES nonlinear solver have been corrected. diff --git a/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst b/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst index aa69457991..12b0f28dec 100644 --- a/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst +++ b/doc/shared/sunadaptcontroller/SUNAdaptController_MRIHTol.rst @@ -156,6 +156,11 @@ also provides the following additional user-callable routines: :param inner_max_tolfac: the parameter :math:`\text{tolfac}_{max}` (must be :math:`> 0`). :returns: :c:type:`SUNErrCode` indicating success or failure. + + .. versionchanged:: x.y.z + + Removed the requirement that ``inner_max_tolfac`` must be :math:`\le 1` + .. note:: diff --git a/src/arkode/arkode_mristep.c b/src/arkode/arkode_mristep.c index ead444c1bf..cdd0508fda 100644 --- a/src/arkode/arkode_mristep.c +++ b/src/arkode/arkode_mristep.c @@ -3574,7 +3574,7 @@ int mriStep_StageERKFast(ARKodeMem ark_mem, ARKodeMRIStepMem step_mem, /* scale the error estimate by 1/rtol to account for different inner/outer tolerances */ step_mem->inner_dsm /= ark_mem->reltol; - SUNLogInfo(ARK_LOGGER, "end-fast-steps", "inner_dsm = %e", + SUNLogInfo(ARK_LOGGER, "accumulated-fast-error", "inner_dsm = %e", step_mem->inner_dsm); } }