Skip to content

Commit

Permalink
Merge pull request ComputationalThermodynamics#63 from NicolasRiel/main
Browse files Browse the repository at this point in the history
MAGEMin 1.3.3
  • Loading branch information
NicolasRiel authored Sep 25, 2023
2 parents d4b1e20 + 5923a44 commit 28b3d39
Show file tree
Hide file tree
Showing 127 changed files with 5,931 additions and 86,994 deletions.
Binary file modified PlotPseudosection.mlapp
Binary file not shown.
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
name = "MAGEMin_C"
uuid = "e5d170eb-415a-4524-987b-12f1bce1ddab"
authors = ["Boris Kaus <[email protected]> & Nicolas Riel <[email protected]>"]
version = "1.2.8"
version = "1.3.3"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
MAGEMin_jll = "763ebaa8-b0d2-5f6b-90ef-4fc23b5db1c4"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
CEnum = "0.4"
MAGEMin_jll = "1.3.1"
ProgressMeter = "1"
julia = "1.6"


8 changes: 8 additions & 0 deletions doc_raw/ckbk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ Pseudosection generator
:maxdepth: 2

ckbk/gui

Predefined bulk-rocks
=====================

.. toctree::
:maxdepth: 2

ckbk/predef
9 changes: 9 additions & 0 deletions doc_raw/ckbk/predef.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. MAGEMin documentation
List of pre-defined bulk-rock composition
=========================================

.. csv-table:: Table Title
:file: /figs/predefined_bulks.csv
:widths: 10, 50, 10, 20, 20, 20
:header-rows: 1
30 changes: 30 additions & 0 deletions doc_raw/figs/predefined_bulks.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
title,comments,test,oxide,frac,db
"FPWorldMedian pelite
Water oversaturated","Forshaw, J. B., & Pattison, D. R. (2023)",0,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, MnO, H2O","70.999, 12.805, 0.771, 3.978, 6.342, 2.7895, 1.481, 0.758, 0.72933, 0.075, 30.0",mp
"FPWorldMedian pelite
Water undersaturated","Forshaw, J. B., & Pattison, D. R. (2023)",1,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, MnO, H2O","70.999, 12.805, 0.771, 3.978, 6.342, 2.7895, 1.481, 0.758, 0.72933, 0.075, 5.0",mp
"Pelite
Water oversaturated","White et al., 2014, Fig 8",2,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, MnO, H2O","64.578, 13.651, 1.586, 5.529, 8.025, 2.943, 2.0, 0.907, 0.65, 0.175, 40.0",mp
"Pelite
Water
undersaturated","White et al., 2014, Fig 8",3,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, MnO, H2O","64.578, 13.651, 1.586, 5.529, 8.025, 2.943, 2.0, 0.907, 0.65, 0.175, 6.244",mp
"Garnet-migmatite
AV0832a","Riel et al., 2013",4,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, MnO, H2O","73.988, 8.6143, 2.0146, 2.7401, 3.8451, 1.7686, 2.482, 0.6393, 0.11, 0.063, 10.0",mp
"SM89
MORB composition","Sun & McDonough, 1989",0,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, H2O","52.47, 9.1, 12.21, 12.71, 8.15, 0.23, 2.61, 1.05, 1.47, 20.0",mb
"Natural amphibolite
LT Granulite",unpublished,1,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, H2O","51.08, 9.68, 13.26, 11.21, 11.66, 0.16, 0.79, 1.37, 0.8, 20.0",mb
"SQA
Synthetic amphibolite","Patino Douce & Beard, 1995",2,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, H2O","60.05, 6.62, 8.31, 9.93, 6.57, 0.44, 1.83, 1.27, 0.33, 4.64",mb
BL478: Sample 478,"Beard & Lofgren, 1991",3,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, H2O","53.96, 9.26, 10.15, 8.11, 10.14, 0.11, 2.54, 1.35, 0.98, 3.42",mb
"KLB1 Peridotite
Anhydrous","Holland et al., 2018",0,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, Cr2O3, H2O","38.494, 1.776, 2.824, 50.566, 5.886, 0.01, 0.25, 0.1, 0.096, 0.109, 0.0",ig
"RE46
Icelandic basalt","Yang et al., 1996",1,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, Cr2O3, H2O","50.72, 9.16, 15.21, 16.25, 7.06, 0.01, 1.47, 0.39, 0.35, 0.01, 0.0",ig
N_MORB - Basalt,"Gale et al., 2013",2,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, Cr2O3, H2O","53.21, 9.41, 12.21, 12.21, 8.65, 0.09, 2.9, 1.21, 0.69, 0.02, 0.0",ig
MIX1-G - Pyroxenite,"Hirschmann et al., 2003",3,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, Cr2O3, H2O","45.25, 8.89, 12.22, 24.68, 6.45, 0.03, 1.39, 0.67, 0.11, 0.02, 0.0",ig
High-Al basalt,"Baker, 1983",4,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, Cr2O3, H2O","54.4, 12.96, 11.31, 7.68, 8.63, 0.54, 3.93, 0.79, 0.41, 0.01, 0.0",ig
Tonalite 101,"Piwinskii, 1968",5,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, Cr2O3, H2O","66.01, 11.98, 7.06, 4.16, 5.3, 1.57, 4.12, 0.66, 0.97, 0.01, 50.0",ig
Wet Basalt,unpublished,6,"SiO2, Al2O3, CaO, MgO, FeOt, K2O, Na2O, TiO2, O, Cr2O3, H2O","50.081, 8.6901, 11.6698, 12.1438, 7.7832, 0.215, 2.4978, 1.0059, 0.467, 0.01, 5.4364",ig
Serpentine oxidized,"Evans & Forst, 2021",0,"SiO2, Al2O3, MgO, FeOt, O, H2O, S","20.044, 0.6256, 29.24, 3.149, 0.7324, 46.755, 0.3",um
Serpentine reduced,"Evans & Forst, 2021",1,"SiO2, Al2O3, MgO, FeOt, O, H2O, S","20.044, 0.6256, 29.24, 3.149, 0.1324, 46.755, 0.3",um
2 changes: 1 addition & 1 deletion doc_raw/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

|
**MAGEMin v1.3.2**
**MAGEMin v1.3.3**
==================

MAGEMin (Mineral Assemblage Gibbs Energy Minimization) is a parallel C library callable from any petrological/geodynamic tool. For a given set of pressure, temperature and bulk-rock composition MAGEMin uses a combination of linear programming, extended Partitioning Gibbs free Energy and gradient-based local minimization to compute the most stable mineral assemblage
Expand Down
197 changes: 117 additions & 80 deletions doc_raw/julia/Run.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. MAGEMin documentation
Single point calculation Tutorial
Serial point calculation Tutorial
=================================

First open a terminal and execute Julia, then type :literal:`using MAGEMin_C` to load the package.
Expand All @@ -12,22 +12,22 @@ Initialize database
*******************
.. code-block:: shell
db = "ig" # database: ig, igneous (Holland et al., 2018); mp, metapelite (White et al 2014b)
gv, z_b, DB, splx_data = init_MAGEMin(db);
# Initialize database - new way
db = "ig" # database: ig, igneous (Holland et al., 2018); mp, metapelite (White et al 2014b); um, ultramafic (Evans & Frost 2021)
data = Initialize_MAGEMin(db, verbose=true);
This initiatizes the global variables and the Database.

|
Set P-T-(pressure temperature)
**********************************************************
.. code-block:: shell
P = 8.
T = 800.
sys_in = "mol" # wt or mol, default is mol
test = 0;
gv = use_predefined_bulk_rock(gv, test, db)
P = 8.0
T = 800.0
:literal:`get_bulk_rock` retrieves the saved bulk-rock composition 0, which corresponds to KLB-1 peridotite.
:literal:`use_predefined_bulk_rock` retrieves the saved bulk-rock composition 0 from database ig, which corresponds to KLB-1 peridotite.

|
Expand All @@ -41,24 +41,52 @@ Use a pre-defined bulk-rock "test" composition
test = 0;
gv = use_predefined_bulk_rock(gv, test, db)
or a custom bulk-rock composition:

.. code-block:: shell
Xoxides = ["SiO2"; "Al2O3"; "CaO"; "MgO"; "FeO"; "Fe2O3"; "K2O"; "Na2O"; "TiO2"; "Cr2O3"; "H2O"];
X = [48.43; 15.19; 11.57; 10.13; 6.65; 1.64; 0.59; 1.87; 0.68; 0.0; 3.0];
sys_in = "wt"
Note that the system unit :literal:`[mol,wt]` has to be provided here.

where :literal:`Xoxides` is a :literal:`Vector(String)` containing the oxide names and :literal:`X` is a :literal:`Vector(Float)` of the :literal:`[mol,wt]` fraction of the bulk-rock composition.
The function converts

:literal:`SiO2`, ..., :literal:`FeO` and :literal:`Fe2O3` in system unit :literal:`[mol,wt]`

to:

:literal:`SiO2`, ..., :literal:`FeOt` and :literal:`O` in system unit :literal:`[mol]`.

Note that if the provided bulk-rock composition includes more oxides than supported, they will be ignored and the composition will be renormalized accordingly. Moreover, if both :literal:`Fe2O3` and :literal:`O` are provided, :literal:`O` will be recalculated as function of :literal:`Fe2O3`. Thus, if you want to prescribe a different :literal:`O` content, do not define :literal:`Fe2O3`!

|
Set the level of verbose :literal:`[-1,0,1]`
********************************************
Set the level of verbose :literal:`[false,true,1]`
**************************************************
.. code-block:: shell
gv.verbose = -1 # switch off any verbose
gv.verbose = false # switch off any verbose
:literal:`-1`, none; :literal:`0`, stable phase assemblage; :literal:`1`, full verbose. By default :literal:`gv.verbose` = 0.
:literal:`false`, none; :literal:`true`, stable phase assemblage; :literal:`1`, full verbose. By default :literal:`gv.verbose` = true.

|
Call optimization routine for given P-T-X
*****************************************
.. code-block:: shell
gv.verbose = -1 # switch off any verbose
out = point_wise_minimization(P,T, gv, z_b, DB, splx_data, sys_in)
out = single_point_minimization(P, T, data, test=0);
if a predefined test is used (see :doc:`/ckbk/predef`) or:

.. code-block:: shell
out = single_point_minimization(P, T, data, X=X, Xoxides=Xoxides, sys_in=sys_in)
if a custom bulk-rock composition is provided.

|
Expand Down Expand Up @@ -104,111 +132,120 @@ The full description of what contains the output structure is given in the CookB

|
Provide custom bulk rock composition
====================================

Examples of serial point calculation
************************************

To define and use your own bulk rock composition we provide a routine that converts bulk-rock composition into the right MAGEMin format.

* For the igneous database:

.. code-block:: shell
bulk_in_ox = ["SiO2"; "Al2O3"; "CaO"; "MgO"; "FeO"; "Fe2O3"; "K2O"; "Na2O"; "TiO2"; "Cr2O3"; "H2O"]
bulk_in = [48.43; 15.19; 11.57; 10.13; 6.65; 1.64; 0.59; 1.87; 0.68; 0.0; 3.0]
sys_in = "wt"
db = "ig" # database: ig, igneous (Holland et al., 2018); mp, metapelite (White et al 2014b)
gv = define_bulk_rock(gv, bulk_in, bulk_in_ox, sys_in, db);
* For the metapelite database
#load MAGEMin
using MAGEMin_C
.. code-block:: shell
data = Initialize_MAGEMin("ig", verbose=false);
bulk_in_ox = ["SiO2"; "Al2O3"; "CaO"; "MgO"; "FeO"; "Fe2O3"; "K2O"; "Na2O"; "TiO2"; "MnO"; "H2O"]
bulk_in = [69.64; 13.76; 1.77; 1.73; 4.32; 0.4; 2.61; 2.41; 0.80; 0.07; 10.0]
sys_in = "wt"
db = "mp" # database: ig, igneous (Holland et al., 2018); mp, metapelite (White et al 2014b)
# One bulk rock for all points
P,T = 10.0, 1100.0
Xoxides = ["SiO2"; "Al2O3"; "CaO"; "MgO"; "FeO"; "Fe2O3"; "K2O"; "Na2O"; "TiO2"; "Cr2O3"; "H2O"];
X = [48.43; 15.19; 11.57; 10.13; 6.65; 1.64; 0.59; 1.87; 0.68; 0.0; 3.0];
sys_in = "wt"
out = single_point_minimization(P, T, data, X=X, Xoxides=Xoxides, sys_in=sys_in)
Finalize_MAGEMin(data)
gv = define_bulk_rock(gv, bulk_in, bulk_in_ox, sys_in, db);
for the metapelite database:

.. code-block:: shell
where :literal:`bulk_in_ox` is a :literal:`Vector(String)` containing the oxide names and :literal:`bulk_in` is a :literal:`Vector(Float)` of the :literal:`[mol,wt]` fraction of the bulk-rock composition.
The function converts
#load MAGEMin
using MAGEMin_C
:literal:`SiO2`, ..., :literal:`FeO` and :literal:`Fe2O3` in system unit :literal:`[mol,wt]`

to:

:literal:`SiO2`, ..., :literal:`FeOt` and :literal:`O` in system unit :literal:`[mol]`.
#initialize
data = Initialize_MAGEMin("mp", verbose=false);
Note that if the provided bulk-rock composition includes more oxides than supported, they will be ignored and the composition will be renormalized accordingly. Moreover, if both :literal:`Fe2O3` and :literal:`O` are provided, :literal:`O` will be recalculated as function of :literal:`Fe2O3`. Thus, if you want to prescribe a different :literal:`O` content, do not define :literal:`Fe2O3`!
# provide bulk-rock composition
P,T = 2.0, 650.0
Xoxides = ["SiO2"; "Al2O3"; "CaO"; "MgO"; "FeO"; "Fe2O3"; "K2O"; "Na2O"; "TiO2"; "MnO"; "H2O"]
X = [69.64; 13.76; 1.77; 1.73; 4.32; 0.4; 2.61; 2.41; 0.80; 0.07; 10.0]
sys_in = "wt"
out = single_point_minimization(P, T, data, X=X, Xoxides=Xoxides, sys_in=sys_in)
Finalize_MAGEMin(data)
A full Julia script demonstrating how to use this function is provided below:
for the ultramafic database:

.. code-block:: shell
#load MAGEMin
using MAGEMin_C
#initialize
db = "ig" # database: ig, igneous (Holland et al., 2018); mp, metapelite (White et al 2014b)
gv, z_b, DB, splx_data = init_MAGEMin(db);
data = Initialize_MAGEMin("um", verbose=false);
# provide bulk-rock composition
bulk_in_ox = ["SiO2"; "Al2O3"; "CaO"; "MgO"; "FeO"; "Fe2O3"; "K2O"; "Na2O"; "TiO2"; "Cr2O3"; "H2O"];
bulk_in = [48.43; 15.19; 11.57; 10.13; 6.65; 1.64; 0.59; 1.87; 0.68; 0.0; 3.0];
sys_in = "wt"
P,T = 2.0, 650.0
out = single_point_minimization(P, T, data, test=0)
Finalize_MAGEMin(data)
# convert bulk rock
gv = define_bulk_rock(gv, bulk_in, bulk_in_ox, sys_in, db);
# provide pressure and temperature conditions
P,T = 10.0, 1100.0;
# switch off any verbose
gv.verbose = -1
Parallel point calculation Tutorial
===================================

# perform minimization
out = point_wise_minimization(P,T, gv, z_b, DB, splx_data, sys_in)
To compute a list of single point calculation in parallel your can use the native Julia multi-threading. To activate multi-threading simply launch the Julia terminal as:

# print output
print_info(out)
.. code-block:: shell
# free memory
finalize_MAGEMin(gv,DB)
julia -t 4
of for the metapelite database:
or

.. code-block:: shell
julia --threads 4
where the number of threads depends on your system, generally twice the number of cores.

|
Examples of serial point calculation
************************************

To run :literal:`n` points, using database :literal:`ig` and :literal:`test 0` (see :doc:`/ckbk/predef`):

.. code-block:: shell
#load MAGEMin
using MAGEMin_C
#initialize
db = "mp" # database: ig, igneous (Holland et al., 2018); mp, metapelite (White et al 2014b)
gv, z_b, DB, splx_data = init_MAGEMin(db);
data = Initialize_MAGEMin("ig", verbose=false);
n = 100;
P = fill(8.0,n)
T = fill(800.0,n)
out = multi_point_minimization(P, T, data, test=1);
Finalize_MAGEMin(data)
# provide bulk-rock composition
bulk_in_ox = ["SiO2"; "Al2O3"; "CaO"; "MgO"; "FeO"; "Fe2O3"; "K2O"; "Na2O"; "TiO2"; "MnO"; "H2O"]
bulk_in = [69.64; 13.76; 1.77; 1.73; 4.32; 0.4; 2.61; 2.41; 0.80; 0.07; 10.0]
sys_in = "wt"
Here the results are stored in :literal:`out` as :literal:`out[1:end]`. Various bulk-rock compositions can be prescribed as:

# convert bulk rock
gv = define_bulk_rock(gv, bulk_in, bulk_in_ox, sys_in, db);
.. code-block:: shell
# provide pressure and temperature conditions
P,T = 4.0, 800.0;
#load MAGEMin
using MAGEMin_C
# switch off any verbose
gv.verbose = -1
#initialize
data = Initialize_MAGEMin("ig", verbose=false);
# perform minimization
out = point_wise_minimization(P,T, gv, z_b, DB, splx_data, sys_in)
#set P-T-X conditions
P = [10.0, 10.0];
T = [1100.0, 1100.0];
Xoxides = ["SiO2"; "Al2O3"; "CaO"; "MgO"; "FeO"; "Fe2O3"; "K2O"; "Na2O"; "TiO2"; "Cr2O3"; "H2O"];
X1 = [48.43; 15.19; 11.57; 10.13; 6.65; 1.64; 0.59; 1.87; 0.68; 0.0; 3.0];
X2 = [49.43; 14.19; 11.57; 10.13; 6.65; 1.64; 0.59; 1.87; 0.68; 0.0; 3.0];
X = [X1,X2];
sys_in = "wt"
out = multi_point_minimization(P, T, data, X=X, Xoxides=Xoxides, sys_in=sys_in)
# print output
print_info(out)
# free memory
finalize_MAGEMin(gv,DB)
Other examples
==============

Several additional tests are provided in :literal:`./test/runtests.jl`.
Loading

0 comments on commit 28b3d39

Please sign in to comment.