CALPHAD Coupling
Overview
PhaseFields.jl provides optional integration with OpenCALPHAD.jl for realistic thermodynamic calculations. This coupling is implemented as a Julia package extension that loads automatically when OpenCALPHAD is imported.
Installation
using Pkg
Pkg.add(url="https://github.com/hsugawa8651/OpenCALPHAD.jl")Basic Usage
using PhaseFields
using OpenCALPHAD # Activates extension automatically
# Load thermodynamic database
db = read_tdb("AgCu.TDB")
# Calculate driving force
T = 1000.0 # Temperature [K]
x = 0.3 # Composition (Cu mole fraction)
ΔG = calphad_driving_force(db, T, x, "FCC_A1", "LIQUID")CALPHAD-Coupled Models
Allen-Cahn with CALPHAD
using PhaseFields
using OpenCALPHAD
db = read_tdb("AgCu.TDB")
T = 1000.0
x = 0.3
# Create coupled model
model = create_calphad_allen_cahn(db, T, x, "FCC_A1", "LIQUID";
τ = 1.0,
W = 1.0,
m = 1e-4 # Scaling factor for ΔG
)
# The model caches the driving force from CALPHADKKS with CALPHAD
db = read_tdb("AgCu.TDB")
T = 1000.0
# Create model with CALPHAD free energies
model, f_s, f_l = create_calphad_kks_model(db, T, "FCC_A1", "LIQUID";
τ = 1.0,
W = 1.0,
m = 1.0,
M_s = 1.0,
M_l = 10.0
)
# Partition with real thermodynamics
c_avg = 0.3
φ = 0.5
c_s, c_l, μ, converged = kks_partition(c_avg, φ, f_s, f_l)WBM with CALPHAD
db = read_tdb("AgCu.TDB")
T = 1000.0
model, f_s, f_l = create_calphad_wbm_model(db, T, "FCC_A1", "LIQUID";
M_φ = 1.0,
κ = 1.0,
W = 1.0,
D_s = 1e-13,
D_l = 1e-9
)Thermodynamic Functions
Driving Force
# Gibbs energy difference: ΔG = G_solid - G_liquid
# Negative ΔG means solid is stable
ΔG = calphad_driving_force(db, T, x, "FCC_A1", "LIQUID")Chemical Potential
# Get chemical potentials for a phase
μ = calphad_chemical_potential(db, "FCC_A1", T, x)Diffusion Potential
# Second derivative d²G/dx² (thermodynamic factor)
d2G = calphad_diffusion_potential(db, "FCC_A1", T, x)API Reference
PhaseFields.AbstractCALPHADCoupledModel — Type
AbstractCALPHADCoupledModelAbstract type for phase field models with CALPHAD thermodynamic coupling. Concrete implementations are provided by the OpenCALPHAD extension.
PhaseFields.calphad_driving_force — Function
calphad_driving_force(db, T, x, solid_phase, liquid_phase)Calculate the thermodynamic driving force for solidification using CALPHAD data.
Requires OpenCALPHAD.jl: Load with using OpenCALPHAD to enable this function.
Arguments
db: OpenCALPHAD Database objectT: Temperature [K]x: Composition (mole fraction of solute)solid_phase: Name of solid phase (e.g., "FCC_A1")liquid_phase: Name of liquid phase (e.g., "LIQUID")
Returns
- Driving force ΔG [J/mol] (negative = solid stable)
PhaseFields.calphad_chemical_potential — Function
calphad_chemical_potential(db, phase, T, x)Get chemical potentials from CALPHAD database.
Requires OpenCALPHAD.jl: Load with using OpenCALPHAD to enable this function.
Returns
- Tuple of chemical potentials (μ₁, μ₂, ...) [J/mol]
PhaseFields.calphad_diffusion_potential — Function
calphad_diffusion_potential(db, phase, T, x)Get second derivative of Gibbs energy d²G/dx² from CALPHAD.
Requires OpenCALPHAD.jl: Load with using OpenCALPHAD to enable this function.
Returns
- d²G/dx² [J/mol]
PhaseFields.create_calphad_allen_cahn — Function
create_calphad_allen_cahn(db, T, x, solid_phase, liquid_phase; kwargs...)Create an Allen-Cahn model coupled with CALPHAD thermodynamics.
Requires OpenCALPHAD.jl: Load with using OpenCALPHAD to enable this function.
Arguments
db: OpenCALPHAD Database objectT: Temperature [K]x: Composition (mole fraction)solid_phase: Name of solid phaseliquid_phase: Name of liquid phase
Keyword Arguments
τ: Relaxation time [s] (default: 1.0)W: Interface width parameter (default: 1.0)m: Scaling factor for ΔG (default: 1e-4)
Returns
- CALPHADAllenCahnModel with cached driving force
PhaseFields.create_calphad_kks_model — Function
create_calphad_kks_model(db, T, solid_phase, liquid_phase; kwargs...)Create a KKS model setup with CALPHAD free energies.
Requires OpenCALPHAD.jl: Load with using OpenCALPHAD to enable this function.
Arguments
db: OpenCALPHAD Database objectT: Temperature [K]solid_phase: Name of solid phaseliquid_phase: Name of liquid phase
Keyword Arguments
τ: Relaxation time [s] (default: 1.0)W: Interface width parameter (default: 1.0)m: Driving force scale (default: 1.0)M_s: Solid mobility (default: 1.0)M_l: Liquid mobility (default: 10.0)
Returns
- Tuple of (KKSModel, CALPHADFreeEnergysolid, CALPHADFreeEnergyliquid)
PhaseFields.create_calphad_wbm_model — Function
create_calphad_wbm_model(db, T, solid_phase, liquid_phase; kwargs...)Create a WBM model setup with CALPHAD free energies.
Requires OpenCALPHAD.jl: Load with using OpenCALPHAD to enable this function.
Arguments
db: OpenCALPHAD Database objectT: Temperature [K]solid_phase: Name of solid phaseliquid_phase: Name of liquid phase
Keyword Arguments
M_φ: Phase field mobility (default: 1.0)κ: Gradient energy coefficient (default: 1.0)W: Barrier height (default: 1.0)D_s: Solid diffusivity (default: 1e-13)D_l: Liquid diffusivity (default: 1e-9)
Returns
- Tuple of (WBMModel, CALPHADFreeEnergysolid, CALPHADFreeEnergyliquid)
See Also
- 381calphadcoupling_demo.jl - Complete CALPHAD coupling demo with plots