Worked solutions to the three exercises of Lecture 8. 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: Thermal Monovacancy Fraction From 300 K to Melting Across Al, Cu, and W")
vac_metals = [
("Al", 0.67, 1.5, "#1f77b4"),
("Cu", 1.28, 1.5, "#d62728"),
("W", 3.60, 1.8, "#2ca02c"),
]
print(f"{'Metal':6s} | {'Tm [K]':>8s} | {'Ev [eV]':>8s} | {'Ev/(kB*Tm)':>11s} | {'x_v(300 K)':>13s} | {'x_v(0.7 Tm)':>13s} | {'x_v(Tm)':>13s}")
print("-" * 86)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9.4, 3.9))
for sym, ev, sv, col in vac_metals:
tm = constants.ELEMENTS_DB[sym]["Tm_K"]
xv_300 = atomistics.vacancy_equilibrium_fraction(300.0, E_v_eV=ev, S_v_kB=sv)
xv_07 = atomistics.vacancy_equilibrium_fraction(0.7 * tm, E_v_eV=ev, S_v_kB=sv)
xv_tm = atomistics.vacancy_equilibrium_fraction(tm, E_v_eV=ev, S_v_kB=sv)
homol_ratio = (ev * constants.EV_TO_J) / (constants.K_B * tm)
print(f"{sym:6s} | {tm:8.2f} | {ev:8.2f} | {homol_ratio:11.2f} | {xv_300:13.3e} | {xv_07:13.3e} | {xv_tm:13.3e}")
assert 1e-5 < xv_tm < 3e-3
assert xv_300 < xv_07 < xv_tm
t_vec = np.linspace(350.0, tm, 200)
xv_vec = atomistics.vacancy_equilibrium_fraction(t_vec, E_v_eV=ev, S_v_kB=sv)
ax1.semilogy(1000.0 / t_vec, xv_vec, lw=2.0, color=col, label=f"{sym} ($E_v={ev}$ eV)")
ax2.semilogy(tm / t_vec, xv_vec, lw=2.0, color=col, label=f"{sym} ($T_m={tm:.0f}$ K)")
ax1.set_ylim(1e-18, 1e-2)
ax1.set_xlabel(r"Inverse Temperature $1000 / T$ [$\mathrm{K}^{-1}$]")
ax1.set_ylabel(r"Equilibrium Vacancy Site Fraction $x_v(T)$ [-]")
ax1.set_title(r"Against $1000/T$")
ax1.legend(fontsize=8)
ax2.set_xlim(1.0, 3.5)
ax2.set_ylim(1e-15, 1e-2)
ax2.set_xlabel(r"Homologous Inverse Temperature $T_m / T$ [-]")
ax2.set_ylabel(r"Equilibrium Vacancy Site Fraction $x_v(T)$ [-]")
ax2.set_title(r"Against $T_m/T$")
ax2.legend(fontsize=8)
label_panels(fig)
plt.show()
_stdout.__exit__(None, None, None); plt.show = _show; plt.close("all")Exercise 1¶
Problem. Verify Stirling’s exact thermodynamic minimum by minimizing (where vacancies per atom and site fraction ) via golden-section search in , confirming agreement with atomistics.vacancy_equilibrium_fraction to < 1e-6 relative error for Al, Cu, and W at .
heading("Exercise 1: Direct Free-Energy Minimization of Stirling Configurational Entropy vs Exact Formula")
inv_phi = (np.sqrt(5.0) - 1.0) / 2.0
for sym, ev, sv in [("Al", 0.67, 1.5), ("Cu", 1.28, 1.5), ("W", 3.60, 1.8)]:
T = constants.ELEMENTS_DB[sym]["Tm_K"]
kT_eV = (constants.K_B * T) / constants.EV_TO_J
def dg_per_atom_eV(ln_u: float) -> float:
u = np.exp(ln_u)
return float(u * (ev - kT_eV * sv) + kT_eV * (u * ln_u - (1.0 + u) * np.log1p(u)))
lo, hi = -20.0, -2.0
for _ in range(90):
c = hi - inv_phi * (hi - lo)
d = lo + inv_phi * (hi - lo)
if dg_per_atom_eV(c) < dg_per_atom_eV(d):
hi = d
else:
lo = c
u_opt = float(np.exp(0.5 * (lo + hi)))
xv_opt = u_opt / (1.0 + u_opt)
xv_lib = atomistics.vacancy_equilibrium_fraction(T, E_v_eV=ev, S_v_kB=sv)
print(f"{sym:3s} at Tm={T:7.2f} K | dg_min = {dg_per_atom_eV(np.log(u_opt)):+.3e} eV/atom | xv_opt = {xv_opt:.7e} vs lib = {xv_lib:.7e}")
assert dg_per_atom_eV(np.log(u_opt)) < 0.0
assert np.isclose(xv_opt, xv_lib, rtol=1e-7)
Exercise 1: Direct Free-Energy Minimization of Stirling Configurational Entropy vs Exact Formula
================================================================================================
Al at Tm= 933.47 K | dg_min = -8.706e-05 eV/atom | xv_opt = 1.0817594e-03 vs lib = 1.0817593e-03
Cu at Tm=1357.77 K | dg_min = -9.301e-06 eV/atom | xv_opt = 7.9493326e-05 vs lib = 7.9493323e-05
W at Tm=3695.00 K | dg_min = -2.369e-05 eV/atom | xv_opt = 7.4392081e-05 vs lib = 7.4392079e-05
Explanation. Differentiating with respect to gives . Because the true lattice-site fraction is , solving for yields with zero dilute-approximation error.
Exercise 2¶
Problem. Verify domain guards on vacancy_equilibrium_fraction and peierls_nabarro_stress, demonstrate the unit bug (E_v / (R * T) instead of (E_v * EV_TO_J) / (K_B * T)), and compute the quenched-in vacancy supersaturation in Aluminum.
heading("Exercise 2: Diagnostic Audit — Unit Bugs, Domain Guards & Quenched Vacancy Supersaturation")
for fn, args in [
(atomistics.vacancy_equilibrium_fraction, (-100.0, 1.0)),
(atomistics.vacancy_equilibrium_fraction, (500.0, 0.0)),
(atomistics.peierls_nabarro_stress, (50.0, 1.05, 2.5, 2.0)),
]:
caught = False
try:
fn(*args)
except ValueError:
caught = True
assert caught is True
# Common student unit bug: dividing E_v [eV] by R*T [J/mol] instead of k_B*T in eV (~96,485x error in exponent):
xv_true_cu = atomistics.vacancy_equilibrium_fraction(1000.0, E_v_eV=1.28, S_v_kB=1.5)
xv_unit_bug = float(np.exp(1.5 - 1.28 / (constants.R * 1000.0)))
print(f"Cu at 1000 K: True x_v = {xv_true_cu:.3e} vs Unit-Bug exp(1.5 - Ev_eV/(R*T)) = {xv_unit_bug:.3f} (unphysical > 1)")
xv_al_900 = atomistics.vacancy_equilibrium_fraction(900.0, E_v_eV=0.67, S_v_kB=1.5)
xv_al_300 = atomistics.vacancy_equilibrium_fraction(300.0, E_v_eV=0.67, S_v_kB=1.5)
supersat = xv_al_900 / xv_al_300
print(f"Al quenched 900 K -> 300 K supersaturation x_v(900)/x_v(300) = {supersat:.3e}x")
assert xv_unit_bug > 4.0 and supersat > 1e7
Exercise 2: Diagnostic Audit — Unit Bugs, Domain Guards & Quenched Vacancy Supersaturation
==========================================================================================
Cu at 1000 K: True x_v = 1.587e-06 vs Unit-Bug exp(1.5 - Ev_eV/(R*T)) = 4.481 (unphysical > 1)
Al quenched 900 K -> 300 K supersaturation x_v(900)/x_v(300) = 3.189e+07x
Explanation. , so at for is 14.85 (giving ), whereas omitting Faraday’s conversion makes the exponent and yields an unphysical site fraction . Rapidly water-quenching Al from traps a -fold vacancy supersaturation that drives room-temperature GP-zone natural aging in 2xxx/7xxx aerospace alloys.
Exercise 3¶
Problem. Implement rank_bcc_slip_planes(symbol) for BCC Fe, W, and Mo with Burgers vector along across the three BCC slip families (), (), and -type/ (, note BCC extinction rule ), verifying that always yields the widest core and lowest Peierls stress.
heading("Exercise 3: Implement It Yourself — BCC Pencil-Glide Slip Plane Ranking ({110}, {112}, {123})")
def rank_bcc_slip_planes(symbol: str) -> list[dict]:
"""Rank BCC <111> edge slip planes ({110}, {112}, {123}) by Peierls-Nabarro shear stress."""
d_el = constants.ELEMENTS_DB[symbol]
cell = lattices.cubic_unit_cell("bcc", d_el["a_A"])
vrh = elasticity.voigt_reuss_hill_cubic(d_el["C11_GPa"], d_el["C12_GPa"], d_el["C44_GPa"])
b_111 = 0.5 * np.sqrt(3.0) * d_el["a_A"]
# In BCC, lattice planes with h+k+l odd have half-spacing (equivalent to doubling Miller indices: (123)->sum=6 even):
planes = [("{110}<111>", (1, 1, 0)), ("{112}<111>", (1, 1, 2)), ("{123}<111>", (1, 2, 3))]
out = []
for name, hkl in planes:
assert sum(hkl) % 2 == 0 # BCC reflection condition guarantees every geometric plane contains atoms
d_A = lattices.interplanar_spacing(hkl, cell["lattice_vectors"])
pn = atomistics.peierls_nabarro_stress(vrh["G_hill"], vrh["nu_hill"], b_A=b_111, d_A=d_A, screw=False)
out.append({"plane": name, "d_over_b": d_A / b_111, "tau_pn_MPa": pn["tau_pn_MPa"]})
out.sort(key=lambda r: r["tau_pn_MPa"])
return out
for sym in ["Fe", "Mo", "W"]:
ranked = rank_bcc_slip_planes(sym)
print(f"{sym:2s} | #1 {ranked[0]['plane']} ({ranked[0]['tau_pn_MPa']:6.1f} MPa, d/b={ranked[0]['d_over_b']:.3f}) "
f"< #2 {ranked[1]['plane']} ({ranked[1]['tau_pn_MPa']:7.1f} MPa) < #3 {ranked[2]['plane']} ({ranked[2]['tau_pn_MPa']:7.1f} MPa)")
assert ranked[0]["plane"] == "{110}<111>"
assert ranked[0]["tau_pn_MPa"] < ranked[1]["tau_pn_MPa"] < ranked[2]["tau_pn_MPa"]
Exercise 3: Implement It Yourself — BCC Pencil-Glide Slip Plane Ranking ({110}, {112}, {123})
=============================================================================================
Fe | #1 {110}<111> ( 168.7 MPa, d/b=0.816) < #2 {112}<111> ( 3566.2 MPa) < #3 {123}<111> (15041.8 MPa)
Mo | #1 {110}<111> ( 250.3 MPa, d/b=0.816) < #2 {112}<111> ( 5367.5 MPa) < #3 {123}<111> (22793.1 MPa)
W | #1 {110}<111> ( 357.1 MPa, d/b=0.816) < #2 {112}<111> ( 7259.5 MPa) < #3 {123}<111> (30060.4 MPa)
Summary. In BCC crystals (Fe, Mo, W), all three plane families , , and satisfy and share the close-packed Burgers direction, but possesses vs. and , making the primary room-temperature BCC slip system.