Conservative Phase-Field: Cahn-Hilliard

SkillDev tools

Simulate conservative phase-fields (spinodal decomposition and phase separation) using the Cahn-Hilliard equation.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the Conservative Phase-Field: Cahn-Hilliard skill

What this skill tells your AI

The instructions your AI receives, as published by learningmatter-mit/atomisticskills in .agents/skills/mat-phase-field-conservative/SKILL.md and read by ahel’s review.

Goal

To simulate the morphological evolution of spinodal decomposition (phase separation) in a binary alloy system using the Cahn-Hilliard equation. This skill solves the 4th-order partial differential equation to track the conservative concentration field $c(\mathbf{r}, t)$ over time.

Instructions

1. Mathematical Formulation

The Cahn-Hilliard equation describes the evolution of a conserved concentration field $c$ down a free energy gradient: $$ \frac{\partial c}{\partial t} = \nabla \cdot \left( M \nabla \frac{\delta F}{\delta c} \right) $$ Where $M$ is the mobility, and $F$ is the Ginzburg-Landau free energy functional incorporating a double-well local potential $f(c) = a c^2(1-c)^2$ and a gradient energy penalty $\frac{\kappa}{2} |\nabla c|^2$.

2. Running the Spinodal Decomposition Simulation

Use the provided script to set up a 2D grid and solve the Cahn-Hilliard equation using FiPy.

# Env: phasefield-agent
python .agents/skills/mat-phase-field-conservative/scripts/run_spinodal_decomposition.py \
    --grid-size 100 \
    --dx 0.25 \
    --steps 100 \
    --dt 0.01 \
    --output spinodal_output.gif

Parameters:

  • --grid-size: Number of grid points per dimension (e.g., 100 for a 100x100 2D grid).
  • --dx: Size of each grid cell.
  • --steps: Total number of time steps to run.
  • --dt: Time step size. Use small values for stability unless using fully implicit solvers.
  • --output: Filepath to save the resulting .gif animation or final .png image.

Examples

Classic Spinodal Decomposition

To benchmark the solver and reproduce the classic interconnected "worm-like" bicontinuous morphology of spinodal decomposition:

# Env: phasefield-agent
python .agents/skills/mat-phase-field-conservative/scripts/run_spinodal_decomposition.py \
    --grid-size 100 \
    --steps 200 \
    --dt 1e-2 \
    --output examples/benchmark-spinodal/classic_spinodal.gif

See the examples/benchmark-spinodal/README.md for the expected output.

Constraints

  • Environments: Scripts require the phasefield-agent Conda environment. Each code block MUST specify the environment.
  • Conservation: The Cahn-Hilliard PDE inherently conserves the global integral of $c$. If using explicit time-stepping with too large of a dt, numerical instability may break conservation.

References

  • Cahn, J. W., & Hilliard, J. E., "Free Energy of a Nonuniform System. I. Interfacial Free Energy", The Journal of Chemical Physics, 1958. DOI
  • Guyer, J. E., Wheeler, D., & Warren, J. A., "FiPy: Partial Differential Equations with Python", Computing in Science & Engineering, 2009. DOI

Author: Bowen Deng

Signals

GitHub stars
164
Forks
24
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
mat-phase-field-conservative
Source
github.com/learningmatter-mit/atomisticskills