Skip to content

Commit ed95f6e

Browse files
authored
fix some clang-tidy issues in nse_net / hybrj (AMReX-Astro#1624)
1 parent 2456fd1 commit ed95f6e

File tree

7 files changed

+25
-30
lines changed

7 files changed

+25
-30
lines changed

nse_solver/nse_solver.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void compute_coulomb_contribution(amrex::Array1D<amrex::Real, 1, NumSpec>& u_c,
123123
// see appendix of Calder 2007, doi:10.1086/510709 for more detail
124124

125125
// reuse existing implementation from screening routine
126-
amrex::Real f = chabrier1998_helmholtz_F<amrex::Real>(gamma);
126+
auto f = chabrier1998_helmholtz_F<amrex::Real>(gamma);
127127

128128
//
129129
// Here u_c is a dimensionless quantity.

unit_test/test_nse_net/burn_cell.H

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ void burn_cell_c()
8787
eos(eos_input_rt, eos_state);
8888

8989
amrex::Real abar_start = eos_state.abar;
90-
amrex::Real e_start = eos_state.e;
9190

9291
// now perturb e and find the T/abar that are consistent with it
9392
// and NSE

util/hybrj/hybrj.H

+15-15
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void hybrj(hybrj_t<neqs>& hj,
108108

109109
if (iter == 1) {
110110
if (hj.mode != 2) {
111-
for (int j = 1; j <= hj.n; ++j) {
111+
for (int j = 1; j <= neqs; ++j) {
112112
hj.diag(j) = hj.wa2(j);
113113
if (hj.wa2(j) == 0.0_rt) {
114114
hj.diag(j) = 1.0_rt;
@@ -122,7 +122,7 @@ void hybrj(hybrj_t<neqs>& hj,
122122
for (int j = 1; j <= neqs; ++j) {
123123
hj.wa3(j) = hj.diag(j) * hj.x(j);
124124
}
125-
xnorm = enorm(hj.n, hj.wa3);
125+
xnorm = enorm(neqs, hj.wa3);
126126
delta = factor * xnorm;
127127
if (delta == 0.0_rt) {
128128
delta = factor;
@@ -131,17 +131,17 @@ void hybrj(hybrj_t<neqs>& hj,
131131

132132
// form (q transpose)*fvec and store in qtf.
133133

134-
for (int i = 1; i <= hj.n; ++i) {
134+
for (int i = 1; i <= neqs; ++i) {
135135
hj.qtf(i) = hj.fvec(i);
136136
}
137137
for (int j = 1; j <= neqs; ++j) {
138138
if (hj.fjac(j,j) != 0.0_rt) {
139139
amrex::Real sum = 0.0_rt;
140-
for (int i = j; i <= hj.n; ++i) {
140+
for (int i = j; i <= neqs; ++i) {
141141
sum += hj.fjac(i,j) * hj.qtf(i);
142142
}
143143
amrex::Real temp = -sum / hj.fjac(j,j);
144-
for (int i = j; i <= hj.n; ++i) {
144+
for (int i = j; i <= neqs; ++i) {
145145
hj.qtf(i) += hj.fjac(i,j) * temp;
146146
}
147147
}
@@ -151,7 +151,7 @@ void hybrj(hybrj_t<neqs>& hj,
151151

152152
bool sing = false;
153153

154-
for (int j = 1; j <= hj.n; ++j) {
154+
for (int j = 1; j <= neqs; ++j) {
155155
int l = j;
156156
int jm1 = j - 1;
157157
if (jm1 >= 1) {
@@ -173,7 +173,7 @@ void hybrj(hybrj_t<neqs>& hj,
173173
// rescale if necessary.
174174

175175
if (hj.mode != 2) {
176-
for (int j = 1; j <= hj.n; ++j) {
176+
for (int j = 1; j <= neqs; ++j) {
177177
hj.diag(j) = amrex::max(hj.diag(j), hj.wa2(j));
178178
}
179179
}
@@ -207,7 +207,7 @@ void hybrj(hybrj_t<neqs>& hj,
207207
hj.wa3(j) = hj.diag(j) * hj.wa1(j);
208208
}
209209

210-
amrex::Real pnorm = enorm(hj.n, hj.wa3);
210+
amrex::Real pnorm = enorm(neqs, hj.wa3);
211211

212212
// on the first iteration, adjust the initial step bound.
213213

@@ -225,7 +225,7 @@ void hybrj(hybrj_t<neqs>& hj,
225225
break;
226226
}
227227

228-
amrex::Real fnorm1 = enorm(hj.n, hj.wa4);
228+
amrex::Real fnorm1 = enorm(neqs, hj.wa4);
229229

230230
// compute the scaled actual reduction.
231231

@@ -237,15 +237,15 @@ void hybrj(hybrj_t<neqs>& hj,
237237
// compute the scaled predicted reduction.
238238

239239
int l = 1;
240-
for (int i = 1; i <= hj.n; ++i) {
240+
for (int i = 1; i <= neqs; ++i) {
241241
amrex::Real sum = 0.0_rt;
242242
for (int j = i; j <= neqs; ++j) {
243243
sum += hj.r(l) * hj.wa1(j);
244244
l += 1;
245245
}
246246
hj.wa3(i) = hj.qtf(i) + sum;
247247
}
248-
amrex::Real temp = enorm(hj.n, hj.wa3);
248+
amrex::Real temp = enorm(neqs, hj.wa3);
249249
amrex::Real prered = 0.0_rt;
250250
if (temp < fnorm) {
251251
prered = 1.0_rt - amrex::Math::powi<2>(temp/fnorm);
@@ -282,13 +282,13 @@ void hybrj(hybrj_t<neqs>& hj,
282282

283283
// successful iteration. update x, fvec, and their norms.
284284

285-
for (int j = 1; j <= hj.n; ++j) {
285+
for (int j = 1; j <= neqs; ++j) {
286286
hj.x(j) = hj.wa2(j);
287287
hj.wa2(j) = hj.diag(j) * hj.x(j);
288288
hj.fvec(j) = hj.wa4(j);
289289
}
290290

291-
xnorm = enorm(hj.n, hj.wa2);
291+
xnorm = enorm(neqs, hj.wa2);
292292
fnorm = fnorm1;
293293
iter++;
294294
}
@@ -348,9 +348,9 @@ void hybrj(hybrj_t<neqs>& hj,
348348
break;
349349
}
350350

351-
for (int j = 1; j <= hj.n; ++j) {
351+
for (int j = 1; j <= neqs; ++j) {
352352
amrex::Real sum = 0.0_rt;
353-
for (int i = 1; i <= hj.n; ++i) {
353+
for (int i = 1; i <= neqs; ++i) {
354354
sum += hj.fjac(i,j) * hj.wa4(i);
355355
}
356356
hj.wa2(j) = (sum - hj.wa3(j)) / pnorm;

util/hybrj/hybrj_dogleg.H

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343

4444
template<int neqs>
4545
AMREX_GPU_HOST_DEVICE AMREX_INLINE
46-
void dogleg(amrex::Array1D<amrex::Real, 1, neqs * (neqs + 1) / 2>& r,
47-
amrex::Array1D<amrex::Real, 1, neqs>& diag,
48-
amrex::Array1D<amrex::Real, 1, neqs>& qtb,
46+
void dogleg(const amrex::Array1D<amrex::Real, 1, neqs * (neqs + 1) / 2>& r,
47+
const amrex::Array1D<amrex::Real, 1, neqs>& diag,
48+
const amrex::Array1D<amrex::Real, 1, neqs>& qtb,
4949
amrex::Real delta,
5050
amrex::Array1D<amrex::Real, 1, neqs>& x,
5151
amrex::Array1D<amrex::Real, 1, neqs>& wa1,

util/hybrj/hybrj_enorm.H

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
template<int neqs>
2626
AMREX_GPU_HOST_DEVICE AMREX_INLINE
27-
amrex::Real enorm(const int n, amrex::Array1D<amrex::Real, 1, neqs>& x) {
27+
amrex::Real enorm(const int n, const amrex::Array1D<amrex::Real, 1, neqs>& x) {
2828

2929
// note: n <= neqs
3030

31-
const amrex::Real rdwarf = 3.834e-20_rt;
32-
const amrex::Real rgiant = 1.304e19_rt;
31+
constexpr amrex::Real rdwarf = 3.834e-20_rt;
32+
constexpr amrex::Real rgiant = 1.304e19_rt;
3333

3434
amrex::Real s1 = 0.0_rt;
3535
amrex::Real s2 = 0.0_rt;

util/hybrj/hybrj_type.H

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,20 @@ using namespace amrex::literals;
1616
// maxfev is a positive integer input variable. termination
1717
// occurs when the number of calls to fcn with iflag = 1
1818
// has reached maxfev.
19-
const int maxfev = 1000;
19+
constexpr int maxfev = 1000;
2020

2121
// factor is a positive input variable used in determining the
2222
// initial step bound. this bound is set to the product of
2323
// factor and the euclidean norm of diag*x if nonzero, or else
2424
// to factor itself. in most cases factor should lie in the
2525
// interval (.1,100.). 100. is a generally recommended value.
26-
const amrex::Real factor = 100.0_rt;
26+
constexpr amrex::Real factor = 100.0_rt;
2727

2828
template<int neqs>
2929
struct hybrj_t {
3030

3131
static_assert(neqs > 0);
3232

33-
// n is a positive integer input variable set to the number
34-
// of functions and variables.
35-
const int n = neqs;
36-
3733
// x is an array of length n. on input x must contain
3834
// an initial estimate of the solution vector. on output x
3935
// contains the final estimate of the solution vector.

util/microphysics_sort.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bool compare(const T& a, const T& b, const bool ascending=true) {
1919

2020
template <typename T>
2121
AMREX_GPU_HOST_DEVICE AMREX_INLINE
22-
void swap(T& a, T& b) {
22+
void swap(T& a, T& b) noexcept {
2323
// Helper function for sorting functions
2424
// Swaps the position of the two input
2525

0 commit comments

Comments
 (0)