A two-dimensional cellular automaton model for primary dendritic solidification in binary alloys.
This repository contains a Fortran cellular automaton solidification code and a small set of Python helper scripts for preparing input files, generating thermal histories, creating starting grids, running simulations, and plotting results.
The model combines:
- explicit liquid-phase solute diffusion on a CA grid
- local-equilibrium partitioning during interface solidification
- orientation-dependent / anisotropic interface capture
- analytical dendrite-tip guidance from KGT / marginal-stability ideas
- macro-scale thermal histories coupled to local CA-scale evolution
- staged solute redistribution during solidification
The dendrite tip is not fully resolved on the CA grid. Instead, the resolved CA transport field is coupled to analytical tip-scale estimates. The intent is to provide a useful teaching, exploration, and model-development framework rather than a fully validated commercial solidification package.
This is a public release of a legacy cellular automaton dendritic solidification model, updated with Python helper scripts for easier use.
The code is intended for teaching, experimentation, and preservation. It is not a validated solidification simulation package, and major changes to the core Fortran model are not expected.
The main Fortran source is:
CAdenv1.f
Compile with:
gfortran -O3 -Wall -Wextra -o CAsim CAdenv1.fRun with:
./CAsimThe simulation reads its main inputs from the files defined in the parameter file, normally:
xparam.txt
xgrid.txt
xthermal.csv
and writes:
data.csv
grid.txt
outN.ppm optional movie/image frames
The typical workflow is:
- create or edit the parameter file
- generate a thermal-history CSV
- generate the starting CA grid
- compile and run the Fortran CA simulation
- plot the final grid and runtime diagnostics
A typical run is:
python3 make1-param.py
python3 make2-thermal.py
python3 make3-grid.py
gfortran -O3 -Wall -Wextra -o CAsim CAdenv1.f
./CAsim
python3 plot.py
python3 data.py data.csvFor a uniform/equiaxed cooling case, replace the thermal-history step with:
python3 make2-uniform.pyInteractive parameter-file editor.
Creates or edits named-value parameter files such as:
xparam.txt
The parameter file stores alloy properties, transport constants, thermal controls, domain size, boundary-condition settings, and default filenames.
Important conventions:
GRADis stored as K/cellVELis stored as cells/sTHETA1andTHETA2are stored in radians, but edited/displayed in degreesDXis the CA cell size in metersDTis the CA time step in secondsDCOEFFis the liquid solute diffusivity in m²/s
The script also prints useful derived checks, including:
D*DT/DX^2- gradient in K/cm
- velocity in µm/s and mm/h
- estimated KGT tip radius relative to grid spacing
Directional-solidification thermal-history generator.
This script creates a moving-gradient thermal history using values from the parameter file. It writes the six-column thermal CSV form read by the Fortran routine LOADTHERMCSV.
Output columns:
time_s,Tref_C,Gx_K_per_m,Gy_K_per_m,cooling_rate_K_per_s,Vthermal_m_per_s
For the simple one-dimensional directional-growth case:
Gx = 0Gy = GRAD/DXVthermal = VEL*DXcooling_rate = GRAD*VEL
Uniform/equiaxed thermal-history generator.
This script creates a spatially uniform macro-temperature history:
Tref(t) = Tref0 - cooling_rate*t
Gx = 0
Gy = 0
This is useful for equiaxed or isotropic-cooling tests.
The script still writes Vthermal_m_per_s, which may be used by the CA/KGT/staged-growth machinery as a velocity scale. In uniform cooling, this velocity does not create a moving thermal gradient because the imposed gradient is zero.
Starting-grid generator.
This script creates the starting CA grid file, normally:
xgrid.txt
It combines:
- the CA parameter file
- the first row of the thermal-history CSV
- a selected seed geometry
Supported seed options include:
- single-crystal bottom seed
- bicrystal bottom seed
- multigrain bottom seed
- random bottom seed orientations
- single center seed
- random centered grains
- no seed / all-liquid start
The generated grid contains:
X Y #liqCells Lcomp Scomp Phase Temp Orient
where:
#liqCells = 1000indicates a fully liquid cell#liqCells = 0indicates a fully solid seed cellPhase = 0is liquidPhase = 1is primary solidOrientis the crystal/growth orientation in radians
Restart/continuation helper. It builds a new starting grid and matched
thermal/parameter files from a previous grid.txt output.
This is useful when a completed CA state should be reused as the starting condition for a follow-on run.
Post-processing helper that creates grid_thick.txt by applying a simple
nearest-neighbor visual thickening of solid cells.
This is for display only; it does not change the simulation result.
Plots the final CA grid output, normally:
grid.txt
The plot emphasizes liquid composition and solid morphology. It can also display the grid in a tiled periodic form for easier visualization of periodic-X simulations.
Plots and summarizes the runtime CSV output:
data.csv
Typical plotted quantities include:
- tip velocity
- undercooling
- KGT tip radius
- Peclet number
- supersaturation
- KGT comparison quantities
DFRZ/ freezing scale history
Because the dendrite tip is not fully resolved on the CA grid, direct undercooling comparisons between the CA field and KGT estimates should be interpreted carefully. Supersaturation comparisons are often the more useful diagnostic.
Creates simple PPM-style visualization output from grid.txt.
This is mainly a lightweight visualization helper and can be useful for quick morphology checks or movie-frame workflows.
The helper scripts use standard Python 3 plus a small set of common packages:
pip install numpy matplotlib pandas mpmathmpmath is only needed for some KGT/Ivantsov diagnostic calculations.
Main run-control parameter file.
This file stores named values used by both the Python helpers and the Fortran simulation.
Typical entries include alloy parameters, transport parameters, thermal parameters, domain size, boundary-condition controls, and filenames.
Thermal-history input file.
This is read by the Fortran code through LOADTHERMCSV.
The preferred six-column form is:
time_s,Tref_C,Gx_K_per_m,Gy_K_per_m,cooling_rate_K_per_s,Vthermal_m_per_s
For older one-dimensional examples, the Fortran reader also accepts the five-column form:
time_s,Tref_C,G_K_per_m,cooling_rate_K_per_s,Vthermal_m_per_s
In that case, G_K_per_m is interpreted as the vertical/Y gradient.
Starting CA grid.
This file is usually generated by make3-grid.py and read by the Fortran simulation at startup.
Runtime diagnostic output.
This file records quantities such as tip position, velocity, undercooling, KGT radius, Peclet number, supersaturation, and mass/transport diagnostics.
Final CA grid state.
This is the main output for post-processing and visualization.
Optional image/movie frames written during the simulation when movie output is enabled.
The Fortran code supports the following boundary-condition modes:
IBCTYPE = 0 closed X, closed Y
IBCTYPE = 1 periodic X, closed Y default
IBCTYPE = 2 closed X, periodic Y
IBCTYPE = 3 periodic X, periodic Y
The parameter IEMBED controls how the initial thermal field is aligned.
IEMBED = 1
Use the imposed thermal history directly.
IEMBED = 0
Shift the imposed thermal history so the initial seed/front aligns
with TL0 - DTSEED. This is the usual standalone default.
The model uses an explicit solute diffusion update, so the quantity
ALPHA = DCOEFF*DT/DX^2
should be monitored.
Stability and resolution depend on:
DCOEFFDTDXVEL- thermal history
- interface update frequency
- dendrite-tip radius relative to grid spacing
The parameter/script workflow reports useful derived checks, including the estimated KGT tip radius relative to DX.
A useful practical rule is that the grid spacing should be small compared with the physical dendrite-tip radius. If the estimated KGT tip radius approaches only a few grid cells, the CA morphology and tip-scale comparison should be interpreted cautiously.
The current model is focused on primary dendritic solidification in an effective binary alloy.
Multicomponent alloys may be approximated through an effective binary description of the primary solidification path, but full mushy-zone evolution, multiphase reactions, and fully coupled thermodynamic descriptions are outside the present model scope.
The code is intended to generate mass-balanced primary microstructure states and to explore the coupling between CA-scale transport and analytical dendrite-tip physics.
The implementation is based on ideas from cellular automaton solidification modeling, dendrite growth theory, KGT/marginal stability, Ivantsov diffusion solutions, Gibbs-Thomson capillarity, and velocity-dependent partitioning.
Key model references include:
- Rappaz, M. and Gandin, C.-A., “Probabilistic modelling of microstructure formation in solidification processes,” Acta Metallurgica et Materialia, 41 (1993) 345–360.
- Kurz, W., Giovanola, B., and Trivedi, R., “Theory of microstructural development during rapid solidification,” Acta Metallurgica, 34 (1986) 823–830.
- Kurz, W. and Fisher, D.J., Fundamentals of Solidification, 4th ed., Trans Tech Publications, 1998.
- Ivantsov, G.P., “Temperature field around a spherical, cylindrical, and needle-shaped crystal growing in a supercooled melt,” Doklady Akademii Nauk SSSR, 58 (1947) 567–569.
- Aziz, M.J., “Model for solute redistribution during rapid solidification,” Journal of Applied Physics, 53 (1982) 1158–1168.
Copyright (c) 2026 David R. Johnson.
Licensed under the MIT License. See the LICENSE file for details.
The core Fortran source code was refactored to modernize its structural control flow and improve logical clarity, and the accompanying Python helper scripts were developed to replace the legacy menu-based workflow, utilizing AI-assisted reworking, cleanup, and extension.