Skip to content

Commit f2094f9

Browse files
authored
std::clamp -> amrex::clamp (#1711)
HIP + GCC 14 doesn't recognize std::clamp as constexpr
1 parent f0c0d2a commit f2094f9

File tree

12 files changed

+58
-39
lines changed

12 files changed

+58
-39
lines changed

EOS/helmholtz/actual_eos.H

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <AMReX.H>
99
#include <AMReX_REAL.H>
1010
#include <AMReX_ParallelDescriptor.H>
11+
#include <AMReX_Algorithm.H>
12+
1113
#include <extern_parameters.H>
1214
#include <fundamental_constants.H>
1315
#include <eos_type.H>
@@ -154,9 +156,9 @@ void apply_electrons (T& state)
154156

155157
// hash locate this temperature and density
156158
int jat = int((std::log10(state.T) - tlo) * tstpi) + 1;
157-
jat = std::clamp(jat, 1, jmax-1) - 1;
159+
jat = amrex::Clamp(jat, 1, jmax-1) - 1;
158160
int iat = int((std::log10(din) - dlo) * dstpi) + 1;
159-
iat = std::clamp(iat, 1, imax-1) - 1;
161+
iat = amrex::Clamp(iat, 1, imax-1) - 1;
160162

161163
amrex::Real fi[36];
162164

@@ -1003,7 +1005,7 @@ void single_iter_update (T& state, int var, int dvar,
10031005
amrex::Real xnew = x - (v - v_want) / dvdx;
10041006

10051007
// Don't let the temperature/density change by more than a factor of two
1006-
xnew = std::clamp(xnew, 0.5_rt * x, 2.0_rt * x);
1008+
xnew = amrex::Clamp(xnew, 0.5_rt * x, 2.0_rt * x);
10071009

10081010
// Don't let us freeze/evacuate
10091011
xnew = amrex::max(smallx, xnew);
@@ -1118,8 +1120,8 @@ void double_iter_update (T& state, int var1, int var2,
11181120

11191121
// Don't let the temperature or density change by more
11201122
// than a factor of two
1121-
tnew = std::clamp(tnew, 0.5e0_rt * told, 2.0e0_rt * told);
1122-
rnew = std::clamp(rnew, 0.5e0_rt * rold, 2.0e0_rt * rold);
1123+
tnew = amrex::Clamp(tnew, 0.5e0_rt * told, 2.0e0_rt * told);
1124+
rnew = amrex::Clamp(rnew, 0.5e0_rt * rold, 2.0e0_rt * rold);
11231125

11241126
// Don't let us freeze or evacuate
11251127
tnew = amrex::max(EOSData::mintemp, tnew);

integration/BackwardEuler/be_integrator.H

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef BE_INTEGRATOR_H
22
#define BE_INTEGRATOR_H
33

4+
#include <AMReX_Algorithm.H>
5+
46
#include <be_type.H>
57
#include <network.H>
68
#include <actual_network.H>
@@ -272,7 +274,7 @@ int be_integrator (BurnT& state, BeT& be)
272274
// backward-Euler has a local truncation error of dt**2
273275

274276
amrex::Real dt_new = dt_sub * std::sqrt(1.0_rt / rel_error);
275-
dt_sub = std::clamp(dt_new, dt_sub / 2.0, 2.0 * dt_sub);
277+
dt_sub = amrex::Clamp(dt_new, dt_sub / 2.0, 2.0 * dt_sub);
276278

277279
} else {
278280

integration/ForwardEuler/actual_integrator.H

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef actual_integrator_H
22
#define actual_integrator_H
33

4+
#include <AMReX_Algorithm.H>
5+
46
#include <network.H>
57
#include <actual_network.H>
68
#ifdef NEW_NETWORK_IMPLEMENTATION
@@ -84,7 +86,7 @@ void clean_state (const amrex::Real time, IntT& int_state, BurnT& state)
8486

8587
// Ensure that the temperature always stays within reasonable limits.
8688

87-
state.T = std::clamp(state.T, EOSData::mintemp, integrator_rp::MAX_TEMP);
89+
state.T = amrex::Clamp(state.T, EOSData::mintemp, integrator_rp::MAX_TEMP);
8890

8991
}
9092

integration/RKC/rkc.H

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef RKC_H
22
#define RKC_H
33

4+
#include <AMReX_Algorithm.H>
5+
46
#include <rkc_type.H>
57
#include <rkc_util.H>
68
#include <burn_type.H>
@@ -306,7 +308,7 @@ int rkclow (BurnT& state, RkcT& rstate)
306308
}
307309
}
308310
absh = std::max(0.1_rt, fac) * absh;
309-
absh = std::clamp(absh, hmin, rstate.hmax);
311+
absh = amrex::Clamp(absh, hmin, rstate.hmax);
310312
errold = err;
311313
hold = h;
312314
h = tdir * absh;

integration/VODE/vode_dvhin.H

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define VODE_DVHIN_H
33

44
#include <AMReX_REAL.H>
5+
#include <AMReX_Algorithm.H>
56

67
#ifdef STRANG
78
#include <integrator_rhs_strang.H>
@@ -124,7 +125,7 @@ void dvhin (BurnT& state, DvodeT& vstate, amrex::Real& H0, int& NITER, int& IER)
124125

125126
// Iteration done. Apply bounds and bias factor. Then exit.
126127
H0 = hnew * 0.5_rt;
127-
H0 = std::clamp(H0, HLB, HUB);
128+
H0 = amrex::Clamp(H0, HLB, HUB);
128129

129130
}
130131

integration/integrator_type_sdc.H

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef INTEGRATOR_TYPE_SDC_H
22
#define INTEGRATOR_TYPE_SDC_H
33

4+
#include <AMReX_Algorithm.H>
5+
46
#include <eos.H>
57
#include <eos_composition.H>
68
#include <burn_type.H>
@@ -19,7 +21,7 @@ void clean_state(const amrex::Real time, BurnT& state, T& int_state)
1921
if (integrator_rp::do_species_clip) {
2022
for (int n = 1; n <= NumSpec; ++n) {
2123
// we use 1-based indexing, so we need to offset SFS
22-
int_state.y(SFS+n) = std::clamp(int_state.y(SFS+n),
24+
int_state.y(SFS+n) = amrex::Clamp(int_state.y(SFS+n),
2325
state.rho * integrator_rp::SMALL_X_SAFE, state.rho);
2426
}
2527
}

integration/integrator_type_strang.H

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef INTEGRATOR_TYPE_STRANG_H
22
#define INTEGRATOR_TYPE_STRANG_H
33

4+
#include <AMReX_Algorithm.H>
5+
46
#include <eos.H>
57
#include <integrator_type.H>
68

@@ -53,7 +55,7 @@ void clean_state (const amrex::Real time, BurnT& state, I& int_state)
5355

5456
if (integrator_rp::do_species_clip) {
5557
for (int n = 1; n <= NumSpec; ++n) {
56-
int_state.y(n) = std::clamp(int_state.y(n), integrator_rp::SMALL_X_SAFE, 1.0_rt);
58+
int_state.y(n) = amrex::Clamp(int_state.y(n), integrator_rp::SMALL_X_SAFE, 1.0_rt);
5759
}
5860
}
5961

integration/nse_update_sdc.H

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef NSE_UPDATE_H
22
#define NSE_UPDATE_H
33

4+
#include <AMReX_Algorithm.H>
5+
46
#include <iostream>
57
#include <fstream>
68
#include <actual_network.H>
@@ -271,7 +273,7 @@ void sdc_nse_burn(BurnT& state, const amrex::Real dt) {
271273

272274
amrex::Real sum_X{0.0_rt};
273275
for (auto & xn : nse_state.X) {
274-
xn = std::clamp(xn, small_x, 1.0_rt);
276+
xn = amrex::Clamp(xn, small_x, 1.0_rt);
275277
sum_X += xn;
276278
}
277279

@@ -581,7 +583,7 @@ void sdc_nse_burn(BurnT& state, const amrex::Real dt) {
581583

582584
amrex::Real sum_X{0.0_rt};
583585
for (auto & xn : nse_state.xn) {
584-
xn = std::clamp(xn, small_x, 1.0_rt);
586+
xn = amrex::Clamp(xn, small_x, 1.0_rt);
585587
sum_X += xn;
586588
}
587589

integration/utils/initial_timestep.H

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define INITIAL_TIMESTEP_H
33

44
#include <AMReX_REAL.H>
5+
#include <AMReX_Algorithm.H>
6+
57
#include <actual_network.H>
68
#ifdef NEW_NETWORK_IMPLEMENTATION
79
#include <rhs.H>
@@ -87,7 +89,7 @@ amrex::Real initial_react_dt (BurnT& burn_state, IntT& int_state,
8789
// Save the final timestep, with a bias factor.
8890

8991
amrex::Real dt = h / 2.0_rt;
90-
dt = std::clamp(h, hL, hU);
92+
dt = amrex::Clamp(h, hL, hU);
9193

9294
dt = amrex::min(dt, integrator_rp::ode_max_dt);
9395

nse_solver/nse_eos.H

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define NSE_EOS_H
33

44
#include <AMReX_REAL.H>
5+
#include <AMReX_Algorithm.H>
56

67
#include <eos.H>
78

@@ -152,7 +153,7 @@ nse_T_abar_from_e(const amrex::Real rho, const amrex::Real e_in,
152153

153154
// update the temperature and abar
154155

155-
T = std::clamp(T + dT, 0.25 * T, 4.0 * T);
156+
T = amrex::Clamp(T + dT, 0.25 * T, 4.0 * T);
156157
abar = eos_state.abar;
157158

158159
// update mu_p and mu_n

nse_tabular/nse_eos.H

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define NSE_EOS_H
33

44
#include <AMReX_REAL.H>
5+
#include <AMReX_Algorithm.H>
56

67
#include <eos.H>
78

@@ -84,7 +85,7 @@ nse_T_abar_from_e(const amrex::Real rho, const amrex::Real e_in, const amrex::Re
8485
+ Ye * eos_state.dedZ * dabar_dT);
8586

8687
// update the temperature
87-
T = std::clamp(T + dT, 0.25 * T, 4.0 * T);
88+
T = amrex::Clamp(T + dT, 0.25 * T, 4.0 * T);
8889

8990
// check convergence
9091

@@ -175,7 +176,7 @@ nse_rho_abar_from_e(const amrex::Real T, const amrex::Real e_in, const amrex::Re
175176
+ Ye * eos_state.dedZ * dabar_drho);
176177

177178
// update the density
178-
rho = std::clamp(rho + drho, 0.25 * rho, 4.0 * rho);
179+
rho = amrex::Clamp(rho + drho, 0.25 * rho, 4.0 * rho);
179180

180181
// check convergence
181182

@@ -266,7 +267,7 @@ nse_T_abar_from_p(const amrex::Real rho, const amrex::Real p_in, const amrex::Re
266267
+ Ye * eos_state.dpdZ * dabar_dT);
267268

268269
// update the temperature
269-
T = std::clamp(T + dT, 0.25 * T, 4.0 * T);
270+
T = amrex::Clamp(T + dT, 0.25 * T, 4.0 * T);
270271

271272
// check convergence
272273

@@ -357,7 +358,7 @@ nse_rho_abar_from_p(const amrex::Real T, const amrex::Real p_in, const amrex::Re
357358
+ Ye * eos_state.dpdZ * dabar_drho);
358359

359360
// update the density
360-
rho = std::clamp(rho + drho, 0.25 * rho, 4.0 * rho);
361+
rho = amrex::Clamp(rho + drho, 0.25 * rho, 4.0 * rho);
361362

362363
// check convergence
363364

nse_tabular/nse_table.H

+20-20
Original file line numberDiff line numberDiff line change
@@ -405,23 +405,23 @@ void nse_interp(nse_table_t& nse_state, bool skip_X_fill=false) {
405405
amrex::Real rmin = nse_table_size::logrho_min;
406406
amrex::Real rmax = nse_table_size::logrho_max;
407407

408-
rholog = std::clamp(rholog, rmin, rmax);
408+
rholog = amrex::Clamp(rholog, rmin, rmax);
409409
}
410410

411411
amrex::Real tlog = std::log10(nse_state.T);
412412
{
413413
amrex::Real tmin = nse_table_size::logT_min;
414414
amrex::Real tmax = nse_table_size::logT_max;
415415

416-
tlog = std::clamp(tlog, tmin, tmax);
416+
tlog = amrex::Clamp(tlog, tmin, tmax);
417417
}
418418

419419
amrex::Real yet = nse_state.Ye;
420420
{
421421
amrex::Real yemin = nse_table_size::ye_min;
422422
amrex::Real yemax = nse_table_size::ye_max;
423423

424-
yet = std::clamp(yet, yemin, yemax);
424+
yet = amrex::Clamp(yet, yemin, yemax);
425425
}
426426

427427
if (nse_table_interp_linear) {
@@ -443,7 +443,7 @@ void nse_interp(nse_table_t& nse_state, bool skip_X_fill=false) {
443443
for (int n = 1; n <= NumSpec; n++) {
444444
amrex::Real _X = trilinear(ir1, it1, ic1, rholog, tlog, yet,
445445
[=] (const int i) {return massfractab(n, i);});
446-
nse_state.X[n-1] = std::clamp(_X, 0.0_rt, 1.0_rt);
446+
nse_state.X[n-1] = amrex::Clamp(_X, 0.0_rt, 1.0_rt);
447447
}
448448
}
449449

@@ -455,13 +455,13 @@ void nse_interp(nse_table_t& nse_state, bool skip_X_fill=false) {
455455
// so we offset one to the left and also ensure that we don't go off the table
456456

457457
int ir0 = nse_get_logrho_index(rholog) - 1;
458-
ir0 = std::clamp(ir0, 1, nse_table_size::nden-3);
458+
ir0 = amrex::Clamp(ir0, 1, nse_table_size::nden-3);
459459

460460
int it0 = nse_get_logT_index(tlog) - 1;
461-
it0 = std::clamp(it0, 1, nse_table_size::ntemp-3);
461+
it0 = amrex::Clamp(it0, 1, nse_table_size::ntemp-3);
462462

463463
int ic0 = nse_get_ye_index(yet) - 1;
464-
ic0 = std::clamp(ic0, 1, nse_table_size::nye-3);
464+
ic0 = amrex::Clamp(ic0, 1, nse_table_size::nye-3);
465465

466466
nse_state.abar = tricubic(ir0, it0, ic0, rholog, tlog, yet, abartab);
467467
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) {
476476
for (int n = 1; n <= NumSpec; n++) {
477477
amrex::Real _X = tricubic(ir0, it0, ic0, rholog, tlog, yet,
478478
[=] (const int i) {return massfractab(n, i);});
479-
nse_state.X[n-1] = std::clamp(_X, 0.0_rt, 1.0_rt);
479+
nse_state.X[n-1] = amrex::Clamp(_X, 0.0_rt, 1.0_rt);
480480
}
481481
}
482482
}
@@ -498,33 +498,33 @@ nse_interp_dT(const amrex::Real temp, const amrex::Real rho, const amrex::Real y
498498
amrex::Real rmin = nse_table_size::logrho_min;
499499
amrex::Real rmax = nse_table_size::logrho_max;
500500

501-
rholog = std::clamp(rholog, rmin, rmax);
501+
rholog = amrex::Clamp(rholog, rmin, rmax);
502502
}
503503

504504
amrex::Real tlog = std::log10(temp);
505505
{
506506
amrex::Real tmin = nse_table_size::logT_min;
507507
amrex::Real tmax = nse_table_size::logT_max;
508508

509-
tlog = std::clamp(tlog, tmin, tmax);
509+
tlog = amrex::Clamp(tlog, tmin, tmax);
510510
}
511511

512512
amrex::Real yet = ye;
513513
{
514514
amrex::Real yemin = nse_table_size::ye_min;
515515
amrex::Real yemax = nse_table_size::ye_max;
516516

517-
yet = std::clamp(yet, yemin, yemax);
517+
yet = amrex::Clamp(yet, yemin, yemax);
518518
}
519519

520520
int ir0 = nse_get_logrho_index(rholog) - 1;
521-
ir0 = std::clamp(ir0, 1, nse_table_size::nden-3);
521+
ir0 = amrex::Clamp(ir0, 1, nse_table_size::nden-3);
522522

523523
int it0 = nse_get_logT_index(tlog) - 1;
524-
it0 = std::clamp(it0, 1, nse_table_size::ntemp-3);
524+
it0 = amrex::Clamp(it0, 1, nse_table_size::ntemp-3);
525525

526526
int ic0 = nse_get_ye_index(yet) - 1;
527-
ic0 = std::clamp(ic0, 1, nse_table_size::nye-3);
527+
ic0 = amrex::Clamp(ic0, 1, nse_table_size::nye-3);
528528

529529
// note: this is returning the derivative wrt log10(T), so we need to
530530
// convert to d/dT
@@ -551,33 +551,33 @@ nse_interp_drho(const amrex::Real temp, const amrex::Real rho, const amrex::Real
551551
amrex::Real rmin = nse_table_size::logrho_min;
552552
amrex::Real rmax = nse_table_size::logrho_max;
553553

554-
rholog = std::clamp(rholog, rmin, rmax);
554+
rholog = amrex::Clamp(rholog, rmin, rmax);
555555
}
556556

557557
amrex::Real tlog = std::log10(temp);
558558
{
559559
amrex::Real tmin = nse_table_size::logT_min;
560560
amrex::Real tmax = nse_table_size::logT_max;
561561

562-
tlog = std::clamp(tlog, tmin, tmax);
562+
tlog = amrex::Clamp(tlog, tmin, tmax);
563563
}
564564

565565
amrex::Real yet = ye;
566566
{
567567
amrex::Real yemin = nse_table_size::ye_min;
568568
amrex::Real yemax = nse_table_size::ye_max;
569569

570-
yet = std::clamp(yet, yemin, yemax);
570+
yet = amrex::Clamp(yet, yemin, yemax);
571571
}
572572

573573
int ir0 = nse_get_logrho_index(rholog) - 1;
574-
ir0 = std::clamp(ir0, 1, nse_table_size::nden-3);
574+
ir0 = amrex::Clamp(ir0, 1, nse_table_size::nden-3);
575575

576576
int it0 = nse_get_logT_index(tlog) - 1;
577-
it0 = std::clamp(it0, 1, nse_table_size::ntemp-3);
577+
it0 = amrex::Clamp(it0, 1, nse_table_size::ntemp-3);
578578

579579
int ic0 = nse_get_ye_index(yet) - 1;
580-
ic0 = std::clamp(ic0, 1, nse_table_size::nye-3);
580+
ic0 = amrex::Clamp(ic0, 1, nse_table_size::nye-3);
581581

582582
// note: this is returning the derivative wrt log10(rho), so we need to
583583
// convert to d/drho

0 commit comments

Comments
 (0)