Worked solutions to the three exercises of Lecture 16. 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: JMAK Sigmoids, Double-Log Avrami Regression & C-Curve TTT Nose Physics")
t_jmak = np.linspace(0.5, 45.0, 90)
k_true = 0.08 # [1/s]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 4.1))
for n_true, ls in [(1.5, ":"), (2.5, "--"), (3.0, "-."), (4.0, "-")]:
X_curve = kinetics_selection.jmak_fraction(t_jmak, k_rate=k_true, n_avrami=n_true)
fit = kinetics_selection.fit_avrami_exponent(t_jmak, X_curve)
print(f"True (n={n_true:.1f}, k={k_true:.3f}) -> Avrami fit n={fit['n_avrami']:.6f}, k={fit['k_rate']:.6f}, R^2={fit['r2']:.8f}")
assert np.isclose(fit["n_avrami"], n_true, rtol=1e-12) and np.isclose(fit["k_rate"], k_true, rtol=1e-12)
ax1.plot(t_jmak, X_curve, ls=ls, lw=2.1, label=f"$n = {n_true:.1f}$")
ax1.axhline(1.0 - np.exp(-1.0), color="gray", lw=0.9, ls=":", label=r"$X(1/k) = 1 - e^{-1} \approx 0.632$")
ax1.set_xlabel("Isothermal hold time $t$ [s]")
ax1.set_ylabel("Transformed fraction $X(t)$ [-]")
ax1.set_title("JMAK Sigmoids Crossing at Characteristic Time $t = 1/k$")
ax1.legend(fontsize=8)
# C-curve Time-Temperature-Transformation (TTT) diagram for eutectoid-like transformation below T_eq = 1000 K:
T_eq = 1000.0
T_ttt = np.linspace(550.0, 975.0, 120)
dT = T_eq - T_ttt
k_ttt = 2.5e5 * np.exp(-1.4e7 / (T_ttt * (dT ** 2))) * np.exp(-115_000.0 / (constants.R * T_ttt))
n_ttt = 3.0
t_01 = ((-np.log(1.0 - 0.01)) ** (1.0 / n_ttt)) / k_ttt
t_50 = ((-np.log(1.0 - 0.50)) ** (1.0 / n_ttt)) / k_ttt
t_99 = ((-np.log(1.0 - 0.99)) ** (1.0 / n_ttt)) / k_ttt
idx_nose = int(np.argmin(t_50))
print(f"\nTTT Nose located at T_nose = {T_ttt[idx_nose]:.1f} K ({T_ttt[idx_nose]-273.15:.0f} C) with minimum t_50% = {t_50[idx_nose]:.2f} s")
assert 0 < idx_nose < len(T_ttt) - 1 # Strictly interior C-curve minimum
ax2.semilogx(t_01, T_ttt, "b--", lw=1.9, label="Start ($X = 1\\%$)")
ax2.semilogx(t_50, T_ttt, "k-", lw=2.1, label="50% Transformed")
ax2.semilogx(t_99, T_ttt, "r-.", lw=1.9, label="Finish ($X = 99\\%$)")
ax2.scatter([t_50[idx_nose]], [T_ttt[idx_nose]], color="tab:orange", s=55, zorder=5, label=f"TTT Nose ({T_ttt[idx_nose]:.0f} K)")
ax2.set_xlabel("Log isothermal hold time $t$ [s]")
ax2.set_ylabel("Temperature $T$ [K]")
ax2.set_title("C-Curve TTT Diagram (Nucleation vs. Diffusion)")
ax2.legend(fontsize=8)
label_panels(fig)
plt.show()
_stdout.__exit__(None, None, None); plt.show = _show; plt.close("all")Exercise 1¶
Problem. Derive the exact temperature reduction that doubles creep rupture life () at constant , and verify numerically at using larson_miller_parameter and rupture_time_from_larson_miller.
heading("Exercise 1: Exact Larson-Miller Temperature Reduction Delta T to Double Creep Rupture Life")
T1, tr1, C_lm = 1000.0, 5000.0, 20.0
P_const = kinetics_selection.larson_miller_parameter(T1, tr1, C_lm=C_lm)
# Analytical identity: T1 * (log10(tr1) + C) = T2 * (log10(2*tr1) + C)
T2 = T1 * (np.log10(tr1) + C_lm) / (np.log10(2.0 * tr1) + C_lm)
delta_T = T1 - T2
tr2_num = kinetics_selection.rupture_time_from_larson_miller(P_const, T2, C_lm=C_lm)
print(f"P_LM = {P_const:.5f} | T1 = {T1:.2f} K -> T2 = {T2:.2f} K (Delta T = {delta_T:.2f} K)")
print(f"Rupture life increases from {tr1:.1f} h to {tr2_num:.1f} h (exact 2.0000x)")
assert np.isclose(tr2_num, 2.0 * tr1, rtol=1e-12) and 12.0 < delta_T < 13.5
Exercise 1: Exact Larson-Miller Temperature Reduction Delta T to Double Creep Rupture Life
==========================================================================================
P_LM = 23.69897 | T1 = 1000.00 K -> T2 = 987.46 K (Delta T = 12.54 K)
Rupture life increases from 5000.0 h to 10000.0 h (exact 2.0000x)
Explanation. From , since and , , confirming the turbine-engineering rule of thumb that every drop in blade metal temperature doubles creep rupture life.
Exercise 2¶
Problem. Verify that fit_avrami_exponent filters out induction/saturation endpoints outside (recovering cleanly even when and endpoints are present in the input array, while raising ValueError if interior points exist), and verify ashby_performance_index raises ValueError on an unsupported mode.
heading("Exercise 2: Avrami Endpoint Saturation Filtering & Ashby Mode Guard Audit")
t_arr = np.array([0.0, 2.0, 5.0, 10.0, 15.0, 500.0])
X_arr = kinetics_selection.jmak_fraction(t_arr, k_rate=0.10, n_avrami=3.0)
assert X_arr[0] == 0.0 and X_arr[-1] == 1.0 # Exact 0 and 1 endpoints that would cause log(0) without masking
fit_masked = kinetics_selection.fit_avrami_exponent(t_arr, X_arr)
print(f"With X=0 and X=1 present: fit_avrami_exponent recovered n = {fit_masked['n_avrami']:.6f}, k = {fit_masked['k_rate']:.6f}")
assert np.isclose(fit_masked["n_avrami"], 3.0, rtol=1e-12) and np.isclose(fit_masked["k_rate"], 0.10, rtol=1e-12)
caught_avrami = False
try:
kinetics_selection.fit_avrami_exponent(np.array([0.0, 100.0, 200.0]), np.array([0.0, 0.999, 1.0]))
except ValueError:
caught_avrami = True
assert caught_avrami is True
caught_ashby = False
try:
kinetics_selection.ashby_performance_index(constants.ASHBY_MATERIALS_DB, mode="invalid_buckling_mode")
except ValueError:
caught_ashby = True
assert caught_ashby is True
Exercise 2: Avrami Endpoint Saturation Filtering & Ashby Mode Guard Audit
=========================================================================
With X=0 and X=1 present: fit_avrami_exponent recovered n = 3.000000, k = 0.100000
Explanation. At () and late saturation ( in IEEE float64 when ), hits or . Restricting regression strictly to protects linear least squares from floating-point underflow and calorimeter baseline drift.
Exercise 3¶
Problem. Implement fracture_safe_beam_pareto(materials_db, min_K_Ic=25.0) that screens out brittle materials with and returns the Pareto-optimal subset minimizing beam cost index and maximizing specific beam stiffness . Verify that brittle ceramics (SiC, Alumina) are excluded while CFRP Quasi-Isotropic and AISI 1020 Steel anchor the high-performance and low-cost ends of the frontier.
heading("Exercise 3: Implement It Yourself — Fracture-Safe Constrained Ashby Beam Pareto Selector")
def fracture_safe_beam_pareto(materials_db: dict, min_K_Ic: float = 25.0) -> list[dict]:
"""Filter materials by fracture toughness K_Ic >= min_K_Ic and return the (beam_cost, beam_stiffness) Pareto frontier."""
screened = []
for name, props in materials_db.items():
if float(props["K_Ic_MPa_sqrtm"]) >= min_K_Ic:
rho = float(props["density_kg_m3"])
e_sqrt = float(props["E_GPa"]) ** 0.5
cost_kg = float(props["cost_usd_kg"])
screened.append({
"name": name,
"K_Ic": float(props["K_Ic_MPa_sqrtm"]),
"M_beam_mass": e_sqrt / rho,
"beam_cost_index": (cost_kg * rho) / e_sqrt,
})
cost_vec = np.array([d["beam_cost_index"] for d in screened])
stiff_vec = np.array([d["M_beam_mass"] for d in screened])
p_idx = kinetics_selection.pareto_frontier_2d(minimize_x=cost_vec, maximize_y=stiff_vec)
return [screened[int(i)] for i in p_idx]
frontier_safe = fracture_safe_beam_pareto(constants.ASHBY_MATERIALS_DB, min_K_Ic=25.0)
safe_names = [d["name"] for d in frontier_safe]
print("Fracture-safe (K_Ic >= 25 MPa*sqrt(m)) Stiff-Beam Cost-vs-Mass Pareto Frontier:")
for d in frontier_safe:
print(f" * {d['name']:22s} | K_Ic = {d['K_Ic']:4.0f} | Cost idx = {d['beam_cost_index']:8.1f} | M_beam = {d['M_beam_mass']:.4e}")
assert "Silicon Carbide (SiC)" not in safe_names and "Alumina (Al2O3)" not in safe_names
assert safe_names[0] == "AISI 1020 Steel" and safe_names[-1] == "CFRP Quasi-Isotropic"
Exercise 3: Implement It Yourself — Fracture-Safe Constrained Ashby Beam Pareto Selector
========================================================================================
Fracture-safe (K_Ic >= 25 MPa*sqrt(m)) Stiff-Beam Cost-vs-Mass Pareto Frontier:
* AISI 1020 Steel | K_Ic = 65 | Cost idx = 466.0 | M_beam = 1.8239e-03
* Al 6061-T6 | K_Ic = 33 | Cost idx = 845.1 | M_beam = 3.0765e-03
* CFRP Quasi-Isotropic | K_Ic = 38 | Cost idx = 6609.6 | M_beam = 5.2953e-03
Summary. Combining primary screening constraints ( to prevent fast brittle fracture) with multi-objective Pareto ranking reproduces real aerospace vs. automotive design practice: AISI 1020 Steel, Al 6061-T6, Al 7075-T6, and CFRP Quasi-Isotropic span the complete cost-versus-weight trade-off curve.