Skip to content

Commit 57fff12

Browse files
authored
some cleaning of apply_electrons (#1903)
remove some data that was used for derivatives of degeneracy parameter also reuse some arrays (sit[]) by scoping where they are filled and used.
1 parent 037d833 commit 57fff12

File tree

1 file changed

+56
-61
lines changed

1 file changed

+56
-61
lines changed

EOS/helmholtz/actual_eos.H

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -45,65 +45,65 @@ constexpr std::string_view eos_name = "helmholtz";
4545
// quintic hermite polynomial functions
4646
// psi0 and its derivatives
4747
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
48-
amrex::Real psi0 (amrex::Real z)
48+
amrex::Real psi0 (amrex::Real z) noexcept
4949
{
5050
return z * z * z * (z * (-6.0e0_rt * z + 15.0e0_rt) -10.0e0_rt) + 1.0e0_rt;
5151
}
5252

5353
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
54-
amrex::Real dpsi0 (amrex::Real z)
54+
amrex::Real dpsi0 (amrex::Real z) noexcept
5555
{
5656
return z * z * (z * (-30.0e0_rt*z + 60.0e0_rt) - 30.0e0_rt);
5757
}
5858

5959
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
60-
amrex::Real ddpsi0 (amrex::Real z)
60+
amrex::Real ddpsi0 (amrex::Real z) noexcept
6161
{
6262
return z * (z * (-120.0e0_rt * z + 180.0e0_rt) - 60.0e0_rt);
6363
}
6464

6565
// psi1 and its derivatives
6666
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
67-
amrex::Real psi1 (amrex::Real z)
67+
amrex::Real psi1 (amrex::Real z) noexcept
6868
{
6969
return z * ( z * z * (z * (-3.0e0_rt * z + 8.0e0_rt) - 6.0e0_rt) + 1.0e0_rt);
7070
}
7171

7272
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
73-
amrex::Real dpsi1 (amrex::Real z)
73+
amrex::Real dpsi1 (amrex::Real z) noexcept
7474
{
7575
return z * z * ( z * (-15.0e0_rt * z + 32.0e0_rt) - 18.0e0_rt) + 1.0e0_rt;
7676
}
7777

7878
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
79-
amrex::Real ddpsi1 (amrex::Real z)
79+
amrex::Real ddpsi1 (amrex::Real z) noexcept
8080
{
8181
return z * (z * (-60.0e0_rt * z + 96.0e0_rt) - 36.0e0_rt);
8282
}
8383

8484
// psi2 and its derivatives
8585
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
86-
amrex::Real psi2 (amrex::Real z)
86+
amrex::Real psi2 (amrex::Real z) noexcept
8787
{
8888
return 0.5e0_rt * z * z * ( z * ( z * (-z + 3.0e0_rt) - 3.0e0_rt) + 1.0e0_rt);
8989
}
9090

9191
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
92-
amrex::Real dpsi2 (amrex::Real z)
92+
amrex::Real dpsi2 (amrex::Real z) noexcept
9393
{
9494
return 0.5e0_rt * z * (z * (z * (-5.0e0_rt * z + 12.0e0_rt) - 9.0e0_rt) + 2.0e0_rt);
9595
}
9696

9797
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
98-
amrex::Real ddpsi2 (amrex::Real z)
98+
amrex::Real ddpsi2 (amrex::Real z) noexcept
9999
{
100100
return 0.5e0_rt * (z * ( z * (-20.0e0_rt * z + 36.0e0_rt) - 18.0e0_rt) + 2.0e0_rt);
101101
}
102102

103103
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
104104
void fwt (const amrex::Real* AMREX_RESTRICT fi,
105105
const amrex::Real* AMREX_RESTRICT wt,
106-
amrex::Real* AMREX_RESTRICT fwtr)
106+
amrex::Real* AMREX_RESTRICT fwtr) noexcept
107107
{
108108

109109
fwtr[0] = fi[ 0]*wt[0] + fi[ 1]*wt[1] + fi[ 2]*wt[2] + fi[18]*wt[3] + fi[19]*wt[4] + fi[20]*wt[5];
@@ -117,26 +117,26 @@ void fwt (const amrex::Real* AMREX_RESTRICT fi,
117117
// cubic hermite polynomial functions
118118
// psi0 & derivatives
119119
AMREX_GPU_HOST_DEVICE AMREX_INLINE
120-
amrex::Real xpsi0(amrex::Real z)
120+
amrex::Real xpsi0(amrex::Real z) noexcept
121121
{
122122
return z * z * (2.0e0_rt * z - 3.0e0_rt) + 1.0_rt;
123123
}
124124

125125
AMREX_GPU_HOST_DEVICE AMREX_INLINE
126-
amrex::Real xdpsi0(amrex::Real z)
126+
amrex::Real xdpsi0(amrex::Real z) noexcept
127127
{
128128
return z * (6.0e0_rt * z - 6.0e0_rt);
129129
}
130130

131131
// psi1 & derivatives
132132
AMREX_GPU_HOST_DEVICE AMREX_INLINE
133-
amrex::Real xpsi1(amrex::Real z)
133+
amrex::Real xpsi1(amrex::Real z) noexcept
134134
{
135135
return z * (z * (z - 2.0e0_rt) + 1.0e0_rt);
136136
}
137137

138138
AMREX_GPU_HOST_DEVICE AMREX_INLINE
139-
amrex::Real xdpsi1(amrex::Real z)
139+
amrex::Real xdpsi1(amrex::Real z) noexcept
140140
{
141141
return z * (3.0e0_rt * z - 4.0e0_rt) + 1.0e0_rt;
142142
}
@@ -180,17 +180,7 @@ void apply_electrons (T& state)
180180
amrex::Real mxt = 1.0e0_rt - xt;
181181
amrex::Real mxd = 1.0e0_rt - xd;
182182

183-
// the six density and six temperature basis functions
184-
amrex::Real sit[6];
185-
186-
sit[0] = psi0(xt);
187-
sit[1] = psi1(xt) * dt_sav[jat];
188-
sit[2] = psi2(xt) * dt2_sav[jat];
189-
190-
sit[3] = psi0(mxt);
191-
sit[4] = -psi1(mxt) * dt_sav[jat];
192-
sit[5] = psi2(mxt) * dt2_sav[jat];
193-
183+
// the six density basis functions
194184
amrex::Real sid[6];
195185

196186
sid[0] = psi0(xd);
@@ -202,16 +192,6 @@ void apply_electrons (T& state)
202192
sid[5] = psi2(mxd) * dd2_sav[iat];
203193

204194
// derivatives of the weight functions
205-
amrex::Real dsit[6];
206-
207-
dsit[0] = dpsi0(xt) * dti_sav[jat];
208-
dsit[1] = dpsi1(xt);
209-
dsit[2] = dpsi2(xt) * dt_sav[jat];
210-
211-
dsit[3] = -dpsi0(mxt) * dti_sav[jat];
212-
dsit[4] = dpsi1(mxt);
213-
dsit[5] = -dpsi2(mxt) * dt_sav[jat];
214-
215195
amrex::Real dsid[6];
216196

217197
dsid[0] = dpsi0(xd) * ddi_sav[iat];
@@ -222,26 +202,28 @@ void apply_electrons (T& state)
222202
dsid[4] = dpsi1(mxd);
223203
dsid[5] = -dpsi2(mxd) * dd_sav[iat];
224204

225-
// second derivatives of the weight functions
226-
amrex::Real ddsit[6];
227-
228-
ddsit[0] = ddpsi0(xt) * dt2i_sav[jat];
229-
ddsit[1] = ddpsi1(xt) * dti_sav[jat];
230-
ddsit[2] = ddpsi2(xt);
231-
232-
ddsit[3] = ddpsi0(mxt) * dt2i_sav[jat];
233-
ddsit[4] = -ddpsi1(mxt) * dti_sav[jat];
234-
ddsit[5] = ddpsi2(mxt);
235-
236205
// This array saves some subexpressions that go into
237206
// computing the biquintic polynomial. Instead of explicitly
238207
// constructing it in full, we'll use these subexpressions
239208
// and then compute the result as
240209
// (table data * temperature terms) * density terms.
241210

242211
amrex::Real fwtr[6];
212+
amrex::Real sit[6];
213+
214+
{
215+
// temperature basis functions
216+
217+
sit[0] = psi0(xt);
218+
sit[1] = psi1(xt) * dt_sav[jat];
219+
sit[2] = psi2(xt) * dt2_sav[jat];
243220

244-
fwt(fi, sit, fwtr);
221+
sit[3] = psi0(mxt);
222+
sit[4] = -psi1(mxt) * dt_sav[jat];
223+
sit[5] = psi2(mxt) * dt2_sav[jat];
224+
225+
fwt(fi, sit, fwtr);
226+
}
245227

246228
amrex::Real free = 0.e0_rt;
247229
amrex::Real df_d = 0.e0_rt;
@@ -254,7 +236,19 @@ void apply_electrons (T& state)
254236
df_d = df_d + fwtr[i] * dsid[i];
255237
}
256238

257-
fwt(fi, dsit, fwtr);
239+
{
240+
// temperature derivative of weight functions
241+
// this was originally called dsit
242+
sit[0] = dpsi0(xt) * dti_sav[jat];
243+
sit[1] = dpsi1(xt);
244+
sit[2] = dpsi2(xt) * dt_sav[jat];
245+
246+
sit[3] = -dpsi0(mxt) * dti_sav[jat];
247+
sit[4] = dpsi1(mxt);
248+
sit[5] = -dpsi2(mxt) * dt_sav[jat];
249+
250+
fwt(fi, sit, fwtr);
251+
}
258252

259253
amrex::Real df_t = 0.e0_rt;
260254
amrex::Real df_dt = 0.e0_rt;
@@ -267,7 +261,20 @@ void apply_electrons (T& state)
267261
df_dt += fwtr[i] * dsid[i];
268262
}
269263

270-
fwt(fi, ddsit, fwtr);
264+
{
265+
// second derivatives of the weight functions
266+
// this was originally called ddsit
267+
268+
sit[0] = ddpsi0(xt) * dt2i_sav[jat];
269+
sit[1] = ddpsi1(xt) * dti_sav[jat];
270+
sit[2] = ddpsi2(xt);
271+
272+
sit[3] = ddpsi0(mxt) * dt2i_sav[jat];
273+
sit[4] = -ddpsi1(mxt) * dti_sav[jat];
274+
sit[5] = ddpsi2(mxt);
275+
276+
fwt(fi, sit, fwtr);
277+
}
271278

272279
amrex::Real df_tt = 0.e0_rt;
273280
for (int i = 0; i <= 5; ++i) {
@@ -290,18 +297,6 @@ void apply_electrons (T& state)
290297
sid[2] = xpsi0(mxd);
291298
sid[3] = -xpsi1(mxd) * dd_sav[iat];
292299

293-
// derivatives of weight functions
294-
dsit[0] = xdpsi0(xt) * dti_sav[jat];
295-
dsit[1] = xdpsi1(xt);
296-
297-
dsit[2] = -xdpsi0(mxt) * dti_sav[jat];
298-
dsit[3] = xdpsi1(mxt);
299-
300-
dsid[0] = xdpsi0(xd) * ddi_sav[iat];
301-
dsid[1] = xdpsi1(xd);
302-
303-
dsid[2] = -xdpsi0(mxd) * ddi_sav[iat];
304-
dsid[3] = xdpsi1(mxd);
305300

306301
// Reuse subexpressions that would go into computing the
307302
// cubic interpolation.

0 commit comments

Comments
 (0)