Common API Reference
This page documents the common types and functions shared across all phase field models.
Types
Interface Parameters
PhaseFields.InterfaceParams — Type
InterfaceParamsParameters for solid-liquid interface modeling.
Fields
W₀::Float64: Interface width parameter [m]σ₀::Float64: Interface energy [J/m²]τ::Float64: Relaxation time [s]δ::Float64: Anisotropy strength [-]n_fold::Int: Anisotropy symmetry (4=FCC, 6=HCP)
Example
# FCC metal with 4-fold anisotropy
params = InterfaceParams(
W₀ = 1e-6, # 1 μm interface width
σ₀ = 0.3, # 0.3 J/m² interface energy
τ = 3e-8, # 30 ns relaxation time
δ = 0.04, # 4% anisotropy
n_fold = 4 # 4-fold cubic symmetry
)Diffusion Parameters
PhaseFields.DiffusionParams — Type
DiffusionParamsTemperature-dependent diffusion parameters.
Fields
D_liquid::Float64: Pre-exponential factor for liquid [m²/s]D_solid::Float64: Pre-exponential factor for solid [m²/s]Q_liquid::Float64: Activation energy for liquid [J/mol]Q_solid::Float64: Activation energy for solid [J/mol]
Example
params = DiffusionParams(
D_liquid = 1e-9, # m²/s
D_solid = 1e-13, # m²/s
Q_liquid = 40e3, # 40 kJ/mol
Q_solid = 80e3 # 80 kJ/mol
)Material Parameters
PhaseFields.MaterialParams — Type
MaterialParamsGeneral material properties.
Fields
Vm::Float64: Molar volume [m³/mol]L::Float64: Latent heat [J/mol]Cp::Float64: Heat capacity [J/(mol·K)]k::Float64: Thermal conductivity [W/(m·K)]
Interpolation Functions
Phase field models use interpolation functions h(φ) and double-well potentials g(φ) to smoothly transition between phases.
Interpolation h(φ)
Properties:
- h(0) = 0, h(1) = 1
- Smooth transition in interface region
using PhaseFields
φ = 0.5
# Polynomial: h = 3φ² - 2φ³
h = h_polynomial(φ)
# Sinusoidal: h = (1 - cos(πφ))/2
h = h_sin(φ)
# Derivative
dh = h_prime(φ)PhaseFields.h_polynomial — Function
h_polynomial(φ::T) where T<:RealPolynomial interpolation function h(φ) = 3φ² - 2φ³.
Most commonly used interpolation for phase field models. Properties: h(0) = 0, h(1) = 1, h'(0) = h'(1) = 0.
Arguments
φ: Order parameter ∈ [0, 1]
Returns
- Interpolated value ∈ [0, 1]
PhaseFields.h_sin — Function
h_sin(φ::T) where T<:RealSinusoidal interpolation function h(φ) = (1 - cos(πφ))/2.
Alternative interpolation with similar properties to polynomial. Properties: h(0) = 0, h(1) = 1, h'(0) = h'(1) = 0.
Arguments
φ: Order parameter ∈ [0, 1]
Returns
- Interpolated value ∈ [0, 1]
PhaseFields.h_prime — Function
h_prime(φ::T) where T<:RealDerivative of polynomial interpolation: h'(φ) = 6φ(1-φ).
Analytical form for better performance than AD.
Arguments
φ: Order parameter ∈ [0, 1]
Returns
- Derivative value
Double-Well g(φ)
Properties:
- g(0) = g(1) = 0
- Maximum at φ = 0.5
- Provides energy barrier
# Standard: g = φ²(1-φ)²
g = g_standard(φ)
# Obstacle: g = |φ(1-φ)|
g = g_obstacle(φ)
# Derivatives
dg = g_prime(φ)
d2g = g_double_prime(φ)PhaseFields.g_standard — Function
g_standard(φ::T) where T<:RealStandard double-well potential g(φ) = φ²(1-φ)².
Properties: g(0) = g(1) = 0, minimum at φ = 0 and φ = 1. Maximum at φ = 0.5 with g(0.5) = 1/16.
Arguments
φ: Order parameter ∈ [0, 1]
Returns
- Potential value ≥ 0
PhaseFields.g_obstacle — Function
g_obstacle(φ::T) where T<:RealObstacle double-well potential g(φ) = φ(1-φ).
Simpler form than standard, but with same zeros. Used in some thin-interface models.
Arguments
φ: Order parameter ∈ [0, 1]
Returns
- Potential value ≥ 0
PhaseFields.g_prime — Function
g_prime(φ::T) where T<:RealDerivative of standard double-well: g'(φ) = 2φ(1-φ)(1-2φ).
Analytical form for better performance than AD.
Arguments
φ: Order parameter ∈ [0, 1]
Returns
- Derivative value
PhaseFields.g_double_prime — Function
g_double_prime(φ::T) where T<:RealSecond derivative of standard double-well: g''(φ) = 2(1 - 6φ + 6φ²).
Arguments
φ: Order parameter ∈ [0, 1]
Returns
- Second derivative value
Anisotropy Functions
For dendritic growth, crystallographic anisotropy modifies the interface energy and kinetics.
Cubic Anisotropy (4-fold)
For FCC and BCC crystals:
θ = π/4 # Angle
# 4-fold anisotropy: a(θ) = 1 + ε cos(4θ)
a = anisotropy_cubic(θ; ε=0.05)PhaseFields.anisotropy_cubic — Function
anisotropy_cubic(θ::T; δ::Real=0.04) where T<:Real4-fold anisotropic interface energy for FCC/BCC crystals.
σ(θ) = 1 + δ·cos(4θ)
Arguments
θ: Interface normal angle [rad]δ: Anisotropy strength (default: 0.04 = 4%)
Returns
- Normalized interface energy (base value = 1)
Example
# Interface energy at θ = 0 (⟨100⟩ direction)
σ = anisotropy_cubic(0.0, δ=0.04) # = 1.04
# Interface energy at θ = π/4 (⟨110⟩ direction)
σ = anisotropy_cubic(π/4, δ=0.04) # = 0.96HCP Anisotropy (6-fold)
For hexagonal crystals:
# 6-fold anisotropy: a(θ) = 1 + ε cos(6θ)
a = anisotropy_hcp(θ; ε=0.05)PhaseFields.anisotropy_hcp — Function
anisotropy_hcp(θ::T; δ::Real=0.02) where T<:Real6-fold anisotropic interface energy for HCP crystals.
σ(θ) = 1 + δ·cos(6θ)
Arguments
θ: Interface normal angle [rad]δ: Anisotropy strength (default: 0.02 = 2%)
Returns
- Normalized interface energy (base value = 1)
Custom Anisotropy
# n-fold anisotropy
a = anisotropy_custom(θ; ε=0.05, n=8)PhaseFields.anisotropy_custom — Function
anisotropy_custom(θ::T; n::Int, δ::Real) where T<:Realn-fold anisotropic interface energy.
σ(θ) = 1 + δ·cos(n·θ)
Arguments
θ: Interface normal angle [rad]n: Symmetry order (4 for cubic, 6 for hexagonal)δ: Anisotropy strength
Returns
- Normalized interface energy (base value = 1)
AD Configuration
PhaseFields.jl uses DifferentiationInterface.jl for automatic differentiation.
PhaseFields.DEFAULT_AD_BACKEND — Constant
Default AD backend (ForwardDiff). Can be changed via set_ad_backend!.
PhaseFields.set_ad_backend! — Function
set_ad_backend!(backend)Set the default AD backend for PhaseFields.jl.
Arguments
backend: A DifferentiationInterface backend (e.g.,DI.AutoForwardDiff())
Example
using DifferentiationInterface
set_ad_backend!(DI.AutoForwardDiff()) # Default
# set_ad_backend!(DI.AutoEnzyme()) # For high performance (future)Module
PhaseFields — Module
PhaseFields.jlPhase Field method simulation package for materials science. Provides domain-specific functionality for solidification modeling with CALPHAD thermodynamic coupling.
Features
- Interface modeling (interpolation, double-well, anisotropy)
- Phase field models (Allen-Cahn, Cahn-Hilliard, KKS, WBM)
- CALPHAD coupling via OpenCALPHAD.jl (optional extension)
- AD-compatible design using DifferentiationInterface.jl