Skip to content

Commit

Permalink
use a helper function to get the index into the NSE tables (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale authored Mar 12, 2024
1 parent 95cb860 commit 124b71b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions nse_tabular/nse_table.H
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
using namespace amrex::literals;
using namespace network_rp;

///
/// given a rho, T, and Ye index, return the 1-d index into the NSE table arrays
///
AMREX_GPU_HOST_DEVICE AMREX_INLINE
int nse_idx(const int ir, const int it, const int ic) {
// this uses a 1-based indexing
return (ir-1) * nse_table_size::ntemp * nse_table_size::nye + (it-1) * nse_table_size::nye + ic;
}

AMREX_INLINE
void init_nse() {

Expand Down Expand Up @@ -46,8 +55,7 @@ void init_nse() {
for (int irho = 1; irho <= nse_table_size::nden; irho++) {
for (int it = 1; it <= nse_table_size::ntemp; it++) {
for (int iye = 1; iye <= nse_table_size::nye; iye++) {
int j = (irho-1) * nse_table_size::ntemp * nse_table_size::nye +
(it-1) * nse_table_size::nye + iye;
const int j = nse_idx(irho, it, iye);

std::getline(nse_table_file, line);
if (line.empty()) {
Expand All @@ -70,12 +78,6 @@ void init_nse() {

}

AMREX_GPU_HOST_DEVICE AMREX_INLINE
int nse_idx(const int ir, const int it, const int ic) {
// this uses a 1-based indexing
return (ir-1) * nse_table_size::ntemp * nse_table_size::nye + (it-1) * nse_table_size::nye + ic;
}

AMREX_GPU_HOST_DEVICE AMREX_INLINE
amrex::Real nse_table_logT(const int it) {
return nse_table_size::logT_min + static_cast<amrex::Real>(it-1) * nse_table_size::dlogT;
Expand Down

0 comments on commit 124b71b

Please sign in to comment.