Skip to content

Commit 3ab4acc

Browse files
authored
some more templating of apply_electrons (#1910)
don't compute the electron number density or degeneracy parameter unless needed. Also block off composition derivatives.
1 parent 935d36b commit 3ab4acc

File tree

1 file changed

+43
-28
lines changed

1 file changed

+43
-28
lines changed

EOS/helmholtz/actual_eos.H

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -348,23 +348,26 @@ void apply_electrons (T& state)
348348

349349

350350
// electron chemical potential etaele
351-
amrex::Real etaele = 0.0e0_rt;
352-
amrex::constexpr_for<0, 16>([&] (auto K) {
353-
constexpr int k = K;
354-
constexpr auto m = electron_table_indexing::map[k];
355-
356-
etaele += ef[jat+m.dj][iat+m.di][m.n] * wdt[k];
357-
});
351+
[[maybe_unused]] amrex::Real etaele{};
352+
if constexpr (has_eta<T>::value) {
353+
amrex::constexpr_for<0, 16>([&] (auto K) {
354+
constexpr int k = K;
355+
constexpr auto m = electron_table_indexing::map[k];
358356

357+
etaele += ef[jat+m.dj][iat+m.di][m.n] * wdt[k];
358+
});
359+
}
359360

360361
// electron + positron number densities
361-
amrex::Real xnefer = 0.0e0_rt;
362-
amrex::constexpr_for<0, 16>([&] (auto K) {
363-
constexpr int k = K;
364-
constexpr auto m = electron_table_indexing::map[k];
362+
[[maybe_unused]] amrex::Real xnefer{};
363+
if constexpr (has_xne_xnp<T>::value) {
364+
amrex::constexpr_for<0, 16>([&] (auto K) {
365+
constexpr int k = K;
366+
constexpr auto m = electron_table_indexing::map[k];
365367

366-
xnefer += xf[jat+m.dj][iat+m.di][m.n] * wdt[k];
367-
});
368+
xnefer += xf[jat+m.dj][iat+m.di][m.n] * wdt[k];
369+
});
370+
}
368371

369372
// the desired electron-positron thermodynamic quantities
370373

@@ -375,22 +378,38 @@ void apply_electrons (T& state)
375378
amrex::Real x = din * din;
376379
amrex::Real pele = x * df_d;
377380
amrex::Real dpepdt = x * df_dt;
378-
[[maybe_unused]] amrex::Real s = dpepdd/state.y_e - 2.0e0_rt * din * df_d;
379-
[[maybe_unused]] amrex::Real dpepda = -ytot1 * (2.0e0_rt * pele + s * din);
380-
[[maybe_unused]] amrex::Real dpepdz = state.rho*ytot1*(2.0e0_rt * din * df_d + s);
381+
[[maybe_unused]] amrex::Real dpepda{};
382+
[[maybe_unused]] amrex::Real dpepdz{};
383+
if constexpr (has_dpdA<T>::value || has_dpdZ<T>::value) {
384+
amrex::Real s = dpepdd/state.y_e - 2.0e0_rt * din * df_d;
385+
if constexpr (has_dpdA<T>::value) {
386+
dpepda = -ytot1 * (2.0e0_rt * pele + s * din);
387+
}
388+
if constexpr (has_dpdZ<T>::value) {
389+
dpepdz = state.rho*ytot1*(2.0e0_rt * din * df_d + s);
390+
}
391+
}
381392

382393
x = state.y_e * state.y_e;
383394
amrex::Real sele = -df_t * state.y_e;
384395
amrex::Real dsepdt = -df_tt * state.y_e;
385396
amrex::Real dsepdd = -df_dt * x;
386-
[[maybe_unused]] amrex::Real dsepda = ytot1 * (state.y_e * df_dt * din - sele);
387-
[[maybe_unused]] amrex::Real dsepdz = -ytot1 * (state.y_e * df_dt * state.rho + df_t);
388397

389398
amrex::Real eele = state.y_e*free + state.T * sele;
390399
amrex::Real deepdt = state.T * dsepdt;
391400
amrex::Real deepdd = x * df_d + state.T * dsepdd;
392-
[[maybe_unused]] amrex::Real deepda = -state.y_e * ytot1 * (free + df_d * din) + state.T * dsepda;
393-
[[maybe_unused]] amrex::Real deepdz = ytot1* (free + state.y_e * df_d * state.rho) + state.T * dsepdz;
401+
402+
[[maybe_unused]] amrex::Real deepda{};
403+
if constexpr (has_dedA<T>::value) {
404+
amrex::Real dsepda = ytot1 * (state.y_e * df_dt * din - sele);
405+
deepda = -state.y_e * ytot1 * (free + df_d * din) + state.T * dsepda;
406+
}
407+
408+
[[maybe_unused]] amrex::Real deepdz{};
409+
if constexpr (has_dedZ<T>::value) {
410+
amrex::Real dsepdz = -ytot1 * (state.y_e * df_dt * state.rho + df_t);
411+
deepdz = ytot1* (free + state.y_e * df_d * state.rho) + state.T * dsepdz;
412+
}
394413

395414
if constexpr (has_pressure<T>::value) {
396415
state.p = state.p + pele;
@@ -549,14 +568,10 @@ void apply_radiation (T& state)
549568

550569
amrex::Real dpraddd = 0.0e0_rt;
551570
amrex::Real dpraddt = 4.0e0_rt * prad * tempi;
552-
[[maybe_unused]] amrex::Real dpradda = 0.0e0_rt;
553-
[[maybe_unused]] amrex::Real dpraddz = 0.0e0_rt;
554571

555572
amrex::Real erad = 3.0e0_rt * prad*deni;
556573
amrex::Real deraddd = -erad * deni;
557574
amrex::Real deraddt = 3.0e0_rt * dpraddt * deni;
558-
[[maybe_unused]] amrex::Real deradda = 0.0e0_rt;
559-
[[maybe_unused]] amrex::Real deraddz = 0.0e0_rt;
560575

561576
amrex::Real srad = (prad * deni + erad) * tempi;
562577
amrex::Real dsraddd = (dpraddd * deni - prad * deni * deni + deraddd) * tempi;
@@ -571,10 +586,10 @@ void apply_radiation (T& state)
571586
state.dpdr = dpraddd;
572587
state.dpdT = dpraddt;
573588
if constexpr (has_dpdA<T>::value) {
574-
state.dpdA = dpradda;
589+
state.dpdA = 0.0_rt;
575590
}
576591
if constexpr (has_dpdZ<T>::value) {
577-
state.dpdZ = dpraddz;
592+
state.dpdZ = 0.0_rt;
578593
}
579594
}
580595

@@ -583,10 +598,10 @@ void apply_radiation (T& state)
583598
state.dedr = deraddd;
584599
state.dedT = deraddt;
585600
if constexpr (has_dedA<T>::value) {
586-
state.dedA = deradda;
601+
state.dedA = 0.0_rt;
587602
}
588603
if constexpr (has_dedZ<T>::value) {
589-
state.dedZ = deraddz;
604+
state.dedZ = 0.0_rt;
590605
}
591606
}
592607

0 commit comments

Comments
 (0)