5. Forward phase-field problem (Allen–Cahn)¶
Phase-field equations describe the evolution of interfaces between phases, for example in alloys during decomposition. They are stiff: a small interface-width parameter makes the solution switch sharply between two values, and plain PINN training often converges to a wrong solution. This tutorial runs the 1D Allen–Cahn benchmark of Wight & Zhao (2021) (see references) from the shipped example and explains its settings.
What you will learn
- the settings a stiff phase-field problem needs (periodic boundary, wide network, many iterations);
- a periodic boundary condition row;
- how to judge a phase-field result against reference data.
The problem. On \( x \in [-1, 1] \), \( t \in [0, 1] \):
with periodic boundary conditions. The cubic term drives \( u \) towards the two phases \( u = \pm 1 \); the small diffusion coefficient makes the interfaces between them thin.
Prerequisites¶
- Tutorial 2.
- Time: the default settings take long on a CPU. The verification run below was shortened.
Steps¶
- In the Examples bar choose Forward, Allen-Cahn 1D – Wight & Zhao, Default. The log says
Default settings: 1D Allen-Cahn (whole interval) solved as in its paper (Wight & Zhao 2021).and that five reference files were loaded for Error Analysis. -
Equations: one output
u, residualdu_t - 0.0001*du_xx + 5*u**3 - 5*u. -
Geometry: x: from
-1to1, t: from0to1. - Initial conditions:
x**2*cos(pi*x). -
Boundary conditions: a single row, BC 1 · Periodic, u, with Periodic in:
x(left ↔ right) and Derivative order:0. A periodic row has no Where: or Value:; it ties the values at the two ends together. -
Neural network: 4 hidden layers of 128 neurons,
tanh. A wider network than in the earlier tutorials, to represent the sharp interfaces. -
Collocation points: 2000 domain, 200 boundary, 200 initial. Training: Adam 20000 iterations, then L-BFGS
- Loss weights: 1 for the equation and the periodic condition, 100 for the initial condition.
-
Training › Adaptive training: Method: is Residual-based Adaptive Refinement (RAR), as in Wight & Zhao's approach: after the training phases, 6 rounds each add the 200 points with the largest residual (out of 20000 candidates) and train again with 5000 Adam and 5000 L-BFGS iterations. RAR is explained in Tutorial 10. These rounds make up most of the run time.
-
Click Solve.
Expected results¶
With enough training the solution develops two plateaus near \( u = 1 \) around \( x = \pm 0.4 \), separated by sharp
interfaces from regions at \( u = -1 \), with a narrow dip at \( x = 0 \) (see the reference curves below). During the RAR
rounds the log prints --- RAR Cycle k/6 --- with the maximum and mean residual.
Our test run on a CPU was far too short for this problem, on purpose, to keep it to 5 minutes: 1500 Adam + 300 L-BFGS iterations and 2 RAR rounds of 500 Adam + 200 L-BFGS (instead of 20000 + 10000 and 6 rounds of 5000 + 5000). It shows the typical failure of an under-trained PINN on Allen–Cahn rather than a solution: the prediction matched the initial condition (relative L2 error 2 × 10⁻² at \( t = 0 \)), but it stayed near zero in the middle instead of growing to the \( u = 1 \) plateaus, so the error rose to 0.89 at \( t = 1 \).
Run the example's settings (or the Tuned ones) before judging the method; on a CPU this takes a long time, and a GPU helps. Always compare with the reference at several times: an error that grows with \( t \) is the signature of this failure mode.
Variations to try¶
These are the subject of later tutorials and are the usual remedies for phase-field problems:
- causal training or time windows (Tutorial 12);
- per-point weights (Tutorial 11);
- an exact initial condition and exact periodicity (Tutorial 9);
- the Tuned settings of this example (Tutorial 13).
Troubleshooting¶
| Symptom | What to check |
|---|---|
| The solution stays near the initial profile, or becomes flat | A known failure mode of plain PINNs on Allen–Cahn: train longer, or use the methods above. |
| The interfaces are smeared | Too few iterations or points; increase them, or use RAR (Tutorial 10). |
| The two ends do not match | Check that the periodic row is present and Periodic in: is x. |
Next steps¶
- Tutorial 6: inverse problems.
- Equations and Boundary conditions in the reference; Time-dependent training in the theory section.




