Worked solutions to the three exercises of Lecture 11. Each solution is computed here and checked with assert statements against an exact identity or an independent calculation. The first code cell sets up the notebook and runs Demonstration 1 of the lecture without showing its output, because some of the solutions use its variables.
try: # use the installed package, or the copy in this repository
import engmaterials
except ImportError:
import pathlib, subprocess, sys
for _root in [pathlib.Path.cwd(), *pathlib.Path.cwd().parents]:
if (_root / "engmaterials" / "__init__.py").exists():
sys.path.insert(0, str(_root))
break
else: # on Google Colab: install from GitHub
subprocess.run([sys.executable, "-m", "pip", "install", "-q",
"git+https://github.com/ktwyw/engmaterials.git"], check=True)
import engmaterials
import inspect
import numpy as np
import matplotlib.pyplot as plt
from engmaterials import (atomistics, constants, diffraction, elasticity, kinetics_selection,
lattices, phase_field, phase_thermodynamics)
from engmaterials.plotting import label_panels, panel_label, use_style
use_style()
def show_source(obj):
"""Return the source code of a library function or class."""
return inspect.getsource(obj)
def heading(text):
print(f"\n{text}\n" + "=" * len(text))
# Demonstration 1 of the lecture, run without output: the solutions use its variables.
import contextlib, io
_show, plt.show = plt.show, lambda *args, **kwargs: None
_stdout = contextlib.redirect_stdout(io.StringIO()); _stdout.__enter__()
heading("Demonstration 1: Equilibrium Solidification Path of Cu-50 at.% Ni via Seltz + Lever Rule")
x0_cuni = 0.50
T_path = [1558.0, 1552.0, 1546.0, 1540.0, 1534.0]
print(f"Overall alloy composition x0 = {x0_cuni:.3f} Ni")
print(f"{'T [K]':>7s} | {'x_L (Liquidus)':>14s} | {'x_S (Solidus)':>14s} | {'f_Liquid':>10s} | {'f_Solid':>10s} | {'Mass Balance x_chk':>18s}")
print("-" * 88)
for tk in T_path:
bounds = phase_thermodynamics.isomorphous_phase_boundaries(tk, 1357.77, 13260.0, 1728.0, 17480.0)
xl, xs = bounds["x_liquidus"], bounds["x_solidus"]
if xl <= x0_cuni <= xs:
fr = phase_thermodynamics.lever_rule(x0_cuni, xl, xs)
f_liq, f_sol = fr["f_alpha"], fr["f_beta"]
x_chk = f_liq * xl + f_sol * xs
print(f"{tk:7.1f} | {xl:14.4f} | {xs:14.4f} | {f_liq:10.4f} | {f_sol:10.4f} | {x_chk:18.8f}")
assert np.isclose(f_liq + f_sol, 1.0, atol=1e-15)
assert np.isclose(x_chk, x0_cuni, atol=1e-15)
_stdout.__exit__(None, None, None); plt.show = _show; plt.close("all")Exercise 1¶
Problem. Verify the analytical Scheil eutectic fraction across Al–Cu alloys with (), confirming that even dilute Al–1.0 wt% Cu forms non-equilibrium eutectic when and that holds to 10-14.
heading("Exercise 1: Non-Equilibrium Scheil Eutectic Fraction & Exact Two-Constituent Solute Conservation")
k_cu, c_E_cu = 0.17, 33.0
print(f"{'c0 [wt%]':>9s} | {'fs_alpha':>10s} | {'f_E_Scheil [%]':>14s} | {'c_bar_alpha':>12s} | {'Solute Sum [wt%]':>16s}")
print("-" * 72)
for c0 in [1.0, 2.0, 3.0, 4.5]:
f_E = (c_E_cu / c0) ** (-1.0 / (1.0 - k_cu))
fs_a = 1.0 - f_E
st = phase_thermodynamics.scheil_gulliver_solidification(fs_a, c_0=c0, k_part=k_cu)
solute_sum = fs_a * st["c_solid_mean"] + f_E * c_E_cu
print(f"{c0:9.2f} | {fs_a:10.5f} | {100.0*f_E:14.3f} | {st['c_solid_mean']:12.5f} | {solute_sum:16.10f}")
assert np.isclose(st["c_liquid"], c_E_cu, rtol=1e-14)
assert np.isclose(solute_sum, c0, rtol=1e-14, atol=1e-14)
assert f_E > 0.014
Exercise 1: Non-Equilibrium Scheil Eutectic Fraction & Exact Two-Constituent Solute Conservation
================================================================================================
c0 [wt%] | fs_alpha | f_E_Scheil [%] | c_bar_alpha | Solute Sum [wt%]
------------------------------------------------------------------------
1.00 | 0.98519 | 1.481 | 0.51906 | 1.0000000000
2.00 | 0.96587 | 3.413 | 0.90454 | 2.0000000000
3.00 | 0.94437 | 5.563 | 1.23279 | 3.0000000000
4.50 | 0.90933 | 9.067 | 1.65821 | 4.5000000000
Explanation. Because as for every , the pure Scheil model () predicts a strictly positive non-equilibrium eutectic fraction for any nonzero solute concentration . In real dilute alloys (Al–1 wt% Cu), a tiny amount of solid-state back-diffusion (, Exercise 3) suffices to cap and eliminate trace eutectic.
Exercise 2¶
Problem. Quantify the false mass-balance violation when instantaneous interfacial concentration is mistakenly used instead of at for , and verify ValueError guards in lever_rule and scheil_gulliver_solidification.
heading("Exercise 2: Diagnostic Audit — Interfacial vs Mean Solid Concentration & Boundary Guards")
c0, fs, k = 4.5, 0.85, 0.17
sg = phase_thermodynamics.scheil_gulliver_solidification(fs, c_0=c0, k_part=k)
true_mass = fs * sg["c_solid_mean"] + (1.0 - fs) * sg["c_liquid"]
false_mass = fs * sg["c_solid_interface"] + (1.0 - fs) * sg["c_liquid"]
rel_violation = abs(false_mass - c0) / c0
print(f"At fs = {fs}: c_s* = {sg['c_solid_interface']:.3f} wt% vs cumulative mean c_bar_s = {sg['c_solid_mean']:.3f} wt%")
print(f"True mass balance = {true_mass:.6f} wt% (exact c0 = {c0})")
print(f"False rim balance = {false_mass:.6f} wt% (overcounts total Cu by +{100.0*rel_violation:.2f}%)")
assert np.isclose(true_mass, c0, atol=1e-14)
assert rel_violation > 0.35
for bad_call in [
lambda: phase_thermodynamics.lever_rule(0.05, 0.20, 0.80), # Outside tie-line
lambda: phase_thermodynamics.lever_rule(0.50, 0.50, 0.50), # Degenerate zero-length tie-line
lambda: phase_thermodynamics.scheil_gulliver_solidification(1.0, 4.5, 0.17), # Singular fs = 1.0
]:
caught = False
try:
bad_call()
except ValueError:
caught = True
assert caught is True
Exercise 2: Diagnostic Audit — Interfacial vs Mean Solid Concentration & Boundary Guards
========================================================================================
At fs = 0.85: c_s* = 3.694 wt% vs cumulative mean c_bar_s = 1.459 wt%
True mass balance = 4.500000 wt% (exact c0 = 4.5)
False rim balance = 6.399441 wt% (overcounts total Cu by +42.21%)
Explanation. Because previously solidified inner dendrite shells remain frozen at lower solute concentrations ( at the core vs. at the rim), multiplying by the rim concentration pretends the entire solid already equilibrated to the rim composition, which overcounts the copper by . Meanwhile, at the power law diverges for because real solidification terminates earlier at a eutectic arrest or solidus.
Exercise 3¶
Problem. Implement clyne_kurz_solidification(f_s, c_0, k_part, alpha_fourier) with () and . Verify exact convergence to scheil_gulliver_solidification as and exact convergence to the equilibrium Lever Rule as .
heading("Exercise 3: Implement It Yourself — Clyne-Kurz Back-Diffusion Bridging Scheil & Equilibrium Lever Rule")
def clyne_kurz_solidification(f_s: np.ndarray | float, c_0: float, k_part: float, alpha_fourier: float) -> dict:
"""Evaluate liquid and interfacial solid composition with finite solid back-diffusion (Clyne-Kurz 1981)."""
fs = np.asarray(f_s, dtype=float)
if alpha_fourier <= 1e-12:
omega_ck = 0.0
else:
a = float(alpha_fourier)
omega_ck = a * (1.0 - np.exp(-1.0 / a)) - 0.5 * np.exp(-0.5 / a)
denom = 1.0 - 2.0 * omega_ck * k_part
c_liq = c_0 * ((1.0 - denom * fs) ** ((k_part - 1.0) / denom))
return {"omega_ck": float(omega_ck), "c_liquid": c_liq, "c_solid_interface": k_part * c_liq}
fs_test = np.linspace(0.0, 0.92, 100)
c0_t, k_t = 4.5, 0.17
ck_zero = clyne_kurz_solidification(fs_test, c0_t, k_t, alpha_fourier=0.0)
sch_ref = phase_thermodynamics.scheil_gulliver_solidification(fs_test, c0_t, k_t)
ck_inf = clyne_kurz_solidification(fs_test, c0_t, k_t, alpha_fourier=1e6)
c_liq_lever = c0_t / (1.0 - (1.0 - k_t) * fs_test) # Exact equilibrium lever rule f_L*c_L + f_s*(k*c_L) = c_0
ck_mid = clyne_kurz_solidification(0.92, c0_t, k_t, alpha_fourier=0.25)
print(f"alpha = 0 (Omega={ck_zero['omega_ck']:.4f}) max |c_L - c_L_Scheil| = {np.max(np.abs(ck_zero['c_liquid'] - sch_ref['c_liquid'])):.2e}")
print(f"alpha = 1e6 (Omega={ck_inf['omega_ck']:.6f}) max |c_L - c_L_Lever| = {np.max(np.abs(ck_inf['c_liquid'] - c_liq_lever)):.2e}")
print(f"At fs = 0.92: Scheil c_L = {sch_ref['c_liquid'][-1]:.2f} wt% | Moderate back-diffusion (alpha=0.25) c_L = {ck_mid['c_liquid']:.2f} wt% | Lever c_L = {c_liq_lever[-1]:.2f} wt%")
assert np.allclose(ck_zero["c_liquid"], sch_ref["c_liquid"], rtol=1e-14, atol=1e-14)
assert np.allclose(ck_inf["c_liquid"], c_liq_lever, rtol=1e-5, atol=1e-5)
assert c_liq_lever[-1] < ck_mid["c_liquid"] < sch_ref["c_liquid"][-1]
Exercise 3: Implement It Yourself — Clyne-Kurz Back-Diffusion Bridging Scheil & Equilibrium Lever Rule
======================================================================================================
alpha = 0 (Omega=0.0000) max |c_L - c_L_Scheil| = 0.00e+00
alpha = 1e6 (Omega=0.500000) max |c_L - c_L_Lever| = 3.49e-06
At fs = 0.92: Scheil c_L = 36.61 wt% | Moderate back-diffusion (alpha=0.25) c_L = 26.29 wt% | Lever c_L = 19.04 wt%
Summary. Clyne–Kurz’s spline function unifies Lecture 11’s entire solidification spectrum into one equation: fast interstitial diffusers such as carbon in -Fe () follow the equilibrium Lever Rule ( at in this example), whereas slow substitutional solutes like Cu in Al during rapid casting () follow Scheil–Gulliver ().