Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute pressure from microphysics eos #335

Merged
merged 57 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f8094cb
compute pressure from microphysics eos
psharda Jul 26, 2023
289e160
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2023
8e50b6d
Merge branch 'quokka-astro:development' into eos-pressure
psharda Jul 26, 2023
343429c
call EOS to compute pressure
psharda Jul 26, 2023
642b3af
add function to compute pressure
psharda Jul 26, 2023
3db466e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2023
aa5a3f6
return pressure times density
psharda Jul 26, 2023
9e28e43
updated microp
psharda Jul 26, 2023
75baed9
change mean mol weight from NAN to arbitrary +ve value to get finite …
psharda Jul 26, 2023
580f3e5
use gamma_law to compute pressure
psharda Jul 26, 2023
c4a36f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2023
380fec7
define a finite mean molecular weight
psharda Jul 26, 2023
fb67ff5
more EOS calls
psharda Jul 26, 2023
e94edec
dont need microp headers
psharda Jul 26, 2023
a70fe90
removed unused var
psharda Jul 26, 2023
6cea067
remove unused vars
psharda Jul 26, 2023
c9ffd1c
remove unused var; assert P
psharda Jul 26, 2023
95db069
fixed warnings
psharda Jul 27, 2023
dac7af8
use EOS compute pressure directly
psharda Jul 27, 2023
483d3b7
updated microp
psharda Jul 27, 2023
7db199b
updated microp
psharda Jul 27, 2023
906b4d9
added ComputeSoundSpeed
psharda Jul 27, 2023
235c18d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2023
abf95f9
updated microp
psharda Jul 27, 2023
1112f9f
spell check
psharda Jul 27, 2023
ebbfe81
pass quokka gamma to microphysics eos
psharda Jul 27, 2023
27ee213
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2023
a7648ca
add function ComputeEintFromPres
psharda Jul 27, 2023
e62a6ed
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2023
1c64f8e
use EOS to find pres and cs
psharda Jul 27, 2023
6d31572
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2023
cdd18da
replace K_S with sound spped calc
psharda Jul 27, 2023
54723a3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2023
c7ca8a0
avoid re-declaaration
psharda Jul 27, 2023
8c56cfc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2023
6ec3096
fix warning
psharda Jul 27, 2023
a5d2714
use microp EOS
psharda Jul 27, 2023
8146b4e
remove ASSERT
psharda Jul 27, 2023
1fcab92
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2023
9dfb12c
remove unused var
psharda Jul 27, 2023
49c46c4
fix bug in EintFromPres
psharda Jul 28, 2023
f3b6ea0
declaring P_L as const double
psharda Jul 28, 2023
0bfb82e
remove unused var
psharda Jul 28, 2023
a50ea5a
remove declaration of P_L
psharda Jul 28, 2023
13c623e
updated microp: ensure exact cancellation
psharda Jul 28, 2023
e07c5e4
remove unused var
psharda Jul 28, 2023
dc4cb27
use finite mean_molecular_weight
psharda Jul 28, 2023
7356796
use finite mol wt and use microphysics for EOS
psharda Jul 28, 2023
04c26d7
use finite mean mol wt
psharda Jul 28, 2023
9dcf491
use microphysics eos
psharda Jul 28, 2023
bed26e3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 28, 2023
16f441a
remove unused var
psharda Jul 28, 2023
b7c3da0
if rho = 0, pres is 0
psharda Jul 29, 2023
6dd9326
return finite pressure for isothermal gamma
psharda Jul 29, 2023
50631c5
@psharda
psharda Jul 29, 2023
deac5f3
use finite mol wt
psharda Jul 30, 2023
77c35b1
minor style changes
psharda Jul 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
[submodule "extern/Microphysics"]
path = extern/Microphysics
url = https://github.com/psharda/Microphysics
branch = development
branch = compute-pressure
40 changes: 40 additions & 0 deletions src/EOS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ template <typename problem_t> class EOS
[[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
ComputePressure(amrex::Real rho, amrex::Real Eint, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;

private:
static constexpr amrex::Real gamma_ = EOS_Traits<problem_t>::gamma;
Expand Down Expand Up @@ -176,6 +178,44 @@ EOS<problem_t>::ComputeEintTempDerivative(const amrex::Real rho, const amrex::Re
return dEint_dT;
}

template <typename problem_t>
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE auto EOS<problem_t>::ComputePressure(amrex::Real rho, amrex::Real Eint,
const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars)
-> amrex::Real
{
// return pressure for an ideal gas
amrex::Real P = NAN;
#ifdef PRIMORDIAL_CHEM
eos_t chemstate; // cannot use burn_t because it does not have pressure
chemstate.rho = rho;
chemstate.e = Eint / rho;
// 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_re, chemstate);
P = chemstate.p * rho;
#else
if constexpr (gamma_ != 1.0) {
chem_eos_t estate;
estate.rho = rho;
estate.e = Eint / rho;
estate.mu = mean_molecular_weight_ / C::m_u;
eos(eos_input_re, estate);
P = estate.p * rho;
}
#endif
return P;
}

} // namespace quokka

#endif // EOS_HPP_
2 changes: 1 addition & 1 deletion src/HydroHighMach/test_hydro_highmach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct HighMachProblem {

template <> struct quokka::EOS_Traits<HighMachProblem> {
static constexpr double gamma = 5. / 3.;
static constexpr double mean_molecular_weight = NAN;
static constexpr double mean_molecular_weight = 1.0;
static constexpr double boltzmann_constant = C::k_B;
};

Expand Down
2 changes: 1 addition & 1 deletion src/HydroShocktube/test_hydro_shocktube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ShocktubeProblem {

template <> struct quokka::EOS_Traits<ShocktubeProblem> {
static constexpr double gamma = 1.4;
static constexpr double mean_molecular_weight = NAN;
static constexpr double mean_molecular_weight = 1.0;
static constexpr double boltzmann_constant = C::k_B;
};

Expand Down
2 changes: 1 addition & 1 deletion src/HydroShocktubeCMA/test_hydro_shocktube_cma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template <> struct SimulationData<ShocktubeProblem> {

template <> struct quokka::EOS_Traits<ShocktubeProblem> {
static constexpr double gamma = 1.4;
static constexpr double mean_molecular_weight = NAN;
static constexpr double mean_molecular_weight = 1.0;
static constexpr double boltzmann_constant = C::k_B;
};

Expand Down
2 changes: 1 addition & 1 deletion src/HydroVacuum/test_hydro_vacuum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ShocktubeProblem {

template <> struct quokka::EOS_Traits<ShocktubeProblem> {
static constexpr double gamma = 1.4;
static constexpr double mean_molecular_weight = NAN;
static constexpr double mean_molecular_weight = 1.0;
static constexpr double boltzmann_constant = C::k_B;
};

Expand Down
20 changes: 9 additions & 11 deletions src/hydro_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ template <typename problem_t> void HydroSystem<problem_t>::ConservedToPrimitive(
const auto kinetic_energy = 0.5 * rho * (vx * vx + vy * vy + vz * vz);
const auto Eint_cons = E - kinetic_energy;

const amrex::Real Pgas = Eint_cons * (HydroSystem<problem_t>::gamma_ - 1.0);
const amrex::Real Pgas = ComputePressure(cons[bx], i, j, k);
const amrex::Real eint_cons = Eint_cons / rho;
const amrex::Real eint_aux = Eint_aux / rho;

Expand Down Expand Up @@ -202,9 +202,7 @@ template <typename problem_t> auto HydroSystem<problem_t>::maxSignalSpeedLocal(a
if constexpr (is_eos_isothermal()) {
cs = cs_iso_;
} else {
const auto Etot = cons[bx](i, j, k, HydroSystem<problem_t>::energy_index);
const auto Eint = Etot - kinetic_energy;
const auto P = Eint * (HydroSystem<problem_t>::gamma_ - 1.0);
const auto P = ComputePressure(cons[bx], i, j, k);
cs = std::sqrt(HydroSystem<problem_t>::gamma_ * P / rho);
}
return {cs + abs_vel};
Expand Down Expand Up @@ -233,11 +231,8 @@ void HydroSystem<problem_t>::ComputeMaxSignalSpeed(amrex::Array4<const amrex::Re
if constexpr (is_eos_isothermal()) {
cs = cs_iso_;
} else {
const auto E = cons(i, j, k, energy_index); // *total* gas energy per unit volume
AMREX_ASSERT(!std::isnan(E));
const auto kinetic_energy = 0.5 * rho * (vx * vx + vy * vy + vz * vz);
const auto thermal_energy = E - kinetic_energy;
const auto P = thermal_energy * (HydroSystem<problem_t>::gamma_ - 1.0);
const auto P = ComputePressure(cons, i, j, k);
AMREX_ASSERT(!std::isnan(P));
cs = std::sqrt(HydroSystem<problem_t>::gamma_ * P / rho);
psharda marked this conversation as resolved.
Show resolved Hide resolved
}
AMREX_ASSERT(cs > 0.);
Expand Down Expand Up @@ -265,7 +260,7 @@ template <typename problem_t> auto HydroSystem<problem_t>::CheckStatesValid(amre
const auto vz = pz / rho;
const auto kinetic_energy = 0.5 * rho * (vx * vx + vy * vy + vz * vz);
const auto thermal_energy = E - kinetic_energy;
const auto P = thermal_energy * (HydroSystem<problem_t>::gamma_ - 1.0);
const auto P = ComputePressure(cons[bx], i, j, k);

bool negativeDensity = (rho <= 0.);
bool negativePressure = (P <= 0.);
Expand Down Expand Up @@ -300,7 +295,10 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE auto HydroSystem<problem_t>::ComputePressure
const auto vz = pz / rho;
const auto kinetic_energy = 0.5 * rho * (vx * vx + vy * vy + vz * vz);
const auto thermal_energy = E - kinetic_energy;
const auto P = thermal_energy * (HydroSystem<problem_t>::gamma_ - 1.0);

amrex::GpuArray<Real, nmscalars_> massScalars = RadSystem<problem_t>::ComputeMassScalars(cons, i, j, k);
amrex::Real P = quokka::EOS<problem_t>::ComputePressure(rho, thermal_energy, massScalars);

return P;
}

Expand Down