Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify/Fix Adaptivity for Small Errors or no CFL #548

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
14ecd14
Remove special case of negative base in SUNRpowerR
Steven-Roberts Jul 30, 2024
dcb14bc
Fix assert condition
Steven-Roberts Jul 30, 2024
19f2dc9
Remove magic constant
Steven-Roberts Jul 30, 2024
53f3dde
Remove TINY parameter
Steven-Roberts Jul 30, 2024
e838c4e
Remove TINY from imexgus controller
Steven-Roberts Jul 30, 2024
9cde50a
Switch to assert
Steven-Roberts Jul 30, 2024
2c2444c
Fix sign of controller in nan case
Steven-Roberts Jul 30, 2024
9cb7bba
Start adaptivity unit test
Steven-Roberts Jul 31, 2024
743913a
Add const and comments to test
Steven-Roberts Aug 1, 2024
b75e78e
Simplify Soderlind controller and handle inf/nan better
Steven-Roberts Aug 1, 2024
2caec18
Clean up controllers
Steven-Roberts Aug 1, 2024
3fbda5b
Apply formatter
Steven-Roberts Aug 1, 2024
ef01f92
Merge branch 'develop' into feature/min-err
Steven-Roberts Aug 23, 2024
299cd5c
Variable initialization cleanup
Steven-Roberts Sep 6, 2024
405ff41
Use I controller on first 2 steps of Soderlind
Steven-Roberts Sep 6, 2024
bc9f312
Remove assert for pow testing
Steven-Roberts Sep 6, 2024
54aa1d5
Update docs
Steven-Roberts Sep 6, 2024
bfdf75e
Update IMEX controller docs
Steven-Roberts Sep 6, 2024
dde1379
Update changelog
Steven-Roberts Sep 6, 2024
facfc39
Clean up time step sign
Steven-Roberts Sep 6, 2024
7badd78
Additional simplifications
Steven-Roberts Sep 6, 2024
641ad92
Merge branch 'develop' into feature/min-err
Steven-Roberts Sep 6, 2024
c472ffe
Additional testing of controller
Steven-Roberts Sep 6, 2024
2452bd6
Remove unnecessary header
Steven-Roberts Sep 6, 2024
13cce12
Correct function names
Steven-Roberts Sep 6, 2024
1950356
Convert SUNRpowerR to macro
Steven-Roberts Sep 6, 2024
5bd4790
Update comments based on @drreynolds suggestions
Steven-Roberts Sep 10, 2024
8d7a267
Fix typos in changelog
Steven-Roberts Sep 10, 2024
a02ca62
Merge branch 'develop' into feature/min-err
Steven-Roberts Sep 10, 2024
7d5161b
Update test/unit_tests/arkode/C_serial/ark_test_adapt.c
Steven-Roberts Sep 11, 2024
fcb7dc6
Add missing SUN_RCONST
Steven-Roberts Sep 11, 2024
1db5b33
Update test/unit_tests/arkode/C_serial/ark_test_adapt.c
Steven-Roberts Sep 11, 2024
f81a60d
Merge branch 'develop' into feature/min-err
Steven-Roberts Sep 11, 2024
7669c93
Add more asserts to controllers
Steven-Roberts Sep 11, 2024
ed094a8
Merge branch 'develop' into feature/min-err
Steven-Roberts Sep 16, 2024
3671f0e
Add non-default controllers in test
Steven-Roberts Sep 26, 2024
a3bac98
Merge branch 'develop' into feature/min-err
Steven-Roberts Sep 26, 2024
fdb3d4a
Fix assertion to allow order 0
Steven-Roberts Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/arkode/arkode_adapt.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int arkAdapt(ARKodeMem ark_mem, ARKodeHAdaptMem hadapt_mem, N_Vector ycur,
"Error in explicit stability function.");
return (ARK_ILL_INPUT);
}
if (h_cfl <= ZERO) { h_cfl = SUN_RCONST(1.0e30) * SUNRabs(hcur); }
if (h_cfl <= ZERO) { h_cfl = INFINITY; }

#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO
SUNLogger_QueueMsg(ARK_LOGGER, SUN_LOGLEVEL_INFO, "ARKODE::arkAdapt",
Expand All @@ -156,7 +156,7 @@ int arkAdapt(ARKodeMem ark_mem, ARKodeHAdaptMem hadapt_mem, N_Vector ycur,
#endif

/* increment the relevant step counter, set desired step */
if (SUNRabs(h_acc) < SUNRabs(h_cfl)) { hadapt_mem->nst_acc++; }
if (SUNRabs(h_acc) <= SUNRabs(h_cfl)) { hadapt_mem->nst_acc++; }
else { hadapt_mem->nst_exp++; }
h_acc = int_dir * SUNMIN(SUNRabs(h_acc), SUNRabs(h_cfl));

Expand Down
14 changes: 10 additions & 4 deletions src/sunadaptcontroller/imexgus/sunadaptcontroller_imexgus.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#define DEFAULT_K1I SUN_RCONST(0.95)
#define DEFAULT_K2I SUN_RCONST(0.95)
#define DEFAULT_BIAS SUN_RCONST(1.5)
#define TINY SUN_RCONST(1.0e-10)

/* -----------------------------------------------------------------
* exported functions
Expand Down Expand Up @@ -135,15 +134,15 @@ SUNErrCode SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C,

/* set usable time-step adaptivity parameters -- first step */
const sunrealtype k = -SUN_RCONST(1.0) / ord;
const sunrealtype e = SUNMAX(SACIMEXGUS_BIAS(C) * dsm, TINY);
const sunrealtype e = SACIMEXGUS_BIAS(C) * dsm;

/* set usable time-step adaptivity parameters -- subsequent steps */
const sunrealtype k1e = -SACIMEXGUS_K1E(C) / ord;
const sunrealtype k2e = -SACIMEXGUS_K2E(C) / ord;
const sunrealtype k1i = -SACIMEXGUS_K1I(C) / ord;
const sunrealtype k2i = -SACIMEXGUS_K2I(C) / ord;
const sunrealtype e1 = SUNMAX(SACIMEXGUS_BIAS(C) * dsm, TINY);
const sunrealtype e2 = e1 / SUNMAX(SACIMEXGUS_EP(C), TINY);
const sunrealtype e1 = SACIMEXGUS_BIAS(C) * dsm;
const sunrealtype e2 = e1 / SACIMEXGUS_EP(C);
const sunrealtype hrat = h / SACIMEXGUS_HP(C);

/* compute estimated time step size, modifying the first step formula */
Expand All @@ -154,6 +153,13 @@ SUNErrCode SUNAdaptController_EstimateStep_ImExGus(SUNAdaptController C,
SUNRpowerR(e1, k1e) * SUNRpowerR(e2, k2e));
}

if (isnan(*hnew))
{
/* hnew can be NAN if multiple e's are 0. In that case, make hnew inf with
* the same sign as h */
*hnew = h / SUN_RCONST(0.0);
}
gardner48 marked this conversation as resolved.
Show resolved Hide resolved

/* return with success */
return SUN_SUCCESS;
}
Expand Down
14 changes: 10 additions & 4 deletions src/sunadaptcontroller/soderlind/sunadaptcontroller_soderlind.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
#define DEFAULT_IMPGUS_K1 SUN_RCONST(0.98) /* Implicit Gustafsson parameters */
#define DEFAULT_IMPGUS_K2 SUN_RCONST(0.95)
#define DEFAULT_BIAS SUN_RCONST(1.5)
#define TINY SUN_RCONST(1.0e-10)

/* -----------------------------------------------------------------
* exported functions
Expand Down Expand Up @@ -322,9 +321,9 @@ SUNErrCode SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C,
const sunrealtype k3 = -SODERLIND_K3(C) / ord;
const sunrealtype k4 = SODERLIND_K4(C);
const sunrealtype k5 = SODERLIND_K5(C);
const sunrealtype e1 = SUNMAX(SODERLIND_BIAS(C) * dsm, TINY);
const sunrealtype e2 = SUNMAX(SODERLIND_EP(C), TINY);
const sunrealtype e3 = SUNMAX(SODERLIND_EPP(C), TINY);
const sunrealtype e1 = SODERLIND_BIAS(C) * dsm;
const sunrealtype e2 = SODERLIND_EP(C);
const sunrealtype e3 = SODERLIND_EPP(C);
const sunrealtype hrat = h / SODERLIND_HP(C);
const sunrealtype hrat2 = SODERLIND_HP(C) / SODERLIND_HPP(C);

Expand All @@ -340,6 +339,13 @@ SUNErrCode SUNAdaptController_EstimateStep_Soderlind(SUNAdaptController C,
SUNRpowerR(hrat, k4) * SUNRpowerR(hrat2, k5);
}

if (isnan(*hnew))
{
/* hnew can be NAN if multiple e's are 0. In that case, make hnew inf with
* the same sign as h */
*hnew = h / SUN_RCONST(0.0);
}

/* return with success */
return SUN_SUCCESS;
}
Expand Down
6 changes: 5 additions & 1 deletion src/sundials/sundials_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <sundials/sundials_math.h>
#include <sundials/sundials_types.h>

#include <assert.h>

sunrealtype SUNRpowerI(sunrealtype base, int exponent)
{
int i, expt;
Expand All @@ -36,7 +38,9 @@ sunrealtype SUNRpowerI(sunrealtype base, int exponent)

sunrealtype SUNRpowerR(sunrealtype base, sunrealtype exponent)
{
if (base <= SUN_RCONST(0.0)) { return (SUN_RCONST(0.0)); }
gardner48 marked this conversation as resolved.
Show resolved Hide resolved
// TODO(SBR): cleanup this and header
// if (base <= SUN_RCONST(0.0)) { return (SUN_RCONST(0.0)); }
assert(base > 0.0);

#if defined(SUNDIALS_DOUBLE_PRECISION)
return (pow(base, exponent));
Expand Down
Loading