Skip to content

Commit

Permalink
MAGEMin_v1.6.1
Browse files Browse the repository at this point in the history
- Added frac_M_vol, frac_F_vol and frac_S_vol output for MAGEMin_C
- Corrected wrong set of W's for spinel in the metapelite and metapelite extended database
- Added molar mass of CO2 for MAGEMin_C (which was leading to failed mpe bulk loading in the App)
  • Loading branch information
NicolasRiel authored Dec 2, 2024
2 parents e2ec98a + 93b22ec commit c60b621
Show file tree
Hide file tree
Showing 24 changed files with 355 additions and 116 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MAGEMin_C"
uuid = "e5d170eb-415a-4524-987b-12f1bce1ddab"
authors = ["Boris Kaus <[email protected]> & Nicolas Riel <[email protected]>"]
version = "1.6.0"
version = "1.6.1"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
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.6.0**
**MAGEMin v1.6.1**
==================

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
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MAGEMin v1.6.0 &mdash; MAGEMin 2022 documentation</title>
<title>MAGEMin v1.6.1 &mdash; MAGEMin 2022 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
Expand Down Expand Up @@ -247,7 +247,7 @@
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="#" class="icon icon-home"></a> &raquo;</li>
<li><strong>MAGEMin v1.6.0</strong></li>
<li><strong>MAGEMin v1.6.1</strong></li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
</li>
Expand All @@ -263,7 +263,7 @@
<div class="line"><br /></div>
</div>
<section id="magemin-v1-5-0">
<h1><strong>MAGEMin v1.6.0</strong><a class="headerlink" href="#magemin-v1-5-0" title="Permalink to this headline"></a></h1>
<h1><strong>MAGEMin v1.6.1</strong><a class="headerlink" href="#magemin-v1-5-0" title="Permalink to this headline"></a></h1>
<p>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</p>
<p>A full description of the minimization approach used in MAGEMin is given in:</p>
<p>Riel, N., Kaus, B. J. P., Green, E. C. R., &amp; Berlie, N. (2022). MAGEMin, an efficient Gibbs energy minimizer: Application to igneous systems. Geochemistry, Geophysics, Geosystems, 23, e2022GC010427. <a class="reference external" href="https://doi.org/10.1029/2022GC010427">https://doi.org/10.1029/2022GC010427</a></p>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/stp.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="External libraries" href="stp/Linux.html" />
<link rel="prev" title="MAGEMin v1.6.0" href="index.html" />
<link rel="prev" title="MAGEMin v1.6.1" href="index.html" />
</head>

<body class="wy-body-for-nav">
Expand Down Expand Up @@ -292,7 +292,7 @@ <h1>Optional (developers)<a class="headerlink" href="#optional-developers" title
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="index.html" class="btn btn-neutral float-left" title="MAGEMin v1.6.0" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="index.html" class="btn btn-neutral float-left" title="MAGEMin v1.6.1" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="stp/Linux.html" class="btn btn-neutral float-right" title="External libraries" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>

Expand Down
9 changes: 6 additions & 3 deletions gen/magemin_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1177,10 +1177,13 @@ struct stb_systems
rho_F::Cdouble
bulk_S_wt::Ptr{Cdouble}
frac_S_wt::Cdouble
frac_S_vol::Cdouble
bulk_M_wt::Ptr{Cdouble}
frac_M_wt::Cdouble
frac_M_vol::Cdouble
bulk_F_wt::Ptr{Cdouble}
frac_F_wt::Cdouble
frac_F_vol::Cdouble
n_ph::Cint
n_PP::Cint
n_SS::Cint
Expand Down Expand Up @@ -1323,7 +1326,7 @@ mutable struct metapelite_datasets
n_pp::Cint
n_ss::Cint
ox::NTuple{11, NTuple{20, Cchar}}
PP::NTuple{23, NTuple{20, Cchar}}
PP::NTuple{24, NTuple{20, Cchar}}
SS::NTuple{18, NTuple{20, Cchar}}
verifyPC::NTuple{18, Cint}
n_SS_PC::NTuple{18, Cint}
Expand All @@ -1349,7 +1352,7 @@ mutable struct metabasite_datasets
n_pp::Cint
n_ss::Cint
ox::NTuple{10, NTuple{20, Cchar}}
PP::NTuple{23, NTuple{20, Cchar}}
PP::NTuple{24, NTuple{20, Cchar}}
SS::NTuple{17, NTuple{20, Cchar}}
verifyPC::NTuple{17, Cint}
n_SS_PC::NTuple{17, Cint}
Expand Down Expand Up @@ -1505,7 +1508,7 @@ mutable struct metapelite_datasets_ext
n_pp::Cint
n_ss::Cint
ox::NTuple{13, NTuple{20, Cchar}}
PP::NTuple{25, NTuple{20, Cchar}}
PP::NTuple{26, NTuple{20, Cchar}}
SS::NTuple{23, NTuple{20, Cchar}}
verifyPC::NTuple{23, Cint}
n_SS_PC::NTuple{23, Cint}
Expand Down
20 changes: 14 additions & 6 deletions julia/MAGEMin_wrappers.jl

Large diffs are not rendered by default.

Binary file modified ref_database/.DS_Store
Binary file not shown.
52 changes: 52 additions & 0 deletions ref_database/TC_ref_database/aq_min.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#=
Test for Aqueous minimizer
=#

species = ["H2O", "Al(OH)2+", "Al(OH)3@", "Al(OH)4-", "Al+3", "AlH3SiO4+2", "AlOH+2", "Ca+2", "CaHSiO3+", "CaOH+", "CaSiO3@", "HSiO3-", "K+", "KAlO2@", "KOH@", "Mg+2", "MgHSiO3+", "MgOH+", "MgSiO3@", "Na+", "NaAl(OH)4@", "NaHSiO3@", "NaOH@", "OH-", "SiO2@"]
G0s = [-378.991999, -1012.553295, -1405.559155, -1669.882646, -260.382070, -2061.778806, -641.559594, -536.589068, -1772.464205, -761.449349, -1705.193764, -1154.160844, -375.639412, -1280.307808, -585.973831, -400.958279, -1617.254393, -701.376817, -1567.329979, -350.424257, -2035.360551, -1485.410150, -563.302949, -179.482769, -970.840788]

oxide_names = ["SiO2", "Al2O3", "CaO", "MgO", "FeO", "K2O", "Na2O", "TiO2", "O", "MnO", "H2O"]
gamma_pc = [-966.661516, -1766.267094, -808.803681, -688.195348, -369.432486, -936.439987, -876.096639, -1018.881760, -238.219822, -526.537851, -379.011475]

matrix = [ 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0;
0.0 0.5 0.0 0.0 0.0 0.0 0.0 0.0 -0.5 0.0 1.0;
0.0 0.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.5;
0.0 0.5 0.0 0.0 0.0 0.0 0.0 0.0 0.5 0.0 2.0;
0.0 0.5 0.0 0.0 0.0 0.0 0.0 0.0 -1.5 0.0 0.0;
1.0 0.5 0.0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

G_H2 = (G0s[id_H2O] - G0s[id_OHm])
70 changes: 70 additions & 0 deletions ref_database/TC_ref_database/aqueous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Aqueous species formulation, using Miron et al., 2017 database.


```math
G_{aq} = \sum_{i=1}^{n^{em}} n_i \mu_i
```

where $n_i$ the molar fraction and $\mu_i$ is the chemical potential of the species $i$.

```math
\mu_i = G_i^0 + RT ln(\gamma_i m_i)
```

where $m_i$ is the molal fraction (!?)

And then develops into:



```math
\mu_i = G_i^0 + RT( ln(\gamma_i) + ln(m_i))
```

```math
\mu_i = G_i^0 + RT( ln(\gamma_i) + ln(\frac{n_i}{n_{H2O} M_{H2O}}))
```

```math
\mu_i = G_i^0 + RT( ln(\gamma_i) + ln(\frac{n_i}{18.015 * n_{H2O}}))
```


---

For solute (aqueous species, excluding water), and assuming $\gamma_i$ = 1 (for now)

```math
\mu_i = G_i^0 + RT ln(m_i)
```

where

```math
m_i = \frac{n_i}{m_{H2O}}
```

so here $n_i$ is again the molar fraction and $m_{H2O}$ is mass of water? Should it be water density?

I could find the following definition:

```math
m_i = \frac{n_i}{n_{H2O} M_{H2O}}
```
and here $n_i$ is the molarity and $M_{H2O}$ is the Molar mass of water (18.015). However, here density of water like we discussed is not appearing, is that right?

Should it simply be:

```math
m_i = \frac{n_i}{\rho_{H2O}}
```

---

For solvant (water):

```math
\mu_{H2O} = G_{H2O }^0 + RT ln(\frac{1}{M_{H2O}})
```

!?
2 changes: 1 addition & 1 deletion src/MAGEMin.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ global_variable SetupDatabase( global_variable gv,

}

if (gv.verbose == 1){
if (gv.verbose == 2){
printf("\n");
printf("--verbose : verbose = %i \n", gv.verbose );
printf("--rg : research group = %s \n", gv.research_group );
Expand Down
8 changes: 4 additions & 4 deletions src/MAGEMin.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,10 @@ typedef struct stb_systems {
double *bulk_M; double frac_M; double rho_M; /* Melt system informations */
double *bulk_F; double frac_F; double rho_F; /* Fluid system informations */

double *bulk_S_wt; double frac_S_wt; /* Solid system informations */
double *bulk_M_wt; double frac_M_wt; /* Melt system informations */
double *bulk_F_wt; double frac_F_wt; /* Fluid system informations */
double *bulk_S_wt; double frac_S_wt; double frac_S_vol; /* Solid system informations */
double *bulk_M_wt; double frac_M_wt; double frac_M_vol; /* Melt system informations */
double *bulk_F_wt; double frac_F_wt; double frac_F_vol; /* Fluid system informations */

int n_ph; /* number of predicted stable phases */
int n_PP; /* number of predicted stable pure phases */
int n_SS; /* number of predicted stable solution phases */
Expand Down
2 changes: 1 addition & 1 deletion src/TC_database/NLopt_opt_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -7718,7 +7718,7 @@ SS_ref NLopt_opt_aq17_function(global_variable gv, SS_ref SS_ref_db){
SS_ref_db.ub[i] = SS_ref_db.bounds[i][1];
}

SS_ref_db.opt = nlopt_create(NLOPT_LN_COBYLA, (n));
SS_ref_db.opt = nlopt_create(NLOPT_LD_SLSQP, (n));
nlopt_set_lower_bounds(SS_ref_db.opt, SS_ref_db.lb);
nlopt_set_upper_bounds(SS_ref_db.opt, SS_ref_db.ub);
nlopt_set_min_objective(SS_ref_db.opt, obj_aq17, &SS_ref_db);
Expand Down
4 changes: 2 additions & 2 deletions src/TC_database/TC_gem_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,11 +1035,11 @@ PP_ref G_FS_function( int len_ox,
PP_ref_db.factor = factor;
PP_ref_db.phase_shearModulus = 0.0;

// printf(" %4s %+10f | factor: %+10f\n",name,PP_ref_db.gbase,PP_ref_db.factor);
// printf(" %4s %+10f %+10f | factor: %+10f\n",name,G,PP_ref_db.gbase,PP_ref_db.factor);
// for (i = 0; i < len_ox; i++){
// printf("%+10f",PP_ref_db.Comp[i]*PP_ref_db.factor);
// }
// printf("\n");
// printf("\n\n");

return (PP_ref_db);
}
12 changes: 6 additions & 6 deletions src/TC_database/TC_init_database.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ oxide_data oxide_info = {
metapelite_dataset metapelite_db = {
62, /* Endmember default dataset number */
11, /* number of oxides */
23, /* number of pure phases */
24, /* number of pure phases */
17, /* number of solution phases */
{"SiO2" ,"Al2O3","CaO" ,"MgO" ,"FeO" ,"K2O" ,"Na2O" ,"TiO2" ,"O" ,"MnO" ,"H2O" },
{"q" ,"crst" ,"trd" ,"coe" ,"stv" ,"ky" ,"sill" ,"and" ,"ru" ,"sph" ,"O2" ,"H2O" ,
{"q" ,"crst" ,"trd" ,"coe" ,"stv" ,"ky" ,"sill" ,"and" ,"ru" ,"sph" ,"O2" ,"H2O" ,"zo" ,
"qfm" ,"qif" ,"nno" ,"hm" ,"cco" ,"aH2O" , "aO2" ,"aMgO" ,"aFeO" ,"aAl2O3" ,"aTiO2" },
{"liq" ,"fsp" ,"bi" ,"g" ,"ep" ,"ma" ,"mu" ,"opx" ,"sa" ,"cd" ,"st" ,"chl" ,"ctd" ,"sp" ,"mt" ,"ilm" ,"ilmm" ,"aq17" },

Expand All @@ -63,10 +63,10 @@ metapelite_dataset metapelite_db = {
metabasite_dataset metabasite_db = {
62, /* Endmember default dataset number */
10, /* number of oxides */
23, /* number of pure phases */
24, /* number of pure phases */
17, /* number of solution phases */
{"SiO2" ,"Al2O3","CaO" ,"MgO" ,"FeO" ,"K2O" ,"Na2O" ,"TiO2" ,"O" ,"H2O" },
{"q" ,"crst" ,"trd" ,"coe" ,"law" ,"ky" ,"sill" ,"and" ,"ru" ,"sph" ,"ab" ,"H2O" ,
{"q" ,"crst" ,"trd" ,"coe" ,"law" ,"ky" ,"sill" ,"and" ,"ru" ,"sph" ,"ab" ,"H2O" ,"zo" ,
"qfm" ,"qif" ,"nno" ,"hm" ,"cco" ,"aH2O" ,"aO2" ,"aMgO" ,"aFeO" ,"aAl2O3" ,"aTiO2" },
{"sp" ,"opx" ,"fsp" ,"liq" ,"mu" ,"ilmm" ,"ilm" ,"ol" ,"hb" ,"ep" ,"g" ,"chl" ,"bi" ,"dio" ,"aug" ,"abc" ,"spn" },

Expand Down Expand Up @@ -232,10 +232,10 @@ mantle_dataset mantle_db = {
metapelite_dataset_ext metapelite_ext_db = {
62, /* Endmember default dataset number */
13, /* number of oxides */
25, /* number of pure phases */
26, /* number of pure phases */
23, /* number of solution phases */
{"SiO2" ,"Al2O3","CaO" ,"MgO" ,"FeO" ,"K2O" ,"Na2O" ,"TiO2" ,"O" ,"MnO" ,"H2O" ,"CO2" ,"S" },
{"q" ,"crst" ,"trd" ,"coe" ,"stv" ,"ky" ,"sill" ,"and" ,"ru" ,"sph" ,"O2" ,"pyr" ,"gph" ,"law" ,
{"q" ,"crst" ,"trd" ,"coe" ,"stv" ,"ky" ,"sill" ,"and" ,"ru" ,"sph" ,"O2" ,"pyr" ,"gph" ,"law" ,"zo" ,
"qfm" ,"qif" ,"nno" ,"hm" ,"cco" ,"aH2O" , "aO2" ,"aMgO" ,"aFeO" ,"aAl2O3" ,"aTiO2" },
{"liq" ,"fsp" ,"bi" ,"g" ,"ep" ,"ma" ,"mu" ,"opx" ,"sa" ,"cd" ,"st" ,"chl" ,"ctd" ,"sp" ,"mt" ,"ilm" ,"ilmm" ,"occm" ,"fl" ,"po" ,"dio" ,"aug" ,"hb" },

Expand Down
6 changes: 3 additions & 3 deletions src/TC_database/TC_init_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
int n_pp;
int n_ss;
char ox[11][20];
char PP[23][20];
char PP[24][20];
char SS[18][20];

int verifyPC[18];
Expand Down Expand Up @@ -54,7 +54,7 @@
int n_pp;
int n_ss;
char ox[10][20];
char PP[23][20];
char PP[24][20];

char SS[17][20];
int verifyPC[17];
Expand Down Expand Up @@ -246,7 +246,7 @@
int n_pp;
int n_ss;
char ox[13][20];
char PP[25][20];
char PP[26][20];
char SS[23][20];

int verifyPC[23];
Expand Down
Loading

0 comments on commit c60b621

Please sign in to comment.