-
Notifications
You must be signed in to change notification settings - Fork 0
/
sulfur_partition_coefficients.py
170 lines (153 loc) · 8.09 KB
/
sulfur_partition_coefficients.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import numpy as np
from scipy.stats import truncnorm
R = 8.3145
# T0 = 1400 # in Celsius
# TK0 = T0 + 273.15 # in kelvin
DELV_RXNI = 12.68-22.1
P0_RXNI = 200
T0_RXNI = 1000
P0_RXNIA = 100
T0_RXNIA = 1400
# DELV_RXNII = 45.94-16.764
DELV_RXNII = -49.5
DELH_RXNII = 32379 #delH/R
P0_RXNII = 100 # in MPa
T0_RXNII = 1100 # in C
class PartitionCoefficient:
"""
P[MPa],Tkc[K], Initial or average melt composition: wtsio2[wt% SiO2], wttio2[wt% TiO2], wtal2o3 [wt% al2o3],
wtfeo[wt% feo,FeO total as FeO], wtmno [wt% MnO], wtmgo[wt% MgO], wtcao[wt% CaO], wtna2o [wt% Na2O],
wtk2o [wt% k2o], wtp2o5 [wt% p2o5], wth2o [wt% h2o]
phih2o, phih2s, and phiso2 : fugacity coefficients of h2o, h2s and so2
monte (==1) for option to return a random number within the estimated error of each kd
logfo2 of fmq buffer, can be calculated with pressure and temperature following Frost(1991)
"""
def __init__(self, P, Tkc, composition, wth2o, phih2o, phih2s, phiso2, monte):
wtsio2 = composition["SiO2"]
wttio2 = composition["TiO2"]
wtal2o3 = composition["Al2O3"]
wtfeo = composition["FeOT"]
wtmno = composition["MnO"]
wtmgo = composition["MgO"]
wtcao = composition["CaO"]
wtna2o = composition["Na2O"]
wtk2o = composition["K2O"]
wtp2o5 = composition["P2O5"]
# Normalize wt % of oxides
oxide_tot = wtsio2 + wttio2 + wtal2o3 + wtfeo + wtmno + wtmgo + wtcao + wtna2o + wtk2o + wtp2o5 + wth2o
wtsio2 = wtsio2 / oxide_tot * 100
wttio2 = wttio2 / oxide_tot * 100
wtal2o3 = wtal2o3 / oxide_tot * 100
wtfeo = wtfeo / oxide_tot * 100
wtmno = wtmno / oxide_tot * 100
wtmgo = wtmgo / oxide_tot * 100
wtcao = wtcao / oxide_tot * 100
wtna2o = wtna2o / oxide_tot * 100
wtk2o = wtk2o / oxide_tot * 100
wtp2o5 = wtp2o5 / oxide_tot * 100
wth2o = wth2o / oxide_tot * 100
# Convert wt % to mole fractions in a single cation base
nsi = wtsio2 / (28.086 + 15.999 * 2) # moles of siO2
nti = wttio2 / (47.867 + 15.999 * 2) # moles of tio2
nal = 2 * wtal2o3 / (26.982 * 2 + 15.999 * 3) # moles of alo1.5
nfe = wtfeo / (55.845 + 15.999) # moles of feo
nmn = wtmno / (54.938 + 15.999) # moles of mno
nmg = wtmgo / (24.305 + 15.999) # moles of mgo
nca = wtcao / (40.078 + 15.999) # moles of cao
nna = 2 * wtna2o / (22.9898 * 2 + 15.999) # moles of nao0.5
nk = 2 * wtk2o / (39.098 * 2 + 15.999) # moles of ko0.5
nph = 2 * wtp2o5 / (30.973 * 2 + 15.999 * 5) # moles of po2.5
self.nh = 2 * wth2o / (15.999 + 2 * 1.0079) # moles of ho0.5
self.ntot = (nsi + nti + nal + nfe + nmn + nmg + nca + nna + nk + nph) # total moles without h2o
self.xsi = nsi / (self.ntot + self.nh)
self.xti = nti / (self.ntot + self.nh)
self.xal = nal / (self.ntot + self.nh)
self.xfe = nfe / (self.ntot + self.nh)
self.xmn = nmn / (self.ntot + self.nh)
self.xmg = nmg / (self.ntot + self.nh)
self.xca = nca / (self.ntot + self.nh)
self.xna = nna / (self.ntot + self.nh)
self.xk = nk / (self.ntot + self.nh)
self.xph = nph / (self.ntot + self.nh)
self.xh = self.nh / (self.ntot + self.nh)
self.Pb = P * 10 # transfer from MPa to bar
self.Tkc = Tkc
self.phiso2 = phiso2
self.ln_feo_coefficient = ((1 - self.xfe) ** 2 * (
28870 - 14710 * self.xmg + 1960 * self.xca + 43300 * self.xna + 95380 * self.xk - 76880 * self.xti)
+ (1 - self.xfe) * (-62190 * self.xsi + 31520 * (self.xsi ** 2))) / (R * Tkc)
# self.ln_S_coefficient = 13.406 * self.xh + (TK0/self.Tkc) * (
# -8.4995 * self.xfe + 1.8019 * self.xsi - 5.1959 * self.xsi*self.xfe - 10.8588 * self.xca)
self.ln_S_coefficient = 20.844 * (self.xh ** 2) - 8.7151 * self.xfe #+ 110.204 * self.xmn
self.excess_ca = 2 * self.xca - self.xal
self.excess_na = self.xna - self.xal
total_oxygen = 2 * (2 * (self.xsi + self.xti) + self.xal * 1.5 + self.xfe + self.xmn + self.xca + 0.5*(self.xna + self.xk + self.xh) + 2.5 * self.xph)
self.nbo = (total_oxygen - 4 * (self.xsi + self.xti + self.xal + self.xph))/(self.xsi + self.xti + self.xal + self.xph)
delh_rxn1 = (-0.4739 * (T0_RXNI + 273.15) + 45431) / R
delh_rxn1a = (-2.7921*(T0_RXNIA + 273.15)-472032) / R
self.residual_rxn1 = 0.616843 + self.ln_S_coefficient - DELV_RXNI*(self.Pb/10 - P0_RXNI)/(R * self.Tkc) \
- (delh_rxn1)*(1/self.Tkc - 1/(T0_RXNI+273.15)) + np.log(self.Pb * phih2o) \
- np.log(self.xfe) - self.ln_feo_coefficient - np.log(self.Pb * phih2s)
# residual_Rxn1 = ln(xh2s) -ln(xS2-) + ln(XH2O_fluid)
# self.residual_rxn1a = 29.79217 + self.ln_S_coefficient - DELV_RXNI*(self.Pb/10 - P0_RXNIA)/(R * self.Tkc) \
# - (delh_rxn1a) * (1/self.Tkc - 1/(T0_RXNIA+273.15)) - np.log(self.Pb) - np.log(phiso2) \
# - np.log(self.xfe) - self.ln_feo_coefficient
# residual_Rxn1a = ln(so2) -ln(xS2-) - 1.5* lnfO2
# self.residual_rxn2 = -0.2394 - DELV_RXNII*(self.Pb/10 - P0_RXNII)/(R * self.Tkc) \
# - DELH_RXNII*(1/self.Tkc - 1/T0_RXNII) - np.log(phiso2) - np.log(self.Pb)\
# - 8.917 * self.excess_ca - 21.7845 * self.excess_na - 1.7147 * self.nbo
self.residual_rxn2 = -0.2556 - DELV_RXNII * (self.Pb / 10 - P0_RXNII) / (R * self.Tkc) \
- DELH_RXNII * (1 / self.Tkc - 1 / (T0_RXNII+273.15))- np.log(phiso2) - np.log(self.Pb) \
- 9.88817 * self.excess_ca - 24.76395 * self.excess_na - 0.97078 * self.nbo
# self.residual_rxn2 = 0.959178 - DELV_RXNII * (self.Pb / 10 - P0_RXNII) / (R * self.Tkc) \
# - DELH_RXNII * (1 / self.Tkc - 1 / (T0_RXNII + 273.15)) - np.log(phiso2) - np.log(self.Pb) \
# + 2.5883241 * self.excess_ca - 15.0809 * self.excess_na - 0.92322 * self.nbo
self.monte = monte
def get_truncated_normal(mean, sd, low, upp):
return truncnorm((low - mean) / sd, (upp - mean) / sd, loc=mean, scale=sd)
#This function calculates the kd between H2S in the vapor and S2- in the melt
def kd_rxn1(self, xh2o):
"""
xh2o: mole fraction of h2o in the vapor, 0-1
"""
rxn1 = self.residual_rxn1 + np.log(xh2o)
sd_rxn1 = 0.44
if self.monte == 1:
rxn1 = np.random.normal(rxn1, sd_rxn1)
return np.exp(rxn1)
# def kd_rxn1a(self, fo2):
# """
# fo2: oxygen fugacity in bar
# """
# rxn1a = self.residual_rxn1a + 1.5 * np.log(fo2)
# sd_rxn1a = 0.45
# if self.monte == 1:
# rxn1a = np.random.normal(rxn1a, sd_rxn1a)
# return np.exp(rxn1a)
# This function calculates the kd between SO2 in the vapor and S6+ in the melt
def kd_rxn2 (self, fo2):
"""
fo2: oxygen fugacity in bar
"""
rxn2 = (self.residual_rxn2 - 0.5 * np.log(fo2))
sd_rxn2 = 0.2136
if self.monte == 1:
rxn2 = np.random.normal(rxn2, sd_rxn2)
return np.exp(rxn2)
# This function calculates the SO2 and H2S in the vapor
def gas_quilibrium(self, fo2, fh2o, phiso2, phih2s):
"""
fo2: oxygen fugacity in bar
fh2o: water fugacity in bar
phiso2: fugacity coefficient of so2
phih2s: fugacity coefficient of h2s
"""
logK = 4.1245 - 27110/self.Tkc
logfo2 = np.log10(fo2)
ratio = 10 ** (1.5*logfo2 - logK - np.log10(fh2o)) * phih2s / phiso2
ratio = ratio / (ratio +1)
return ratio
def hydrogen_equilibrium(self, fo2, fh2o):
logK = 12510/self.Tkc-0.979*np.log10(self.Tkc)+0.483
logfH2 = np.log10(fh2o)-0.5*np.log10(fo2)-logK
return 10**logfH2