Worked solutions to the three exercises of Lecture 5. 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: 6x6 Voigt Stiffness C, Compliance S = C^-1 & Exact Analytical Inversion (Cu)")
cu = constants.ELEMENTS_DB["Cu"]
C11, C12, C44 = cu["C11_GPa"], cu["C12_GPa"], cu["C44_GPa"]
C_cu = elasticity.cubic_stiffness_voigt(C11, C12, C44)
S_cu = elasticity.cubic_compliance_voigt(C11, C12, C44)
S11_ex = (C11 + C12) / ((C11 - C12) * (C11 + 2.0 * C12))
S12_ex = -C12 / ((C11 - C12) * (C11 + 2.0 * C12))
S44_ex = 1.0 / C44
print("Cu Voigt Stiffness C [GPa]:\n", C_cu)
print(f"\nS11 = {S_cu[0,0]:.6f} 1/GPa (exact = {S11_ex:.6f}) -> E_[100] = 1/S11 = {1.0/S_cu[0,0]:.3f} GPa")
print(f"S12 = {S_cu[0,1]:.6f} 1/GPa (exact = {S12_ex:.6f}) -> nu_[100] = -S12/S11 = {-S_cu[0,1]/S_cu[0,0]:.4f}")
print(f"S44 = {S_cu[3,3]:.6f} 1/GPa (exact = {S44_ex:.6f})")
assert np.allclose(C_cu @ S_cu, np.eye(6), atol=1e-15)
assert np.isclose(S_cu[0, 0], S11_ex, rtol=1e-14)
assert np.isclose(S_cu[0, 1], S12_ex, rtol=1e-14)
assert np.isclose(S_cu[3, 3], S44_ex, rtol=1e-14)
_stdout.__exit__(None, None, None); plt.show = _show; plt.close("all")Exercise 1¶
Problem. Generate a 600-direction spherical Fibonacci grid and verify across all 12 cubic elements in ELEMENTS_DB that is bounded strictly between and , ordered according to .
heading("Exercise 1: Global Spherical Extremal Bounds on E(n) Across All 12 Cubic Elements")
idx_f = np.arange(600, dtype=float) + 0.5
phi_f = np.arccos(1.0 - 2.0 * idx_f / 600.0)
th_f = np.pi * (1.0 + np.sqrt(5.0)) * idx_f
dirs_600 = np.column_stack([np.sin(phi_f) * np.cos(th_f), np.sin(phi_f) * np.sin(th_f), np.cos(phi_f)])
for sym, m in constants.ELEMENTS_DB.items():
if m["C11_GPa"] is None:
continue
c11, c12, c44 = m["C11_GPa"], m["C12_GPa"], m["C44_GPa"]
az = elasticity.zener_anisotropy(c11, c12, c44)
e_grid = elasticity.directional_youngs_modulus_cubic(c11, c12, c44, dirs_600)
e100 = elasticity.directional_youngs_modulus_cubic(c11, c12, c44, [1, 0, 0])
e111 = elasticity.directional_youngs_modulus_cubic(c11, c12, c44, [1, 1, 1])
lo, hi = (e100, e111) if az >= 1.0 else (e111, e100)
print(f"{sym:9s} | A_Z = {az:6.3f} | Theoretical [{lo:6.1f}, {hi:6.1f}] GPa | Grid [{np.min(e_grid):6.1f}, {np.max(e_grid):6.1f}] GPa")
assert np.all((e_grid >= lo - 1e-10) & (e_grid <= hi + 1e-10))
Exercise 1: Global Spherical Extremal Bounds on E(n) Across All 12 Cubic Elements
=================================================================================
Cu | A_Z = 3.209 | Theoretical [ 66.7, 191.1] GPa | Grid [ 66.8, 191.1] GPa
Al | A_Z = 1.217 | Theoretical [ 63.3, 75.6] GPa | Grid [ 63.3, 75.6] GPa
Ni | A_Z = 2.514 | Theoretical [ 136.3, 304.0] GPa | Grid [ 136.4, 304.0] GPa
Au | A_Z = 2.877 | Theoretical [ 42.6, 116.6] GPa | Grid [ 42.6, 116.5] GPa
Ag | A_Z = 3.013 | Theoretical [ 43.7, 120.4] GPa | Grid [ 43.8, 120.4] GPa
Fe | A_Z = 2.407 | Theoretical [ 132.3, 283.3] GPa | Grid [ 132.4, 283.3] GPa
W | A_Z = 1.010 | Theoretical [ 407.4, 410.9] GPa | Grid [ 407.4, 410.9] GPa
Mo | A_Z = 0.714 | Theoretical [ 287.3, 383.6] GPa | Grid [ 287.3, 383.4] GPa
Cr | A_Z = 0.714 | Theoretical [ 250.4, 328.0] GPa | Grid [ 250.4, 327.9] GPa
Si | A_Z = 1.564 | Theoretical [ 130.1, 187.9] GPa | Grid [ 130.2, 187.8] GPa
Ge | A_Z = 1.666 | Theoretical [ 102.1, 154.5] GPa | Grid [ 102.2, 154.5] GPa
C-diamond | A_Z = 1.213 | Theoretical [1050.0, 1206.2] GPa | Grid [1050.2, 1206.1] GPa
Explanation. By Cauchy–Schwarz, , attained at () and (). Because is linear in , its global extrema on must lie at and .
Exercise 2¶
Problem. Quantify the spurious anisotropy created along [111] in an isotropic crystal (, ) when is mistakenly written as , and verify Born instability detection on .
heading("Exercise 2: Diagnostic Audit — Missing Voigt 1/2 Factor & Tetragonal Instability Trap")
C11_iso, C12_iso, C44_iso = 260.0, 100.0, 80.0
assert np.isclose(elasticity.zener_anisotropy(C11_iso, C12_iso, C44_iso), 1.0, rtol=1e-15)
S_iso = elasticity.cubic_compliance_voigt(C11_iso, C12_iso, C44_iso)
s11, s12, s44 = S_iso[0, 0], S_iso[0, 1], S_iso[3, 3]
e100_true = elasticity.directional_youngs_modulus_cubic(C11_iso, C12_iso, C44_iso, [1, 0, 0])
e111_true = elasticity.directional_youngs_modulus_cubic(C11_iso, C12_iso, C44_iso, [1, 1, 1])
e111_voigt_bug = 1.0 / (s11 - 2.0 * (s11 - s12 - s44) * (1.0 / 3.0)) # Bug: missing 0.5 before s44
print(f"Isotropic solid (A_Z=1): E_[100] = {e100_true:.3f} GPa, True E_[111] = {e111_true:.3f} GPa")
print(f"Missing-1/2 Voigt bug : E_[111]_bug = {e111_voigt_bug:.3f} GPa (spurious {100.0*(e111_true - e111_voigt_bug)/e111_true:.2f}% drop)")
assert np.isclose(e100_true, e111_true, rtol=1e-14)
assert abs(e111_voigt_bug - e111_true) / e111_true > 0.25
trap = elasticity.verify_born_stability_cubic(150.0, 170.0, 60.0)
print(f"Positive-entry trap (150, 170, 60): stable = {trap['stable']}, min eigenvalue = {np.min(trap['eigenvalues_GPa']):.1f} GPa")
assert not trap["stable"] and np.isclose(np.min(trap["eigenvalues_GPa"]), -20.0, atol=1e-12)
Exercise 2: Diagnostic Audit — Missing Voigt 1/2 Factor & Tetragonal Instability Trap
=====================================================================================
Isotropic solid (A_Z=1): E_[100] = 204.444 GPa, True E_[111] = 204.444 GPa
Missing-1/2 Voigt bug : E_[111]_bug = 110.400 GPa (spurious 46.00% drop)
Positive-entry trap (150, 170, 60): stable = False, min eigenvalue = -20.0 GPa
Explanation. Because Voigt compliance stores , tensor shear compliance is (making ). Omitting the breaks rotational invariance even for an isotropic solid. Meanwhile, has all positive entries and positive bulk modulus (), yet spontaneously shears tetragonally ().
Exercise 3¶
Problem. Implement cubic_hydrostatic_linear_compressibility(C11, C12, C44, directions) under hydrostatic pressure and verify on Cu and Au that is strictly independent of crystallographic direction.
heading("Exercise 3: Implement It Yourself — Isotropic Linear Compressibility of Anisotropic Cubic Crystals")
def cubic_hydrostatic_linear_compressibility(
C11: float, C12: float, C44: float, directions: np.ndarray
) -> np.ndarray:
"""Compute directional linear compressibility beta_lin(n) [1/GPa] under unit hydrostatic pressure."""
s_mat = elasticity.cubic_compliance_voigt(C11, C12, C44)
eps_voigt = s_mat @ np.array([-1.0, -1.0, -1.0, 0.0, 0.0, 0.0])
eps_tensor = np.array([
[eps_voigt[0], 0.5 * eps_voigt[5], 0.5 * eps_voigt[4]],
[0.5 * eps_voigt[5], eps_voigt[1], 0.5 * eps_voigt[3]],
[0.5 * eps_voigt[4], 0.5 * eps_voigt[3], eps_voigt[2]],
])
dirs = np.atleast_2d(np.asarray(directions, dtype=float))
n_unit = dirs / np.linalg.norm(dirs, axis=1, keepdims=True)
return -np.einsum("ni,ij,nj->n", n_unit, eps_tensor, n_unit)
test_dirs = np.array([[1, 0, 0], [1, 1, 0], [1, 1, 1], [1, 2, 3], [-2, 5, 1]], dtype=float)
for sym in ["Cu", "Au", "Cr"]:
m = constants.ELEMENTS_DB[sym]
b_mod = elasticity.verify_born_stability_cubic(m["C11_GPa"], m["C12_GPa"], m["C44_GPa"])["bulk_modulus_GPa"]
beta_vec = cubic_hydrostatic_linear_compressibility(m["C11_GPa"], m["C12_GPa"], m["C44_GPa"], test_dirs)
print(f"{sym}: beta_lin across 5 directions = {np.round(beta_vec * 1e3, 6)} 10^-3/GPa vs 1/(3B) = {1e3 / (3.0 * b_mod):.6f}")
assert np.allclose(beta_vec, 1.0 / (3.0 * b_mod), rtol=1e-14)
Exercise 3: Implement It Yourself — Isotropic Linear Compressibility of Anisotropic Cubic Crystals
==================================================================================================
Cu: beta_lin across 5 directions = [2.431907 2.431907 2.431907 2.431907 2.431907] 10^-3/GPa vs 1/(3B) = 2.431907
Au: beta_lin across 5 directions = [1.92864 1.92864 1.92864 1.92864 1.92864] 10^-3/GPa vs 1/(3B) = 1.928640
Cr: beta_lin across 5 directions = [2.059308 2.059308 2.059308 2.059308 2.059308] 10^-3/GPa vs 1/(3B) = 2.059308
Summary. Unlike 4th-rank uniaxial Young’s modulus (which has two cubic invariants and varies up to with direction), directional linear compressibility is a symmetric 2nd-rank tensor, and by Neumann’s symmetry principle, every 2nd-rank tensor in a cubic crystal (thermal expansion, electrical conductivity, diffusivity, and hydrostatic linear compressibility) is strictly proportional to , so cubic crystals never change shape under uniform hydrostatic pressure.