def dydt(t, y, *args): O, DIC = y datain = datain = np.array([[S, T, 0, 0, 0, 0, 0, TA, DIC]]) dataout = co2sys.CO2sys(datain, const=10) CO2 = dataout['CO2'][0] HCO3 = dataout['HCO3'][0] MM = HCO3 / (HCO3 + KM) Pt = MM * P * I(t) dO = Pt - R + kla * air(t) * (O2H - O) dDIC = -Pt + R + kla * air(t) * (CO2H - CO2) # dTA = +2*RR*Pt return [dO, dDIC]
def dydt_exact( t, y, *args ): O,DIC,Alk= y datain = datain = np.array([[S,T,0,0,0,0,0,Alk,DIC]]) dataout=co2sys.CO2sys(datain,const=10) CO2 = dataout['CO2'][0] HCO3 = dataout['HCO3'][0] KM = 100 MM = HCO3/(HCO3+KM) dO = MM*P*I(t)*1.5-R +kla*air(t)*(O2H - O) dDIC = -MM*P*I(t) +R +kla*air(t)*(CO2H -CO2) dAlk = +2*RR*MM*P*I(t) return [dO,dDIC,dAlk]
def dydt(t, y, *args): O, DIC, Alk = y HCO3 = HCO3_approx(DIC, Alk, S, T) CO2 = CO2_approx(DIC, Alk, S, T) pH = pH_approx(DIC, Alk) #pH,CO2,HCO3,CO3 = iterate_CO2sys( DIC, Alk ) datain = datain = np.array([[S, T, 0, 0, 0, 0, 0, Alk, DIC]]) dataout = co2sys.CO2sys(datain, const=10) CO2 = dataout['CO2'][0] HCO3 = dataout['HCO3'][0] KM = 100 MM = HCO3 / (HCO3 + KM) dO = MM * P * I(t) * 1.5 - R + kla * air(t) * (O2H - O) dDIC = -MM * P * I(t) + R + kla * air(t) * (CO2H - CO2) dAlk = +2 * RR * MM * P * I(t) return [dO, dDIC, dAlk]
time = np.linspace(3, 5.5, 301) ys = np.zeros([len(y0), len(time)]) r = ode(dydt).set_integrator('dopri5') r.set_initial_value(y0, time[0]) ys[:, 0] = y0 for i, t in enumerate(time[1:]): r.integrate(t) ys[:, i + 1] = r.y datain = np.tile([S, T, 0, 0, 0, 0, 0, TA, DIC], [len(ys[0]), 1]) datain[:, 8] = ys[1] #datain[:,7]=ys[2] dataout = co2sys.CO2sys(datain, 10) fig, axs = plt.subplots(7, 1, sharex=True) ax = axs[0] ax.plot(time, ys[0]) ax.set_ylabel("O2") ax = axs[1] ax.plot(time, ys[1]) ax.set_ylabel("DIC") ax = axs[2] ax.plot(time, dataout['CO2']) ax.set_ylabel("CO2") ax = axs[3] ax.plot(time, dataout['HCO3']) ax.set_ylabel("HCO3")
KM = 200. print("P = ", P) print("kLA = ", kla) DIC = 500 K1 = co2sys.K1_H2CO3(TK, S, const=10) * 1e6 RT1 = 800 K2 = co2sys.K2_H2CO3(TK, S, const=10) * 1e6 RT2 = 830 KW = co2sys.K_W(TK, S) * 1e12 RT3 = 800 datain = np.array([[S, T, 0, 0, 0, 0, 0, 2400, DIC]]) dataout = co2sys.CO2sys(datain, const=10) y0 = [210., *dataout[['CO2', 'HCO3', 'CO3', 'pH']][0], 0] y0[4] = 10**(-y0[4]) * 1e6 y0[5] = dataout['OH'][0] * 1e6 def dydt(t, y, *args): O, CO2, HCO3, CO3, H, OH = y MM = HCO3 / (HCO3 + KM) R1 = (K1 * RT1 * CO2 - RT1 * H * HCO3) R2 = (K2 * RT2 * HCO3 - RT2 * H * CO3) R3 = KW * RT3 - RT3 * H * OH dO = MM * P * I(t) - R + kla * air(t) * (O2H - O) dCO2 = +kla * air(t) * (CO2H - CO2) - R1