1 #ifndef SRC_SNAP_THERMODYNAMICS_THERMODYNAMICS_HPP_
2 #define SRC_SNAP_THERMODYNAMICS_THERMODYNAMICS_HPP_
15 #include <yaml-cpp/yaml.h>
18 #include <athena/athena.hpp>
19 #include <athena/hydro/hydro.hpp>
20 #include <athena/mesh/mesh.hpp>
24 #include <configure.hpp>
60 return p3 * exp((1. - 1. / t) * beta - delta * log(t));
85 enum {
Size = 1 + NVAPOR + NCLOUD };
189 Real cpd =
Rd_ * gammad / (gammad - 1.);
244 bool misty =
false)
const;
256 bool misty =
false)
const;
265 Real grav = 0., Real userp = 0.)
const;
285 auto &w = pmb->phydro->w;
287 pow(
p0 / w(IPR, k,
j, i),
GetChi(pmb, k,
j, i));
301 Real
GetTemp(MeshBlock
const *pmb,
int k,
int j,
int i)
const {
302 auto &w = pmb->phydro->w;
303 return w(IPR, k,
j, i) / (w(IDN, k,
j, i) *
Rd_ *
RovRd(pmb, k,
j, i));
310 Real
GetMu(MeshBlock
const *pmb,
int k,
int j,
int i)
const;
317 Real
RovRd(MeshBlock
const *pmb,
int k,
int j,
int i)
const {
319 auto &w = pmb->phydro->w;
320 #pragma omp simd reduction(+ : feps)
321 for (
int n = 1; n <= NVAPOR; ++n)
333 Real
GetCvMass(MeshBlock
const *pmb,
int k,
int j,
int i)
const;
342 Real
GetCpMass(MeshBlock
const *pmb,
int k,
int j,
int i)
const;
348 Real
GetChi(MeshBlock
const *pmb,
int k,
int j,
int i)
const;
354 Real
GetGamma(MeshBlock
const *pmb,
int k,
int j,
int i)
const;
358 Real
GetPres(MeshBlock
const *pmb,
int k,
int j,
int i)
const;
382 return qfrac.
w[n] / (qfrac.
w[n] + rates[0]);
402 Real adlnTdlnP)
const;
404 Real adlnTdlnP)
const;
423 std::array<Real, Size>
mu_;
466 std::array<Real, 1 + NVAPOR>
t3_;
469 std::array<Real, 1 + NVAPOR>
p3_;
std::vector< AirParcel > AirColumn
Real RovRd(MeshBlock const *pmb, int k, int j, int i) const
Inverse of the mean molecular weight (no cloud)
Real GetMuRatio(int n) const
Real GetInvMu(int n) const
std::array< Real, Size > cp_ratio_mass_
ratio of specific heat capacities [J/mol] at constant pressure
static constexpr Real RefPres
RealArrayX TryEquilibriumTP_VaporCloud(AirParcel const &qfrac, int ivapor, Real cv_hat=0., bool misty=false) const
Calculate the equilibrium mole transfer by cloud reaction vapor -> cloud.
Real GetCvRatioMass(int n) const
void SaturationAdjustment(AirColumn &ac) const
std::array< Real, Size > cp_ratio_mole_
ratio of specific heat capacities [J/mol] at constant pressure
std::array< Real, Size > cv_ratio_mass_
ratio of specific heat capacities [J/mol] at constant volume
std::array< Real, Size > inv_mu_ratio_
inverse ratio of mean molecular weights
Real GetLatentEnergyMass(int n, Real temp=0.) const
Temperature dependent specific latent energy [J/kg] of condensates at constant volume .
std::array< Real, Size > beta_
Dimensionless latent heat.
Real GetCvRatioMole(int n) const
Real getDensityMole(AirParcel const &qfrac) const
Real GetCpMassRef(int n) const
static constexpr Real RefTemp
void enrollVaporFunctions()
custom functions for vapor (to be overridden by user mods)
Real PotentialTemp(MeshBlock *pmb, Real p0, int k, int j, int i) const
Calculate potential temperature from primitive variable.
Real gammad_ref_
reference polytropic index of dry air
Real MoistStaticEnergy(MeshBlock const *pmb, Real gz, int k, int j, int i) const
Moist static energy.
Real calDlnTDlnP(AirParcel const &qfrac, Real latent[]) const
Calculate moist adiabatic temperature gradient.
std::array< Real, Size > latent_energy_mass_
latent energy at constant volume [J/kg]
std::map< IndexPair, ReactionInfo > cloud_reaction_map_
reaction information map
static Thermodynamics const * GetInstance()
Return a pointer to the one and only instance of Thermodynamics.
int sa_max_iter_
maximum saturation adjustment iterations
Real GetCvMass(AirParcel const &qfrac, int n) const
int GetCloudIndex(int i, int j) const
std::vector< IndexSet > cloud_index_set_
cloud index set
Real sa_ftol_
saturation adjustment temperature tolerance
static Thermodynamics * fromYAMLInput(YAML::Node node)
std::array< Real, Size > inv_mu_
inverse molecular weight [mol/kg]
std::array< Real, 1+NVAPOR > p3_
triple point pressure [pa]
Real GetLatentHeatMole(int i, std::vector< Real > const &rates, Real temp) const
Real RelativeHumidity(MeshBlock const *pmb, int n, int k, int j, int i) const
Relative humidity.
Real GetLatentEnergyMole(int n, Real temp=0.) const
Temperature dependent specific latent energy [J/mol] of condensates at constant volume.
void updateTPConservingU(AirParcel *qfrac, Real rmole, Real umole) const
update T/P
std::vector< std::vector< SatVaporPresFunc1 > > SVPFunc1Container
Real GetCpRatioMass(int n) const
static Thermodynamics * fromLegacyInput(ParameterInput *pin)
std::map< IndexPair, SatVaporPresFunc2 > SVPFunc2Container
SVPFunc1Container svp_func1_
saturation vapor pressure function: Vapor -> Cloud
void Extrapolate(AirParcel *qfrac, Real dzORdlnp, Method method, Real grav=0., Real userp=0.) const
std::array< Real, 1+NVAPOR > t3_
triple point temperature [K]
Real RovRd(AirParcel const &qfrac) const
std::array< Real, Size > mu_
molecular weight [kg/mol]
Real GetChi(AirParcel const &qfrac) const
std::array< Real, Size > delta_
Dimensionless differences in specific heat capacity.
Real GetCvMole(AirParcel const &qfrac, int n) const
Real GetCvMassRef(int n) const
Reference specific heat capacity [J/(kg K)] at constant volume.
static Thermodynamics * mythermo_
pointer to the single Thermodynamics instance
Real GetCpMass(AirParcel const &qfrac, int n) const
Real GetLatentHeatMass(int i, std::vector< Real > const &rates, Real temp) const
Real EquivalentPotentialTemp(MeshBlock *pmb, Real p0, int v, int k, int j, int i) const
Calculate equivalent potential temperature from primitive variable.
Real GetInvMuRatio(int n) const
Real GetCpRatioMole(int n) const
SVPFunc2Container svp_func2_
saturation vapor pressure function: Vapor + Vapor -> Cloud
Real sa_relax_
saturation adjustment relaxation parameter
std::array< Real, Size > latent_energy_mole_
latent energy at constant volume [J/mol]
Real GetTemp(MeshBlock const *pmb, int k, int j, int i) const
Calculate temperature from primitive variable.
std::array< Real, Size > cv_ratio_mole_
ratio of specific heat capacities [J/mol] at constant volume
static void Destroy()
Destroy the one and only instance of Thermodynamics.
std::array< Real, Size > mu_ratio_
ratio of mean molecular weights
Real GetGammadRef() const
reference adiabatic index of dry air [1]
Real Rd_
ideal gas constant of dry air in J/kg
static Thermodynamics const * InitFromAthenaInput(ParameterInput *pin)
void EquilibrateTP(AirParcel *qfrac) const
Real GetCpMole(AirParcel const &qfrac, int n) const
void rk4IntegrateLnp(AirParcel *qfrac, Real dlnp, Method method, Real adlnTdlnP) const
void setTotalEquivalentVapor(AirParcel *qfrac) const
Real GetEnthalpyMass(MeshBlock const *pmb, int k, int j, int i) const
specific enthalpy [J/kg] of the air parcel
Real GetPres(MeshBlock const *pmb, int k, int j, int i) const
RealArray3 TryEquilibriumTP_VaporVaporCloud(AirParcel const &air, IndexPair ij, Real cv_hat=0., bool misty=false) const
Calculate the equilibrium mole transfer by cloud reaction vapor1 + vapor2 -> cloud.
Real GetGammad(AirParcel const &var) const
adiaibatic index of dry air [1]
Real GetGamma(MeshBlock const *pmb, int k, int j, int i) const
Polytropic index.
Real RelativeHumidity(AirParcel const &qfrac, int n) const
Real getInternalEnergyMole(AirParcel const &qfrac) const
void rk4IntegrateZ(AirParcel *qfrac, Real dlnp, Method method, Real grav, Real adlnTdlnP) const
std::vector< int > IndexSet
std::array< Real, 3 > RealArray3
std::pair< int, int > IndexPair
Real NullSatVaporPres2(AirParcel const &, int, int, int)
Real(*)(AirParcel const &, int i, int j) SatVaporPresFunc1
std::pair< ReactionIndx, ReactionStoi > ReactionInfo
std::array< int, MAX_REACTANT > ReactionIndx
Real(*)(AirParcel const &, int i, int j, int k) SatVaporPresFunc2
Real SatVaporPresIdeal(Real t, Real p3, Real beta, Real delta)
std::vector< Real > RealArrayX
Real saha_ionization_electron_density(Real T, Real num, Real ion_ev)
Real NullSatVaporPres1(AirParcel const &, int, int)
void read_thermo_property(Real var[], char const name[], int len, Real v0, ParameterInput *pin)
std::array< int, MAX_REACTANT > ReactionStoi