-
Notifications
You must be signed in to change notification settings - Fork 41
/
test_solidsolution.py
436 lines (352 loc) · 14.8 KB
/
test_solidsolution.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
from __future__ import absolute_import
import unittest
import os
import sys
import warnings
sys.path.insert(1, os.path.abspath('..'))
import numpy as np
import burnman
from burnman.mineral import Mineral
from burnman.combinedmineral import CombinedMineral
from burnman.processchemistry import dictionarize_formula, formula_mass
from burnman.processchemistry import formula_to_string, sum_formulae
from util import BurnManTest
class forsterite (Mineral):
def __init__(self):
formula = 'Mg2.0Si1.0O4.0'
formula = dictionarize_formula(formula)
self.params = {
'name': 'fo',
'formula': formula,
'equation_of_state': 'hp_tmt',
'H_0': -2172590.0,
'S_0': 95.1,
'V_0': 4.366e-05,
'Cp': [233.3, 0.001494, -603800.0, -1869.7],
'a_0': 2.85e-05,
'K_0': 1.285e+11,
'Kprime_0': 3.84,
'Kdprime_0': -3e-11,
'n': sum(formula.values()),
'molar_mass': formula_mass(formula)}
Mineral.__init__(self)
class fayalite (Mineral):
def __init__(self):
formula = 'Fe2.0Si1.0O4.0'
formula = dictionarize_formula(formula)
self.params = {
'name': 'fa',
'formula': formula,
'equation_of_state': 'hp_tmt',
'H_0': -1477720.0,
'S_0': 151.0,
'V_0': 4.631e-05,
'Cp': [201.1, 0.01733, -1960600.0, -900.9],
'a_0': 2.82e-05,
'K_0': 1.256e+11,
'Kprime_0': 4.68,
'Kdprime_0': -3.7e-11,
'n': sum(formula.values()),
'molar_mass': formula_mass(formula)}
Mineral.__init__(self)
made_forsterite = CombinedMineral([forsterite(), forsterite()], [0.5, 0.5])
# One-mineral solid solution
class forsterite_ss(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = 'Dummy solid solution'
self.solution_type = 'symmetric'
self.endmembers = [[forsterite(), '[Mg]2SiO4']]
self.energy_interaction = []
burnman.SolidSolution.__init__(self, molar_fractions)
# Two-mineral solid solution
class forsterite_forsterite_ss(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = 'Fo-Fo solid solution'
self.solution_type = 'symmetric'
self.endmembers = [[forsterite(), '[Mg]2SiO4'], [
forsterite(), '[Mg]2SiO4']]
self.energy_interaction = [[0.]]
burnman.SolidSolution.__init__(self, molar_fractions)
# Ideal solid solution
class olivine_ideal_ss(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = 'Fo-Fo solid solution'
self.solution_type = 'ideal'
self.endmembers = [[
forsterite(), '[Mg]2SiO4'], [fayalite(), '[Fe]2SiO4']]
burnman.SolidSolution.__init__(self, molar_fractions)
# Olivine solid solution
class olivine_ss(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = 'Olivine'
self.solution_type = 'symmetric'
self.endmembers = [[
forsterite(), '[Mg]2SiO4'], [fayalite(), '[Fe]2SiO4']]
self.energy_interaction = [[8.4e3]]
burnman.SolidSolution.__init__(self, molar_fractions)
# Olivine solid solution with combined endmember
class olivine_ss2(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = 'Olivine'
self.solution_type = 'symmetric'
self.endmembers = [[
made_forsterite, '[Mg]2SiO4'], [fayalite(), '[Fe]2SiO4']]
self.energy_interaction = [[8.4e3]]
burnman.SolidSolution.__init__(self, molar_fractions)
# Orthopyroxene solid solution
class orthopyroxene(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
# Name
self.name = 'orthopyroxene'
self.solution_type = 'symmetric'
self.endmembers = [[forsterite(), '[Mg][Mg]Si2O6'], [
forsterite(), '[Mg1/2Al1/2][Mg1/2Al1/2]AlSiO6']]
self.energy_interaction = [[burnman.constants.gas_constant * 1.0e3]]
burnman.SolidSolution.__init__(self, molar_fractions)
# Three-endmember, two site symmetric solid solution
class two_site_ss(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = 'two_site_ss'
self.solution_type = 'symmetric'
self.endmembers = [[forsterite(), '[Mg]3[Al]2Si3O12'], [
forsterite(), '[Fe]3[Al]2Si3O12'], [forsterite(), '[Mg]3[Mg1/2Si1/2]2Si3O12']]
self.energy_interaction = [[10.0e3, 5.0e3], [-10.0e3]]
burnman.SolidSolution.__init__(self, molar_fractions)
# Three-endmember, two site asymmetric solid solution
class two_site_ss_asymmetric(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = 'two_site_ss (asymmetric)'
self.solution_type = 'asymmetric'
self.endmembers = [[forsterite(), '[Mg]3[Al]2Si3O12'], [
forsterite(), '[Fe]3[Al]2Si3O12'], [forsterite(), '[Mg]3[Mg1/2Si1/2]2Si3O12']]
self.alphas = [1., 2., 2.]
self.energy_interaction = [[10.0e3, 5.0e3], [-10.0e3]]
burnman.SolidSolution.__init__(self, molar_fractions)
# Three-endmember, two site solid solution
class two_site_ss_subregular(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
# Name
self.name = 'two_site_ss (subregular symmetric)'
self.solution_type = 'subregular'
self.endmembers = [[forsterite(), '[Mg]3[Al]2Si3O12'], [
forsterite(), '[Fe]3[Al]2Si3O12'], [forsterite(), '[Mg]3[Mg1/2Si1/2]2Si3O12']]
# Interaction parameters
self.energy_interaction = [
[[10.e3, 10.e3], [5.e3, 5.e3]], [[-10.e3, -10.e3]]]
burnman.SolidSolution.__init__(self, molar_fractions)
# Three-endmember, two site solid solution
class two_site_ss_subregular_asymmetric(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
# Name
self.name = 'two_site_ss (subregular symmetric)'
self.solution_type = 'subregular'
self.endmembers = [[forsterite(), '[Mg]3[Al]2Si3O12'], [
forsterite(), '[Fe]3[Al]2Si3O12'], [forsterite(), '[Mg]3[Mg1/2Si1/2]2Si3O12']]
# Interaction parameters
self.energy_interaction = [
[[10.e3, -10.e3], [5.e3, 3.e3]], [[-10.e3, -10.e3]]]
burnman.SolidSolution.__init__(self, molar_fractions)
class test_solidsolution(BurnManTest):
def setup_1min_ss(self):
P = 1.e5
T = 1000.
fo = forsterite()
fo.set_state(P, T)
fo_ss = forsterite_ss()
fo_ss.set_composition([1.0])
fo_ss.set_state(P, T)
return fo, fo_ss
def setup_2min_ss(self):
P = 1.e5
T = 1000.
fo = forsterite()
fo.set_state(P, T)
fo_fo_ss = forsterite_forsterite_ss()
fo_fo_ss.set_composition([0.3, 0.7])
fo_fo_ss.set_state(P, T)
return fo, fo_fo_ss
def setup_ol_ss(self):
P = 1.e5
T = 1000.
fo = forsterite()
fo.set_state(P, T)
ol_ss = olivine_ss()
ol_ss.set_composition([1.0, 0.0])
ol_ss.set_state(P, T)
return fo, ol_ss
def setup_ol_ss2(self):
P = 1.e5
T = 1000.
fo = forsterite()
fo.set_state(P, T)
ol_ss = olivine_ss2()
ol_ss.set_composition([1.0, 0.0])
ol_ss.set_state(P, T)
return fo, ol_ss
def test_1_gibbs(self):
fo, fo_ss = self.setup_1min_ss()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
endmember_properties = [fo.gibbs, fo.H, fo.S, fo.V, fo.C_p,
fo.C_v, fo.alpha, fo.K_T, fo.K_S, fo.gr, fo.G]
ss_properties = [fo_ss.gibbs, fo_ss.H, fo_ss.S, fo_ss.V, fo_ss.C_p,
fo_ss.C_v, fo_ss.alpha, fo_ss.K_T, fo_ss.K_S, fo_ss.gr, fo_ss.G]
assert len(w) == 3 # we expect to trigger 3 shear modulus warnings
self.assertArraysAlmostEqual(endmember_properties, ss_properties)
def test_2_gibbs(self):
fo, fo_ss = self.setup_2min_ss()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
endmember_properties = [fo.gibbs, fo.H, fo.S, fo.V, fo.C_p,
fo.C_v, fo.alpha, fo.K_T, fo.K_S, fo.gr, fo.G]
ss_properties = [fo_ss.gibbs, fo_ss.H, fo_ss.S, fo_ss.V, fo_ss.C_p,
fo_ss.C_v, fo_ss.alpha, fo_ss.K_T, fo_ss.K_S, fo_ss.gr, fo_ss.G]
assert len(w) == 4 # we expect to trigger 4 shear modulus warnings
self.assertArraysAlmostEqual(endmember_properties, ss_properties)
def test_ol_gibbs(self):
fo, fo_ss = self.setup_ol_ss()
endmember_properties = [
fo.gibbs, fo.H, fo.S, fo.V, fo.C_p, fo.C_v, fo.alpha, fo.K_T, fo.K_S, fo.gr]
ss_properties = [fo_ss.gibbs, fo_ss.H, fo_ss.S, fo_ss.V,
fo_ss.C_p, fo_ss.C_v, fo_ss.alpha, fo_ss.K_T, fo_ss.K_S, fo_ss.gr]
self.assertArraysAlmostEqual(endmember_properties, ss_properties)
def test_ol_gibbs2(self):
fo, fo_ss = self.setup_ol_ss2()
endmember_properties = [
fo.gibbs, fo.H, fo.S, fo.V, fo.C_p, fo.C_v, fo.alpha, fo.K_T, fo.K_S, fo.gr]
ss_properties = [fo_ss.gibbs, fo_ss.H, fo_ss.S, fo_ss.V,
fo_ss.C_p, fo_ss.C_v, fo_ss.alpha, fo_ss.K_T, fo_ss.K_S, fo_ss.gr]
self.assertArraysAlmostEqual(endmember_properties, ss_properties)
def test_ol_Wh(self):
ol_ss = olivine_ss()
H_excess = ol_ss.solution_model.excess_enthalpy(
1.e5, 1000., [0.5, 0.5]) # Hxs = Exs if Vxs=0
We = ol_ss.solution_model.We[0][1]
self.assertArraysAlmostEqual([We / 4.0], [H_excess])
def test_order_disorder(self):
opx = orthopyroxene()
opx.set_composition(np.array([0.0, 1.0]))
opx.set_state(1.e5, 300.)
self.assertArraysAlmostEqual([opx.excess_gibbs], [0.])
def test_site_totals(self):
ss = two_site_ss()
ss.set_composition([0.3, 0.3, 0.4])
ss.set_state(1.e5, 300.)
site_fractions = np.dot(
ss.molar_fractions, ss.solution_model.endmember_occupancies)
i = 0
site_fill = []
ones = [1.] * ss.solution_model.n_sites
for site in ss.solution_model.sites:
site_fill.append(sum(site_fractions[i:i + len(site)]))
i += len(site)
self.assertArraysAlmostEqual(site_fill, ones)
def test_set_method(self):
ss = olivine_ss()
ss.set_method('hp_tmt')
def test_molar_mass(self):
ss = olivine_ss()
ss.set_composition(np.array([0.5, 0.5]))
self.assertArraysAlmostEqual([ss.molar_mass], [0.5 *
forsterite().params['molar_mass'] + 0.5 * fayalite().params['molar_mass']])
def test_asymmetric_model_hessian_one_component_change(self):
ss = two_site_ss_asymmetric()
f0 = np.array([0.25, 0.35, 0.4])
ss.set_state(1.e5, 300.)
dp = 1.e-6
H = np.zeros((3, 3))
for i in range(3):
f = np.array(f0)
f[i] -= dp/2.
f /= np.sum(f)
ss.set_composition(f)
dGdx1 = ss.partial_gibbs
f = np.array(f0)
f[i] += dp/2.
f /= np.sum(f)
ss.set_composition(f)
dGdx2 = ss.partial_gibbs
H[i,:] = (dGdx2 - dGdx1)/dp
ss.set_composition(f0)
for i in range(3):
self.assertArraysAlmostEqual(ss.gibbs_hessian[i], H[i])
def test_subregular_model_hessian_one_component_change(self):
ss = two_site_ss_subregular()
f0 = np.array([0.25, 0.35, 0.4])
ss.set_state(1.e5, 300.)
dp = 1.e-6
H = np.zeros((3, 3))
for i in range(3):
f = np.array(f0)
f[i] -= dp/2.
f /= np.sum(f)
ss.set_composition(f)
dGdx1 = ss.partial_gibbs
f = np.array(f0)
f[i] += dp/2.
f /= np.sum(f)
ss.set_composition(f)
dGdx2 = ss.partial_gibbs
H[i, :] = (dGdx2 - dGdx1)/dp
ss.set_composition(f0)
for i in range(3):
self.assertArraysAlmostEqual(ss.gibbs_hessian[i], H[i])
def test_asymmetric_model_hessian_multicomponent_change(self):
ss = two_site_ss_asymmetric()
f0 = np.array([0.25, 0.35, 0.4])
ss.set_composition(f0)
ss.set_state(1.e5, 300.)
H0 = ss.gibbs_hessian
df = np.array([2.e-6, -1.5e-6, -0.5e-6])
ss.set_composition(f0 - df/2.)
dGdx1 = ss.partial_gibbs
ss.set_composition(f0 + df/2.)
dGdx2 = ss.partial_gibbs
for i in range(3):
self.assertArraysAlmostEqual(H0.dot(df), dGdx2 - dGdx1)
def test_subregular_model_hessian_multicomponent_change(self):
ss = two_site_ss_subregular_asymmetric()
f0 = [0.25, 0.35, 0.4]
ss.set_composition(f0)
ss.set_state(1.e5, 300.)
H0 = ss.gibbs_hessian
df = np.array([2.e-6, -1.5e-6, -0.5e-6])
ss.set_composition(f0 - df/2.)
dGdx1 = ss.partial_gibbs
ss.set_composition(f0 + df/2.)
dGdx2 = ss.partial_gibbs
for i in range(3):
self.assertArraysAlmostEqual(H0.dot(df), dGdx2 - dGdx1)
def test_subregular(self):
ss0 = two_site_ss()
ss1 = two_site_ss_subregular()
ss0.set_composition([0.3, 0.3, 0.4])
ss0.set_state(1.e5, 300.)
ss1.set_composition([0.3, 0.3, 0.4])
ss1.set_state(1.e5, 300.)
self.assertArraysAlmostEqual(
ss0.excess_partial_gibbs, ss1.excess_partial_gibbs)
def test_activities_ideal(self):
ol = olivine_ideal_ss()
ol.set_composition(np.array([0.5, 0.5]))
ol.set_state(1.e5, 1000.)
self.assertArraysAlmostEqual(ol.activities, [0.25, 0.25])
def test_activity_coefficients_ideal(self):
ol = olivine_ideal_ss()
ol.set_composition(np.array([0.5, 0.5]))
ol.set_state(1.e5, 1000.)
self.assertArraysAlmostEqual(ol.activity_coefficients, [1., 1.])
def test_activity_coefficients_non_ideal(self):
opx = orthopyroxene()
opx.set_composition(np.array([0.0, 1.0]))
opx.set_state(1.e5, 1000.)
self.assertArraysAlmostEqual(
opx.activity_coefficients, [np.exp(1.), 1.])
def test_formula(self):
ol = olivine_ideal_ss()
ol.set_composition([0.5, 0.5])
self.assertEqual(formula_to_string(ol.formula), 'MgFeSiO4')
self.assertEqual(formula_to_string(sum_formulae(ol.endmember_formulae,
[0.5, 0.5])), 'MgFeSiO4')
if __name__ == '__main__':
unittest.main()