From f2094f962405677934765af88383c496d91bd735 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sun, 12 Jan 2025 13:03:59 -0500 Subject: [PATCH] std::clamp -> amrex::clamp (#1711) HIP + GCC 14 doesn't recognize std::clamp as constexpr --- EOS/helmholtz/actual_eos.H | 12 +++--- integration/BackwardEuler/be_integrator.H | 4 +- integration/ForwardEuler/actual_integrator.H | 4 +- integration/RKC/rkc.H | 4 +- integration/VODE/vode_dvhin.H | 3 +- integration/integrator_type_sdc.H | 4 +- integration/integrator_type_strang.H | 4 +- integration/nse_update_sdc.H | 6 ++- integration/utils/initial_timestep.H | 4 +- nse_solver/nse_eos.H | 3 +- nse_tabular/nse_eos.H | 9 +++-- nse_tabular/nse_table.H | 40 ++++++++++---------- 12 files changed, 58 insertions(+), 39 deletions(-) diff --git a/EOS/helmholtz/actual_eos.H b/EOS/helmholtz/actual_eos.H index 2a7eb64cd3..71768510b0 100644 --- a/EOS/helmholtz/actual_eos.H +++ b/EOS/helmholtz/actual_eos.H @@ -8,6 +8,8 @@ #include #include #include +#include + #include #include #include @@ -154,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 = std::clamp(jat, 1, jmax-1) - 1; + jat = amrex::Clamp(jat, 1, jmax-1) - 1; int iat = int((std::log10(din) - dlo) * dstpi) + 1; - iat = std::clamp(iat, 1, imax-1) - 1; + iat = amrex::Clamp(iat, 1, imax-1) - 1; amrex::Real fi[36]; @@ -1003,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 = std::clamp(xnew, 0.5_rt * x, 2.0_rt * x); + xnew = amrex::Clamp(xnew, 0.5_rt * x, 2.0_rt * x); // Don't let us freeze/evacuate xnew = amrex::max(smallx, xnew); @@ -1118,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 = std::clamp(tnew, 0.5e0_rt * told, 2.0e0_rt * told); - rnew = std::clamp(rnew, 0.5e0_rt * rold, 2.0e0_rt * rold); + tnew = amrex::Clamp(tnew, 0.5e0_rt * told, 2.0e0_rt * told); + rnew = amrex::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 0c63a2f274..ef0ff29a63 100644 --- a/integration/BackwardEuler/be_integrator.H +++ b/integration/BackwardEuler/be_integrator.H @@ -1,6 +1,8 @@ #ifndef BE_INTEGRATOR_H #define BE_INTEGRATOR_H +#include + #include #include #include @@ -272,7 +274,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::sqrt(1.0_rt / rel_error); - dt_sub = std::clamp(dt_new, dt_sub / 2.0, 2.0 * dt_sub); + dt_sub = amrex::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 7bf5d6e8bc..ca2a189d80 100644 --- a/integration/ForwardEuler/actual_integrator.H +++ b/integration/ForwardEuler/actual_integrator.H @@ -1,6 +1,8 @@ #ifndef actual_integrator_H #define actual_integrator_H +#include + #include #include #ifdef NEW_NETWORK_IMPLEMENTATION @@ -84,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 = std::clamp(state.T, EOSData::mintemp, integrator_rp::MAX_TEMP); + state.T = amrex::Clamp(state.T, EOSData::mintemp, integrator_rp::MAX_TEMP); } diff --git a/integration/RKC/rkc.H b/integration/RKC/rkc.H index 62973d03e1..25393632b3 100644 --- a/integration/RKC/rkc.H +++ b/integration/RKC/rkc.H @@ -1,6 +1,8 @@ #ifndef RKC_H #define RKC_H +#include + #include #include #include @@ -306,7 +308,7 @@ int rkclow (BurnT& state, RkcT& rstate) } } absh = std::max(0.1_rt, fac) * absh; - absh = std::clamp(absh, hmin, rstate.hmax); + absh = amrex::Clamp(absh, hmin, rstate.hmax); errold = err; hold = h; h = tdir * absh; diff --git a/integration/VODE/vode_dvhin.H b/integration/VODE/vode_dvhin.H index 20c6747224..96c18b5756 100644 --- a/integration/VODE/vode_dvhin.H +++ b/integration/VODE/vode_dvhin.H @@ -2,6 +2,7 @@ #define VODE_DVHIN_H #include +#include #ifdef STRANG #include @@ -124,7 +125,7 @@ void dvhin (BurnT& state, DvodeT& vstate, amrex::Real& H0, int& NITER, int& IER) // Iteration done. Apply bounds and bias factor. Then exit. H0 = hnew * 0.5_rt; - H0 = std::clamp(H0, HLB, HUB); + H0 = amrex::Clamp(H0, HLB, HUB); } diff --git a/integration/integrator_type_sdc.H b/integration/integrator_type_sdc.H index 99c058bccc..f30d3ad7be 100644 --- a/integration/integrator_type_sdc.H +++ b/integration/integrator_type_sdc.H @@ -1,6 +1,8 @@ #ifndef INTEGRATOR_TYPE_SDC_H #define INTEGRATOR_TYPE_SDC_H +#include + #include #include #include @@ -19,7 +21,7 @@ void clean_state(const amrex::Real time, BurnT& state, T& int_state) if (integrator_rp::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) = std::clamp(int_state.y(SFS+n), + int_state.y(SFS+n) = amrex::Clamp(int_state.y(SFS+n), state.rho * integrator_rp::SMALL_X_SAFE, state.rho); } } diff --git a/integration/integrator_type_strang.H b/integration/integrator_type_strang.H index 6efc3fcf4d..7eb3c6d60f 100644 --- a/integration/integrator_type_strang.H +++ b/integration/integrator_type_strang.H @@ -1,6 +1,8 @@ #ifndef INTEGRATOR_TYPE_STRANG_H #define INTEGRATOR_TYPE_STRANG_H +#include + #include #include @@ -53,7 +55,7 @@ void clean_state (const amrex::Real time, BurnT& state, I& int_state) if (integrator_rp::do_species_clip) { for (int n = 1; n <= NumSpec; ++n) { - int_state.y(n) = std::clamp(int_state.y(n), integrator_rp::SMALL_X_SAFE, 1.0_rt); + int_state.y(n) = amrex::Clamp(int_state.y(n), integrator_rp::SMALL_X_SAFE, 1.0_rt); } } diff --git a/integration/nse_update_sdc.H b/integration/nse_update_sdc.H index ed4913bb27..6756b3006a 100644 --- a/integration/nse_update_sdc.H +++ b/integration/nse_update_sdc.H @@ -1,6 +1,8 @@ #ifndef NSE_UPDATE_H #define NSE_UPDATE_H +#include + #include #include #include @@ -271,7 +273,7 @@ void sdc_nse_burn(BurnT& state, const amrex::Real dt) { amrex::Real sum_X{0.0_rt}; for (auto & xn : nse_state.X) { - xn = std::clamp(xn, small_x, 1.0_rt); + xn = amrex::Clamp(xn, small_x, 1.0_rt); sum_X += xn; } @@ -581,7 +583,7 @@ void sdc_nse_burn(BurnT& state, const amrex::Real dt) { amrex::Real sum_X{0.0_rt}; for (auto & xn : nse_state.xn) { - xn = std::clamp(xn, small_x, 1.0_rt); + xn = amrex::Clamp(xn, small_x, 1.0_rt); sum_X += xn; } diff --git a/integration/utils/initial_timestep.H b/integration/utils/initial_timestep.H index ce6c2ef0ac..c53fa026f7 100644 --- a/integration/utils/initial_timestep.H +++ b/integration/utils/initial_timestep.H @@ -2,6 +2,8 @@ #define INITIAL_TIMESTEP_H #include +#include + #include #ifdef NEW_NETWORK_IMPLEMENTATION #include @@ -87,7 +89,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 = std::clamp(h, hL, hU); + dt = amrex::Clamp(h, hL, hU); dt = amrex::min(dt, integrator_rp::ode_max_dt); diff --git a/nse_solver/nse_eos.H b/nse_solver/nse_eos.H index 69d4fccc44..6816ad31fa 100644 --- a/nse_solver/nse_eos.H +++ b/nse_solver/nse_eos.H @@ -2,6 +2,7 @@ #define NSE_EOS_H #include +#include #include @@ -152,7 +153,7 @@ nse_T_abar_from_e(const amrex::Real rho, const amrex::Real e_in, // update the temperature and abar - T = std::clamp(T + dT, 0.25 * T, 4.0 * T); + T = amrex::Clamp(T + dT, 0.25 * T, 4.0 * T); abar = eos_state.abar; // update mu_p and mu_n diff --git a/nse_tabular/nse_eos.H b/nse_tabular/nse_eos.H index 1006889325..243cf6b6a0 100644 --- a/nse_tabular/nse_eos.H +++ b/nse_tabular/nse_eos.H @@ -2,6 +2,7 @@ #define NSE_EOS_H #include +#include #include @@ -84,7 +85,7 @@ nse_T_abar_from_e(const amrex::Real rho, const amrex::Real e_in, const amrex::Re + Ye * eos_state.dedZ * dabar_dT); // update the temperature - T = std::clamp(T + dT, 0.25 * T, 4.0 * T); + T = amrex::Clamp(T + dT, 0.25 * T, 4.0 * T); // check convergence @@ -175,7 +176,7 @@ nse_rho_abar_from_e(const amrex::Real T, const amrex::Real e_in, const amrex::Re + Ye * eos_state.dedZ * dabar_drho); // update the density - rho = std::clamp(rho + drho, 0.25 * rho, 4.0 * rho); + rho = amrex::Clamp(rho + drho, 0.25 * rho, 4.0 * rho); // check convergence @@ -266,7 +267,7 @@ nse_T_abar_from_p(const amrex::Real rho, const amrex::Real p_in, const amrex::Re + Ye * eos_state.dpdZ * dabar_dT); // update the temperature - T = std::clamp(T + dT, 0.25 * T, 4.0 * T); + T = amrex::Clamp(T + dT, 0.25 * T, 4.0 * T); // check convergence @@ -357,7 +358,7 @@ nse_rho_abar_from_p(const amrex::Real T, const amrex::Real p_in, const amrex::Re + Ye * eos_state.dpdZ * dabar_drho); // update the density - rho = std::clamp(rho + drho, 0.25 * rho, 4.0 * rho); + rho = amrex::Clamp(rho + drho, 0.25 * rho, 4.0 * rho); // check convergence diff --git a/nse_tabular/nse_table.H b/nse_tabular/nse_table.H index 9e5f00bafe..b5c585647b 100644 --- a/nse_tabular/nse_table.H +++ b/nse_tabular/nse_table.H @@ -405,7 +405,7 @@ void nse_interp(nse_table_t& nse_state, bool skip_X_fill=false) { amrex::Real rmin = nse_table_size::logrho_min; amrex::Real rmax = nse_table_size::logrho_max; - rholog = std::clamp(rholog, rmin, rmax); + rholog = amrex::Clamp(rholog, rmin, rmax); } amrex::Real tlog = std::log10(nse_state.T); @@ -413,7 +413,7 @@ void nse_interp(nse_table_t& nse_state, bool skip_X_fill=false) { amrex::Real tmin = nse_table_size::logT_min; amrex::Real tmax = nse_table_size::logT_max; - tlog = std::clamp(tlog, tmin, tmax); + tlog = amrex::Clamp(tlog, tmin, tmax); } amrex::Real yet = nse_state.Ye; @@ -421,7 +421,7 @@ void nse_interp(nse_table_t& nse_state, bool skip_X_fill=false) { amrex::Real yemin = nse_table_size::ye_min; amrex::Real yemax = nse_table_size::ye_max; - yet = std::clamp(yet, yemin, yemax); + yet = amrex::Clamp(yet, yemin, yemax); } if (nse_table_interp_linear) { @@ -443,7 +443,7 @@ void nse_interp(nse_table_t& nse_state, bool skip_X_fill=false) { for (int n = 1; n <= NumSpec; n++) { amrex::Real _X = trilinear(ir1, it1, ic1, rholog, tlog, yet, [=] (const int i) {return massfractab(n, i);}); - nse_state.X[n-1] = std::clamp(_X, 0.0_rt, 1.0_rt); + nse_state.X[n-1] = amrex::Clamp(_X, 0.0_rt, 1.0_rt); } } @@ -455,13 +455,13 @@ void nse_interp(nse_table_t& nse_state, bool skip_X_fill=false) { // so we offset one to the left and also ensure that we don't go off the table int ir0 = nse_get_logrho_index(rholog) - 1; - ir0 = std::clamp(ir0, 1, nse_table_size::nden-3); + ir0 = amrex::Clamp(ir0, 1, nse_table_size::nden-3); int it0 = nse_get_logT_index(tlog) - 1; - it0 = std::clamp(it0, 1, nse_table_size::ntemp-3); + it0 = amrex::Clamp(it0, 1, nse_table_size::ntemp-3); int ic0 = nse_get_ye_index(yet) - 1; - ic0 = std::clamp(ic0, 1, nse_table_size::nye-3); + ic0 = amrex::Clamp(ic0, 1, nse_table_size::nye-3); nse_state.abar = tricubic(ir0, it0, ic0, rholog, tlog, yet, abartab); nse_state.bea = tricubic(ir0, it0, ic0, rholog, tlog, yet, beatab); @@ -476,7 +476,7 @@ void nse_interp(nse_table_t& nse_state, bool skip_X_fill=false) { for (int n = 1; n <= NumSpec; n++) { amrex::Real _X = tricubic(ir0, it0, ic0, rholog, tlog, yet, [=] (const int i) {return massfractab(n, i);}); - nse_state.X[n-1] = std::clamp(_X, 0.0_rt, 1.0_rt); + nse_state.X[n-1] = amrex::Clamp(_X, 0.0_rt, 1.0_rt); } } } @@ -498,7 +498,7 @@ nse_interp_dT(const amrex::Real temp, const amrex::Real rho, const amrex::Real y amrex::Real rmin = nse_table_size::logrho_min; amrex::Real rmax = nse_table_size::logrho_max; - rholog = std::clamp(rholog, rmin, rmax); + rholog = amrex::Clamp(rholog, rmin, rmax); } amrex::Real tlog = std::log10(temp); @@ -506,7 +506,7 @@ nse_interp_dT(const amrex::Real temp, const amrex::Real rho, const amrex::Real y amrex::Real tmin = nse_table_size::logT_min; amrex::Real tmax = nse_table_size::logT_max; - tlog = std::clamp(tlog, tmin, tmax); + tlog = amrex::Clamp(tlog, tmin, tmax); } amrex::Real yet = ye; @@ -514,17 +514,17 @@ nse_interp_dT(const amrex::Real temp, const amrex::Real rho, const amrex::Real y amrex::Real yemin = nse_table_size::ye_min; amrex::Real yemax = nse_table_size::ye_max; - yet = std::clamp(yet, yemin, yemax); + yet = amrex::Clamp(yet, yemin, yemax); } int ir0 = nse_get_logrho_index(rholog) - 1; - ir0 = std::clamp(ir0, 1, nse_table_size::nden-3); + ir0 = amrex::Clamp(ir0, 1, nse_table_size::nden-3); int it0 = nse_get_logT_index(tlog) - 1; - it0 = std::clamp(it0, 1, nse_table_size::ntemp-3); + it0 = amrex::Clamp(it0, 1, nse_table_size::ntemp-3); int ic0 = nse_get_ye_index(yet) - 1; - ic0 = std::clamp(ic0, 1, nse_table_size::nye-3); + ic0 = amrex::Clamp(ic0, 1, nse_table_size::nye-3); // note: this is returning the derivative wrt log10(T), so we need to // convert to d/dT @@ -551,7 +551,7 @@ nse_interp_drho(const amrex::Real temp, const amrex::Real rho, const amrex::Real amrex::Real rmin = nse_table_size::logrho_min; amrex::Real rmax = nse_table_size::logrho_max; - rholog = std::clamp(rholog, rmin, rmax); + rholog = amrex::Clamp(rholog, rmin, rmax); } amrex::Real tlog = std::log10(temp); @@ -559,7 +559,7 @@ nse_interp_drho(const amrex::Real temp, const amrex::Real rho, const amrex::Real amrex::Real tmin = nse_table_size::logT_min; amrex::Real tmax = nse_table_size::logT_max; - tlog = std::clamp(tlog, tmin, tmax); + tlog = amrex::Clamp(tlog, tmin, tmax); } amrex::Real yet = ye; @@ -567,17 +567,17 @@ nse_interp_drho(const amrex::Real temp, const amrex::Real rho, const amrex::Real amrex::Real yemin = nse_table_size::ye_min; amrex::Real yemax = nse_table_size::ye_max; - yet = std::clamp(yet, yemin, yemax); + yet = amrex::Clamp(yet, yemin, yemax); } int ir0 = nse_get_logrho_index(rholog) - 1; - ir0 = std::clamp(ir0, 1, nse_table_size::nden-3); + ir0 = amrex::Clamp(ir0, 1, nse_table_size::nden-3); int it0 = nse_get_logT_index(tlog) - 1; - it0 = std::clamp(it0, 1, nse_table_size::ntemp-3); + it0 = amrex::Clamp(it0, 1, nse_table_size::ntemp-3); int ic0 = nse_get_ye_index(yet) - 1; - ic0 = std::clamp(ic0, 1, nse_table_size::nye-3); + ic0 = amrex::Clamp(ic0, 1, nse_table_size::nye-3); // note: this is returning the derivative wrt log10(rho), so we need to // convert to d/drho