Skip to content

Commit e575de7

Browse files
committed
improved composite example equilibrate routine
1 parent 47d6e76 commit e575de7

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

examples/example_composite.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
compositional, thermodynamic and thermoelastic properties.
2828
* How to use the stoichiometric and reaction affinity methods to solve
2929
simple thermodynamic equilibrium problems.
30+
31+
Please see example_equilibrate.py for more advanced (and user-friendly)
32+
examples of equilibration of a composite material.
3033
"""
3134

3235
import numpy as np
@@ -35,6 +38,7 @@
3538

3639

3740
import burnman
41+
from burnman import equilibrate
3842
from burnman import minerals
3943

4044

@@ -213,19 +217,20 @@ def delta_affinity_two_binaries_P_x_Fe_wad(x, T):
213217

214218
# Now solve for the equilibrium state at a range of pressures
215219
# less than the univariant pressure
216-
def delta_affinity_two_binaries_x_Fe_ol_wad(x, P, T):
217-
x_fe_ol, x_fe_wad = x
218-
rock.set_state(P, T)
219-
ol.set_composition([1.0 - x_fe_ol, x_fe_ol])
220-
wad.set_composition([1.0 - x_fe_wad, x_fe_wad])
221-
return rock.reaction_affinities
222-
223220
pressures = np.linspace(10.0e9, fo_mwd.pressure, 21)
224-
x_fe_ols = np.zeros_like(pressures)
225-
x_fe_wads = np.zeros_like(pressures)
226-
for i, P in enumerate(pressures[:-1]):
227-
sol = fsolve(delta_affinity_two_binaries_x_Fe_ol_wad, [0.1, 0.1], args=(P, T))
228-
x_fe_ols[i], x_fe_wads[i] = sol
221+
free_compositional_vectors = [{"Mg": 1.0, "Fe": -1.0}]
222+
composition = {"Mg": 1.8, "Fe": 0.2, "Si": 1.0, "O": 4.0}
223+
equality_constraints = [["P", pressures], ["T", T], ["phase_fraction", [ol, 0.5]]]
224+
sol, prm = equilibrate(
225+
composition, rock, equality_constraints, free_compositional_vectors
226+
)
227+
228+
x_fe_ols = np.array(
229+
[s.assemblage.phases[0].molar_fractions[1] if s.success else 0 for s in sol]
230+
)
231+
x_fe_wads = np.array(
232+
[s.assemblage.phases[1].molar_fractions[1] if s.success else 0 for s in sol]
233+
)
229234

230235
# Pretty-print the results
231236
print(f"Olivine-wadsleyite equilibria at {T} K:")

0 commit comments

Comments
 (0)