Skip to content

Commit

Permalink
add function ComputeEintFromPres
Browse files Browse the repository at this point in the history
  • Loading branch information
psharda committed Jul 27, 2023
1 parent 27ee213 commit a7648ca
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions src/EOS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ template <typename problem_t> class EOS
[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputeEintFromTgas(amrex::Real rho, amrex::Real Tgas, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;
[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputeEintFromPres(amrex::Real rho, amrex::Real Pressure, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;
[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputeEintTempDerivative(amrex::Real rho, amrex::Real Tgas, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {})
-> amrex::Real;
[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
Expand All @@ -64,7 +66,7 @@ AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE auto EOS<problem_t>::ComputeTgasFromEin
const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars)
-> amrex::Real
{
// return temperature for an ideal gas
// return temperature for an ideal gas given density and internal energy
amrex::Real Tgas = NAN;

#ifdef PRIMORDIAL_CHEM
Expand Down Expand Up @@ -104,7 +106,7 @@ AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE auto EOS<problem_t>::ComputeEintFromTga
const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars)
-> amrex::Real
{
// return internal energy density for a gamma-law ideal gas
// return internal energy density given density and temperature
amrex::Real Eint = NAN;

#ifdef PRIMORDIAL_CHEM
Expand Down Expand Up @@ -140,6 +142,47 @@ AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE auto EOS<problem_t>::ComputeEintFromTga
return Eint;
}


template <typename problem_t>
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE auto EOS<problem_t>::ComputeEintFromPres(amrex::Real rho, amrex::Real Pressure,
const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars)
-> amrex::Real
{
// return internal energy density given density and pressure
amrex::Real Eint = NAN;

#ifdef PRIMORDIAL_CHEM
eos_t chemstate;
chemstate.rho = rho;
chemstate.p = Pressure;
// initialize array of number densities
for (int ii = 0; ii < NumSpec; ++ii) {
chemstate.xn[ii] = -1.0;
}

if (massScalars) {
const auto &massArray = *massScalars;
for (int nn = 0; nn < nmscalars_; ++nn) {
chemstate.xn[nn] = massArray[nn] / spmasses[nn]; // massScalars are partial densities (massFractions * rho)
}
}

eos(eos_input_rp, chemstate);
Eint = chemstate.e * chemstate.rho;
#else
if constexpr (gamma_ != 1.0) {
chem_eos_t estate;
estate.rho = rho;
estate.p = Pressure;
estate.mu = mean_molecular_weight_ / C::m_u;
eos(eos_input_rp, estate);
Eint = estate.e * rho * boltzmann_constant_ / C::k_B;
}
#endif
return Eint;
}


template <typename problem_t>
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE auto
EOS<problem_t>::ComputeEintTempDerivative(const amrex::Real rho, const amrex::Real Tgas,
Expand Down

0 comments on commit a7648ca

Please sign in to comment.