MagmaForge: Fractional Crystallization#

Demonstrates how to run an equilibrium crystallization routine using MagmaForge.

Open this code in an executable MyBinder instance (MyBinder links may be slow to load– please be patient!):

https://mybinder.org/badge_logo.svg

Initialization#

Import necessary packages:

from thermoengine import magmaforge

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

Define a bulk composition:

morb_oxides = pd.Series({
            'SiO2':  48.68,
            'TiO2':   1.01,
            'Al2O3': 17.64,
            'Fe2O3':  0.89,
            'Cr2O3':  0.0425,
            'FeO':    7.59,
            'MgO':    9.10,
            'CaO':   12.45,
            'Na2O':   2.65,
            'K2O':    0.03,
            'P2O5':   0.08,
            'H2O':    0.2},)

System and Calculations#

Define system using magmaforge:

sys = magmaforge.System(comp=morb_oxides,
                        T_liquidus=True,
                        P_bar=1000.0,
                        logfO2 = ('QFM', -1),
                        database='MELTS_v1_0',
                        )
/workspaces/ThermoEngineLite/thermoengine/thermoengine/magmaforge/system.py:259: UserWarning: Warning: Setting an fO2 value will redistribute the FeO and Fe2O3 values given.
  warnings.warn('Warning: Setting an fO2 value will redistribute the FeO and Fe2O3 values given.')

Crystallize system:

sys.crystallize(method='frac',
                T_step=4,
                fix_fO2=True,
                T_final_C = 1000
                )
<thermoengine.magmaforge.system.System object at 0xffff8347c710>

Output#

Phase mass table (with solid masses reported prior to fractionation)

tbl = sys.history.get_phase_mass_table(phases='present', prior_to_fractionation=True)

tbl
Liquid Olivine Feldspar Clinopyroxene Spinel
1503.086379 100.361498 0.000000 0.000000 0.000000 0.000000
1499.086379 100.350385 0.000000 0.000000 0.000000 0.011318
1495.086379 99.657206 0.000000 0.684155 0.000000 0.009300
1491.086379 97.368749 0.250292 2.041873 0.000000 0.003024
1487.086379 92.683198 1.253080 3.454072 0.000000 0.000000
1483.086379 88.481843 1.135702 3.111499 0.000000 0.000000
1479.086379 84.693706 1.025929 2.803563 0.000000 0.000000
1475.086379 81.260093 0.931730 2.539157 0.000000 0.000000
1471.086379 77.248135 0.771180 2.430287 0.844636 0.000000
1467.086379 72.169175 0.545663 2.367123 2.205566 0.001152
1463.086379 67.703759 0.477050 2.087489 1.943776 0.008353
1459.086379 63.757664 0.424159 1.856001 1.703370 0.007698
1455.086379 60.244818 0.380231 1.662463 1.502849 0.007113
1451.086379 57.097035 0.343372 1.499026 1.334103 0.006650
1447.086379 54.259668 0.312207 1.359747 1.190755 0.006289
1443.086379 51.688283 0.285628 1.240117 1.068078 0.006019
1439.086379 49.346544 0.262860 1.136579 0.962212 0.005829
1435.086379 47.204291 0.243212 1.046389 0.870335 0.005716
1431.086379 45.236388 0.226208 0.967330 0.790050 0.005682
1427.086379 43.421580 0.211395 0.897662 0.719607 0.005738
1423.086379 41.741834 0.198480 0.835944 0.657456 0.005907
1419.086379 40.181584 0.187156 0.781038 0.602494 0.006235
1415.086379 38.727212 0.177197 0.732018 0.553814 0.006810
1411.086379 37.366450 0.168405 0.688173 0.510788 0.007802
1407.086379 36.087671 0.160560 0.649016 0.473149 0.009531
1403.086379 34.879187 0.153452 0.614297 0.440920 0.012492
1399.086379 33.729006 0.146860 0.583907 0.414216 0.017207
1395.086379 32.625339 0.140604 0.557718 0.392851 0.023968
1391.086379 31.557089 0.134515 0.535535 0.376400 0.032869
1387.086379 30.513362 0.128423 0.517270 0.364619 0.044202
1383.086379 29.479308 0.121883 0.503843 0.359125 0.059839
1379.086379 28.402048 0.112208 0.504521 0.376581 0.094719
1375.086379 27.003417 0.083641 0.575549 0.514351 0.237353
1371.086379 25.504282 0.066004 0.596147 0.550037 0.303037
1367.086379 24.191993 0.067415 0.544188 0.460854 0.256711
1363.086379 23.040997 0.069143 0.496708 0.384828 0.215091
1359.086379 22.019506 0.070331 0.456783 0.324800 0.182521
1355.086379 21.103773 0.071227 0.422821 0.276540 0.156613
1351.086379 20.275694 0.071996 0.393591 0.237079 0.135676
1347.086379 19.521187 0.072710 0.368168 0.204365 0.118525
1343.086379 18.829123 0.073412 0.345838 0.176924 0.104307
1339.086379 18.190577 0.074097 0.326044 0.153706 0.092400
1335.086379 17.598305 0.074750 0.308344 0.133928 0.082336
1331.086379 17.046364 0.075341 0.292384 0.117005 0.073763
1327.086379 16.529842 0.075836 0.277880 0.102487 0.066407
1323.086379 16.044649 0.076203 0.264601 0.090014 0.060054
1319.086379 15.587361 0.076420 0.252360 0.079290 0.054535
1315.086379 15.155100 0.076471 0.241008 0.070063 0.049715
1311.086379 14.745432 0.076352 0.230421 0.062119 0.045483
1307.086379 14.356292 0.076056 0.220501 0.055279 0.041751
1303.086379 13.985920 0.075582 0.211167 0.049387 0.038448
1299.086379 13.632804 0.074943 0.202352 0.044305 0.035512
1295.086379 13.295644 0.074141 0.194003 0.039923 0.032894
1291.086379 12.973304 0.073192 0.186079 0.036137 0.030552
1287.086379 12.664782 0.072098 0.178556 0.032868 0.028454
1283.086379 12.369205 0.070881 0.171389 0.030039 0.026567
1279.086379 12.085805 0.069544 0.164549 0.027596 0.024867
1275.086379 11.813895 0.068095 0.158016 0.025489 0.023333
1271.086379 11.552853 0.066558 0.151770 0.023667 0.021945


Magma Evolution plot

magmaforge.plot.magma_evolution(sys.history, prior_to_fractionation=True)
plot magmaforge crystallization frac

If you want to specify the color for each phase, you can assign them via a dictionary:

phase_colors = {'Spinel': 'gray',
                'Feldspar': 'tan',
                'Olivine': 'springgreen',
                'Clinopyroxene' : 'green',
                'Orthopyroxene': 'darkolivegreen'}

magmaforge.plot.magma_evolution(sys.history, phase_colors=phase_colors, prior_to_fractionation=True)
plot magmaforge crystallization frac

Return useful output variables#

The following commands demonstrate examples of how to return properties for all states in system’s history. Other properties can be accessed as well– see https://thermoenginelite.readthedocs.io/en/latest/api/magmaforge_system.html for more information.

T = sys.history.get_temperatures(unit='C')
P = sys.history.get_pressures(unit='bar')
logfO2 = sys.history.get_logfO2s(buffer='QFM')
liq_comp = sys.history.get_phase_comps(phase_name='Liquid', unit='wt_oxides')
phase_frac_table = sys.history.get_phase_frac_table(phases='present')

print(T) # replace with whichever variable you would like to access
[1229.93637935 1225.93637935 1221.93637935 1217.93637935 1213.93637935
 1209.93637935 1205.93637935 1201.93637935 1197.93637935 1193.93637935
 1189.93637935 1185.93637935 1181.93637935 1177.93637935 1173.93637935
 1169.93637935 1165.93637935 1161.93637935 1157.93637935 1153.93637935
 1149.93637935 1145.93637935 1141.93637935 1137.93637935 1133.93637935
 1129.93637935 1125.93637935 1121.93637935 1117.93637935 1113.93637935
 1109.93637935 1105.93637935 1101.93637935 1097.93637935 1093.93637935
 1089.93637935 1085.93637935 1081.93637935 1077.93637935 1073.93637935
 1069.93637935 1065.93637935 1061.93637935 1057.93637935 1053.93637935
 1049.93637935 1045.93637935 1041.93637935 1037.93637935 1033.93637935
 1029.93637935 1025.93637935 1021.93637935 1017.93637935 1013.93637935
 1009.93637935 1005.93637935 1001.93637935  997.93637935]

If you wish to save the full state history, you can do so with the .save_full_state_history_table() method. Soon, you will be able to reload this table into MagmaForge to access its properties.

sys.history.save_full_state_history_table(filename='magmaforge_output.csv', P_unit='bar', T_unit='K', fO2_buffer='QFM')

Total running time of the script: (0 minutes 21.875 seconds)

Gallery generated by Sphinx-Gallery