Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAGEMin_C v1.5.7 #55

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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.5.6"
version = "1.5.7"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand All @@ -17,6 +17,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
CEnum = "0.4"
DataFrames = "1.6.1"
CSV = "0.10.14"
MAGEMin_jll = "1.5.2 - 1.5.2"
MAGEMin_jll = "1.5.3 - 1.5.3"
ProgressMeter = "1"
julia = "1.6"
10 changes: 8 additions & 2 deletions gen/epilogue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct SS_data
Vs::Cdouble
Comp::Vector{Cdouble}
Comp_wt::Vector{Cdouble}
Comp_apfu::Vector{Cdouble}
compVariables::Vector{Cdouble}
compVariablesNames::Vector{String}
siteFractions::Vector{Cdouble}
Expand All @@ -29,12 +30,14 @@ struct SS_data
emChemPot::Vector{Cdouble}
emComp::Vector{Vector{Float64}}
emComp_wt::Vector{Vector{Float64}}
emComp_apfu::Vector{Vector{Float64}}
end

function Base.convert(::Type{SS_data}, a::stb_SS_phases)
return SS_data(a.f, a.G, a.deltaG, a.V, a.alpha, a.entropy, a.enthalpy, a.cp, a.rho, a.bulkMod, a.shearMod, a.Vp, a.Vs,
unsafe_wrap( Vector{Cdouble}, a.Comp, a.nOx),
unsafe_wrap( Vector{Cdouble}, a.Comp_wt, a.nOx),
unsafe_wrap( Vector{Cdouble}, a.Comp_apfu, a.nOx),
unsafe_wrap( Vector{Cdouble}, a.compVariables, a.n_xeos),
unsafe_string.( unsafe_wrap( Vector{Ptr{Int8}}, a.compVariablesNames,a.n_xeos)),
unsafe_wrap( Vector{Cdouble}, a.siteFractions, a.n_sf),
Expand All @@ -44,7 +47,8 @@ function Base.convert(::Type{SS_data}, a::stb_SS_phases)
unsafe_wrap( Vector{Cdouble}, a.emFrac_wt, a.n_em),
unsafe_wrap( Vector{Cdouble}, a.emChemPot, a.n_em),
unsafe_wrap.(Vector{Cdouble}, unsafe_wrap( Vector{Ptr{Cdouble}}, a.emComp, a.n_em), a.nOx),
unsafe_wrap.(Vector{Cdouble}, unsafe_wrap( Vector{Ptr{Cdouble}}, a.emComp_wt, a.n_em), a.nOx) )
unsafe_wrap.(Vector{Cdouble}, unsafe_wrap( Vector{Ptr{Cdouble}}, a.emComp_wt, a.n_em), a.nOx),
unsafe_wrap.(Vector{Cdouble}, unsafe_wrap( Vector{Ptr{Cdouble}}, a.emComp_apfu, a.n_em), a.nOx) )
end

# metastable phases
Expand Down Expand Up @@ -92,12 +96,14 @@ struct PP_data
Vs::Cdouble
Comp::Vector{Cdouble}
Comp_wt::Vector{Cdouble}
Comp_apfu::Vector{Cdouble}
end

function Base.convert(::Type{PP_data}, a::stb_PP_phases)
return PP_data(a.f, a.G, a.deltaG, a.V, a.alpha, a.entropy, a.enthalpy, a.cp, a.rho, a.bulkMod, a.shearMod, a.Vp, a.Vs,
unsafe_wrap(Vector{Cdouble},a.Comp, a.nOx),
unsafe_wrap(Vector{Cdouble},a.Comp_wt, a.nOx))
unsafe_wrap(Vector{Cdouble},a.Comp_wt, a.nOx),
unsafe_wrap(Vector{Cdouble},a.Comp_apfu, a.nOx))
end


Expand Down
77 changes: 75 additions & 2 deletions gen/magemin_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ mutable struct global_variables
numPoint::Cint
global_ite::Cint
H2O_id::Cint
S_id::Cint
Al2O3_id::Cint
K2O_id::Cint
O_id::Cint
Expand Down Expand Up @@ -1033,6 +1034,8 @@ struct stb_SS_phases
emComp::Ptr{Ptr{Cdouble}}
Comp_wt::Ptr{Cdouble}
emComp_wt::Ptr{Ptr{Cdouble}}
Comp_apfu::Ptr{Cdouble}
emComp_apfu::Ptr{Ptr{Cdouble}}
end

const stb_SS_phase = stb_SS_phases
Expand Down Expand Up @@ -1073,6 +1076,7 @@ struct stb_PP_phases
Vs::Cdouble
Comp::Ptr{Cdouble}
Comp_wt::Ptr{Cdouble}
Comp_apfu::Ptr{Cdouble}
end

const stb_PP_phase = stb_PP_phases
Expand Down Expand Up @@ -1170,6 +1174,10 @@ function get_bulk_ultramafic(gv)
ccall((:get_bulk_ultramafic, libMAGEMin), global_variable, (global_variable,), gv)
end

function get_bulk_ultramafic_ext(gv)
ccall((:get_bulk_ultramafic_ext, libMAGEMin), global_variable, (global_variable,), gv)
end

mutable struct Database
PP_ref_db::Ptr{PP_ref}
SS_ref_db::Ptr{SS_ref}
Expand Down Expand Up @@ -1237,6 +1245,10 @@ function TC_SS_init_um(SS_init, gv)
ccall((:TC_SS_init_um, libMAGEMin), Cvoid, (Ptr{SS_init_type}, global_variable), SS_init, gv)
end

function TC_SS_init_um_ext(SS_init, gv)
ccall((:TC_SS_init_um_ext, libMAGEMin), Cvoid, (Ptr{SS_init_type}, global_variable), SS_init, gv)
end

function TC_SS_init(SS_init, gv)
ccall((:TC_SS_init, libMAGEMin), Cvoid, (Ptr{SS_init_type}, global_variable), SS_init, gv)
end
Expand Down Expand Up @@ -1269,6 +1281,10 @@ function G_SS_um_EM_function(gv, SS_ref_db, EM_dataset, z_b, name)
ccall((:G_SS_um_EM_function, libMAGEMin), SS_ref, (global_variable, SS_ref, Cint, bulk_info, Ptr{Cchar}), gv, SS_ref_db, EM_dataset, z_b, name)
end

function G_SS_um_ext_EM_function(gv, SS_ref_db, EM_dataset, z_b, name)
ccall((:G_SS_um_ext_EM_function, libMAGEMin), SS_ref, (global_variable, SS_ref, Cint, bulk_info, Ptr{Cchar}), gv, SS_ref_db, EM_dataset, z_b, name)
end

mutable struct em_datas
C::NTuple{14, Cdouble}
ElShearMod::Cdouble
Expand Down Expand Up @@ -1303,6 +1319,10 @@ function TC_um_objective_init_function(SS_objective, gv)
ccall((:TC_um_objective_init_function, libMAGEMin), Cvoid, (Ptr{obj_type}, global_variable), SS_objective, gv)
end

function TC_um_ext_objective_init_function(SS_objective, gv)
ccall((:TC_um_ext_objective_init_function, libMAGEMin), Cvoid, (Ptr{obj_type}, global_variable), SS_objective, gv)
end

function TC_SS_objective_init_function(SS_objective, gv)
ccall((:TC_SS_objective_init_function, libMAGEMin), Cvoid, (Ptr{obj_type}, global_variable), SS_objective, gv)
end
Expand Down Expand Up @@ -1566,6 +1586,18 @@ function obj_um_po(n, x, grad, SS_ref_db)
ccall((:obj_um_po, libMAGEMin), Cdouble, (Cuint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cvoid}), n, x, grad, SS_ref_db)
end

function obj_ume_pl4tr(n, x, grad, SS_ref_db)
ccall((:obj_ume_pl4tr, libMAGEMin), Cdouble, (Cuint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cvoid}), n, x, grad, SS_ref_db)
end

function obj_ume_hb(n, x, grad, SS_ref_db)
ccall((:obj_ume_hb, libMAGEMin), Cdouble, (Cuint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cvoid}), n, x, grad, SS_ref_db)
end

function obj_ume_aug(n, x, grad, SS_ref_db)
ccall((:obj_ume_aug, libMAGEMin), Cdouble, (Cuint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cvoid}), n, x, grad, SS_ref_db)
end

function obj_aq17(n, x, grad, SS_ref_db)
ccall((:obj_aq17, libMAGEMin), Cdouble, (Cuint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cvoid}), n, x, grad, SS_ref_db)
end
Expand All @@ -1590,6 +1622,10 @@ function TC_um_PC_init(PC_read, gv)
ccall((:TC_um_PC_init, libMAGEMin), Cvoid, (Ptr{PC_type}, global_variable), PC_read, gv)
end

function TC_um_ext_PC_init(PC_read, gv)
ccall((:TC_um_ext_PC_init, libMAGEMin), Cvoid, (Ptr{PC_type}, global_variable), PC_read, gv)
end

# typedef void ( * sf_type ) ( unsigned m , double * result , unsigned n , const double * x , double * grad , void * data )
const sf_type = Ptr{Cvoid}

Expand All @@ -1616,6 +1652,10 @@ function TC_um_NLopt_opt_init(NLopt_opt, gv)
ccall((:TC_um_NLopt_opt_init, libMAGEMin), Cvoid, (Ptr{NLopt_type}, global_variable), NLopt_opt, gv)
end

function TC_um_ext_NLopt_opt_init(NLopt_opt, gv)
ccall((:TC_um_ext_NLopt_opt_init, libMAGEMin), Cvoid, (Ptr{NLopt_type}, global_variable), NLopt_opt, gv)
end

function TC_NLopt_opt_init(NLopt_opt, gv)
ccall((:TC_NLopt_opt_init, libMAGEMin), Cvoid, (Ptr{NLopt_type}, global_variable), NLopt_opt, gv)
end
Expand Down Expand Up @@ -1678,6 +1718,7 @@ mutable struct oxide_datas
oxMass::NTuple{15, Cdouble}
atPerOx::NTuple{15, Cdouble}
ElEntropy::NTuple{15, Cdouble}
OPerOx::NTuple{15, Cdouble}
oxide_datas() = new()
end

Expand Down Expand Up @@ -1791,6 +1832,32 @@ end

const ultramafic_dataset = ultramafic_datasets

mutable struct ultramafic_ext_datasets
ds_version::Cint
n_ox::Cint
n_pp::Cint
n_ss::Cint
ox::NTuple{9, NTuple{20, Cchar}}
PP::NTuple{21, NTuple{20, Cchar}}
SS::NTuple{15, NTuple{20, Cchar}}
verifyPC::NTuple{15, Cint}
n_SS_PC::NTuple{15, Cint}
SS_PC_stp::NTuple{15, Cdouble}
PC_df_add::Cdouble
solver_switch_T::Cdouble
min_melt_T::Cdouble
inner_PGE_ite::Cdouble
max_n_phase::Cdouble
max_g_phase::Cdouble
max_fac::Cdouble
merge_value::Cdouble
re_in_n::Cdouble
obj_tol::Cdouble
ultramafic_ext_datasets() = new()
end

const ultramafic_ext_dataset = ultramafic_ext_datasets

function global_variable_TC_init(gv, z_b)
ccall((:global_variable_TC_init, libMAGEMin), global_variable, (global_variable, Ptr{bulk_info}), gv, z_b)
end
Expand Down Expand Up @@ -2328,6 +2395,7 @@ struct SS_data
Vs::Cdouble
Comp::Vector{Cdouble}
Comp_wt::Vector{Cdouble}
Comp_apfu::Vector{Cdouble}
compVariables::Vector{Cdouble}
compVariablesNames::Vector{String}
siteFractions::Vector{Cdouble}
Expand All @@ -2338,12 +2406,14 @@ struct SS_data
emChemPot::Vector{Cdouble}
emComp::Vector{Vector{Float64}}
emComp_wt::Vector{Vector{Float64}}
emComp_apfu::Vector{Vector{Float64}}
end

function Base.convert(::Type{SS_data}, a::stb_SS_phases)
return SS_data(a.f, a.G, a.deltaG, a.V, a.alpha, a.entropy, a.enthalpy, a.cp, a.rho, a.bulkMod, a.shearMod, a.Vp, a.Vs,
unsafe_wrap( Vector{Cdouble}, a.Comp, a.nOx),
unsafe_wrap( Vector{Cdouble}, a.Comp_wt, a.nOx),
unsafe_wrap( Vector{Cdouble}, a.Comp_apfu, a.nOx),
unsafe_wrap( Vector{Cdouble}, a.compVariables, a.n_xeos),
unsafe_string.( unsafe_wrap( Vector{Ptr{Int8}}, a.compVariablesNames,a.n_xeos)),
unsafe_wrap( Vector{Cdouble}, a.siteFractions, a.n_sf),
Expand All @@ -2353,7 +2423,8 @@ function Base.convert(::Type{SS_data}, a::stb_SS_phases)
unsafe_wrap( Vector{Cdouble}, a.emFrac_wt, a.n_em),
unsafe_wrap( Vector{Cdouble}, a.emChemPot, a.n_em),
unsafe_wrap.(Vector{Cdouble}, unsafe_wrap( Vector{Ptr{Cdouble}}, a.emComp, a.n_em), a.nOx),
unsafe_wrap.(Vector{Cdouble}, unsafe_wrap( Vector{Ptr{Cdouble}}, a.emComp_wt, a.n_em), a.nOx) )
unsafe_wrap.(Vector{Cdouble}, unsafe_wrap( Vector{Ptr{Cdouble}}, a.emComp_wt, a.n_em), a.nOx),
unsafe_wrap.(Vector{Cdouble}, unsafe_wrap( Vector{Ptr{Cdouble}}, a.emComp_apfu, a.n_em), a.nOx) )
end

# metastable phases
Expand Down Expand Up @@ -2401,12 +2472,14 @@ struct PP_data
Vs::Cdouble
Comp::Vector{Cdouble}
Comp_wt::Vector{Cdouble}
Comp_apfu::Vector{Cdouble}
end

function Base.convert(::Type{PP_data}, a::stb_PP_phases)
return PP_data(a.f, a.G, a.deltaG, a.V, a.alpha, a.entropy, a.enthalpy, a.cp, a.rho, a.bulkMod, a.shearMod, a.Vp, a.Vs,
unsafe_wrap(Vector{Cdouble},a.Comp, a.nOx),
unsafe_wrap(Vector{Cdouble},a.Comp_wt, a.nOx))
unsafe_wrap(Vector{Cdouble},a.Comp_wt, a.nOx),
unsafe_wrap(Vector{Cdouble},a.Comp_apfu, a.nOx))
end


Expand Down
43 changes: 36 additions & 7 deletions julia/MAGEMin_wrappers.jl

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions julia/export2CSV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function MAGEMin_data2dataframe( out:: Union{Vector{gmin_struct{Float64, Int64}}
Symbol("aFeO") => Float64[],
Symbol("density[kg/m3]") => Float64[],
Symbol("volume[cm3/mol]") => Float64[],
Symbol("heatCapacity[kJ/K]")=> Float64[],
Symbol("heatCapacity[J/K]")=> Float64[],
Symbol("alpha[1/K]") => Float64[],
Symbol("Entropy[J/K]") => Float64[],
Symbol("Enthalpy[J]") => Float64[],
Expand Down Expand Up @@ -239,7 +239,7 @@ function MAGEMin_data2dataframe( out:: Union{Vector{gmin_struct{Float64, Int64}}
"aFeO" => out[k].aFeO,
"density[kg/m3]" => out[k].rho,
"volume[cm3/mol]" => out[k].V,
"heatCapacity[kJ/K]"=> out[k].cp,
"heatCapacity[J/K]"=> out[k].s_cp,
"alpha[1/K]" => out[k].alpha,
"Entropy[J/K]" => out[k].entropy,
"Enthalpy[J]" => out[k].enthalpy,
Expand Down
15 changes: 13 additions & 2 deletions src/MAGEMin.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ int runMAGEMin( int argc,
/*
get bulk rock composition parsed from args
*/

if (gv.EM_database == 0){
gv = get_bulk_metapelite( gv );
}
Expand All @@ -166,6 +167,9 @@ int runMAGEMin( int argc,
else if (gv.EM_database == 4){
gv = get_bulk_ultramafic( gv );
}
else if (gv.EM_database == 5){
gv = get_bulk_ultramafic_ext( gv );
}
else{
printf(" Wrong database...\n");
}
Expand Down Expand Up @@ -859,6 +863,9 @@ global_variable ReadCommandLineOptions( global_variable gv,
else if (strcmp(gv.db, "um") == 0){
gv.EM_database = 4;
}
else if (strcmp(gv.db, "ume") == 0){
gv.EM_database = 5;
}
else {
printf(" No or wrong database acronym has been provided, using default (Igneous [ig])\n");
gv.EM_database = 2;
Expand All @@ -882,12 +889,12 @@ Databases InitializeDatabases( global_variable gv,
/**
Allocate memory for each solution phase according to their specificities (n_em, sf etc)
*/

SS_init_type SS_init[gv.len_ss];

TC_SS_init( SS_init,
gv );


DB.SS_ref_db = malloc ((gv.len_ss) * sizeof(SS_ref));
for (int iss = 0; iss < gv.len_ss; iss++){

Expand Down Expand Up @@ -976,11 +983,13 @@ void FreeDatabases( global_variable gv,
for ( i = 0; i < n_ox; i++){
if (DB.sp[0].PP[i].Comp !=NULL) free( DB.sp[0].PP[i].Comp );
if (DB.sp[0].PP[i].Comp_wt !=NULL) free( DB.sp[0].PP[i].Comp_wt );
if (DB.sp[0].PP[i].Comp_apfu !=NULL) free( DB.sp[0].PP[i].Comp_apfu );
}

for ( i = 0; i < n_ox; i++){
if (DB.sp[0].SS[i].Comp !=NULL) free( DB.sp[0].SS[i].Comp );
if (DB.sp[0].SS[i].Comp_wt !=NULL) free( DB.sp[0].SS[i].Comp_wt );
if (DB.sp[0].SS[i].Comp_apfu !=NULL) free( DB.sp[0].SS[i].Comp_apfu );
if (DB.sp[0].SS[i].compVariables !=NULL) free( DB.sp[0].SS[i].compVariables );
if (DB.sp[0].SS[i].siteFractions !=NULL) free( DB.sp[0].SS[i].siteFractions );
if (DB.sp[0].SS[i].emFrac !=NULL) free( DB.sp[0].SS[i].emFrac );
Expand All @@ -991,13 +1000,15 @@ void FreeDatabases( global_variable gv,
if (DB.sp[0].SS[i].siteFractionsNames[j] !=NULL) free( DB.sp[0].SS[i].siteFractionsNames[j] );
if (DB.sp[0].SS[i].emNames[j] !=NULL) free( DB.sp[0].SS[i].emNames[j] );
if (DB.sp[0].SS[i].emComp[j] !=NULL) free( DB.sp[0].SS[i].emComp[j] );
if (DB.sp[0].SS[i].emComp_wt[j] !=NULL) free( DB.sp[0].SS[i].emComp_wt[j] );
if (DB.sp[0].SS[i].emComp_wt[j] !=NULL) free( DB.sp[0].SS[i].emComp_wt[j] );
if (DB.sp[0].SS[i].emComp_apfu[j] !=NULL) free( DB.sp[0].SS[i].emComp_apfu[j] );
}
if (DB.sp[0].SS[i].compVariablesNames !=NULL) free( DB.sp[0].SS[i].compVariablesNames );
if (DB.sp[0].SS[i].siteFractionsNames !=NULL) free( DB.sp[0].SS[i].siteFractionsNames );
if (DB.sp[0].SS[i].emNames !=NULL) free( DB.sp[0].SS[i].emNames );
if (DB.sp[0].SS[i].emComp !=NULL) free( DB.sp[0].SS[i].emComp );
if (DB.sp[0].SS[i].emComp_wt !=NULL) free( DB.sp[0].SS[i].emComp_wt );
if (DB.sp[0].SS[i].emComp_apfu !=NULL) free( DB.sp[0].SS[i].emComp_apfu );
}

/* free metastable assemblage */
Expand Down
9 changes: 8 additions & 1 deletion src/MAGEMin.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ typedef struct global_variables {
int numPoint; /** the number of the current point */
int global_ite; /** global iteration increment */
int H2O_id;
int S_id;
int Al2O3_id;
int K2O_id;
int O_id;
Expand Down Expand Up @@ -607,7 +608,10 @@ typedef struct stb_SS_phases {

double *Comp_wt;
double **emComp_wt;


double *Comp_apfu;
double **emComp_apfu;

//double *siteFrac;

} stb_SS_phase;
Expand Down Expand Up @@ -657,6 +661,8 @@ typedef struct stb_PP_phases {
double *Comp;
double *Comp_wt;

double *Comp_apfu;

} stb_PP_phase;

/* structure to store informations of stable phase equilibria */
Expand Down Expand Up @@ -746,6 +752,7 @@ global_variable global_variable_init( global_variable gv,
global_variable get_bulk_igneous( global_variable gv );
global_variable get_bulk_metapelite( global_variable gv );
global_variable get_bulk_ultramafic( global_variable gv );
global_variable get_bulk_ultramafic_ext( global_variable gv );

/** Stores databases **/
typedef struct Database { PP_ref *PP_ref_db; /** Pure phases */
Expand Down
Loading
Loading