top of page

Cosmic Web Formation with an N‑Body Model

  • Writer: Chaitanya Singh
    Chaitanya Singh
  • Jul 22
  • 3 min read

This simulation offers a minimal‑effort glimpse into how gravity sculpts the large‑scale structure of the universe: the so‑called cosmic web of filaments, clusters, and voids. By letting a thousand or two particles evolve under mutual gravitational attraction in a square box, you’ll watch diffuse clouds collapse into filaments and knots—an echo of galaxy superclusters and the vast empty regions between them.


1. The Physical Picture

  • Particles as Mass Elements: We represent matter by 2,000 identical “particles” scattered randomly in a two‑dimensional square region. Each particle carries one unit of mass.

  • Newtonian Gravity in a Box: Every particle attracts every other with a force proportional to the product of their masses (here always one) divided by the third power of their separation. In symbols, the acceleration of particle i due to particle j isacceleration ∝ 1 / (distanceᵢⱼ)³ × (displacement vector from j to i).To avoid infinite forces when two particles come extremely close, we add a small constant—called the softening length squared—to every squared distance before taking the square root. This mimics a slight smoothing of the mass distribution.

  • Periodic or Fixed Walls: In a more realistic cosmological box one would impose periodic boundaries so that particles leaving one edge reenter on the opposite side. In our simple demo, we keep particles inside the box without wrapping, merely drawing the evolving positions between zero and the box size.


2. Numerical Integration

  • Time Step: We march the system forward in uniform steps of Δt = 0.01.

  • Velocity Verlet Scheme: To update positions and velocities with minimal energy drift, we use the two‑stage Velocity Verlet algorithm:

    1. Compute current accelerations for all particles by summing gravitational pulls from every other particle.

    2. Advance each position by adding velocity×Δt plus half acceleration×(Δt)².

    3. Recompute accelerations at the new positions.

    4. Update each velocity by adding half the sum of old and new accelerations multiplied by Δt.

This method ensures stable, accurate evolution even when local densities and hence forces become large.


3. Visualizing the Web

  • Black Background, White Dots: Each particle is drawn as a tiny white point on a black canvas, reminiscent of dark‑matter simulations where filaments stand out against voids.

  • Animation: Over the course of 300 frames (with a brief pause between each), you’ll see initially random points begin to cluster. Small clumps merge into longer strands; filaments intersect at dense knots, and large empty regions voids open up around these structures.


4. What You’ll Observe

  1. Small‑Scale Clumping: At first, nearby particles gravitationally attract, forming tiny aggregates.

  2. Filament Growth: As time goes on, these aggregates pull in neighbors along preferred directions, stretching into thread‑like filaments.

  3. Node Formation: Where multiple filaments cross, dense “nodes” emerge—analogous to galaxy clusters in the real universe.

  4. Void Expansion: Regions between filaments become depleted, leading to large, near‑empty zones.

These features mirror the cosmic web seen in large cosmological simulations, albeit in a very simplified two‑dimensional toy model.


5. Tuning the Parameters

  • Number of Particles (N)Increasing N sharpens filaments but raises the computational cost as forces scale like N².

  • Gravitational Constant (G)A larger G accelerates collapse, producing structures faster but risking numerical instability if too large.

  • Softening LengthA bigger softening length smooths out very small‑scale clumps, emphasizing broader filaments.

  • Time Step (Δt)A smaller Δt improves accuracy during rapid collapses but requires more iterations to reach the same “physical” time.


6. Next Steps and Extensions

  • Three‑Dimensional ExtensionAdd a third coordinate to simulate a true volumetric cosmic web.

  • Periodic BoundariesImplement wrap‑around at the box edges to avoid artificial edge effects.

  • Adaptive ResolutionFocus computational effort where density is highest, using techniques like tree codes or adaptive mesh refinement.

  • Cosmological ExpansionIntroduce a scale factor to simulate the universe’s expansion, combining gravity with Hubble flow.


This simple N‑body demonstration offers a hands‑on window into the gravitational dynamics that knit the universe’s large‑scale tapestry. Tweak the settings, watch filaments grow, and get an intuitive feel for cosmic structure formation!

Comments


LinkedIn

  • LinkedIn

© 2025 by Chaitanya Singh

bottom of page