Skip to content

Commit c254132

Browse files
committed
improve SLB24 benchmarking
1 parent 8277500 commit c254132

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

burnman/tools/equilibration.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,22 +631,22 @@ def get_equilibration_parameters(assemblage, composition, free_compositional_vec
631631

632632
# Process parameter names
633633
prm.parameter_names = ["Pressure (Pa)", "Temperature (K)"]
634-
prm.default_tolerances = [1.0, 1.0e-3]
634+
prm.default_tolerances = [1.0, 1.0e-6]
635635
for i, n in enumerate(assemblage.endmembers_per_phase):
636636
prm.parameter_names.append("x({0})".format(assemblage.phases[i].name))
637-
prm.default_tolerances.append(1.0e-6)
637+
prm.default_tolerances.append(1.0e-9)
638638
if n > 1:
639639
p_names = [
640640
"p({0} in {1})".format(n, assemblage.phases[i].name)
641641
for n in assemblage.phases[i].endmember_names[1:]
642642
]
643643
prm.parameter_names.extend(p_names)
644-
prm.default_tolerances.extend([1.0e-6] * len(p_names))
644+
prm.default_tolerances.extend([1.0e-9] * len(p_names))
645645

646646
n_free_compositional_vectors = len(free_compositional_vectors)
647647
for i in range(n_free_compositional_vectors):
648648
prm.parameter_names.append(f"v_{i}")
649-
prm.default_tolerances.append(1.0e-6)
649+
prm.default_tolerances.append(1.0e-9)
650650

651651
prm.default_tolerances = np.array(prm.default_tolerances)
652652

@@ -1036,6 +1036,10 @@ def equilibrate(
10361036
if sol.success and len(assemblage.reaction_affinities) > 0.0:
10371037
maxres = np.max(np.abs(assemblage.reaction_affinities)) + 1.0e-5
10381038
assemblage.equilibrium_tolerance = maxres
1039+
assert maxres < 10.0, (
1040+
"Equilibrium not satisfied to high enough precision. "
1041+
f"Max reaction affinity is {maxres} J/mol. Try reducing tol."
1042+
)
10391043

10401044
if store_assemblage:
10411045
sol.assemblage = assemblage.copy()

misc/benchmarks/slb_2024_benchmarks.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def check_fper_entropy():
6060
def check_fig_1_fper_relaxed():
6161
print("\nChecking Figure 1...")
6262
fper = SLB_2024.ferropericlase_relaxed()
63+
fper_unrelaxed = SLB_2024.ferropericlase()
6364
c = molar_volume_from_unit_cell_volume(1.0, SLB_2024.periclase().params["Z"])
6465

6566
pressures = np.linspace(1.0e5, 140.0e9, 141)
@@ -80,7 +81,26 @@ def check_fig_1_fper_relaxed():
8081
ax[3].imshow(fig4, extent=[0.0, 200.0, 0.0, 4000.0], aspect="auto")
8182

8283
for x_fe in [0.1, 0.3, 0.5, 1.0]:
83-
fper.set_composition([1.0 - x_fe, x_fe, 0.0, 0.0])
84+
# First, we need to equilibrate the system at 1 bar and 1473 K
85+
# according to the caption of SLB2024 Figure 1
86+
assemblage = Composite([fper_unrelaxed, SLB_2024.gamma_fcc_iron()], [0.5, 0.5])
87+
composition = {
88+
"Mg": (1.0 - x_fe),
89+
"Fe": 1.0,
90+
"O": 1.0,
91+
"Na": 1.0e-9,
92+
"Al": 1.0e-9,
93+
}
94+
fper_unrelaxed.set_composition(
95+
[1.0 - x_fe, x_fe * 0.98, x_fe * 0.01, 0.0, x_fe * 0.01]
96+
)
97+
equality_constraints = [["P", 1.0e5], ["T", 1473.0]]
98+
_, _ = equilibrate(composition, assemblage, equality_constraints)
99+
f = fper_unrelaxed.molar_fractions
100+
molar_fractions = [f[0], f[1] + f[2], f[3], f[4]] # combine HS and LS Fe
101+
102+
# Now use that composition of ferropericlase in the relaxed solution
103+
fper.set_composition(molar_fractions)
84104
Vs, K_Ss = fper.evaluate(["V", "K_S"], pressures, temperatures)
85105

86106
ax[0].plot(pressures / 1.0e9, Vs / c, linestyle=":", linewidth=3.0)
@@ -353,6 +373,7 @@ def check_fig_7_fO2():
353373
wu = simplify_composite_with_composition(
354374
Composite([wu]), {"Fe": 1, "O": 1.01}
355375
).phases[0]
376+
assert len(wu.endmembers) == 3 # check that the simplification worked
356377

357378
hepv = SLB_2024.hepv()
358379
hppv = SLB_2024.hppv()
@@ -435,17 +456,15 @@ def check_fig_7_fO2():
435456
T = 1500.0
436457
for i, P in enumerate(pressures):
437458
assemblage.set_state(P, T)
438-
try:
439-
sol = equilibrate(assemblage.formula, assemblage, [["P", P], ["T", T]])[
440-
0
441-
]
442-
if sol.success:
443-
mu_O2 = assemblage.chemical_potential([{"O": 2.0}])[0]
444-
O2_gas.set_state(1.0e5, T)
445-
O2_gibbs = O2_gas.gibbs + f
446-
logfO2[i] = (mu_O2 - O2_gibbs) / (gas_constant * T) / np.log(10.0)
447-
except AssertionError:
448-
pass
459+
sol, _ = equilibrate(
460+
assemblage.formula, assemblage, [["P", P], ["T", T]], tol=1.0e-10
461+
)
462+
if sol.success:
463+
mu_O2 = sol.assemblage.chemical_potential([{"O": 2.0}])[0]
464+
O2_gas.set_state(1.0e5, T)
465+
O2_gibbs = O2_gas.gibbs + f
466+
logfO2[i] = (mu_O2 - O2_gibbs) / (gas_constant * T) / np.log(10.0)
467+
449468
ax[0].plot(pressures / 1.0e9, logfO2, linestyle=":", linewidth=3.0)
450469

451470
ax[0].set_ylim(-14, 22)

0 commit comments

Comments
 (0)