Allen-Cahn Model

Overview

The Allen-Cahn equation describes the evolution of a non-conserved order parameter. It is widely used for modeling solidification, grain growth, and phase transformations.

The phase field variable φ represents:

  • φ = 1: Solid phase
  • φ = 0: Liquid phase
  • 0 < φ < 1: Diffuse interface

Mathematical Formulation

The Allen-Cahn equation:

\[\tau \frac{\partial \phi}{\partial t} = W^2 \nabla^2 \phi - g'(\phi) + m \cdot h'(\phi) \cdot \Delta G\]

where:

  • τ: Relaxation time [s]
  • W: Interface width parameter
  • g(φ): Double-well potential (e.g., φ²(1-φ)²)
  • h(φ): Interpolation function (e.g., 3φ² - 2φ³)
  • ΔG: Thermodynamic driving force [J/mol]
  • m: Scaling factor for driving force

Quick Example

Basic Usage

using PhaseFields

# Create model
model = AllenCahnModel(τ=1.0, W=1.0, m=0.1)

# Compute right-hand side
φ = 0.5
∇²φ = -0.1  # Laplacian
ΔG = -100.0  # Driving force (negative = solidification)

dφdt = allen_cahn_rhs(model, φ, ∇²φ, ΔG)

With DifferentialEquations.jl

using PhaseFields
using OrdinaryDiffEq

# Model and grid
model = AllenCahnModel(τ=1.0, W=0.05)
grid = UniformGrid1D(N=101, L=1.0)
bc = NeumannBC()

# Initial condition: tanh interface
x0 = 0.3
φ0 = [0.5 * (1 - tanh((x - x0) / (2 * model.W))) for x in grid.x]

# Create and solve ODE problem
prob = create_allen_cahn_problem(model, grid, bc, φ0, (0.0, 2.0))
sol = solve(prob, Tsit5())

API Reference

PhaseFields.AllenCahnModelType
AllenCahnModel(; τ=1.0, W=1.0, m=1.0)

Allen-Cahn model for non-conserved order parameter evolution.

The Allen-Cahn equation: τ ∂φ/∂t = W²∇²φ - g'(φ) + m·ΔG·h'(φ)

where:

  • φ: Order parameter (0 = solid, 1 = liquid)
  • τ: Relaxation time [s]
  • W: Interface width parameter [m]
  • g(φ): Double-well potential
  • h(φ): Interpolation function
  • ΔG: Driving force [J/mol]
  • m: Driving force coupling constant

Fields

  • τ::Float64: Relaxation time [s] (default: 1.0)
  • W::Float64: Interface width parameter [m] (default: 1.0)
  • m::Float64: Driving force scale [-] (default: 1.0)

Example

model = AllenCahnModel()                    # all defaults
model = AllenCahnModel(τ=3e-8, W=1e-6)      # partial
model = AllenCahnModel(τ=3e-8, W=1e-6, m=1.0)  # full
source
PhaseFields.allen_cahn_rhsFunction
allen_cahn_rhs(model::AllenCahnModel, φ::T, ∇²φ::T, ΔG::T) where T<:Real

Compute the right-hand side of the Allen-Cahn equation.

∂φ/∂t = (W²∇²φ - g'(φ) + m·ΔG·h'(φ)) / τ

This function is AD-compatible for sensitivity analysis.

Arguments

  • model: AllenCahnModel parameters
  • φ: Order parameter at current point
  • ∇²φ: Laplacian of order parameter
  • ΔG: Driving force [J/mol]

Returns

  • Time derivative ∂φ/∂t [1/s]

Example

model = AllenCahnModel(τ=3e-8, W=1e-6, m=1.0)
dφdt = allen_cahn_rhs(model, 0.5, -100.0, -5000.0)
source
allen_cahn_rhs(model::AllenCahnModel, φ, ∇²φ, ΔG)

Non-typed version for convenience.

source
PhaseFields.AllenCahnODEParamsType
AllenCahnODEParams{M, G, BC, A}

Parameters for Allen-Cahn ODE integration.

Type Parameters

  • M: Model type
  • G: Grid type (UniformGrid1D or UniformGrid2D)
  • BC: Boundary condition type
  • A: Laplacian workspace array type

Fields

  • model::M: Phase field model parameters
  • grid::G: Spatial discretization (1D or 2D)
  • bc::BC: Boundary conditions
  • ∇²φ::A: Pre-allocated Laplacian workspace
source
PhaseFields.allen_cahn_ode!Function
allen_cahn_ode!(dφ, φ, p::AllenCahnODEParams, t)

In-place RHS function for Allen-Cahn equation compatible with OrdinaryDiffEq.jl.

Computes: dφ/dt = (W²∇²φ - g'(φ)) / τ

Works with both 1D and 2D grids. For 2D, input/output vectors are automatically reshaped to/from matrices for Laplacian computation.

source
PhaseFields.create_allen_cahn_problemFunction
create_allen_cahn_problem(model, grid, bc, φ0, tspan)

Create ODEProblem for Allen-Cahn equation.

Arguments

  • model::AllenCahnModel: Phase field model
  • grid::UniformGrid1D: Spatial grid
  • bc::BoundaryCondition: Boundary conditions
  • φ0: Initial condition
  • tspan: Time span (tstart, tend)

Returns

  • ODEProblem ready for solve()

Example

using OrdinaryDiffEq

model = AllenCahnModel(τ=1.0, W=0.1)
grid = UniformGrid1D(N=100, L=1.0)
φ0 = [0.5 + 0.1*sin(2π*x) for x in grid.x]

prob = create_allen_cahn_problem(model, grid, NeumannBC(), φ0, (0.0, 10.0))
sol = solve(prob, Tsit5())
source
create_allen_cahn_problem(model, grid::UniformGrid2D, bc, φ0, tspan)

Create ODEProblem for 2D Allen-Cahn equation.

Arguments

  • model::AllenCahnModel: Phase field model
  • grid::UniformGrid2D: 2D spatial grid
  • bc::BoundaryCondition: Boundary conditions
  • φ0::AbstractMatrix: Initial condition (Nx × Ny matrix)
  • tspan: Time span (tstart, tend)

Returns

  • ODEProblem ready for solve()

Note

The initial condition matrix is vectorized column-major (Julia default). Solution vectors can be reshaped back using reshape(sol.u[i], grid.Nx, grid.Ny).

Example

using OrdinaryDiffEq

model = AllenCahnModel(τ=1.0, W=0.1)
grid = UniformGrid2D(Nx=50, Ny=50, Lx=1.0, Ly=1.0)

# Circular interface
φ0 = [sqrt((x-0.5)^2 + (y-0.5)^2) < 0.3 ? 1.0 : 0.0 for x in grid.x, y in grid.y]

prob = create_allen_cahn_problem(model, grid, NeumannBC(), φ0, (0.0, 1.0))
sol = solve(prob, Tsit5())

# Reshape solution
φ_final = reshape(sol.u[end], grid.Nx, grid.Ny)
source

See Also