Phase Transitions Simulation
Phase Transitions and the Boltzmann Distribution
This set of notes covers the core concepts behind phase transitions, the Boltzmann distribution, and the liquid‑vapor model—a simple discretized fluid simulation that exhibits phase transitions. The material explains why randomness is used to model large systems, how temperature and chemical potential control equilibrium behavior, and how the simulation algorithm samples from the Boltzmann distribution.
What Is a Phase Transition?
A phase transition is a discontinuity in a system’s equilibrium behavior when a control parameter (such as temperature or pressure) is varied.
Different phases of matter (solid, liquid, gas) correspond to different ways molecules interact. In ice, molecules form a rigid, long‑range structure; in water, interactions still allow ripples; in steam, there is almost no long‑range interaction.
Phase transitions are not chemical reactions—the molecules remain the same (e.g., H₂O in all three phases).
The equilibrium phase of a system depends on parameters like temperature and pressure. Crossing a line on a phase diagram triggers a transition, but this transition does not happen instantly in real time; it is the behavior after the system settles.
At very high temperatures and pressures, a supercritical fluid exists where liquid and gas vary continuously—no phase transition occurs when moving through this region.
The Liquid‑Vapor Model Simulation
The simulation shows blue pixels (molecules) and white pixels (empty space) on a grid, representing a discretized fluid.
Two parameters control the simulation: temperature (T) and chemical potential (μ) .
Pressure is tricky to use in a fixed‑size simulation, so chemical potential is used instead. It plays a role analogous to pressure: at high chemical potential, more molecules appear (like decreasing volume).
At high temperatures, molecule density varies smoothly with chemical potential (supercritical region). At low temperatures, crossing a threshold causes a phase transition where density jumps from low (gas) to high (liquid), skipping intermediate values.
During the transition, the picture shows only dense liquid regions and sparse gas regions, separated by well‑defined curves.
Why Randomness? The Need for Statistical Mechanics
A microstate contains all information about every particle’s position and velocity. For a large number of particles (e.g., 1023 in a teaspoon of water), tracking every microstate is impossible.
Instead of predicting exact positions, we approximate a deterministic microstate by a random microstate. Randomness stands in for our ignorance and is a proven practical tool.
The key insight: we only care about the macrostate (large‑scale behavior like density), not individual particle motions.
The Boltzmann Distribution
The Boltzmann distribution gives the probability of any microstate x in a system at fixed temperature T:
where E(x) is the energy of the microstate. (Boltzmann’s constant k is set to 1 by choosing appropriate units.)
States with higher energy have lower probability, and vice versa.
To find the most likely energy level, we must also consider the number of microstates at that energy.
Entropy and Free Energy
Let Ω(E) be the set of microstates with energy E. The entropy S(E) is:
The probability of seeing a microstate in Ω(E) is proportional to e−E/T⋅∣Ω(E)∣=e−E/T+S(E).
The free energy F is defined as:
The most likely energy level minimizes F, because maximizing e−E/T+S is equivalent to minimizing E−TS.
At low temperature: minimizing E dominates (nature favors low‑energy states).
At high temperature: maximizing S dominates (nature favors high‑entropy, disordered states).
The competition between energy and entropy, mediated by temperature, is the fundamental cause of phase transitions.
Deriving the Boltzmann Distribution
Step 1: Isolated System
In a completely isolated system with fixed energy E, all microstates are equally likely. Each microstate has probability 1/∣Ω(E)∣.
Step 2: Two Systems in Contact
When two isolated systems at different energies are brought into thermal contact, energy can flow between them. The combined system is isolated.
The total energy Etotal=E1+E2 is fixed.
A small energy packet dE flows in the direction that increases the combined entropy S12=S1(E1)+S2(E2).
The derivative of entropy with respect to energy gives:
Energy flows from system 2 to system 1 if dE1dS1>dE2dS2. At equilibrium, these derivatives equalize.
Temperature is defined as:
Thus, energy flows from hotter (small dS/dE) to colder (large dS/dE) systems. Adding energy increases the number of microstates more at low temperatures than at high temperatures.
Step 3: System in Contact with a Heat Bath
To fix a system at temperature T, place it in contact with a huge heat bath at that temperature. The bath’s temperature does not change appreciably.
The combined system (bath + small system) is isolated with total energy E0.
For a microstate x of the small system (energy E(x)), the number of compatible microstates of the bath is ∣Ωbath(E0−E(x))∣=eSbath(E0−E(x)).
Because the bath is huge, its derivative dSbath/dE is constant =1/T, so:
Then:
This completes the derivation.
Application to the Liquid‑Vapor Model
Energy Function
Each pixel can hold at most one molecule (no overlapping).
Molecules gain energy −1 for each pair of adjacent (neighboring) molecules. This models the attractive “sweet spot” of intermolecular forces.
The total energy of a microstate is:
Lower energy (more negative) corresponds to more clumped molecules.
Entropy‑Energy Competition
Gas phase (high temperature): many microstates exist with molecules spread out → high entropy, high energy. The system favors high entropy because T is large, so the free energy F=E−TS is minimized by large S.
Liquid phase (low temperature): few microstates exist with a single droplet → low entropy, low energy. The energy term dominates F, so the system prefers low energy.
No macrostate can simultaneously have low energy and high entropy; temperature determines which wins.
Sampling the Boltzmann Distribution: Kawasaki Dynamics
Directly sampling from the distribution (e.g., by enumerating all microstates) is impossible because the number of microstates grows exponentially.
Instead, the simulation performs a random walk through the space of microstates, making small local changes.
Algorithm (Kawasaki Dynamics):
Choose two random pixels.
If one contains a molecule and the other is empty, consider swapping the molecule to the empty pixel.
Compute the energy difference ΔE=E(x′)−E(x) between the current microstate x and the swapped microstate x′.
The ratio of Boltzmann probabilities is:
P(x)P(x′)=e−ΔE/TGiven only these two choices, the probability of swapping (i.e., moving to x′) is:
Pswap=1+e−ΔE/Te−ΔE/TRepeat many times.
The energy difference depends only on the at‑most 8 neighbors of the two pixels, so it can be computed quickly.
This algorithm is a Markov chain Monte Carlo method. It converges to the Boltzmann distribution after enough steps (like shuffling cards).
Allowing swaps between any two pixels (teleportation) speeds up convergence compared to only neighboring swaps.
Allowing Molecule Number to Change: Chemical Potential
Real phase diagrams have two control parameters (e.g., temperature and pressure). In the simulation, pressure is replaced by chemical potential (μ) , which controls molecule count.
Chemical potential is defined as:
where N is the number of molecules. It equalizes when two systems can exchange particles through a permeable wall.
To fix both T and μ, put the small system in contact with a huge reservoir at fixed T and μ that can exchange energy and particles.
The probability of a microstate becomes:
Positive μ favors more molecules; negative μ favors fewer.
This allows a simpler algorithm: pick one pixel and randomly add or remove a molecule, with acceptance probability based on the energy and chemical potential changes.
Phase Diagram of the Model
The phase diagram shows density (fraction of blue pixels) as a function of T and μ.
High temperature: density varies smoothly with μ → supercritical fluid region (no phase transition).
High chemical potential (μ > −2): density changes smoothly with T → liquid phase.
Low chemical potential (μ < −2): density changes smoothly with T → gas phase.
At low temperatures, crossing a line between liquid and gas causes a discontinuous jump in density—the phase transition line.
The shape of the phase diagram qualitatively matches that of real H₂O in the liquid‑gas region.
Universality
The model is extremely simplified (square lattice, no kinetic energy, simple interaction), yet it reproduces the essential features of a real phase diagram.
This illustrates universality: many microscopic details are unimportant; only a few fundamental rules determine macroscopic behavior. This is a key principle of statistical mechanics.
Interesting Behaviors
Droplets and Bubbles
During the phase transition, the system forms droplets (liquid in gas) or bubbles (gas in liquid) because density cannot change smoothly.
At very low temperatures, droplets become square due to the lattice. At higher (but still subcritical) temperatures, droplets are rounder.
The shape of droplets as a function of temperature can be described mathematically (see Wulff shape).
Metastability
When crossing the phase transition line by a small amount, the system often remains in the “wrong” phase (e.g., gas instead of liquid) for a long time.
This is metastability. The system needs a sufficiently large droplet to trigger the phase change; otherwise, small droplets shrink.
Real‑world example: supercooled water below freezing that doesn’t turn to ice until disturbed.
Critical Point
At the critical point (the end of the phase transition line), the system exhibits scale invariance: it looks similar at all magnifications, with fractal‑like structures.
At the critical temperature, the density is exactly 1/2 (for this model) if the lattice is symmetric.
This behavior sparks ideas like the critical brain hypothesis (brains may operate near criticality for optimal information processing).
Connections to Other Models
Ising Model (Magnet)
Replace molecules with “up” spins and empty spaces with “down” spins.
Energy favors aligned neighbors; chemical potential becomes an external magnetic field.
The liquid‑vapor model is exactly the same as the Ising model under this identification.
With Dobrushin boundary conditions (left side up, right side down), interesting domain walls appear, especially at criticality.
XY Model (Continuous Spin)
If spins can point in any direction (parameterized by a color wheel), the phase transition disappears in two dimensions.
Instead, vortices form—points where all colors meet, with positive and negative orientations.
Vortices behave like charged particles: opposite types attract, same types repel. This is the XY model, which exhibits a Kosterlitz‑Thouless transition.
Why Exact Solutions Are Limited
In two dimensions, the critical temperature of the Ising/liquid‑vapor model is known exactly:
In three dimensions, no exact formula exists—only numerical approximations.
A fully realistic model of water (3D, moving molecules, electromagnetic interactions) is mathematically intractable.
The lesson: simplify models while retaining essential features to gain conceptual understanding. Rigorous analysis of simplified models can reveal the fundamental mechanisms behind phase transitions.
These notes form the foundation for understanding phase transitions, the Boltzmann distribution, and how simple computational models can capture real‑world behavior. The second part of this series simplifies the model further to allow complete mathematical analysis.

Ask anything
We've read this whole study set, so questions about it get the best answers.