-
Notifications
You must be signed in to change notification settings - Fork 41
/
test_solidsolution.py
1223 lines (1042 loc) · 40.9 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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import absolute_import
from util import BurnManTest
import unittest
import numpy as np
import warnings
import burnman
from burnman import Mineral
from burnman import CombinedMineral
from burnman.classes.solutionmodel import IdealSolution
from burnman.classes.solutionmodel import SymmetricRegularSolution
from burnman.classes.solutionmodel import SubregularSolution
from burnman.classes.solutionmodel import AsymmetricRegularSolution
from burnman.classes.solutionmodel import FunctionSolution
from burnman.classes.solutionmodel import PolynomialSolution
from burnman.utils.chemistry import dictionarize_formula, formula_mass
from burnman.utils.chemistry import formula_to_string, sum_formulae
from burnman.minerals import HGP_2018_ds633
from burnman.minerals.SLB_2011 import mg_post_perovskite
from burnman.minerals.SLB_2011 import fe_post_perovskite
from burnman.minerals.SLB_2011 import al_post_perovskite
from burnman.tools.eos import check_eos_consistency
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.285e11,
"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.256e11,
"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_model = SymmetricRegularSolution(
endmembers=[[forsterite(), "[Mg]2SiO4"]], 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_model = SymmetricRegularSolution(
endmembers=[[forsterite(), "[Mg]2SiO4"], [forsterite(), "[Mg]2SiO4"]],
energy_interaction=[[0.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_model = IdealSolution(
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_model = SymmetricRegularSolution(
endmembers=[[forsterite(), "[Mg]2SiO4"], [fayalite(), "[Fe]2SiO4"]],
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_model = SymmetricRegularSolution(
endmembers=[[made_forsterite, "[Mg]2SiO4"], [fayalite(), "[Fe]2SiO4"]],
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_model = SymmetricRegularSolution(
endmembers=[
[forsterite(), "[Mg][Mg]Si2O6"],
[forsterite(), "[Mg1/2Al1/2][Mg1/2Al1/2]AlSiO6"],
],
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_model = SymmetricRegularSolution(
endmembers=[
[forsterite(), "[Mg]3[Al]2Si3O12"],
[forsterite(), "[Fe]3[Al]2Si3O12"],
[forsterite(), "[Mg]3[Mg1/2Si1/2]2Si3O12"],
],
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_model = AsymmetricRegularSolution(
endmembers=[
[forsterite(), "[Mg]3[Al]2Si3O12"],
[forsterite(), "[Fe]3[Al]2Si3O12"],
[forsterite(), "[Mg]3[Mg1/2Si1/2]2Si3O12"],
],
alphas=[1.0, 2.0, 2.0],
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):
self.name = "two_site_ss (subregular symmetric)"
self.solution_model = SubregularSolution(
endmembers=[
[forsterite(), "[Mg]3[Al]2Si3O12"],
[forsterite(), "[Fe]3[Al]2Si3O12"],
[forsterite(), "[Mg]3[Mg1/2Si1/2]2Si3O12"],
],
energy_interaction=[
[[10.0e3, 10.0e3], [5.0e3, 5.0e3]],
[[-10.0e3, -10.0e3]],
],
)
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):
self.name = "two_site_ss (subregular symmetric)"
self.solution_model = SubregularSolution(
endmembers=[
[forsterite(), "[Mg]3[Al]2Si3O12"],
[forsterite(), "[Fe]3[Al]2Si3O12"],
[forsterite(), "[Mg]3[Mg1/2Si1/2]2Si3O12"],
],
energy_interaction=[
[[10.0e3, -10.0e3], [5.0e3, 3.0e3]],
[[-10.0e3, -10.0e3]],
],
)
burnman.SolidSolution.__init__(self, molar_fractions)
# Three-endmember, two site solid solution with ternary term
class two_site_ss_subregular_ternary(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = "two_site_ss (subregular)"
self.solution_model = SubregularSolution(
endmembers=[
[forsterite(), "[Mg]3[Al]2Si3O12"],
[forsterite(), "[Fe]3[Al]2Si3O12"],
[forsterite(), "[Mg]3[Mg1/2Si1/2]2Si3O12"],
],
energy_interaction=[
[[10.0e3, -10.0e3], [5.0e3, 3.0e3]],
[[-10.0e3, -10.0e3]],
],
entropy_interaction=[[[1.0, -2.0], [0.0, 1.0]], [[0.0, 0.0]]],
energy_ternary_terms=[[0, 1, 2, 3.0e3]],
)
burnman.SolidSolution.__init__(self, molar_fractions)
# As above, but using the PolynomialSolution model
class two_site_ss_polynomial_ternary(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = "two_site_ss (subregular from polynomial)"
self.solution_model = PolynomialSolution(
endmembers=[
[forsterite(), "[Mg]3[Al]2Si3O12"],
[forsterite(), "[Fe]3[Al]2Si3O12"],
[forsterite(), "[Mg]3[Mg1/2Si1/2]2Si3O12"],
],
ESV_interactions=[
# Wj and Wi terms in Helffrich and Wood
[10.0e3, 1.0, 0.0, 0, 1, 1, 2],
[-10.0e3, -2.0, 0.0, 0, 2, 1, 1],
[5.0e3, 0.0, 0.0, 0, 1, 2, 2],
[3.0e3, 1.0, 0.0, 0, 2, 2, 1],
[-10.0e3, 0.0, 0.0, 1, 1, 2, 2],
[-10.0e3, 0.0, 0.0, 1, 2, 2, 1],
# 0.5*Wk terms in Helffrich and Wood
# Because there are only three endmembers, there
# is only one additional term for each term above:
[5.0e3, 0.5, 0.0, 0, 1, 1, 1, 2, 1],
[-5.0e3, -1.0, 0.0, 0, 1, 1, 1, 2, 1],
[2.5e3, 0.0, 0.0, 0, 1, 1, 1, 2, 1],
[1.5e3, 0.5, 0.0, 0, 1, 1, 1, 2, 1],
[-5.0e3, 0.0, 0.0, 0, 1, 1, 1, 2, 1],
[-5.0e3, 0.0, 0.0, 0, 1, 1, 1, 2, 1],
# Ternary term
[3.0e3, 0.0, 0.0, 0, 1, 1, 1, 2, 1],
],
)
burnman.SolidSolution.__init__(self, molar_fractions)
# As above, but using a transformation matrix to change the order of
# endmembers.
# The defined interactions are a function of the transformed endmembers,
# not the ones defined by the endmembers parameter
# So in this example, p[0] for the ESV_interactions corresponds to
# the proportion of the second endmember in the endmembers list,
# p[1] to the last endmember, and p[2] to the first.
class two_site_ss_polynomial_ternary_transformed(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = "two_site_ss (subregular from polynomial)"
self.solution_model = PolynomialSolution(
endmembers=[
[forsterite(), "[Mg]3[Mg1/2Si1/2]2Si3O12"],
[forsterite(), "[Mg]3[Al]2Si3O12"],
[forsterite(), "[Fe]3[Al]2Si3O12"],
],
ESV_interactions=[
# Wj and Wi terms in Helffrich and Wood
[10.0e3, 1.0, 0.0, 0, 1, 1, 2],
[-10.0e3, -2.0, 0.0, 0, 2, 1, 1],
[5.0e3, 0.0, 0.0, 0, 1, 2, 2],
[3.0e3, 1.0, 0.0, 0, 2, 2, 1],
[-10.0e3, 0.0, 0.0, 1, 1, 2, 2],
[-10.0e3, 0.0, 0.0, 1, 2, 2, 1],
# 0.5*Wk terms in Helffrich and Wood
# Because there are only three endmembers, there
# is only one additional term for each term above:
[5.0e3, 0.5, 0.0, 0, 1, 1, 1, 2, 1],
[-5.0e3, -1.0, 0.0, 0, 1, 1, 1, 2, 1],
[2.5e3, 0.0, 0.0, 0, 1, 1, 1, 2, 1],
[1.5e3, 0.5, 0.0, 0, 1, 1, 1, 2, 1],
[-5.0e3, 0.0, 0.0, 0, 1, 1, 1, 2, 1],
[-5.0e3, 0.0, 0.0, 0, 1, 1, 1, 2, 1],
# Ternary term
[3.0e3, 0.0, 0.0, 0, 1, 1, 1, 2, 1],
],
transformation_matrix=np.array(
[[0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [1.0, 0.0, 0.0]]
),
)
burnman.SolidSolution.__init__(self, molar_fractions)
class two_site_ss_polynomial_high_order_transformed(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = "two_site_ss (high order from polynomial)"
self.solution_model = PolynomialSolution(
endmembers=[
[forsterite(), "[Mg]3[Mg1/2Si1/2]2Si3O12"],
[forsterite(), "[Mg]3[Al]2Si3O12"],
[forsterite(), "[Fe]3[Al]2Si3O12"],
],
ESV_interactions=[
# Wj and Wi terms in Helffrich and Wood
[10.0e3, 1.0, 0.0, 0, 1, 1, 2],
[-10.0e3, -2.0, 0.0, 0, 2, 1, 6],
[5.0e3, 0.5, 0.0, 0, 6, 1, 1, 2, 1],
],
transformation_matrix=np.array(
[[0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [1.0, 0.0, 0.0]]
),
)
burnman.SolidSolution.__init__(self, molar_fractions)
# Polynomial solution using extra endmembers
# to define the mixing terms
fo1 = forsterite()
fo2 = forsterite()
fo2.property_modifiers = [
["linear", {"delta_E": 1200.0, "delta_S": 5.0, "delta_V": 1.0e-6}]
]
class polynomial_mbr_mixing(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = "binary mbr mixing (polynomial)"
self.solution_model = PolynomialSolution(
endmembers=[
[forsterite(), "[Mg]2"],
[fayalite(), "[Mg]2"],
],
interaction_endmembers=[fo2, fo1],
endmember_coefficients_and_interactions=[[1.0, -1.0, 0, 1, 1, 1]],
)
burnman.SolidSolution.__init__(self, molar_fractions)
class regular_copy_polynomial_mbr_mixing(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = "binary mbr mixing (regular)"
self.solution_model = SymmetricRegularSolution(
endmembers=[
[forsterite(), "[Mg]2"],
[fayalite(), "[Mg]2"],
],
energy_interaction=[[1200.0]],
entropy_interaction=[[5.0]],
volume_interaction=[[1.0e-6]],
)
burnman.SolidSolution.__init__(self, molar_fractions)
fo3 = forsterite()
fo3.property_modifiers = [
["linear", {"delta_E": 600.0, "delta_S": 2.5, "delta_V": 0.5e-6}]
]
class polynomial_esv_and_mbr_mixing(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = "two_site_ss (subregular symmetric)"
self.solution_model = PolynomialSolution(
endmembers=[
[forsterite(), "[Mg]2"],
[fayalite(), "[Mg]2"],
],
ESV_interactions=[[600.0, 2.5, 0.5e-6, 0, 1, 1, 1]],
interaction_endmembers=[fo3, fo1],
endmember_coefficients_and_interactions=[[1.0, -1.0, 0, 1, 1, 1]],
)
burnman.SolidSolution.__init__(self, molar_fractions)
class polynomial_esv_and_mbr_mixing_2(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = "two_site_ss (subregular symmetric)"
self.solution_model = PolynomialSolution(
endmembers=[
[forsterite(), "[Mg]2"],
[fayalite(), "[Mg]2"],
],
ESV_interactions=[[600.0, 2.5, 0.5e-6, 0, 1, 1, 1]],
interaction_endmembers=[fayalite(), fo1],
endmember_coefficients_and_interactions=[[1.0, -1.0, 0, 1, 1, 1]],
)
burnman.SolidSolution.__init__(self, molar_fractions)
# Temkin solution
class temkin_ss(burnman.SolidSolution):
def __init__(self, molar_fractions=None):
self.name = "ol-q-water melt (HGP 2018)"
self.solution_model = IdealSolution(
endmembers=[
[HGP_2018_ds633.foL(), "[Mg]4[Sitet]1[Vac]2"],
[HGP_2018_ds633.faL(), "[Fe]4[Sitet]1[Vac]2"],
[HGP_2018_ds633.qL(), "[]0[Sinet]1[Vac]2"],
[HGP_2018_ds633.h2oL(), "[]0[]0[H]2"],
]
)
burnman.SolidSolution.__init__(self, molar_fractions)
class ppv_symmetric(burnman.Solution):
def __init__(self, molar_fractions=None):
self.name = "post-perovskite/bridgmanite"
self.solution_model = SymmetricRegularSolution(
endmembers=[
[mg_post_perovskite(), "[Mg][Si]O3"],
[fe_post_perovskite(), "[Fe][Si]O3"],
[al_post_perovskite(), "[Al][Al]O3"],
],
energy_interaction=[[0.0, 60.0e3], [0.0]],
)
burnman.Solution.__init__(self, molar_fractions=molar_fractions)
def excess_gibbs_function_ppv(pressure, temperature, molar_amounts):
n_moles = sum(molar_amounts)
molar_fractions = molar_amounts / n_moles
return n_moles * 60.0e3 * molar_fractions[0] * molar_fractions[2]
class ppv_function(burnman.Solution):
def __init__(self, molar_fractions=None):
self.name = "post-perovskite/bridgmanite"
self.solution_model = FunctionSolution(
endmembers=[
[mg_post_perovskite(), "[Mg][Si]O3"],
[fe_post_perovskite(), "[Fe][Si]O3"],
[al_post_perovskite(), "[Al][Al]O3"],
],
excess_gibbs_function=excess_gibbs_function_ppv,
)
burnman.Solution.__init__(self, molar_fractions=molar_fractions)
class test_solidsolution(BurnManTest):
def setup_1min_ss(self):
P = 1.0e5
T = 1000.0
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.0e5
T = 1000.0
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.0e5
T = 1000.0
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.0e5
T = 1000.0
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_set_state_with_volume(self):
m = olivine_ss()
m.set_composition([0.5, 0.5])
P0 = 6.0e9
T0 = 1000.0
T1 = 298.15
m.set_state(P0, T0)
V = m.V
m.set_state_with_volume(V, T1)
P1 = m.pressure
m.set_state(P0, T0) # forget new state
m.set_state(P1, T1) # return to new state
self.assertFloatEqual(V, m.V)
def test_ol_Wh(self):
ol_ss = olivine_ss()
H_excess = ol_ss.solution_model.excess_enthalpy(
1.0e5, 1000.0, [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.0e5, 300.0)
self.assertArraysAlmostEqual([opx.excess_gibbs], [0.0])
def test_site_totals(self):
ss = two_site_ss()
ss.set_composition([0.3, 0.3, 0.4])
ss.set_state(1.0e5, 300.0)
site_fractions = np.dot(
ss.molar_fractions, ss.solution_model.endmember_occupancies
)
i = 0
site_fill = []
ones = [1.0] * 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.0e5, 300.0)
dp = 1.0e-6
H = np.zeros((3, 3))
for i in range(3):
f = np.array(f0)
f[i] -= dp / 2.0
f /= np.sum(f)
ss.set_composition(f)
dGdx1 = ss.partial_gibbs
f = np.array(f0)
f[i] += dp / 2.0
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.0e5, 300.0)
dp = 1.0e-6
H = np.zeros((3, 3))
for i in range(3):
f = np.array(f0)
f[i] -= dp / 2.0
f /= np.sum(f)
ss.set_composition(f)
dGdx1 = ss.partial_gibbs
f = np.array(f0)
f[i] += dp / 2.0
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.0e5, 300.0)
H0 = ss.gibbs_hessian
df = np.array([2.0e-6, -1.5e-6, -0.5e-6])
ss.set_composition(f0 - df / 2.0)
dGdx1 = ss.partial_gibbs
ss.set_composition(f0 + df / 2.0)
dGdx2 = ss.partial_gibbs
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.0e5, 300.0)
H0 = ss.gibbs_hessian
df = np.array([2.0e-6, -1.5e-6, -0.5e-6])
ss.set_composition(f0 - df / 2.0)
dGdx1 = ss.partial_gibbs
ss.set_composition(f0 + df / 2.0)
dGdx2 = ss.partial_gibbs
self.assertArraysAlmostEqual(H0.dot(df), dGdx2 - dGdx1)
def test_subregular_model_ternary_partial_entropy_multicomponent_change(self):
ss = two_site_ss_subregular_ternary()
f0 = np.array([0.25, 0.35, 0.4])
ss.set_composition(f0)
ss.set_state(1.0e9, 1000.0)
dSdx = ss.partial_entropies
df = 0.0001
dSdx2 = np.empty(3)
for i, f_mod in enumerate(np.eye(3) * df):
ss.set_composition((f0 - f_mod / 2) / (1.0 - df / 2.0))
S0 = ss.S * (1.0 - df / 2.0)
ss.set_composition((f0 + f_mod / 2) / (1.0 + df / 2.0))
S1 = ss.S * (1.0 + df / 2.0)
dSdx2[i] = (S1 - S0) / df
self.assertArraysAlmostEqual(dSdx, dSdx2)
def test_subregular_model_ternary_hessian_multicomponent_change(self):
ss = two_site_ss_subregular_ternary()
f0 = [0.25, 0.35, 0.4]
ss.set_composition(f0)
ss.set_state(1.0e5, 300.0)
H0 = ss.gibbs_hessian
df = np.array([2.0e-6, -1.5e-6, -0.5e-6])
ss.set_composition(f0 - df / 2.0)
dGdx1 = ss.partial_gibbs
ss.set_composition(f0 + df / 2.0)
dGdx2 = ss.partial_gibbs
self.assertArraysAlmostEqual(H0.dot(df), dGdx2 - dGdx1)
def test_polynomial_model_partial_entropy_multicomponent_change(self):
ss = two_site_ss_polynomial_ternary()
f0 = np.array([0.25, 0.35, 0.4])
ss.set_composition(f0)
ss.set_state(1.0e9, 1000.0)
dSdx = ss.partial_entropies
df = 0.0001
dSdx2 = np.empty(3)
for i, f_mod in enumerate(np.eye(3) * df):
ss.set_composition((f0 - f_mod / 2) / (1.0 - df / 2.0))
S0 = ss.S * (1.0 - df / 2.0)
ss.set_composition((f0 + f_mod / 2) / (1.0 + df / 2.0))
S1 = ss.S * (1.0 + df / 2.0)
dSdx2[i] = (S1 - S0) / df
self.assertArraysAlmostEqual(dSdx, dSdx2)
def test_polynomial_high_order_transformed(self):
ss = two_site_ss_polynomial_high_order_transformed()
f0 = [0.25, 0.35, 0.4]
ss.set_composition(f0)
ss.set_state(1.0e5, 300.0)
HG0 = ss.gibbs_hessian
HS0 = ss.entropy_hessian
HV0 = ss.volume_hessian
dGdx0 = ss.partial_gibbs
dSdx0 = ss.partial_entropies
dVdx0 = ss.partial_volumes
df = np.array([2.0e-6, -1.5e-6, -0.5e-6])
ss.set_composition(f0 - df / 2.0)
G1 = ss.gibbs
S1 = ss.S
V1 = ss.V
dGdx1 = ss.partial_gibbs
dSdx1 = ss.partial_entropies
dVdx1 = ss.partial_volumes
ss.set_composition(f0 + df / 2.0)
G2 = ss.gibbs
S2 = ss.S
V2 = ss.V
dGdx2 = ss.partial_gibbs
dSdx2 = ss.partial_entropies
dVdx2 = ss.partial_volumes
self.assertArraysAlmostEqual(
[dGdx0.dot(df), dSdx0.dot(df), dVdx0.dot(df)], [G2 - G1, S2 - S1, V2 - V1]
)
self.assertArraysAlmostEqual(HG0.dot(df), dGdx2 - dGdx1)
self.assertArraysAlmostEqual(HS0.dot(df), dSdx2 - dSdx1)
self.assertArraysAlmostEqual(HV0.dot(df), dVdx2 - dVdx1)
def test_polynomial_using_subregular_scalars(self):
ss1 = two_site_ss_subregular_ternary()
ss2 = two_site_ss_polynomial_ternary()
f0 = [0.25, 0.35, 0.4]
for ss in [ss1, ss2]:
ss.set_state(1.0e5, 300.0)
ss.set_composition(f0)
ss1_properties = [
ss1.gibbs,
ss1.H,
ss1.S,
ss1.V,
ss1.C_p,
ss1.C_v,
ss1.alpha,
ss1.K_T,
ss1.K_S,
ss1.gr,
]
ss2_properties = [
ss2.gibbs,
ss2.H,
ss2.S,
ss2.V,
ss2.C_p,
ss2.C_v,
ss2.alpha,
ss2.K_T,
ss2.K_S,
ss2.gr,
]
self.assertArraysAlmostEqual(ss1_properties, ss2_properties)
def test_polynomial_using_subregular_gibbs(self):
ss1 = two_site_ss_subregular_ternary()
ss2 = two_site_ss_polynomial_ternary()
f0 = [0.25, 0.35, 0.4]
for ss in [ss1, ss2]:
ss.set_state(1.0e5, 300.0)
ss.set_composition(f0)
self.assertArraysAlmostEqual(ss1.excess_partial_gibbs, ss2.excess_partial_gibbs)
self.assertArraysAlmostEqual(
ss1.gibbs_hessian.flatten(), ss2.gibbs_hessian.flatten()
)
def test_polynomial_using_subregular_entropy(self):
ss1 = two_site_ss_subregular_ternary()
ss2 = two_site_ss_polynomial_ternary()
f0 = [0.25, 0.35, 0.4]
for ss in [ss1, ss2]:
ss.set_state(1.0e5, 300.0)
ss.set_composition(f0)
self.assertArraysAlmostEqual(
ss1.excess_partial_entropies, ss2.excess_partial_entropies
)
self.assertArraysAlmostEqual(
ss1.entropy_hessian.flatten(), ss2.entropy_hessian.flatten()
)
def test_polynomial_using_subregular_volume(self):
ss1 = two_site_ss_subregular_ternary()
ss2 = two_site_ss_polynomial_ternary()
f0 = [0.25, 0.35, 0.4]
for ss in [ss1, ss2]:
ss.set_state(1.0e5, 300.0)
ss.set_composition(f0)
self.assertArraysAlmostEqual(
ss1.excess_partial_volumes, ss2.excess_partial_volumes
)
self.assertArraysAlmostEqual(
ss1.volume_hessian.flatten(), ss2.volume_hessian.flatten()
)
self.assertArraysAlmostEqual(ss1.partial_gibbs, ss2.partial_gibbs)
self.assertArraysAlmostEqual(ss1.partial_entropies, ss2.partial_entropies)
self.assertArraysAlmostEqual(ss1.partial_volumes, ss2.partial_volumes)
def test_polynomial_consistency(self):
ss = polynomial_esv_and_mbr_mixing_2()
ss.set_composition([0.4, 0.6])
self.assertTrue(check_eos_consistency(ss))
def test_polynomial_mbr_mixing(self):
ss1 = polynomial_mbr_mixing()
ss2 = regular_copy_polynomial_mbr_mixing()
f0 = [0.25, 0.75]
for ss in [ss1, ss2]:
ss.set_state(1.0e5, 300.0)
ss.set_composition(f0)
self.assertAlmostEqual(
ss1.excess_gibbs, 0.25 * 0.75 * (1200.0 - 300.0 * 5 + 1.0e5 * 1.0e-6)
)
self.assertAlmostEqual(ss1.excess_entropy, 0.25 * 0.75 * 5)
self.assertAlmostEqual(ss1.excess_volume, 0.25 * 0.75 * 1.0e-6)
self.assertArraysAlmostEqual(ss1.partial_gibbs, ss2.partial_gibbs)
self.assertArraysAlmostEqual(ss1.partial_entropies, ss2.partial_entropies)
self.assertArraysAlmostEqual(ss1.partial_volumes, ss2.partial_volumes)
def test_polynomial_ESV_and_mbr_mixing(self):
ss = polynomial_esv_and_mbr_mixing()
f0 = [0.25, 0.75]
ss.set_state(1.0e5, 300.0)
ss.set_composition(f0)
self.assertAlmostEqual(
ss.excess_gibbs, 0.25 * 0.75 * (1200.0 - 300.0 * 5 + 1.0e5 * 1.0e-6)
)
self.assertAlmostEqual(ss.excess_entropy, 0.25 * 0.75 * 5)
self.assertAlmostEqual(ss.excess_volume, 0.25 * 0.75 * 1.0e-6)
def test_polynomial_ternary_transformed(self):
ss1 = two_site_ss_polynomial_ternary()
ss2 = two_site_ss_polynomial_ternary_transformed()
for ss in [ss1, ss2]:
ss.set_state(1.0e5, 300.0)
f = np.array([0.25, 0.35, 0.4])
ss1.set_composition(f)
# roll forward to set composition
ss2.set_composition(np.roll(f, 1))
self.assertAlmostEqual(ss1.excess_gibbs, ss2.excess_gibbs)
# roll back to compare properties
self.assertArraysAlmostEqual(ss1.partial_gibbs, np.roll(ss2.partial_gibbs, -1))
self.assertArraysAlmostEqual(
ss1.partial_entropies, np.roll(ss2.partial_entropies, -1)
)
self.assertArraysAlmostEqual(
ss1.partial_volumes, np.roll(ss2.partial_volumes, -1)
)