Not every microstructural field in metallurgy is conserved. While solute concentration must obey mass continuity, crystallographic grain orientation, antiphase domain order in () intermetallics, and ferroelectric polarization are non-conserved order parameters that can relax locally by short-range atomic jumps across a boundary without long-range diffusion. In 1979, Samuel M. Allen and John W. Cahn showed that such interfaces migrate along their normal at a speed directly proportional to local mean curvature (), causing circular 2-D grains to shrink in area at a constant universal rate independent of grain size. In this lecture we verify this area law for a shrinking circle with phase_field.allen_cahn_2d_spectral and contrast curvature-driven coarsening against diffusion-limited Cahn–Hilliard coarsening.
Learning objectives¶
Distinguish non-conserved gradient flows (, Model A) from conserved flows (, Model B).
Integrate 2-D non-conserved domain evolution via
phase_field.allen_cahn_2d_spectraland contrast non-conservedphase_fractionsagainst conservedcahn_hilliard_2d_spectralon the same circular island.Derive and quantitatively verify the Allen–Cahn sharp-interface curvature velocity and linear shrinking-area law .
Contrast multi-domain coarsening exponents: Allen–Cahn curvature-driven growth () versus Cahn–Hilliard diffusion-limited Ostwald ripening ().
Time: about 60 min
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))1. Principles and governing equations¶
For a non-conserved crystallographic or antiphase order parameter governed by the Ginzburg–Landau free energy , the Allen–Cahn equation (Allen & Cahn, Acta Metall. 27, 1085, 1979) postulates local relaxation directly proportional to with kinetic mobility :
The equation contains the second-order Laplacian (semi-implicit Fourier denominator in phase_field.allen_cahn_2d_spectral), in contrast to the fourth-order biharmonic of Cahn–Hilliard.
1.1 Matched Asymptotic Sharp-Interface Motion by Mean Curvature¶
Near a smoothly curved 2-D domain boundary of radius of curvature separating () from (), the polar Laplacian expands as . Substituting the traveling diffuse profile , where cancels the planar equilibrium balance, leaves:
Multiplying by yields the celebrated Allen–Cahn / Mullins–von Neumann shrinking-circle area law:
Remarkably, the barrier height drops out of completely ( with grain-boundary mobility ), and the circular grain loses area at a constant rate until it vanishes at .
heading("Demonstration 1: Conserved Cahn-Hilliard vs Non-Conserved Allen-Cahn on an Identical Circular Island")
nx_ac, ny_ac = 64, 64
Lx_ac, Ly_ac = 64.0, 64.0
W_ac, kap_ac, L_mob = 1.0, 2.0, 1.0 # diffuse width l_w = sqrt(2*2/1) = 2.0 grid spacings (well-resolved)
lw_ac = np.sqrt(2.0 * kap_ac / W_ac)
xg_ac = np.linspace(0.0, Lx_ac, nx_ac, endpoint=False)
X_ac, Y_ac = np.meshgrid(xg_ac, xg_ac, indexing="ij")
R0 = 18.0
r_dist = np.sqrt((X_ac - 0.5 * Lx_ac) ** 2 + (Y_ac - 0.5 * Ly_ac) ** 2)
circle_init = 0.5 * (1.0 - np.tanh((r_dist - R0) / lw_ac))
ac_circle = phase_field.allen_cahn_2d_spectral(
circle_init, Lx=Lx_ac, Ly=Ly_ac, dt=0.025, n_steps=600, L_mob=L_mob, W=W_ac, kappa=kap_ac, record_every=75
)
ch_circle = phase_field.cahn_hilliard_2d_spectral(
circle_init, Lx=Lx_ac, Ly=Ly_ac, dt=0.025, n_steps=600, M=1.0, W=W_ac, kappa=kap_ac, record_every=75
)
area_ac = (Lx_ac * Ly_ac) * ac_circle["phase_fractions"]
area_ch = (Lx_ac * Ly_ac) * ch_circle["mean_compositions"]
area_exact = area_ac[0] - 2.0 * np.pi * L_mob * kap_ac * ac_circle["times"]
print(f"Initial island area A(0) = {area_ac[0]:.2f} (pi*R0^2 = {np.pi * R0**2:.2f})")
print(f"At t = 15.0: Allen-Cahn area = {area_ac[-1]:.2f} vs analytical A0 - 2*pi*L*kappa*t = {area_exact[-1]:.2f}")
print(f"At t = 15.0: Cahn-Hilliard conserved integral = {area_ch[-1]:.6f} (drift = {abs(area_ch[-1] - area_ch[0]):.2e})")
assert np.isclose(area_ac[-1], area_exact[-1], rtol=0.015)
assert abs(area_ch[-1] - area_ch[0]) < 1e-11
Demonstration 1: Conserved Cahn-Hilliard vs Non-Conserved Allen-Cahn on an Identical Circular Island
====================================================================================================
Initial island area A(0) = 1028.21 (pi*R0^2 = 1017.88)
At t = 15.0: Allen-Cahn area = 840.75 vs analytical A0 - 2*pi*L*kappa*t = 839.72
At t = 15.0: Cahn-Hilliard conserved integral = 1028.211393 (drift = 0.00e+00)
What Demonstration 1 shows. Starting from the same circular domain (, ), the conserved Cahn–Hilliard droplet (ch_circle) cannot shrink because there are no larger droplets to absorb its solute, its integrated mass stays at 1028.211393. Meanwhile, the non-conserved Allen–Cahn antiphase domain (ac_circle) shrinks inward under its own capillary curvature to , close to the sharp-interface prediction (difference ).
2. Quantitative Verification of & Independence from ¶
Equation (1.3) makes two quantitative predictions:
is a straight line of slope , and follows the parabolic shrinking law .
Doubling the bulk barrier height (which narrows the interface thickness and raises surface tension by ) does not change at all. We test both predictions directly.
heading("Demonstration 2: Linear Area Decay Slope & Invariance with Respect to Barrier Height W")
ac_W2 = phase_field.allen_cahn_2d_spectral(
0.5 * (1.0 - np.tanh((r_dist - R0) / np.sqrt(2.0 * kap_ac / 2.0))),
Lx=Lx_ac, Ly=Ly_ac, dt=0.025, n_steps=600, L_mob=L_mob, W=2.0, kappa=kap_ac, record_every=75,
)
area_W2 = (Lx_ac * Ly_ac) * ac_W2["phase_fractions"]
t_vec = ac_circle["times"]
slope_W1 = float(np.polyfit(t_vec, area_ac, 1)[0])
slope_W2 = float(np.polyfit(t_vec, area_W2, 1)[0])
slope_theory = -2.0 * np.pi * L_mob * kap_ac
print(f"Analytical slope -2*pi*L_mob*kappa = {slope_theory:.5f}")
print(f"Measured slope for W = 1.0 (l_w = 2.0) = {slope_W1:.5f} (rel err = {abs(slope_W1 - slope_theory)/abs(slope_theory):.3%})")
print(f"Measured slope for W = 2.0 (l_w = 1.4) = {slope_W2:.5f} (rel err = {abs(slope_W2 - slope_theory)/abs(slope_theory):.3%})")
assert np.isclose(slope_W1, slope_theory, rtol=0.015)
assert np.isclose(slope_W2, slope_theory, rtol=0.025)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 4))
ax1.plot(t_vec, area_exact, "k-", lw=2.2, label=r"Exact $A_0 - 2\pi L_{\mathrm{mob}}\kappa t$")
ax1.plot(t_vec, area_ac, "o", ms=6, label=r"Allen–Cahn ($W = 1.0$)")
ax1.plot(t_vec, area_W2, "x", ms=7, mew=1.8, label=r"Allen–Cahn ($W = 2.0$, same slope)")
ax1.plot(ch_circle["times"], area_ch, "s--", lw=1.6, label="Cahn–Hilliard (conserved)")
ax1.set_xlabel("Time $t$ [arb. units]")
ax1.set_ylabel("Domain area $A(t)$ [grid$^2$]")
ax1.set_title("Linear Area Shrinkage & $W$-Invariance")
ax1.legend(fontsize=8)
R_num = np.sqrt(area_ac / np.pi)
R_th = np.sqrt(area_ac[0] / np.pi - 2.0 * L_mob * kap_ac * t_vec)
ax2.plot(t_vec, R_th, "k-", lw=2.2, label=r"Exact $\sqrt{R_0^2 - 2 L_{\mathrm{mob}}\kappa t}$")
ax2.plot(t_vec, R_num, "o", color="tab:orange", ms=6, label="Simulated $R(t) = \\sqrt{A(t)/\\pi}$")
ax2.set_xlabel("Time $t$ [arb. units]")
ax2.set_ylabel("Grain radius $R(t)$ [grid units]")
ax2.set_title("Accelerating Curvature Collapse ($v_n \\propto -1/R$)")
ax2.legend(fontsize=8)
label_panels(fig)
plt.show()
Demonstration 2: Linear Area Decay Slope & Invariance with Respect to Barrier Height W
======================================================================================
Analytical slope -2*pi*L_mob*kappa = -12.56637
Measured slope for W = 1.0 (l_w = 2.0) = -12.49719 (rel err = 0.551%)
Measured slope for W = 2.0 (l_w = 1.4) = -12.34800 (rel err = 1.738%)

Figure 14.1. A shrinking circular domain. (a) Area against time for the Allen–Cahn equation with two barrier heights and for the Cahn–Hilliard equation, with the sharp-interface result. (b) Radius against time.
What Demonstration 2 shows. Both and give slopes within and of ; the agreement is better for the wider interface, which the grid resolves better. In panel (b), as shrinks, local curvature grows, so the inward interface velocity accelerates steeply toward final grain disappearance.
3. Multi-Domain Grain Coarsening: (Allen–Cahn) vs. (Cahn–Hilliard)¶
Why do antiphase domains and polycrystals coarsen faster than conserved precipitates?
Allen–Cahn (Model A, Non-Conserved): Characteristic domain radius moves at curvature speed (parabolic grain growth law).
Cahn–Hilliard (Model B, Conserved): Solute must diffuse across a distance down a Gibbs–Thomson chemical potential gradient , giving (LSW Ostwald ripening law).
We evolve the same random initial order field on a 48x48 domain under both allen_cahn_2d_spectral and cahn_hilliard_2d_spectral and compare their characteristic domain growth.
heading("Demonstration 3: Multi-Domain Coarsening — Allen-Cahn (t^{1/2}) vs Cahn-Hilliard (t^{1/3})")
rng_coarsen = np.random.default_rng(1403)
nx_c, ny_c = 48, 48
Lx_c, Ly_c = 48.0, 48.0
init_rand = 0.50 + rng_coarsen.uniform(-0.08, 0.08, size=(nx_c, ny_c))
init_rand -= (np.mean(init_rand) - 0.50)
ac_multi = phase_field.allen_cahn_2d_spectral(
init_rand, Lx=Lx_c, Ly=Ly_c, dt=0.20, n_steps=200, L_mob=1.0, W=2.0, kappa=1.0, record_every=20
)
ch_multi = phase_field.cahn_hilliard_2d_spectral(
init_rand, Lx=Lx_c, Ly=Ly_c, dt=0.20, n_steps=200, M=1.0, W=2.0, kappa=1.0, record_every=20
)
ld_ac = np.array([phase_field.characteristic_domain_size_2d(s, Lx=Lx_c, Ly=Ly_c) for s in ac_multi["snapshots"]])
ld_ch = ch_multi["domain_sizes"]
t_c = ac_multi["times"]
print(f"{'Time t':>8s} | {'L_d Allen-Cahn':>15s} | {'L_d Cahn-Hilliard':>18s} | {'F_AC':>10s} | {'F_CH':>10s}")
print("-" * 72)
for idx in range(0, len(t_c), 2):
print(f"{t_c[idx]:8.1f} | {ld_ac[idx]:15.2f} | {ld_ch[idx]:18.2f} | {ac_multi['free_energies'][idx]:10.2f} | {ch_multi['free_energies'][idx]:10.2f}")
assert ld_ac[-1] > 1.4 * ld_ch[-1]
assert np.all(np.diff(ac_multi["free_energies"]) <= 1e-12)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 4))
ax1.plot(t_c[1:], ld_ac[1:], "o-", lw=2.1, label=r"Allen–Cahn ($v_n \propto -1/R \Rightarrow t^{1/2}$)")
ax1.plot(t_c[1:], ld_ch[1:], "s--", lw=2.1, label=r"Cahn–Hilliard (diffusion $\Rightarrow t^{1/3}$)")
ax1.set_xlabel("Time $t$ [arb. units]")
ax1.set_ylabel("Characteristic domain size $L_d(t)$ [grid units]")
ax1.set_title("Faster Non-Conserved vs. Conserved Coarsening")
ax1.legend(fontsize=8)
im = ax2.imshow(ac_multi["final"].T, origin="lower", extent=[0, Lx_c, 0, Ly_c], cmap="viridis", vmin=0.0, vmax=1.0)
ax2.set_title(f"Allen–Cahn Antiphase Domains at $t = 40$ ($L_d = {ld_ac[-1]:.1f}$)")
ax2.set_xlabel("$x$ [grid units]")
ax2.set_ylabel("$y$ [grid units]")
plt.colorbar(im, ax=ax2, fraction=0.046, label="$\\eta(x,y)$")
label_panels(fig)
plt.show()
Demonstration 3: Multi-Domain Coarsening — Allen-Cahn (t^{1/2}) vs Cahn-Hilliard (t^{1/3})
==========================================================================================
Time t | L_d Allen-Cahn | L_d Cahn-Hilliard | F_AC | F_CH
------------------------------------------------------------------------
0.0 | 2.59 | 2.59 | 298.71 | 298.71
8.0 | 18.18 | 7.49 | 81.04 | 214.40
16.0 | 22.72 | 8.75 | 56.85 | 181.53
24.0 | 24.15 | 9.78 | 50.53 | 159.58
32.0 | 25.28 | 10.62 | 45.45 | 144.19
40.0 | 26.50 | 11.35 | 40.59 | 133.69

Figure 14.2. (a) Domain size against time for non-conserved (Allen–Cahn) and conserved (Cahn–Hilliard) dynamics from the same initial noise. (b) The Allen–Cahn field at .
What Demonstration 3 shows. Starting from identical random fluctuations at , non-conserved Allen–Cahn order relaxation immediately coarsens long-wavelength patches without waiting for long-range diffusive transport, and reaches , against 11.4 for conserved Cahn–Hilliard dynamics. The run is too short and the box too small to measure the exponents and themselves. Also, in Allen–Cahn, even the uniform mode is linearly unstable ( peaks at ).
4. Sensitivity to the parameters¶
What happens in Allen–Cahn if the initial average order parameter is asymmetric ()? Unlike Cahn–Hilliard (which preserves minority droplets forever at ), an asymmetric non-conserved system has more convex curvature on the minority phase, causing the minority domains to shrink and disappear completely as the entire crystal orders into a single variant ( or ).
heading("Demonstration 4: Asymmetric Initial Bias Sweep — Minority Variant Elimination in Allen-Cahn")
base_noise = rng_coarsen.uniform(-0.06, 0.06, size=(48, 48))
base_noise -= np.mean(base_noise)
print(f"{'Initial <eta_0>':>15s} | {'<eta> at t=15':>14s} | {'<eta> at t=35':>14s} | {'Final F[eta]':>13s} | {'Asymptotic Fate'}")
print("-" * 84)
final_fracs = []
for eta_bias in [0.35, 0.45, 0.50, 0.55, 0.65]:
r_b = phase_field.allen_cahn_2d_spectral(
eta_bias + base_noise, Lx=48.0, Ly=48.0, dt=0.25, n_steps=140, L_mob=1.0, W=2.0, kappa=1.0, record_every=60
)
final_fracs.append(r_b["phase_fractions"][-1])
fate = "Single-domain eta -> 0" if r_b["phase_fractions"][-1] < 0.05 else (
"Single-domain eta -> 1" if r_b["phase_fractions"][-1] > 0.95 else "Coarsening antiphase walls"
)
print(f"{eta_bias:15.2f} | {r_b['phase_fractions'][1]:14.4f} | {r_b['phase_fractions'][-1]:14.4f} | {r_b['free_energies'][-1]:13.4f} | {fate}")
assert final_fracs[0] < 0.01 and final_fracs[-1] > 0.99
Demonstration 4: Asymmetric Initial Bias Sweep — Minority Variant Elimination in Allen-Cahn
===========================================================================================
Initial <eta_0> | <eta> at t=15 | <eta> at t=35 | Final F[eta] | Asymptotic Fate
------------------------------------------------------------------------------------
0.35 | 0.0000 | 0.0000 | 0.0000 | Single-domain eta -> 0
0.45 | 0.0000 | 0.0000 | 0.0000 | Single-domain eta -> 0
0.50 | 0.4869 | 0.4412 | 55.3409 | Coarsening antiphase walls
0.55 | 1.0000 | 1.0000 | 0.0000 | Single-domain eta -> 1
0.65 | 1.0000 | 1.0000 | 0.0000 | Single-domain eta -> 1
Inside the algorithm¶
What Demonstration 4 shows. Because , any macroscopic bias away from is exponentially amplified. At and 0.65, the minority antiphase domains collapse by (<eta> = 0.0000 and 1.0000, F[eta] = 0.0000), leaving a defect-free single-variant crystal.
Below we inspect phase_field.allen_cahn_2d_spectral and verify its semi-implicit spectral update against a NumPy implementation.
Check against the library¶
heading("Inside the Algorithm: phase_field.allen_cahn_2d_spectral")
print(show_source(phase_field.allen_cahn_2d_spectral))
eta_step = circle_init.copy()
kx = 2.0 * np.pi * np.fft.fftfreq(nx_ac, d=Lx_ac / nx_ac)
ky = 2.0 * np.pi * np.fft.fftfreq(ny_ac, d=Ly_ac / ny_ac)
kx2, ky2 = np.meshgrid(kx, ky, indexing="ij")
denom_ac = 1.0 + 0.20 * L_mob * kap_ac * (kx2 ** 2 + ky2 ** 2)
df_hat = np.fft.fft2(2.0 * W_ac * eta_step * (1.0 - eta_step) * (1.0 - 2.0 * eta_step))
eta_hand_1 = np.real(np.fft.ifft2((np.fft.fft2(eta_step) - 0.20 * L_mob * df_hat) / denom_ac))
eta_lib_1 = phase_field.allen_cahn_2d_spectral(circle_init, Lx_ac, Ly_ac, dt=0.20, n_steps=1, L_mob=L_mob, W=W_ac, kappa=kap_ac)["final"]
print("Single-step max |eta_hand - eta_lib|:", float(np.max(np.abs(eta_hand_1 - eta_lib_1))))
assert np.allclose(eta_hand_1, eta_lib_1, rtol=1e-15, atol=1e-15)
Inside the Algorithm: phase_field.allen_cahn_2d_spectral
========================================================
def allen_cahn_2d_spectral(
eta_init: np.ndarray,
Lx: float,
Ly: float,
dt: float,
n_steps: int,
L_mob: float = 1.0,
W: float = 1.0,
kappa: float = 1.0,
record_every: int = 25,
) -> dict:
"""Integrate 2-D periodic non-conserved Allen-Cahn equation d(eta)/dt = -L_mob*[f'(eta) - kappa*lap(eta)]."""
eta = np.asarray(eta_init, dtype=float).copy()
if eta.ndim != 2:
raise ValueError("eta_init must be a 2-D array.")
nx, ny = eta.shape
dx, dy = float(Lx) / nx, float(Ly) / ny
kx = 2.0 * np.pi * np.fft.fftfreq(nx, d=dx)
ky = 2.0 * np.pi * np.fft.fftfreq(ny, d=dy)
kx_2d, ky_2d = np.meshgrid(kx, ky, indexing="ij")
k2 = kx_2d**2 + ky_2d**2
denom = 1.0 + dt * L_mob * kappa * k2
eta_hat = np.fft.fft2(eta)
times = [0.0]
snaps = [eta.copy()]
energies = [ginzburg_landau_free_energy_2d(eta, Lx=Lx, Ly=Ly, W=W, kappa=kappa)]
fractions = [float(np.mean(eta))]
for step in range(1, n_steps + 1):
df_hat = np.fft.fft2(double_well_potential(eta, W=W)["df_dc"])
eta_hat = (eta_hat - dt * L_mob * df_hat) / denom
eta = np.real(np.fft.ifft2(eta_hat))
if step % record_every == 0 or step == n_steps:
times.append(step * dt)
snaps.append(eta.copy())
energies.append(ginzburg_landau_free_energy_2d(eta, Lx=Lx, Ly=Ly, W=W, kappa=kappa))
fractions.append(float(np.mean(eta)))
return {
"times": np.array(times, dtype=float),
"snapshots": np.array(snaps, dtype=float),
"free_energies": np.array(energies, dtype=float),
"phase_fractions": np.array(fractions, dtype=float),
"final": eta,
}
Single-step max |eta_hand - eta_lib|: 0.0
Exercises¶
Worked solutions are in 14_solutions.ipynb. The cell below the list is a short self-check to start from.
Verify a result. Simulate a circular domain ( on , , ) for via
allen_cahn_2d_spectral() and verify that the fitted area rate agrees with within .Find how it fails. Verify
allen_cahn_2d_spectralraisesValueErroron 1-D input, and demonstrate the grid-pinning failure mode on (): compare a resolved interface () against an under-resolved interface () and show that the under-resolved circle becomes artificially trapped on the grid.Implement it yourself. Implement
track_circular_grain_extinction(R0=8.0, L_mob=1.0, kappa=2.0, W=1.0)on a domain to verify the analytical extinction time : confirm linearity () for and complete grain disappearance () by .
heading("Self-check for the exercises")
r_check = phase_field.allen_cahn_2d_spectral(
circle_init, Lx=64.0, Ly=64.0, dt=0.025, n_steps=200, L_mob=0.5, W=1.0, kappa=2.0, record_every=50
)
slope_chk = float(np.polyfit(r_check["times"], 64.0 * 64.0 * r_check["phase_fractions"], 1)[0])
slope_ex = -2.0 * np.pi * 0.5 * 2.0
print(f"Shrinking-circle dA/dt = {slope_chk:.4f} vs exact -2*pi*L_mob*kappa = {slope_ex:.4f}")
assert np.isclose(slope_chk, slope_ex, rtol=0.015)
print("All checks passed.")
Self-check for the exercises
============================
Shrinking-circle dA/dt = -6.2723 vs exact -2*pi*L_mob*kappa = -6.2832
All checks passed.