Worked solutions to the three exercises of Lecture 17. 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: Stage 1 & 2 ICME Screening — Lattice Density, XRD, Atomistics & Pugh Ductility")
el_A, el_B = constants.ELEMENTS_DB["Al"], constants.ELEMENTS_DB["Cu"]
def screen_fcc_alloy_composition(x_sol: float, T_homog_K: float = 850.0) -> dict:
"""Link constants, lattices, diffraction, atomistics, and elasticity for an FCC Al_{1-x}Cu_x model alloy."""
a_alloy = (1.0 - x_sol) * el_A["a_A"] + x_sol * el_B["a_A"]
mw_alloy = (1.0 - x_sol) * el_A["Mw"] + x_sol * el_B["Mw"]
z_alloy = (1.0 - x_sol) * el_A["Z"] + x_sol * el_B["Z"]
cell = lattices.cubic_unit_cell("fcc", a_A=a_alloy)
vol_A3 = lattices.metric_tensor(cell["lattice_vectors"])["volume_A3"]
rho_kg_m3 = 1000.0 * lattices.theoretical_density_g_cm3(mw_alloy, cell["n_atoms"], vol_A3)
d111 = lattices.interplanar_spacing((1, 1, 1), cell["lattice_vectors"])
b_burgers = a_alloy / np.sqrt(2.0)
xrd_peaks = diffraction.simulate_powder_xrd("fcc", a_A=a_alloy, max_hkl=2, atomic_Z=z_alloy)
tt_111 = xrd_peaks[0]["two_theta_deg"]
c11 = (1.0 - x_sol) * el_A["C11_GPa"] + x_sol * el_B["C11_GPa"]
c12 = (1.0 - x_sol) * el_A["C12_GPa"] + x_sol * el_B["C12_GPa"]
c44 = (1.0 - x_sol) * el_A["C44_GPa"] + x_sol * el_B["C44_GPa"]
born = elasticity.verify_born_stability_cubic(c11, c12, c44)
vrh = elasticity.voigt_reuss_hill_cubic(c11, c12, c44)
az = elasticity.zener_anisotropy(c11, c12, c44)
pn = atomistics.peierls_nabarro_stress(G_GPa=vrh["G_hill"], nu=vrh["nu_hill"], b_A=b_burgers, d_A=d111)
xv = atomistics.vacancy_equilibrium_fraction(T_homog_K, E_v_eV=0.75 + 0.30 * x_sol, S_v_kB=1.5)
return {
"x": x_sol, "a_A": a_alloy, "rho_kg_m3": rho_kg_m3, "tt_111_deg": tt_111,
"b_nm": 0.1 * b_burgers, "born_stable": born["stable"], "A_Z": az,
"E_GPa": vrh["E_hill"], "G_GPa": vrh["G_hill"], "pugh_B_G": vrh["pugh_B_over_G"],
"ductile": vrh["ductile_by_pugh"], "tau_pn_MPa": pn["tau_pn_MPa"], "x_vac": float(xv),
}
print(f"{'x_Cu':>6s} | {'a [A]':>7s} | {'rho [kg/m^3]':>12s} | {'2theta_111':>10s} | {'E_Hill [GPa]':>12s} | {'Pugh B/G':>9s} | {'tau_PN [MPa]':>12s} | {'x_vac(850K)':>11s}")
print("-" * 102)
for x_val in [0.00, 0.25, 0.35, 0.50]:
sc = screen_fcc_alloy_composition(x_val)
print(f"{sc['x']:6.2f} | {sc['a_A']:7.4f} | {sc['rho_kg_m3']:12.0f} | {sc['tt_111_deg']:10.2f} | "
f"{sc['E_GPa']:12.1f} | {sc['pugh_B_G']:9.2f} | {sc['tau_pn_MPa']:12.1f} | {sc['x_vac']:11.2e}")
assert sc["born_stable"] is True and sc["ductile"] is True
# Contrast against covalent Silicon in ELEMENTS_DB (Pugh B/G < 1.75 -> intrinsically brittle):
si_el = constants.ELEMENTS_DB["Si"]
si_vrh = elasticity.voigt_reuss_hill_cubic(si_el["C11_GPa"], si_el["C12_GPa"], si_el["C44_GPa"])
print(f"\nBrittle reference check — Diamond-cubic Si: Pugh B/G = {si_vrh['pugh_B_over_G']:.2f} (< 1.75), ductile_by_pugh = {si_vrh['ductile_by_pugh']}")
assert si_vrh["ductile_by_pugh"] is False
_stdout.__exit__(None, None, None); plt.show = _show; plt.close("all")Exercise 1¶
Problem. Screen all 12 cubic elements in constants.ELEMENTS_DB using lattices.element_crystal_summary, diffraction.simulate_powder_xrd, and elasticity.voigt_reuss_hill_cubic. Verify for every element, verify the first allowed XRD reflection is for FCC, for BCC, and for diamond-cubic (with systematically absent), and verify Pugh’s classifies all 5 FCC metals as ductile and all 3 diamond-cubic semiconductors/insulators as brittle.
heading("Exercise 1: High-Throughput Crystallographic, XRD & VRH Ductility Screening Across ELEMENTS_DB")
print(f"{'Sym':>9s} | {'Struct':>7s} | {'rho [g/cm3]':>11s} | {'1st XRD Peak':>12s} | {'G_R <= G_H <= G_V [GPa]':>26s} | {'Pugh B/G':>9s} | {'Ductile?'}")
print("-" * 98)
for sym, props in constants.ELEMENTS_DB.items():
if props["structure"] == "hcp":
continue
summ = lattices.element_crystal_summary(sym)
pks = diffraction.simulate_powder_xrd(props["structure"], a_A=props["a_A"], max_hkl=2, atomic_Z=props["Z"])
vrh = elasticity.voigt_reuss_hill_cubic(props["C11_GPa"], props["C12_GPa"], props["C44_GPa"])
assert vrh["G_voigt"] >= vrh["G_hill"] - 1e-12 and vrh["G_hill"] >= vrh["G_reuss"] - 1e-12
hkl_first = tuple(sorted((abs(x) for x in pks[0]["hkl"]), reverse=True))
if props["structure"] == "fcc":
assert hkl_first == (1, 1, 1) and vrh["ductile_by_pugh"] is True
elif props["structure"] == "bcc":
assert hkl_first == (1, 1, 0)
elif props["structure"] == "diamond":
assert hkl_first == (1, 1, 1) and vrh["ductile_by_pugh"] is False
# Verify systematic absence of {200} in diamond-cubic
hkl_norms = [sum(i * i for i in pk["hkl"]) for pk in pks]
assert 4 not in hkl_norms
bounds_str = f"{vrh['G_reuss']:5.1f} <= {vrh['G_hill']:5.1f} <= {vrh['G_voigt']:5.1f}"
print(f"{sym:>9s} | {props['structure']:>7s} | {summ['density_g_cm3']:11.3f} | {str(pks[0]['hkl']):>12s} | {bounds_str:>26s} | {vrh['pugh_B_over_G']:9.2f} | {vrh['ductile_by_pugh']}")
Exercise 1: High-Throughput Crystallographic, XRD & VRH Ductility Screening Across ELEMENTS_DB
==============================================================================================
Sym | Struct | rho [g/cm3] | 1st XRD Peak | G_R <= G_H <= G_V [GPa] | Pugh B/G | Ductile?
--------------------------------------------------------------------------------------------------
Cu | fcc | 8.935 | (1, 1, 1) | 40.0 <= 47.3 <= 54.6 | 2.90 | True
Al | fcc | 2.699 | (1, 1, 1) | 26.0 <= 26.2 <= 26.3 | 2.92 | True
Ni | fcc | 8.908 | (1, 1, 1) | 77.7 <= 86.2 <= 94.7 | 2.09 | True
Au | fcc | 19.288 | (1, 1, 1) | 24.0 <= 27.5 <= 31.0 | 6.28 | True
Ag | fcc | 10.508 | (1, 1, 1) | 25.5 <= 29.7 <= 33.8 | 3.49 | True
Fe | bcc | 7.874 | (1, 1, 0) | 74.5 <= 81.8 <= 89.2 | 2.04 | True
W | bcc | 19.254 | (1, 1, 0) | 160.0 <= 160.0 <= 160.0 | 1.94 | True
Mo | bcc | 10.224 | (1, 1, 0) | 123.3 <= 125.0 <= 126.7 | 2.08 | True
Cr | bcc | 7.008 | (1, 1, 0) | 113.8 <= 115.4 <= 116.9 | 1.40 | False
Si | diamond | 2.329 | (1, 1, 1) | 65.0 <= 66.5 <= 68.1 | 1.47 | False
Ge | diamond | 5.327 | (1, 1, 1) | 52.8 <= 54.4 <= 56.1 | 1.38 | False
C-diamond | diamond | 3.516 | (1, 1, 1) | 531.6 <= 534.0 <= 536.4 | 0.83 | False
Explanation. Directional covalent bonds in diamond-cubic , , and -diamond strongly resist bond-bending shear ( is large relative to bulk compression , giving negative Cauchy pressure and ), whereas non-directional metallic bonding in FCC yields positive Cauchy pressure and .
Exercise 2¶
Problem. Audit two industrial ICME heat-treatment failure modes for (): (a) furnace overshoot to , where regular_solution_spinodal returns None and everywhere; and (b) off-composition melt outside the Landau spinodal , where cahn_hilliard_1d_spectral damps composition fluctuations exponentially instead of forming precipitates.
heading("Exercise 2: Heat-Treating Above T_c or Outside the Spinodal — Fluctuation Decay Failure Audit")
omega_val = 14_500.0
Tc = phase_thermodynamics.regular_solution_critical_temp(omega_val)
spin_above = phase_thermodynamics.regular_solution_spinodal(910.0, omega_val)
reg_910 = phase_thermodynamics.regular_solution_free_energy(np.linspace(0.05, 0.95, 19), T_K=910.0, omega_J_mol=omega_val)
print(f"Critical temp T_c = {Tc:.2f} K | At T_bad = 910 K: spinodal = {spin_above}, min(d^2G/dx^2) = {np.min(reg_910['d2G_dx2']):.1f} J/mol (> 0)")
assert spin_above is None and np.all(reg_910["d2G_dx2"] > 0.0)
# Off-composition alloy c0 = 0.08 (outside spinodal [0.2113, 0.7887]) vs inside spinodal c0 = 0.45:
rng_f = np.random.default_rng(1709)
pert = rng_f.uniform(-0.02, 0.02, size=64)
pert -= np.mean(pert)
sim_out = phase_field.cahn_hilliard_1d_spectral(0.08 + pert, L=32.0, dt=0.10, n_steps=450, M=1.0, W=2.0, kappa=0.5)
sim_in = phase_field.cahn_hilliard_1d_spectral(0.45 + pert, L=32.0, dt=0.10, n_steps=450, M=1.0, W=2.0, kappa=0.5)
std_init = float(np.std(pert))
std_out = float(np.std(sim_out["final"]))
std_in = float(np.std(sim_in["final"]))
print(f"Outside spinodal (c0=0.08): fluctuation std decayed {std_init:.4f} -> {std_out:.6f} (DISSOLVED)")
print(f"Inside spinodal (c0=0.45): fluctuation std grew {std_init:.4f} -> {std_in:.4f} (PHASE SEPARATED)")
assert std_out < 0.01 * std_init and std_in > 25.0 * std_init
Exercise 2: Heat-Treating Above T_c or Outside the Spinodal — Fluctuation Decay Failure Audit
=============================================================================================
Critical temp T_c = 871.97 K | At T_bad = 910 K: spinodal = None, min(d^2G/dx^2) = 1264.6 J/mol (> 0)
Outside spinodal (c0=0.08): fluctuation std decayed 0.0124 -> 0.000043 (DISSOLVED)
Inside spinodal (c0=0.45): fluctuation std grew 0.0124 -> 0.3986 (PHASE SEPARATED)
Explanation. Whenever or , the chemical curvature makes the effective diffusivity strictly downhill. Every wavenumber has , so small fluctuations decay and the solution stays uniform.
Exercise 3¶
Problem. Implement icme_pareto_alloy_optimizer(x_ni_grid, d_grain_grid_um) for ductile FCC solid-solution structural alloys (assumed costs of 9 USD/kg for Cu and 18 USD/kg for Ni), coupling lattices, elasticity, and kinetics_selection (hall_petch_yield_strength + pareto_frontier_2d) to find all non-dominated schedules minimizing volumetric cost () while maximizing specific yield strength ().
heading("Exercise 3: Implement It Yourself — Multi-Objective Cu-Ni ICME Alloy & Grain-Size Pareto Optimizer")
def icme_pareto_alloy_optimizer(x_ni_grid: np.ndarray, d_grain_grid_um: np.ndarray) -> list[dict]:
"""Screen ductile Cu_{1-x}Ni_x FCC alloys and extract the (volumetric_cost, specific_strength) Pareto frontier."""
cu, ni = constants.ELEMENTS_DB["Cu"], constants.ELEMENTS_DB["Ni"]
designs = []
for x_ni in x_ni_grid:
x_f = float(x_ni)
a_lat = (1.0 - x_f) * cu["a_A"] + x_f * ni["a_A"]
mw = (1.0 - x_f) * cu["Mw"] + x_f * ni["Mw"]
cell = lattices.cubic_unit_cell("fcc", a_A=a_lat)
vol = lattices.metric_tensor(cell["lattice_vectors"])["volume_A3"]
rho_kg_m3 = 1000.0 * lattices.theoretical_density_g_cm3(mw, cell["n_atoms"], vol)
c11 = (1.0 - x_f) * cu["C11_GPa"] + x_f * ni["C11_GPa"]
c12 = (1.0 - x_f) * cu["C12_GPa"] + x_f * ni["C12_GPa"]
c44 = (1.0 - x_f) * cu["C44_GPa"] + x_f * ni["C44_GPa"]
vrh = elasticity.voigt_reuss_hill_cubic(c11, c12, c44)
if not vrh["ductile_by_pugh"]:
continue
cost_usd_kg = (1.0 - x_f) * 9.0 + x_f * 18.0
vol_cost = cost_usd_kg * rho_kg_m3
# Labusch-Fleischer solid-solution strengthening + modulus scaling:
sig_0 = 55.0 + 0.35 * vrh["G_hill"] + 380.0 * ((x_f * (1.0 - x_f)) ** (2.0 / 3.0))
for dg in d_grain_grid_um:
dg_f = float(dg)
# Grain-refinement thermomechanical rolling adds processing cost proportional to d^{-1/2}:
proc_vol_cost = vol_cost * (1.0 + 0.12 / np.sqrt(dg_f))
sy = kinetics_selection.hall_petch_yield_strength(dg_f, sigma_0_MPa=sig_0, k_hp_MPa_sqrt_um=240.0)
designs.append({
"x_Ni": x_f,
"d_grain_um": dg_f,
"rho_kg_m3": rho_kg_m3,
"E_GPa": vrh["E_hill"],
"pugh_B_G": vrh["pugh_B_over_G"],
"vol_cost_usd_m3": proc_vol_cost,
"sigma_y_MPa": sy,
"specific_strength": sy / rho_kg_m3,
})
cost_arr = np.array([d["vol_cost_usd_m3"] for d in designs])
spec_sy = np.array([d["specific_strength"] for d in designs])
p_idx = kinetics_selection.pareto_frontier_2d(minimize_x=cost_arr, maximize_y=spec_sy)
return [designs[int(i)] for i in p_idx]
pareto_cuni = icme_pareto_alloy_optimizer(np.linspace(0.10, 0.80, 8), np.array([1.0, 4.0, 16.0, 50.0]))
print(f"Found {len(pareto_cuni)} Pareto-optimal Cu-Ni ICME schedules (sorted from lowest cost to highest specific strength):")
for d in pareto_cuni[:4] + pareto_cuni[-3:]:
print(f" x_Ni={d['x_Ni']:.2f}, d={d['d_grain_um']:4.1f} um | E={d['E_GPa']:5.1f} GPa | Pugh={d['pugh_B_G']:.2f} | "
f"Cost={d['vol_cost_usd_m3']/1e3:6.1f} k$/m3 | sigma_y={d['sigma_y_MPa']:5.1f} MPa | spec={d['specific_strength']:.4f}")
costs_p = np.array([d["vol_cost_usd_m3"] for d in pareto_cuni])
spec_p = np.array([d["specific_strength"] for d in pareto_cuni])
assert len(pareto_cuni) >= 5
assert np.all(np.diff(costs_p) >= 0.0) and np.all(np.diff(spec_p) > 0.0)
assert all(d["pugh_B_G"] > 1.75 for d in pareto_cuni)
Exercise 3: Implement It Yourself — Multi-Objective Cu-Ni ICME Alloy & Grain-Size Pareto Optimizer
==================================================================================================
Found 8 Pareto-optimal Cu-Ni ICME schedules (sorted from lowest cost to highest specific strength):
x_Ni=0.10, d=50.0 um | E=137.2 GPa | Pugh=2.76 | Cost= 90.0 k$/m3 | sigma_y=183.2 MPa | spec=0.0205
x_Ni=0.10, d=16.0 um | E=137.2 GPa | Pugh=2.76 | Cost= 91.1 k$/m3 | sigma_y=209.3 MPa | spec=0.0234
x_Ni=0.10, d= 4.0 um | E=137.2 GPa | Pugh=2.76 | Cost= 93.8 k$/m3 | sigma_y=269.3 MPa | spec=0.0301
x_Ni=0.10, d= 1.0 um | E=137.2 GPa | Pugh=2.76 | Cost= 99.1 k$/m3 | sigma_y=389.3 MPa | spec=0.0436
x_Ni=0.30, d= 1.0 um | E=156.7 GPa | Pugh=2.54 | Cost= 117.0 k$/m3 | sigma_y=449.9 MPa | spec=0.0504
x_Ni=0.40, d= 1.0 um | E=166.3 GPa | Pugh=2.45 | Cost= 126.0 k$/m3 | sigma_y=463.8 MPa | spec=0.0519
x_Ni=0.50, d= 1.0 um | E=175.8 GPa | Pugh=2.37 | Cost= 135.0 k$/m3 | sigma_y=469.2 MPa | spec=0.0526
Summary. The project connects the scales of the book: starting at the Ångström crystal unit cell (lattices, diffraction, atomistics), homogenizing single-crystal elasticity (elasticity), mapping thermodynamic phase stability and phase-field microstructure (phase_thermodynamics, phase_field), and closing the design loop on macroscopic multi-objective Pareto frontiers (kinetics_selection).