From 8f856105e71544313e10cfd5118c8f9a5b7f6efe Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sun, 21 Jul 2024 14:46:37 -0400 Subject: [PATCH] switch some more min(max(..)) to std::clamp --- EOS/helmholtz/actual_eos.H | 10 +++++----- integration/BackwardEuler/be_integrator.H | 2 +- integration/ForwardEuler/actual_integrator.H | 2 +- integration/RKC/rkc.H | 2 +- integration/integrator_type_sdc.H | 3 +-- integration/integrator_type_strang.H | 2 +- integration/utils/initial_timestep.H | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/EOS/helmholtz/actual_eos.H b/EOS/helmholtz/actual_eos.H index febdfe07d8..dfe8983e0c 100644 --- a/EOS/helmholtz/actual_eos.H +++ b/EOS/helmholtz/actual_eos.H @@ -156,9 +156,9 @@ void apply_electrons (T& state) // hash locate this temperature and density int jat = int((std::log10(state.T) - tlo) * tstpi) + 1; - jat = amrex::max(1, amrex::min(jat, jmax-1)) - 1; + jat = std::clamp(jat, 1, jmax-1) - 1; int iat = int((std::log10(din) - dlo) * dstpi) + 1; - iat = amrex::max(1, amrex::min(iat, imax-1)) - 1; + iat = std::clamp(iat, 1, imax-1) - 1; amrex::Real fi[36]; @@ -1005,7 +1005,7 @@ void single_iter_update (T& state, int var, int dvar, amrex::Real xnew = x - (v - v_want) / dvdx; // Don't let the temperature/density change by more than a factor of two - xnew = amrex::max(0.5_rt * x, amrex::min(xnew, 2.0_rt * x)); + xnew = std::clamp(xnew, 0.5_rt * x, 2.0_rt * x); // Don't let us freeze/evacuate xnew = amrex::max(smallx, xnew); @@ -1120,8 +1120,8 @@ void double_iter_update (T& state, int var1, int var2, // Don't let the temperature or density change by more // than a factor of two - tnew = amrex::max(0.5e0_rt * told, amrex::min(tnew, 2.0e0_rt * told)); - rnew = amrex::max(0.5e0_rt * rold, amrex::min(rnew, 2.0e0_rt * rold)); + tnew = std::clamp(tnew, 0.5e0_rt * told, 2.0e0_rt * told); + rnew = std::clamp(rnew, 0.5e0_rt * rold, 2.0e0_rt * rold); // Don't let us freeze or evacuate tnew = amrex::max(EOSData::mintemp, tnew); diff --git a/integration/BackwardEuler/be_integrator.H b/integration/BackwardEuler/be_integrator.H index 2d858a7b57..6ce4ddeb9e 100644 --- a/integration/BackwardEuler/be_integrator.H +++ b/integration/BackwardEuler/be_integrator.H @@ -272,7 +272,7 @@ int be_integrator (BurnT& state, BeT& be) // backward-Euler has a local truncation error of dt**2 amrex::Real dt_new = dt_sub * std::pow(1.0_rt / rel_error, 0.5_rt); - dt_sub = amrex::min(amrex::max(dt_new, dt_sub / 2.0), 2.0 * dt_sub); + dt_sub = std::clamp(dt_new, dt_sub / 2.0, 2.0 * dt_sub); } else { diff --git a/integration/ForwardEuler/actual_integrator.H b/integration/ForwardEuler/actual_integrator.H index e52b8cb678..6fd19d1a59 100644 --- a/integration/ForwardEuler/actual_integrator.H +++ b/integration/ForwardEuler/actual_integrator.H @@ -86,7 +86,7 @@ void clean_state (const amrex::Real time, IntT& int_state, BurnT& state) // Ensure that the temperature always stays within reasonable limits. - state.T = amrex::min(MAX_TEMP, amrex::max(state.T, EOSData::mintemp)); + state.T = std::clamp(state.T, EOSData::mintemp, MAX_TEMP); } diff --git a/integration/RKC/rkc.H b/integration/RKC/rkc.H index 55d3a3c5b4..958cffc3ca 100644 --- a/integration/RKC/rkc.H +++ b/integration/RKC/rkc.H @@ -308,7 +308,7 @@ int rkclow (BurnT& state, RkcT& rstate) } } absh = std::max(0.1_rt, fac) * absh; - absh = std::max(hmin, std::min(rstate.hmax, absh)); + absh = std::clamp(absh, hmin, rstate.hmax); errold = err; hold = h; h = tdir * absh; diff --git a/integration/integrator_type_sdc.H b/integration/integrator_type_sdc.H index 4d65e03c7e..7913d610a6 100644 --- a/integration/integrator_type_sdc.H +++ b/integration/integrator_type_sdc.H @@ -21,8 +21,7 @@ void clean_state(const amrex::Real time, BurnT& state, T& int_state) if (do_species_clip) { for (int n = 1; n <= NumSpec; ++n) { // we use 1-based indexing, so we need to offset SFS - int_state.y(SFS+n) = amrex::max(amrex::min(int_state.y(SFS+n), state.rho), - state.rho * SMALL_X_SAFE); + int_state.y(SFS+n) = std::clamp(int_state.y(SFS+n), state.rho * SMALL_X_SAFE, state.rho); } } diff --git a/integration/integrator_type_strang.H b/integration/integrator_type_strang.H index 35dfd7174f..09bc40307b 100644 --- a/integration/integrator_type_strang.H +++ b/integration/integrator_type_strang.H @@ -55,7 +55,7 @@ void clean_state (const amrex::Real time, BurnT& state, I& int_state) if (do_species_clip) { for (int n = 1; n <= NumSpec; ++n) { - int_state.y(n) = amrex::max(amrex::min(int_state.y(n), 1.0_rt), SMALL_X_SAFE); + int_state.y(n) = std::clamp(int_state.y(n), SMALL_X_SAFE, 1.0_rt); } } diff --git a/integration/utils/initial_timestep.H b/integration/utils/initial_timestep.H index 876b571103..9d7f5cd9f4 100644 --- a/integration/utils/initial_timestep.H +++ b/integration/utils/initial_timestep.H @@ -87,7 +87,7 @@ amrex::Real initial_react_dt (BurnT& burn_state, IntT& int_state, // Save the final timestep, with a bias factor. amrex::Real dt = h / 2.0_rt; - dt = amrex::min(amrex::max(h, hL), hU); + dt = std::clamp(h, hL, hU); dt = amrex::min(dt, ode_max_dt);