Skip to content

Commit

Permalink
fix CO2 quench
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Oct 6, 2024
1 parent b25f736 commit fa8b32e
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions photochem/extensions/gasgiants.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,26 @@ def initialize_to_climate_equilibrium_PT(self, P_in, T_in, Kzz_in, metallicity,
if gdat.initial_cond_with_quenching:

# Apply quenching to mixing ratios
mix1['CH4'][quench_levels[0]:] = mix1['CH4'][quench_levels[0]]
mix1['CO'][quench_levels[0]:] = mix1['CO'][quench_levels[0]]
mix1['CO2'][quench_levels[1]:] = mix1['CO2'][quench_levels[1]]
mix1['NH3'][quench_levels[2]:] = mix1['NH3'][quench_levels[2]]
mix1['HCN'][quench_levels[3]:] = mix1['HCN'][quench_levels[3]]

# Quenching out H2 at the CH4 level seems to work well
mix1['H2'][quench_levels[0]:] = mix1['H2'][quench_levels[0]]
if "CH4" in mix1:
mix1['CH4'][quench_levels[0]:] = mix1['CH4'][quench_levels[0]]
if "CO" in mix1:
mix1['CO'][quench_levels[0]:] = mix1['CO'][quench_levels[0]]
if "NH3" in mix1:
mix1['NH3'][quench_levels[2]:] = mix1['NH3'][quench_levels[2]]
if "HCN" in mix1:
mix1['HCN'][quench_levels[3]:] = mix1['HCN'][quench_levels[3]]
if "H2" in mix1:
# Quenching out H2 at the CH4 level seems to work well
mix1['H2'][quench_levels[0]:] = mix1['H2'][quench_levels[0]]

if "CO2" in mix1:
# First, I need to equilibrate CO2 against quenched CO, H2O and H2.
# mix1['CO2'] = equilibrate_CO2_to_CO(mix1['CO'], mix1['H2O'], mix1['H2'], T1)
# Next, I apply the quench.
mix1['CO2'][quench_levels[1]:] = mix1['CO2'][quench_levels[1]]

# Normalize mixing ratios
mix_tot = np.zeros(mix1['CH4'].shape[0])
mix_tot = np.zeros(mix1['H2'].shape[0])
for key in mix1:
mix_tot += mix1[key]
for key in mix1:
Expand Down Expand Up @@ -679,6 +688,31 @@ def CO2_quench_timescale(T, P):
tq = 1.0e-10*P_bars**-0.5*np.exp(38_000.0/T)
return tq

@nb.njit()
def equilibrate_CO2_to_CO(fCO, fH2O, fH2, T):
"""The mole fraction of CO2 in equilibrium with CO, H2O and H2.
From Equation 43 in Zahnle and Marley (2014).
Parameters
----------
fCO : float
The CO mole fraction
fH2O : float
The H2O mole fraction
fH2 : float
The H2 mole fraction
T : float
Temperature in K
Returns
-------
float
The CO2 mole fraction
"""
K = 18.3*np.exp(-2376/T - (932/T)**2)
fCO2 = (fCO*fH2O)/(K*fH2)
return fCO2

@nb.njit()
def scale_height(T, mubar, grav):
"All inputs are CGS."
Expand Down

0 comments on commit fa8b32e

Please sign in to comment.