Skip to content

Instantly share code, notes, and snippets.

@tadeu
Last active December 18, 2015 11:39
Show Gist options
  • Select an option

  • Save tadeu/5777171 to your computer and use it in GitHub Desktop.

Select an option

Save tadeu/5777171 to your computer and use it in GitHub Desktop.
pH.py
(C_co2_o, m_co2, V_g, P_co2, V_o, V_w, C_co2_w, C_hco3, C_co3, m_h2s, P_h2s, C_h2s_o, C_h2s_w, C_hs, alk_tot, C_oh, C_h, K1, K2, K_h2s) = symbols(
'C_co2_o m_co2 V_g P_co2 V_o V_w C_co2_w C_hco3 C_co3 m_h2s P_h2s C_h2s_o C_h2s_w C_hs alk_tot C_oh C_h K1 K2 K_h2s')
eq_co2_mass = ( m_co2 - V_g * P_co2 + V_o * C_co2_o + V_w * (C_co2_w + C_hco3 + C_co3) )
eq_h2s_mass = ( m_h2s - V_g * P_h2s + V_o * C_h2s_o + V_w * (C_h2s_w + C_hs) )
eq_alk = ( alk_tot - C_hco3 + 2 * C_co3 + C_hs + C_oh - C_h )
eq_h2co3_1st = (K1 - C_h * C_hco3 / C_co2_w)
eq_h2co3_2nd = (K2 - C_h * C_co3 / C_hco3)
eq_h2s_dissoc = (K_h2s - C_hs * C_h / C_h2s_w)
equations = [eq_co2_mass, eq_h2s_mass, eq_alk, eq_h2co3_1st, eq_h2co3_2nd, eq_h2s_dissoc]
unknowns = [C_co2_o, C_h2s_o, C_h, C_hco3, C_co3, C_h2s_w]
# equations = [eq_h2co3_1st, eq_h2co3_2nd, eq_h2s_dissoc]
# unknowns = [C_co2_w, C_hco3, C_h2s_w]
solve(equations, *unknowns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment