Skip to content

Commit

Permalink
more eosparm: now everywhere except Efield & BCs
Browse files Browse the repository at this point in the history
  • Loading branch information
baperry2 committed Sep 16, 2024
1 parent d090043 commit 0b22bbf
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 38 deletions.
3 changes: 2 additions & 1 deletion Source/PeleLMeX_DeriveFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,15 @@ pelelmex_dermolefrac(
AMREX_ASSERT(!a_pelelm->m_incompressible);
auto const in_dat = statefab.array();
auto der = derfab.array(dcomp);
auto const* leosparm = a_pelelm->eos_parms.device_parm();
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
amrex::Real Yt[NUM_SPECIES] = {0.0};
amrex::Real Xt[NUM_SPECIES] = {0.0};
amrex::Real rhoinv = 1.0 / in_dat(i, j, k, DENSITY);
for (int n = 0; n < NUM_SPECIES; n++) {
Yt[n] = in_dat(i, j, k, FIRSTSPEC + n) * rhoinv;
}
auto eos = pele::physics::PhysicsType::eos();
auto eos = pele::physics::PhysicsType::eos(leosparm);
eos.Y2X(Yt, Xt);
for (int n = 0; n < NUM_SPECIES; n++) {
der(i, j, k, n) = Xt[n];
Expand Down
9 changes: 5 additions & 4 deletions Source/PeleLMeX_Diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,11 @@ PeleLM::addWbarTerm(
// Wbar flux is : - \rho Y_m / \overline{W} * D_m * \nabla
// \overline{W} with beta_m = \rho * D_m below
amrex::ParallelFor(
ebx,
[need_wbar_fluxes, gradWbar_ar, beta_ar, rhoY, spFlux_ar,
spwbarFlux_ar] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
auto eos = pele::physics::PhysicsType::eos();
ebx, [need_wbar_fluxes, gradWbar_ar, beta_ar, rhoY, spFlux_ar,
spwbarFlux_ar,
eosparm =
leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
auto eos = pele::physics::PhysicsType::eos(eosparm);
// Get Wbar from rhoYs
amrex::Real rho = 0.0;
for (int n = 0; n < NUM_SPECIES; n++) {
Expand Down
4 changes: 3 additions & 1 deletion Source/PeleLMeX_Forces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,17 @@ PeleLM::addSpark(const TimeStamp& a_timestamp)
Print() << m_spark[n] << " active" << std::endl;
}

auto eos = pele::physics::PhysicsType::eos();
auto statema = getLevelDataPtr(lev, a_timestamp)->state.const_arrays();
auto extma = m_extSource[lev]->arrays();
auto const* leosparm = eos_parms.device_parm();

amrex::ParallelFor(
*m_extSource[lev],
[=, spark_duration = m_spark_duration[n], spark_temp = m_spark_temp[n],
eosparm = leosparm,
spark_radius = m_spark_radius
[n]] AMREX_GPU_DEVICE(int box_no, int i, int j, int k) noexcept {
auto eos = pele::physics::PhysicsType::eos(eosparm);
Real dist_to_center = std::sqrt(AMREX_D_TERM(
(i - spark_idx[0]) * (i - spark_idx[0]) * dx[0] * dx[0],
+(j - spark_idx[1]) * (j - spark_idx[1]) * dx[1] * dx[1],
Expand Down
53 changes: 28 additions & 25 deletions Source/PeleLMeX_Plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile)
ldata_p->gp.setVal(0.0);

ProbParm const* lprobparm = prob_parm_d;
auto const* leosparm = eos_parms.device_parm();

// If m_do_patch_flow_variables is set as true, call user-defined function to
// patch flow variables
Expand All @@ -994,38 +995,40 @@ PeleLM::initLevelDataFromPlt(int a_lev, const std::string& a_dataPltFile)
auto const& rhoY_arr = ldata_p->state.array(mfi, FIRSTSPEC);
auto const& rhoH_arr = ldata_p->state.array(mfi, RHOH);
auto const& temp_arr = ldata_p->state.array(mfi, TEMP);
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
auto eos = pele::physics::PhysicsType::eos();
Real massfrac[NUM_SPECIES] = {0.0};
Real sumYs = 0.0;
for (int n = 0; n < NUM_SPECIES; n++) {
massfrac[n] = rhoY_arr(i, j, k, n);
amrex::ParallelFor(
bx,
[=, eosparm = leosparm] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
auto eos = pele::physics::PhysicsType::eos(eosparm);
Real massfrac[NUM_SPECIES] = {0.0};
Real sumYs = 0.0;
for (int n = 0; n < NUM_SPECIES; n++) {
massfrac[n] = rhoY_arr(i, j, k, n);
#ifdef N2_ID
if (n != N2_ID) {
sumYs += massfrac[n];
}
if (n != N2_ID) {
sumYs += massfrac[n];
}
#endif
}
}
#ifdef N2_ID
massfrac[N2_ID] = 1.0 - sumYs;
massfrac[N2_ID] = 1.0 - sumYs;
#endif

// Get density
Real P_cgs = lprobparm->P_mean * 10.0;
Real rho_cgs = 0.0;
eos.PYT2R(P_cgs, massfrac, temp_arr(i, j, k), rho_cgs);
rho_arr(i, j, k) = rho_cgs * 1.0e3;
// Get density
Real P_cgs = lprobparm->P_mean * 10.0;
Real rho_cgs = 0.0;
eos.PYT2R(P_cgs, massfrac, temp_arr(i, j, k), rho_cgs);
rho_arr(i, j, k) = rho_cgs * 1.0e3;

// Get enthalpy
Real h_cgs = 0.0;
eos.TY2H(temp_arr(i, j, k), massfrac, h_cgs);
rhoH_arr(i, j, k) = h_cgs * 1.0e-4 * rho_arr(i, j, k);
// Get enthalpy
Real h_cgs = 0.0;
eos.TY2H(temp_arr(i, j, k), massfrac, h_cgs);
rhoH_arr(i, j, k) = h_cgs * 1.0e-4 * rho_arr(i, j, k);

// Fill rhoYs
for (int n = 0; n < NUM_SPECIES; n++) {
rhoY_arr(i, j, k, n) = massfrac[n] * rho_arr(i, j, k);
}
});
// Fill rhoYs
for (int n = 0; n < NUM_SPECIES; n++) {
rhoY_arr(i, j, k, n) = massfrac[n] * rho_arr(i, j, k);
}
});
}

// Initialize thermodynamic pressure
Expand Down
4 changes: 2 additions & 2 deletions Source/PeleLMeX_Reactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ PeleLM::advanceChemistry(int lev, const Real& a_dt, MultiFab& a_extForcing)
auto const& FnE = a_extForcing.array(mfi, NUM_SPECIES + 1);
auto const& rhoYe_n = ldataNew_p->state.array(mfi, FIRSTSPEC + E_ID);
auto const& FrhoYe = a_extForcing.array(mfi, E_ID);
auto eos = pele::physics::PhysicsType::eos();
auto eos = pele::physics::PhysicsType::eos(&eos_parms.host_parm());
Real mwt[NUM_SPECIES] = {0.0};
eos.molecular_weight(mwt);
ParallelFor(
Expand Down Expand Up @@ -245,7 +245,7 @@ PeleLM::advanceChemistryBAChem(
auto const& FnE = chemForcing.array(mfi, NUM_SPECIES + 1);
auto const& rhoYe_o = chemState.array(mfi, E_ID);
auto const& FrhoYe = chemForcing.array(mfi, E_ID);
auto eos = pele::physics::PhysicsType::eos();
auto eos = pele::physics::PhysicsType::eos(&eos_parms.host_parm());
Real mwt[NUM_SPECIES] = {0.0};
eos.molecular_weight(mwt);
ParallelFor(
Expand Down
2 changes: 1 addition & 1 deletion Source/PeleLMeX_TransportProp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ PeleLM::calcDiffusivity(const TimeStamp& a_time)
auto const& kma = ldata_p->mob_cc.arrays();
GpuArray<Real, NUM_SPECIES> mwt{0.0};
{
auto eos = pele::physics::PhysicsType::eos();
auto eos = pele::physics::PhysicsType::eos(leosparm);
eos.molecular_weight(mwt.arr);
}
#endif
Expand Down
12 changes: 8 additions & 4 deletions Source/PeleLMeX_Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ PeleLM::floorSpecies(const TimeStamp& a_time)

auto* ldata_p = getLevelDataPtr(lev, a_time);
auto const& sma = ldata_p->state.arrays();
auto const* leosparm = eos_parms.device_parm();

amrex::ParallelFor(
ldata_p->state,
Expand All @@ -676,7 +677,7 @@ PeleLM::floorSpecies(const TimeStamp& a_time)
}

// ... as well as rhoh
auto eos = pele::physics::PhysicsType::eos();
auto eos = pele::physics::PhysicsType::eos(leosparm);
Real massfrac[NUM_SPECIES] = {0.0};
Real rhoinv = Real(1.0) / sma[box_no](i, j, k, DENSITY);
for (int n = 0; n < NUM_SPECIES; n++) {
Expand Down Expand Up @@ -1447,7 +1448,8 @@ PeleLM::updateTypicalValuesChem()
}
typical_values_chem[NUM_SPECIES] = typical_values[TEMP];
#ifdef PELE_USE_EFIELD
auto eos = pele::physics::PhysicsType::eos();
auto const* leosparm = &eos_parms.host_parm();
auto eos = pele::physics::PhysicsType::eos(leosparm);
Real mwt[NUM_SPECIES] = {0.0};
eos.molecular_weight(mwt);
typical_values_chem[E_ID] =
Expand Down Expand Up @@ -1727,7 +1729,8 @@ PeleLM::initMixtureFraction()
}
}

auto eos = pele::physics::PhysicsType::eos();
auto const* leosparm = &eos_parms.host_parm();
auto eos = pele::physics::PhysicsType::eos(leosparm);
// Overwrite with user-defined value if provided in input file
ParmParse pp("peleLM");
std::string MFformat;
Expand Down Expand Up @@ -1881,7 +1884,8 @@ PeleLM::parseComposition(
massFrac[i] = compoIn[i];
}
} else if (compositionType == "mole") { // mole
auto eos = pele::physics::PhysicsType::eos();
auto const* leosparm = &eos_parms.host_parm();
auto eos = pele::physics::PhysicsType::eos(leosparm);
eos.X2Y(compoIn, massFrac);
} else {
Abort("Unknown mixtureFraction.type ! Should be 'mass' or 'mole'");
Expand Down

0 comments on commit 0b22bbf

Please sign in to comment.