Module 10: From smooth to lumpy · Lesson 10.9 · about 16 min
Universes in a computer
How cosmologists grow a universe in a computer: particles, gravity on a grid, softening and expanding boxes, from Millennium to IllustrisTNG, with a live model.
Module 10 · about 16 minutes. Read first: 10.6 How galaxies form. Gravity’s equations are simple, but following billions of masses pulling on each other is impossible by hand. Since the 1980s, cosmologists have grown whole universes in computers, from the measured ripples to today’s web of galaxies. By the end you will be able to explain how a simulation works, what its particles and boxes mean, and what simulations can and cannot tell us.
1. The N-body idea
Fill a box with N particles of dark matter. Work out the pull on each from all the others, nudge the speeds (a kick), move the particles a little (a drift), and repeat thousands of times. That is an N-body simulation. The pull on particle i is Newton’s law, added up over every other particle j, with one change:
- ai
- the acceleration of particle i
- mj, xj
- the mass and position of each other particle
- ε
- the softening length. Without it, two particles passing very close would pull infinitely hard and fling each other apart. Each particle stands for a smooth cloud, so gravity is softened at distances below ε (a few kiloparsecs or less)
- Physical meaning
- Newton's inverse-square law (Newton's gravity), summed over everything. Newton is enough: the particles move far slower than light, and the expansion is handled separately (section 2).
Each “particle” is not a real particle but a sample of the matter: the box’s total mass shared out equally. In big simulations each is a cloud of millions to billions of suns.
2. Boxes that expand
A simulation cannot hold the whole universe, so it follows a cube, typically tens to thousands of megaparsecs across, and wraps it around at the edges: a particle leaving through the right face comes back in through the left, so there are no edges and the cube is a fair sample of an endless universe. Positions are measured in comoving units that stretch with the universe (Lesson 5.1); the computer only tracks the extra motion caused by lumps, with the expansion rate taken from the Friedmann equation.
The run begins at a redshift of roughly 50 to 130, while the lumps are still small. The starting positions come from a random field with exactly the ripple strengths measured by the CMB and galaxy surveys, displaced with Zel’dovich’s straight-line rule (Lesson 10.4). Nothing about the web is put in by hand.
3. Doing the sum quickly
Adding up every pair takes about N²/2 sums per step. For ten billion particles that is far too slow.
Two tricks cut it to about N log N:
- Tree codes (Josh Barnes and Piet Hut, 1986) group far-away particles into boxes and treat each box as one mass, like looking at a distant city as one light.
- Particle-mesh codes spread the mass onto a grid and find gravity for the whole grid at once with a fast Fourier transform. Modern codes like GADGET combine both: mesh for long range, tree for short.
4. From dark matter to galaxies
Dark matter alone gives the scaffolding: halos, subhalos and the web, all from gravity and the starting ripples, with no knobs to turn. Galaxies need gas too. Hydrodynamic simulations add the gas, with its pressure, shocks and cooling. But stars, supernovae and black holes act on scales far smaller than one simulation cell, so they enter as approximate subgrid recipes, tuned to match a few observed facts such as how many galaxies there are of each mass. The best runs then reproduce many other things they were not tuned for, such as the mix of spirals and ellipticals.
- Millennium Run (2005): Volker Springel and the Virgo Consortium followed about 10 billion particles (2160³) in a box 500 h⁻¹ Mpc (about 700 Mpc) across, then “painted” galaxies onto its halos with simple models.
- Illustris (2014) and IllustrisTNG (2018): gas, stars and black holes together in boxes up to about 300 Mpc across.
- EAGLE (2015): the Virgo Consortium’s galaxy simulation, tuned to the masses and sizes of galaxies today.
- 1941 Erik Holmberg simulates two colliding galaxies with 74 light bulbs, measuring "gravity" with light meters.
- 1985 Davis, Efstathiou, Frenk and White run cold dark matter universes with 32,768 particles: they look like the real galaxy maps.
- 1986 Barnes and Hut's tree algorithm.
- 2005 The Millennium Run: 10 billion particles.
- 2014-18 Illustris, EAGLE and IllustrisTNG grow realistic galaxies with gas and feedback.
“Simulations just show whatever their makers put in.” For dark matter, the only inputs are gravity, the amounts of each ingredient and the starting ripples, all measured independently; the web, the halos and their NFW shape (Lesson 10.3) come out by themselves. Galaxy physics is different: its subgrid recipes are tuned, so a simulation’s galaxies are a test only of what was not tuned.
- An N-body simulation follows particles that each stand for a cloud of matter, adding up gravity (softened at short range) and stepping forwards: kick, drift, repeat.
- Boxes are comoving and wrap around; the starting positions follow the measured ripples.
- Tree and particle-mesh methods cut the work from N² to about N log N.
- Dark matter-only runs have no tunable knobs; galaxy simulations add gas and tuned subgrid recipes for stars and black holes.
- Landmarks: Davis-Efstathiou-Frenk-White (1985), Millennium (2005, 10 billion particles), Illustris, EAGLE, IllustrisTNG.
Check yourself
Sources
- E. Holmberg (1941), On the clustering tendencies among the nebulae. II. A study of encounters between laboratory models of stellar systems by a new integration procedure, ApJ 94, 385 https://doi.org/10.1086/144344
- M. Davis, G. Efstathiou, C. S. Frenk and S. D. M. White (1985), The evolution of large-scale structure in a universe dominated by cold dark matter, ApJ 292, 371 https://doi.org/10.1086/163168
- J. Barnes and P. Hut (1986), A hierarchical O(N log N) force-calculation algorithm, Nature 324, 446 https://doi.org/10.1038/324446a0
- V. Springel et al. (2005), Simulations of the formation, evolution and clustering of galaxies and quasars, Nature 435, 629 https://doi.org/10.1038/nature03597
- M. Vogelsberger et al. (2014), Properties of galaxies reproduced by a hydrodynamic simulation, Nature 509, 177 https://doi.org/10.1038/nature13316
- J. Schaye et al. (2015), The EAGLE project: simulating the evolution and assembly of galaxies and their environments, MNRAS 446, 521 https://doi.org/10.1093/mnras/stu2058
- V. Springel et al. (2018), First results from the IllustrisTNG simulations: matter and galaxy clustering, MNRAS 475, 676 https://doi.org/10.1093/mnras/stx3304
Your ticks stay in this browser. Save them as a file on the course home.
Updated 2026-11-22. Numbers are rounded for teaching; measured values come from the sources listed in each lesson. Simulations run in your browser; nothing you type is sent anywhere.