I want to calculate the gas temperature of cells and I saw the answer on "Frequently Asked Questions":
And the code in tutorial is:
def utherm_ne_to_temp(utherm, nelec):
""" Convert the InternalEnergy and ElectronAbundance of gas cells to temperature in [log K]. """
hydrogen_massfrac = 0.76 # approximate
mass_proton = 1.672622e-24 # cgs
gamma = 5/3
boltzmann = 1.380650e-16 # cgs (erg/K)
# unit system
UnitLength_in_cm = 3.085678e21 # 1.0 kpc
UnitMass_in_g = 1.989e43 # 1.0e10 solar masses
UnitVelocity_in_cm_per_s = 1.0e5 # 1 km/sec
UnitTime_in_s = UnitLength_in_cm / UnitVelocity_in_cm_per_s
UnitEnergy_in_cgs = UnitMass_in_g * UnitLength_in_cm**2.0 / UnitTime_in_s**2.0
# calculate mean molecular weight
meanmolwt = 4.0/(1.0 + 3.0 * hydrogen_massfrac + 4.0* hydrogen_massfrac * nelec)
meanmolwt *= mass_proton
# calculate temperature (K)
temp = utherm * (gamma-1.0) / boltzmann * UnitEnergy_in_cgs / UnitMass_in_g * meanmolwt
temp = np.log10(temp)
return temp.astype('float32')
My question is why does the formula for calculating temperature need to include the term of "UnitEnergy/UnitMass"? Isn't the units of "InternalEnergy (per unit mass) " is [ (km/s)^2 ], and to convert to cgs [ (cm/s)^2 ], do we just need to times (10^5 )^2 ?
Hi,
I want to calculate the gas temperature of cells and I saw the answer on "Frequently Asked Questions":
And the code in tutorial is:
My question is why does the formula for calculating temperature need to include the term of "UnitEnergy/UnitMass"? Isn't the units of "InternalEnergy (per unit mass) " is [ (km/s)^2 ], and to convert to cgs [ (cm/s)^2 ], do we just need to times (10^5 )^2 ?
And I notice that someone had proposed similar question before: https://www.tng-project.org/data/forum/topic/338/cold-and-hot-gas/.
I'm just curious about why the code convert "UnitLength, UnitMass, UnitVelocity" to cgs first and then calculate :
Best wish,
Morris
UnitEnergy_in_cgs/UnitMass_in_g
is 1e10, for the TNG simulations.