0% found this document useful (0 votes)
6 views52 pages

N-Body Simulation in Cosmology: Thesis To Be Submitted in Partial Fulfillment of The Requirements For The Degree

This thesis by Aurobinda Majhi presents a detailed implementation of an N-body simulation using the Particle-Mesh method to analyze large-scale structure formation in the universe. It discusses the incorporation of various techniques, including the Zel’dovich approximation and different mass assignment schemes, and validates the simulation through tests on force accuracy and energy conservation. The findings emphasize the balance between computational efficiency and accuracy, offering a framework for further research in cosmology.

Uploaded by

swarajitdhar6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views52 pages

N-Body Simulation in Cosmology: Thesis To Be Submitted in Partial Fulfillment of The Requirements For The Degree

This thesis by Aurobinda Majhi presents a detailed implementation of an N-body simulation using the Particle-Mesh method to analyze large-scale structure formation in the universe. It discusses the incorporation of various techniques, including the Zel’dovich approximation and different mass assignment schemes, and validates the simulation through tests on force accuracy and energy conservation. The findings emphasize the balance between computational efficiency and accuracy, offering a framework for further research in cosmology.

Uploaded by

swarajitdhar6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

N-body Simulation in Cosmology

Thesis to be submitted in partial fulfillment of the


requirements for the degree

of

Masters in Science

by

Aurobinda Majhi
23PH40014

Under the guidance of

Prof. Somnath Bharadwaj

PHYSICS
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
Department of Physics
Indian Institute of Technology,
Kharagpur
India - 721302

CERTIFICATE

This is to certify that we have examined the thesis entitled N-body Simulation
in Cosmology, submitted by Aurobinda Majhi(Roll Number: 23PH40014 ) a
postgraduate student of Department of Physics in partial fulfillment for the award
of degree of Masters in Science. We hereby accord our approval of it as a study carried
out and presented in a manner required for its acceptance in partial fulfillment for
the Post Graduate Degree for which it has been submitted. The thesis has fulfilled all
the requirements as per the regulations of the Institute and has reached the standard
needed for submission.

Supervisor
Department of Physics
Indian Institute of Technology,
Kharagpur

Place: Kharagpur
Date:

ii
ABSTRACT

This thesis presents a comprehensive implementation of a cosmological N-body simu-


lation using the Particle-Mesh (PM) method to study large-scale structure formation
in the universe. The simulation incorporates the Zel’dovich approximation for initial
conditions, three mass assignment schemes (NGP, CIC, TSC), and both Poisson and
telegraph equation solvers for gravitational potential calculations. Key tests validate
force accuracy, energy conservation, and the impact of resolution, demonstrating that
higher-order interpolation (e.g., TSC) reduces errors by 15% compared to NGP. The
simulation leverages Fourier-based Poisson solvers and leapfrog integration to model
structure growth in a ΛCDM universe, with analysis tools for power spectra and two-
point correlation functions. Results highlight the trade-offs between computational
efficiency and accuracy, with recommendations for future extensions such as adaptive
mesh refinement. This work bridges theoretical cosmology and numerical methods,
providing a robust framework for studying cosmic web formation.

Keywords: N body Simulation, Paricle-Mesh method, Telegraph Equation Solver,


Poisson equation Solver

iii
Contents

1 N-body simulation 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Equations of motion . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Equations of motion in simulation space . . . . . . . . . . . . . . . . 6
1.4 Vlasov equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4.1 Eulerian Vlasov Equation . . . . . . . . . . . . . . . . . . . . 7
1.4.2 Lagrangian Vlasov Equation . . . . . . . . . . . . . . . . . . . 7
1.4.3 0th moment of Vlasov equation . . . . . . . . . . . . . . . . . 8
1.4.4 1st moment of Vlasov equation . . . . . . . . . . . . . . . . . 8

2 Simulation 11
2.1 Begin of Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Initial perturbation from grid position . . . . . . . . . . . . . . . . . 11
2.2.1 Fourier representation of density contrast from Power spectrum 12
2.2.2 Initial Power Spectrum . . . . . . . . . . . . . . . . . . . . . . 12
2.2.3 Zel’dovich Approximation . . . . . . . . . . . . . . . . . . . . 14
2.3 Mass asignment to grid position . . . . . . . . . . . . . . . . . . . . . 15
2.3.1 NGP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3.2 CIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3.3 TSC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 Potential Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4.1 Poisson equation . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.4.2 Telegraph equation . . . . . . . . . . . . . . . . . . . . . . . . 20
2.5 Calculate Force . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.6 Position and Velocity update . . . . . . . . . . . . . . . . . . . . . . . 22
2.7 flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

iv
3 Tests for the simulation program 25
3.1 Tests for Mass asignment . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.1.1 Test for uniform distribution . . . . . . . . . . . . . . . . . . . 25
3.1.2 Fourier space Validation . . . . . . . . . . . . . . . . . . . . . 25
3.2 Force accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2.1 Force accuracy test - I . . . . . . . . . . . . . . . . . . . . . . 27
3.2.2 Force accuracy test - II . . . . . . . . . . . . . . . . . . . . . . 27
3.3 Energy Conservation . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.3.1 Energy conservation Test - I . . . . . . . . . . . . . . . . . . . 28
3.3.2 Energy conservation Test - II . . . . . . . . . . . . . . . . . . 29
3.4 Effect of Force Resolution . . . . . . . . . . . . . . . . . . . . . . . . 30
3.4.1 One dimensional perturbation test . . . . . . . . . . . . . . . 30
3.4.2 3 dimensional perturbation test . . . . . . . . . . . . . . . . . 32
3.5 Telegraph equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.5.1 Static density tests . . . . . . . . . . . . . . . . . . . . . . . . 35
3.5.2 Gaussian density test . . . . . . . . . . . . . . . . . . . . . . . 36
3.5.3 Compairing Total Force with Poisson Solver . . . . . . . . . . 37
3.5.4 Iteration vs Error . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.5.5 kappa vs Error . . . . . . . . . . . . . . . . . . . . . . . . . . 39

4 Program 42
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.2 Class Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.2.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.2.2 Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.2.3 Cosmology Calculations . . . . . . . . . . . . . . . . . . . . . 43
4.2.4 Mass Assignment . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2.5 Poisson Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2.6 Force Calculations . . . . . . . . . . . . . . . . . . . . . . . . 44
4.2.7 Time Integration . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.2.8 Energy Calculations . . . . . . . . . . . . . . . . . . . . . . . 44
4.2.9 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.2.10 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

5 Conclusion 45

v
Chapter 1

N-body simulation

1.1 Introduction
N-body simulations in cosmology are computational techniques used to model the
evolution of particle systems under mutual gravitational interactions. These simula-
tions are crucial for understanding the formation of cosmic structures like galaxies,
galaxy clusters, and the cosmic web. Each particle represents a macro object, such
as a galaxy or a dark matter halo, allowing large-scale matter behavior to be studied
over cosmic timescales.
Simulations begin with a nearly homogeneous particle distribution, where each
particle approximates a galaxy by representing a large number of stars. Over time,
density fluctuations grow due to gravitational instability, forming cosmic structures.
The evolution of density contrast in an expanding universe is computed by solving
the gravitational field generated by all particles. The resulting field updates particle
velocities and positions iteratively, generating a new gravitational potential at each
time step. This iterative process continues until the final cosmic structure emerges,
providing insights into large-scale universe evolution.

1.2 Equations of motion


To find the equation of motion of particles, we have to find the lagrangian of a
single particle under the gravitational potential ψ(⃗r, t), which is given by,

1
L = m⃗r˙ 2 − mψ(⃗r, t) (1.1)
2

1
Here ⃗r is the physical position vector of the particle of mass m from the origin.
The scalar potential ψ(⃗r, t) satisfies the equation:

∇2 ψ(⃗r, t) = 4πGρ(⃗r) (1.2)

Consider the expanding coordinate system. In this coordinate system we take


account for the fact that the universe is expanding.
We define comoving coordinates ⃗x as fixed positions in the expanding coordinate
system, unaffected by the universe’s expansion. The actual physical coordinates ⃗r
can be obtained from the comoving coordinates using the following equation:

⃗r = a(t)⃗x

Here a(t) is the Hubble flow constant. Putting this in to the lagrangian we would
get,
1
L = m(ȧ⃗x + a⃗x˙ )2 − mψ(⃗x, t) (1.3)
2
*we are going to write ⃗x as x for simplicity.
The Poisson equation becomes,

∇2 ψ(x, t) = 4πGa2 ρ(r) (1.4)

*the a2 terms comes from the ∇2 operator after the transformation.


Action integral of a single particle is,
Z t2
S= Ldt
t1

or, Z t2
1
S= ( m(ȧx + aẋ)2 − mψ(x, t))dt (1.5)
t1 2
Take ȧ = da
dt
⇒ dt = da

, dx
dt
= dx
da
ȧ = x′ ȧ and m = 1. So the action integral is now
becomes,
Z a2
1 ψ
S= ( (ȧa2 x′2 + ȧx2 + 2ȧax′ x) − )da (1.6)
a1 2 ȧ
2
we add and subtract the term aäx2ȧ
,
Z a2
1 aäx2 aäx2 ψ
S= ( (ȧa2 x′2 + ȧx2 + 2ȧax′ x + )− − )da (1.7)
a1 2 ȧ 2ȧ ȧ

2
By adding this term we have can write the 3 terms as,

d aäx2
(ȧax2 ) = + ȧx2 + 2ȧax′ x
da ȧ
Now the action integral is rewritten as,
Z a2
1 a
( ȧa2 x′2 − ϕ)da + ȧax2 a21

S= (1.8)
a1 2

Where,
äax2 ψ
ϕ= + (1.9)
2ȧ ȧ
Let Z a2
′ 1
S = ( ȧa2 x′2 − ϕ)da
a1 2
Then both S and S’ will result in same equation of motion. So Final action integral
becomes, Z a2
1
S= ( ȧa2 x′2 − ϕ)da (1.10)
a1 2
Our new scalar potential Now follows the equation,
¨
3a 4πGa2 ρ
∇2 ϕ = + (1.11)
H ȧ
*∇2 x2 = 6 as x is a 3d vector.
Where H(a) is called the Hubble parameter whose value is,

H(a) =
a
Friedman equation is given by,

Λc2
 
ä 4πG 3p
=− ρ̄ + 2 +
a 3 c 3

Here p is the the pressure exerted by the contents of the universe (matter, radia-
tion, dark energy, etc.) and Λ is a constant energy density filling space homogeneously,
representing dark energy and ρ̄ is the mean density.
we set p = 0 for matter dominated era and Λ = 0 matter or radiation dominated
epochs. Then Friedmann’s equation can be written as,
ä 4πG
=− ρ̄
a 3

3
putting this in equation for ϕ we get,
4πGaρ̄
∇2 ϕ = δ (1.12)
H
We defined another parameter δ(x, t) which is called density contrast, that defined
as:
ρ − ρ̄
δ(x, t) = (1.13)
ρ̄
Lagrangian form for the action integral equation (1.10) is,
1
L = ȧa2 x′2 − ϕ (1.14)
2
Momentum of the particle from the lagrangian is obtained from the relation,
∂L
P =
∂x′
⇒ P = ȧa2 x′ = H(a)a3 x′

dx P v
⇒ = 3
= (1.15)
da H(a)a H(a)a3
and From Euler-Lagrange’s equation we obtain,
dv
= −∇ϕ (1.16)
da
Equations 1.14 and 1.15, together with Equation 1.12 are the essential equations
required to fully understand the motion of the particle in this framework.
We further modify Equation 1.12 by simplifying it, specifically by altering the
potential term ϕ , to achieve a more reduced form,
4πGa ′
ϕ= ρ̄ϕ
H(a)
Friedmann’s equation is given as,
3H02
ρc =
8πG
Where ρc is the critical density and H0 is the Hubble parameter at a time t = 0.
The density parameter Ω compares the mean density to the critical density:
ρ̄
Ω = Ω m + Ωr + ΩΛ =
ρc

4
Ω = 1, The universe is flat.(Curvature parameter k = 0)
Ω > 1, The universe is closed.(Curvature parameter k = +1)
Ω < 1, The universe is Open.(Curvature parameter k = −1)
For our purposes we take Ω = 1.
ρ̄ = ρc

In an expanding universe, the mean matter density scales inversely with the cube
of the scale factor because matter dilutes as the volume increases:

ρ̄ = a−3 ρ¯o

or,
3H02
ρ̄ = a−3
8πG
So the potential becomes,
4πGa −3 3H02 ′
ϕ= a ϕ
H(a) 8πG
or,

3 H0
ϕ= ϕ′ (1.17)
2 a2 E(a)
Where,
H(a) = H0 E(a)

So our new equation of motion becomes,


dx v
= (1.18)
da H(a)a3

dv 3 H0
=− 2 ∇ϕ′ (1.19)
da 2 a E(a)

∇2 ϕ′ = δ (1.20)

*From here on we have taken ϕ′ as ϕ.


We transform the equations 1.18, 1.19 and 1.20 into simulation space to begin our
simulation.

5
1.3 Equations of motion in simulation space
In the simulation space, the position and velocity of a particle can be expressed in
terms of scaled variables as follows:

x = LX

v = LH0 V
Define,
ϕ
ϕ̃ =
L2
˜ = L∇

So putting all these into our equation of motion we get,
dX V
= 3 (1.21)
da a E(a)
dV 3 1 ˜ ϕ̃
=− 2 ∇ (1.22)
da 2 a E(a)
˜ 2 ϕ̃ = δ
∇ (1.23)
Equations 1.21, 1.22, and 1.23 collectively represent the equations of motion es-
sential for conducting the simulation.
Our code generates a three-dimensional grid of evenly spaced cubes, each with
side length L. The grid follows periodic boundary conditions, meaning that if any
coordinate reaches N, it wraps around to zero. This ensures seamless continuity in
simulations and maintains a consistent spatial structure across all dimensions.

1.4 Vlasov equation


The Vlasov equation (or collisionless Boltzmann equation) describes the evolution of
the phase-space distribution function f(r, v, t) for a system of collisionless particles
(e.g., dark matter in cosmology or plasma in astrophysics). There are two forms of
the Vlasov equation, depending on the choice of coordinates:

• Eulerian Vlasov Equation (fixed coordinates in phase space).

• Lagrangian Vlasov Equation (co-moving with particles).

6
1.4.1 Eulerian Vlasov Equation
To derive the Eulerian Vlsov eqution we assueme that the particles move under grav-
itational potential ϕ(r, t) and there is no collison between them. The distribution
function f(r, v, t) gives the number density of particles in phase space.
The continuity equation in phase space (Liouville’s theorem) states that the total
time derivative of f is zero:
df
=0
dt
expanding using the chain rule:
∂f dr dv
+ .∇r f + .∇v f = 0
∂t dt dt
since,
dr
=v
dt
and,
dv
= −∇r ϕ
dt
∂f
+ v.∇r f − ∇r ϕ.∇v f = 0 (1.24)
∂t
This is the Eulerian Vlasov equation. The term ∂f
∂t
represents the change in distri-
bution function f at a fixed point in phase space. The term ⃗v · ∇r f describes the
transport of particles through space due to their velocity, while −∇r Φ · ∇v f captures
changes in velocity from forces like gravity or potentials.

1.4.2 Lagrangian Vlasov Equation


we transform the eulerian equation to lagrangian by trasnforming it into comoving
cooridnate.
From Lagrangian L we get,
∂L
p= = a2 ẋ =⇒ p = a2 v
∂ ẋ

∂L
ṗ = v̇ = = −∇x ϕ
∂x
Define the co-moving distribution function f(x,p,t). Then equation (1.24) becomes,
∂fc p
+ .∇x fc − a∇x ϕ.∇v fc = 0 (1.25)
∂t a
This is the Lagrangian Vlasov equation.

7
1.4.3 0th moment of Vlasov equation
integrate equation (1.25) with respect to v,
Z  
∂fc p
+ .∇x fc − a∇x ϕ.∇v fc d3 v = 0
∂t a

define, Z
ρ = f d3 v
Z
vf d3 v = ρv

Then the integration will give,


∂ρ 1
+ ∇.(ρv) = 0
∂t a
we assume that the change of the quantity mean density ρ̄ with respect to time is,
∂ ρ̄
=0
∂t
Putting this we get the 0th moment of the vlasov equation as,
∂δ 1
ρ̄ + ∇.(ρV ) = 0
∂t a
∂δ 1
+ ∇.(Vi (1 + δ)) = 0 (1.26)
∂t a
*Vi = vi /a

The zeroth moment of the Vlasov equation gives the continuity equation, repre-
senting mass or number density conservation in phase space. The first moment gives
the momentum equation, describing how the bulk velocity of particles evolves under
external forces like gravity or electromagnetic fields, linking microscopic dynamics to
macroscopic fluid behavior.

1.4.4 1st moment of Vlasov equation


integrate equation (1.25) with respect to v by multiplying v,
Z  
∂fc p
v + .∇x fc − a∇x ϕ.∇v fc d3 v = 0
∂t a

8
define, Z
πij = pi pj f d3 v
v
V =
a
Then the integral becomes,
∂Vi ȧ 1 ∂Vi 1 ∂πij 1 ∂ϕ
+ Vj + Vj + + =0
∂t a a ∂x ρ̄(1 + δ)a3 ∂xi a ∂xi

The first moment of the Vlasov equation gives the momentum equation, which
describes how momentum flows and changes within a fluid over time. Velocity disper-
sion simply measures how much individual particle velocities differ from the average
velocity of the system. In smooth, streamline flow — where particle paths don’t cross
— the stress or pressure from velocity dispersion becomes zero.
So our equation becomes,
∂Vi ȧ 1 ∂Vi 1 ∂ϕ
+ Vj + Vj =− (1.27)
∂t a a ∂x a ∂xi
taking only linear terms, taking divergence of (27) and putting equation (26) in
it and also using (20), we get

∂ 2δ ȧ ∂δ
2
+2 =δ (1.28)
∂t a ∂t
Lets take a trial solution for the equation (1.28),

δ = D(t)δ(x)

Then we got,

D̈ + 2 Ḋ = D
a
This is the Linear growth equation, the growing mode refers to the solution of
the density perturbation equation that describes how small initial fluctuations in the
matter density of the universe grow over time due to gravitational instability. In
the early universe, regions with slightly higher density attract more matter, causing
these overdense regions to become even denser. This positive feedback leads to the
formation of large-scale structures like galaxies and galaxy clusters. The growing
mode dominates in the matter-dominated era of the universe, while the decaying
mode, which decreases over time, becomes negligible. The rate of growth of these

9
perturbations depends on factors like the expansion rate of the universe and the
background matter content.
Solution for the growing mode is,

D = E(a)

and,
a
da′
Z
D = E(a) (1.29)
0 a′3 E 3 (a′ )

Equation (1.29) is important becomes it gives,

1. If Ωm = 1(matter-dominated universe), this gives D = a (Growing).

2. If Ωk = 1(curvature-dominated universe), this gives D = constant (No growth).

3. If ΩΛ = 1(Dark energy dominated universe), this gives D = K − a12 (Decaying).

10
Chapter 2

Simulation

2.1 Begin of Simulation


The ParticleMeshSimulation class implements a cosmological N-body simulation us-
ing the Particle-Mesh (PM) method. It creates a 3D grid representing a periodic
universe filled with particles whose motions are governed by gravity. Initial condi-
tions are generated using the Zel’dovich approximation, which sets up particle dis-
placements and velocities based on a linear theory of structure formation. The code
supports several mass assignment schemes such as Nearest Grid Point (NGP), Cloud-
In-Cell (CIC), and Triangular Shaped Cloud (TSC), each providing different levels of
interpolation accuracy when mapping particle masses to the grid.
To compute gravitational forces, the simulation solves Poisson’s equation in Fourier
space using Fast Fourier Transforms (FFT). This process involves calculating the den-
sity field on the grid, applying a Green’s function to get the gravitational potential,
and then deriving forces using finite differences. These forces are then interpolated
back to the particle positions to update their velocities and positions over time. The
time evolution of the particles reflects the influence of gravitational clustering, allow-
ing the formation of structures such as filaments and voids over cosmic time.

2.2 Initial perturbation from grid position


Once all the particles are placed on the middlle of the grid cell, we shift the position
of each particle slightly off the grid. This is done to create nearly uniform density
contrast allowing structure formation. The slight displacement helps to improve the

11
accuracy of the simulation by allowing the particles to interact more naturally, as
their positions are no longer constrained to the grid intersections.

2.2.1 Fourier representation of density contrast from Power


spectrum
We assume that the initial density fluctuations δ(x) are a Gaussian random field given
by,
p
∆(k) = P (k) [a(k) + ib(k)] (2.1)

Where ∆(k) is the Fourier representation of density contrast δ and P(K) is the
power Spectrum. where a(k) and b(k) are two real valued, independent Gaussian
random variables of unit variance, and the power spectrum is given by,

P (k) = ⟨δ(k) δ ∗ (k)⟩

2.2.2 Initial Power Spectrum


We model the linear power spectrum as,

P (k) = AT 2 (k)k ns (2.2)

Where A, T(K) and ns are Amplitude, Transfer function and the Spectral index.
ns = 1, Scale invariant(Harrison-Zel’dovich spectrum).
ns > 1, ”Blue” spectrum (more power at small scales).
ns < 1, ”Red” spectrum (more power at large scales).
From the Latest Planck(2018) results gives the value of spectral index as,

ns = 0.9649 ± 0.0042

The transfer function T(k) relates the initial power spectrum Pinit (from inflation,
for example) to the matter power spectrum P(k) observed at a later time:

P (k) = Pinit T 2 (k)

where k is the wavenumber, representing the scale of a fluctuation. T(k) encodes


the effects of the growth of structure, radiation pressure, dark matter, baryon acous-
tic oscillations, and other processes that suppress or enhance fluctuations on different
scales.

12
T (k) → 1 on large scales (small k), where the initial conditions remain mostly un-
changed.
T (k) < 1 on small scales (large k), where processes like Silk damping and horizon
crossing reduce power.
The Transfer function has the form,

T (k) = fb Tb (k) + (1 − fb )Tm (k) (2.3)

Where Tb (k) and Tm (k) are the baryon transfer function and CDM+Neutrino
transfer function and fb is the baryon fraction given by,
Ωb
fb =
Ωm
The baryon transfer function is given by,
sin(ks) −( k k )2
Tb = e silk
ks
Where the quantity s and ksilk are given by,
44.5ln( Ω9,83
mh
2)
s= p
1 + 10(Ωh2 )3/4

ksilk ≈ 0.1(Ωh2 )3/4


and the CDM+Neutrino transfer function is given by,
1 + 2.34q
Tm = [1 + 3.89q + (16.1q)2 + (5.46q)3 + (6.71q)4 ]−1/4
2.34q
Where the quantity q is,
k
q=
Γkeq
Here Γ called the Sugiyama factor or shape factor and is given by,

Γ = Ωm h

and,
ke q = 0.0764Ωm h2
Define the quantity σ8 , as the variance of matter fluctuation smoothed at R =
−1
8h M pc, where R is the Radius. Then σ8 is given by,
Z ∞ 3
2 k P (k) 2 dk
σ8 = |W (k)|
0 2π 2 k

13
Putting the equation for Power spectrum P(k) we get,
Z ∞
2 dk
σ8 = AT 2 (k)k ns |W (k)|2
0 k
or,
σ82
A=
I
Where, Z ∞
dk
I= T 2 (k)k ns |W (k)|2
0 k
Here W(kR) is the fourier transform of the top-hat window function which repre-
sents averaging over a spherical volume and is given by,
sin(kR) − kRcos(kR)
W (kR) = 3
(kR)3
From plancks(2018) results we get the value of σ as,
r
Ωm
σ8 = 0.81
0.3
By Calculating the value of I and σ8 we can find the value of A and by calculating
T(k) we can find the power spectrum and Thus fourier representation of the density
contrast.

2.2.3 Zel’dovich Approximation


The Zel’dovich Approximation (ZA) is a first-order Lagrangian perturbation theory
approach used in cosmology to model the evolution of density perturbations and the
formation of large-scale structure in the universe.
The Zeldovich Approximation uses the Lagrangian approach to model how par-
ticles move from their initial positions to their final positions due to gravitational
clustering.
The ZA describes the motion of particles via a displacement field ψ(q, t), which
maps initial (Lagrangian) positions q to final (Eulerian) positions xat time t:

x(q, t) = q + ψ(q, t)

The displacement field can be written as,

ψ(q, t) = D(t)ψ0 (q)

14
so,
x(q, t) = q + D(t)ψ0 (q)
and since the velocity is the time derivative of the position we get,

v(q, t) = Ḋ(t)ψ0 (q)

solution of equation (1.29) gives,

Ḋ = Hf D
dlnD
where f = dlna
is the growth rate.
The growth rate f describes how fast perturbations grow relative to the expansion:

f = Ωγm

Where γ ≈ 0.55 for ΛCDM.

2.3 Mass asignment to grid position


In N-body cosmological simulations, we assign the mass of particles to grid positions
to convert a system of discrete particles into a continuous density field. This step
is essential because solving equations like Poisson’s equation for gravitational poten-
tial requires a smooth density distribution rather than isolated point masses. By
spreading or assigning particle masses onto nearby grid points using methods like
Nearest Grid Point (NGP), Cloud-in-Cell (CIC), or Triangular Shaped Cloud (TSC),
we effectively estimate the local density at each grid cell. This allows us to compute
gravitational forces efficiently in Fourier space using Fast Fourier Transforms (FFT)
and ensures the simulation captures large-scale structure formation more accurately
while maintaining computational feasibility.

2.3.1 NGP
In this particle scheme we assign mass of the particle to single nearest grid point.
X
ρ= WN GP (xi − n)

Where WN GP is the weight function given by,


(
1, δxi ≤ 1/2
WN GP (xi − n) =
0, else

15
Where δxi = xi − n. For three dimension we multiply the three weight function for
total function.
W = Wx Wy Wz

2.3.2 CIC
After the displacement, the particles are no longer confined to the grid points, but
we still define the density at the grid points. In this method, we distribute the mass
of each particle across several nearest neighboring grid points. First, we identify the
8 surrounding grid points in the 3D simulation space. Then, we assign the particle’s
mass to these 8 grid points, weighted by their distance from the particle’s position.

WCIC (xi − n) = 1 − δxi , δxi ≤ 1

2.3.3 TSC
The Triangular Shaped Cloud (TSC) method is a commonly used mass assignment
scheme in N-body cosmological simulations. It is an improvement over simpler meth-
ods like Nearest Grid Point (NGP) and Cloud-in-Cell (CIC), providing smoother and
more accurate density estimates. In TSC, a particle’s mass is distributed not only
to its nearest grid point but also to neighboring grid points within a certain range,
following a triangular weight function. The weight decreases linearly with distance
from the particle’s position, ensuring continuity and reducing noise in the density
field. This helps to minimize artifacts in force calculations and improves the accuracy
of the simulation, especially on small scales.
(
3
− δxi , δxi ≤ 1/2
WT SC (xi − n) = 41 3 2
2 2
− δxi , 21 ≤ δxi ≤ 3
2

2.4 Potential Calculation


In my simulation, I have used two different approaches to calculate the gravitational
potential: the Poisson equation and the Telegraph equation. The Poisson equation
is the standard method in cosmology, directly relating the density contrast to the
potential through a simple inverse Laplacian. However, it assumes instantaneous ac-
tion at a distance, which may not always capture time-dependent effects accurately.
On the other hand, the Telegraph equation introduces a finite propagation speed for

16
changes in potential, adding a time derivative term. This allows the potential to
evolve dynamically over time rather than responding instantly, making it useful for
studying systems where delayed gravitational response or wave-like behavior of po-
tential is important. Comparing both approaches helps in understanding their effects
on structure formation and the evolution of density perturbations in the universe.

2.4.1 Poisson equation


The Poisson equation is a fundamental equation in cosmology and gravitational
physics, used to relate the gravitational potential to the matter density distribu-
tion. In comoving coordinates, it is written as ∇2 ϕ = δ where ϕ is the gravitational
potential, δ is the density contrast. The Poisson equation assumes that any change
in the matter distribution instantly affects the gravitational potential everywhere,
reflecting the idea of action at a distance. It is widely used in N-body simulations
to compute gravitational forces and study the growth of structures like galaxies and
clusters in the universe. We will solve this equation using fourier transform method.
We solve the Poisson equation using the Fourier Transform method in N-body
cosmology because it simplifies the mathematical complexity and greatly improves
computational efficiency. In real space, solving ∇2 ϕ = δ involves handling second-
order derivatives, which is computationally expensive for large 3D grids.However, in
Fourier space, the Laplacian operator ∇2 becomes a simple multiplication by −k 2
where k is the wavevector.
Fourier tranform of a quantity A is given as,
X n1 m1 n2 m2 n3 m3
Bn = Am exp[−2πi( + + )]
m
N1 N2 N3

while its inverse transform is given as,


X n1 m1 n2 m2 n3 m3
Am = Bn exp[2πi( + + ))]
n
N1 N2 N3

So if we apply the fourier transformation to poisson equation we would get,

−k 2 ϕ̃ = ∆ (2.4)

with,
X 2πni
k2 = ( )2
i
Ni

17
Where ϕ̃ is the fourier transform of ϕ and ∆ is the fourier transform of δ.


ϕ̃ = − (2.5)
k2
This is much easier and faster to solve. After finding ϕ̃ in Fourier space, we apply
the inverse Fourier Transform to get the potential ϕ in real space. This method,
combined with Fast Fourier Transform (FFT) algorithms, makes solving the Poisson
equation on large grids practical and accurate, especially in cosmological simulations
where periodic boundary conditions are used.
The Fourier Transform method naturally handles periodic boundary conditions,
which is why it is widely used in cosmological N-body simulations. In this approach,
the simulation box is treated as if it repeats infinitely in all directions, creating a
periodic universe. This assumption fits well with the Fast Fourier Transform (FFT)
algorithm, which inherently assumes that the input data is periodic. When we solve
the Poisson equation in Fourier space, the periodicity ensures that any gravitational
effect due to particles near the boundary of the box is smoothly connected to the
particles on the opposite side. This avoids artificial edge effects and ensures that the
gravitational potential and forces are consistent throughout the simulation domain.
Thus, the Fourier method not only simplifies solving the Poisson equation but also
elegantly incorporates periodic boundary conditions essential for modeling an infinite,
homogeneous, and isotropic universe.
The solution of poisson equation can be realized in terms of green’s function
G(x,x’) as
X
ϕl,m,n = Gp,q,r δp,q,r e2iπ(lp+mq+nr)/M (2.6)
p,q,r

where M is the grid size in one axis.For poisson equation there are two green’s function
can be used. The usual one is,
(
0, p=q=r=0
Gp,q,r = 1
(2.7)
− k2 else,

while the Green’s function of the seven-point finite-difference approximation (FDA)


to the Laplacian is,
(
0, p=q=r=0
Gp,q,r = 2 (2.8)
− L4 P 1
2 else,
m sin (Lkm /2)

18
This can be obtained by using central difference method then transforming it into
fourier space.
We can solve the poisson equation by reducing it in matrix form. Using central
difference poison’s equation for 1 dimension can be approximated as,

∂ 2ϕ ϕi+1,j,k − 2ϕi,j,k + ϕi−1,j,k


2

∂x h2
Where h is the grid spacing. So in 3d the it can be written as,

ϕi+1,j,k + ϕi−1,j,k + ϕi,j+1,k + ϕi,j−1,k + ϕi,j,k+1 + ϕi,j,k−1 − 6ϕi,j,k


∇2 ϕi,j,k ≈ (2.9)
h2
Now we are going to create a sparse matirx A and tranform our scalar potential
ϕ and density contrast δ to be a vector. So the poisson equation in this form be,

Aϕ = δ (2.10)
where Aϕ is equivalent to the equation 2.10. So the matrix A would be in the
form,
 
−6 1 0 ... ...
 1 −6 0 ... ...
 
0 1 −6 ... ...
. . . .... ..
   
ϕ0,0,0 δ0,0,0
ϕ1,0,0 
 , δ = δ1,0,0 
 
Also ϕ and δ in this representation would be, ϕ = 
ϕ2,0,0  δ2,0,0 
... ...
So to calculate ϕ given δ we would need to solve the equation,

ϕ = A−1 δ (2.11)

Using the matrix form of the Poisson equation offers several advantages, especially
when dealing with non-periodic boundary conditions or more complex geometries
where Fourier methods may not be directly applicable.
The key advantages are:

• Flexibility in Boundary Conditions: Unlike Fourier methods which assume pe-


riodicity, matrix methods can easily handle fixed, reflective, or open boundary
conditions.

19
• Locality: It allows for a more localized treatment of gravity without assuming
the whole universe repeats itself, which is useful for isolated systems.

• Handling Irregular Grids: Matrix methods can handle adaptive or non-uniform


grids better, which may arise in regions of high density or complicated struc-
tures.

• Better Control Over Accuracy: Directly solving the matrix system can provide
better accuracy in small-scale structures where Fourier methods might introduce
smoothing errors due to grid resolution limits.

However, the main drawback is that matrix methods are computationally more ex-
pensive for large 3D grids compared to Fourier methods, unless optimized solvers (like
multigrid or iterative methods) are used.

2.4.2 Telegraph equation


While the standard Poisson equation relates the gravitational potential ϕ to the den-
sity distribution ρ, the telegraph equation introduces a small time-dependent term
to control numerical instabilities and improve convergence during iterative solutions.
The modified equation takes the form:
∂ 2ϕ
2
− c2g ∇2 ϕ = −c2g δ
∂t
where cg is an artificial propagation speed for the potential (not the speed of light).The
extra time derivative term helps smooth out fluctuations and allows the potential to
evolve more gradually towards its correct value, particularly useful in adaptive mesh
or particle-mesh simulations. This approach ensures better stability while preserving
the essential physics of gravitational interactions.
∂ϕ
In numerical simulations of gravitational systems, an additional ∂t
term is often
added to the Poisson equation to improve stability and convergence. The standard
Poisson equation assumes that the gravitational potential ϕ responds instantaneously
to changes in the density field ρ which can lead to numerical instabilities, especially
when the density changes rapidly or has discontinuities. By introducing a time-
dependent term, the modified equation allows the potential to evolve gradually to-
wards its correct value, rather than changing abruptly. This acts as a damping mech-
anism, suppressing high-frequency noise and improving the stability of the solution.

20
The added term effectively mimics a finite signal propagation speed for gravitational
interactions, ensuring smoother and more stable evolution of the potential in iterative
solvers commonly used in N-body or particle-mesh simulations.
The damped equation is,

∂ 2ϕ ∂ϕ
2
+ 2κ − c2g ∇2 ϕ = −c2g δ
∂t ∂t
*we take cg = 1 for entire simulation.
Since in our simulation we have transformed the variable t to a, the telegrpah
equation becomes,

∂ 2ϕ dH ∂ϕ
a2 H 2 2
+ aH[H + a + 2κ] − ∇2 ϕ = −δ
∂a da ∂a
or
∂ 2ϕ 1 1 dH 2κ ∂ϕ ∇2 ϕ δ
+ [ + + ] − = − (2.12)
∂a2 a H da aH ∂a a2 H 2 a2 H 2
In numerical simulations, it is often advantageous to split a second-order differential
equation into two coupled first-order equations.The main reason for this is that most
standard time integration schemes, like Euler or Runge-Kutta methods, are naturally
designed to handle first-order equations. By converting a second-order derivative
into two first-order derivatives, we can treat the problem as a system of coupled
ordinary differential equations (ODEs), which are easier to solve numerically with
better control over accuracy and stability.
∂ϕ
=ψ (2.13)
∂a
∂ϕ ∇2 ϕ δ 1 1 dH 2κ
= 2 2 − 2 2 −[ + + ]ψ (2.14)
∂a aH aH a H da aH
The telegraph equation provides a faster alternative to the Poisson equation. In
the standard Poisson equation, the gravitational potential is solved by inverting the
Laplacian operator, which often requires computationally expensive global operations
like Fourier transforms or iterative solvers that take time to converge, especially for
large grids or rapidly changing density fields. In contrast, the telegraph equation in-
troduces a time-dependent term that allows the potential to evolve gradually towards
its correct value through local updates at each time step. This effectively converts
the problem from a global elliptic equation to a local hyperbolic-type equation, where
information propagates at a finite speed. As a result, the telegraph equation can often

21
reach an accurate solution in fewer iterations, with simpler and faster computations
at each step, making it highly suitable for dynamic simulations with evolving density
distributions.

2.5 Calculate Force


The gravitational force experienced by the particle is,

F = −∇ϕ

So using Finite difference method we get,

ϕi+1,j,k − ϕi−1,j,k
FX ≈
2h

ϕi,j+1,k − ϕi,j−1,k
FY ≈
2h

ϕi,j,k+1 − ϕi,j,k+1
FZ ≈
2h
box length 32
Here h = 1 is the grid spacing.h = grid size
= 32
= 1.
Once the force is calculated on grid points we will calculate the force on the
particle using some interpolation method like CIC.

2.6 Position and Velocity update


The Leapfrog method is a widely used numerical integration technique in N-body
simulations, particularly for solving the equations of motion in cosmology. It is a
second-order, symplectic integrator, which means it conserves energy and momentum
better over long time periods compared to simple methods like Euler integration. In
the Leapfrog scheme, the positions and velocities of particles are updated in a stag-
gered way — velocities are updated at half time steps, while positions are updated
at full time steps. This ”leapfrogging” of updates helps maintain stability and accu-
racy, especially when dealing with gravitational forces that can vary rapidly in dense
regions. One of the key advantages of the Leapfrog method is that it provides good
long-term behavior even with relatively large time steps, making it highly suitable
for simulating the evolution of large-scale structures in the universe.

22
After calculating the force on the particle we displace it from its position using the
Leapfrog method. The steps for calculating the displaced position and final velocity
are,

F0 ∆t
1. v1/2 = v0 + 2

2. x1 = x0 + v1/2 ∆t
F1 ∆t
3. v1 = v1/2 + 2

Repeat this method at each time step. Calculating third step is not required, and
it introduces additional compute power so we remove the third step in our simulation.

23
2.7 flowchart

24
Chapter 3

Tests for the simulation program

3.1 Tests for Mass asignment


3.1.1 Test for uniform distribution
In the ParticleMeshSimulation() class, we have implemented a method called ini-
tial positions grid center() that places each particle exactly at the center of its cor-
responding grid cell. After initializing the particles this way, we compute the density
contrast δ using both NGP, CIC and TSC mass assignment schemes to verify whether
the results agree with the expected theoretical solution.
We obtained the sum of all values in δ as -3169.0 for the NGP,CIC and the TSC
scheme. This result is expected because, in our implementation, the size of the density
grid is taken to be (grid size + 1)3 and since in uniform grid one particle is assigned to
each grid point, there will be some grid point that will have no particle contribution
and this is exactly the difference between particle number and the size of density grid.

3.1.2 Fourier space Validation


In particle-mesh (PM) methods, a crucial step is assigning the mass of particles to a
regular grid so that the density field can be analyzed using Fourier transforms. How-
ever, the choice of mass assignment scheme introduces window effects in Fourier space,
altering the measured power spectrum from its true form. Two of the most commonly
used mass assignment schemes in numerical simulations are the Nearest-Grid-Point
(NGP) method and the Cloud-In-Cell (CIC) method, both of which introduce char-
acteristic artifacts in Fourier space.

25
In the NGP scheme, each particle contributes its entire mass to its nearest grid
point, resulting in a discontinuous and sharply localized distribution in real space.
The corresponding window function in Fourier space takes the form of a sinc function.
Specifically, the Fourier transform of the NGP window function is given by:

WN GP = sinc(k/2)

The discontinuous nature of the NGP (Nearest Grid Point) mass assignment scheme
causes significant aliasing effects in Fourier space (fig 1). Since NGP assigns the entire
mass of a particle to the nearest grid point without any smoothing, the resulting
density field exhibits sharp discontinuities. In Fourier space, such abrupt features
translate to a slowly decaying window function, allowing considerable power to remain
at high-frequency modes. However, due to the finite resolution of the grid, these high-
frequency modes cannot be properly resolved and get aliased, or folded back, into
lower frequencies. This aliasing effect artificially enhances the power at low k-values,
distorting the true large-scale structure of the density field.

Figure 3.1: Left: Figure between k vs P(k). While CIC followed the theoretical curve NGP
did not due to aliasing effect. Right: figure between k vs the ratio of power spectrum between
CIC and NGP

On the other hand, the CIC scheme distributes the mass of each particle over
its nearest neighboring grid points using linear interpolation, resulting in a smoother
density distribution in real space. The corresponding Fourier-space window function
is the square of the NGP window function, given by:

WCIC = sinc2 (k/2)

26
This window function leads to less severe aliasing compared to NGP, owing to the
smoother transition between grid cells in real space. Nonetheless, the suppression of
power at large k-values still persists, though it is less sharp than in the NGP case.

3.2 Force accuracy


3.2.1 Force accuracy test - I
We considered two different scenarios, in which we placed two particles at varying
separations, in one scenario, the particles were placed far apart, while in the other,
they were positioned close to each other.
In the scenario where the particles are placed far apart (for example, one at
(12, 16, 16) and the other at (14, 16, 16)), we calculate the force on the first particle
due to the second one using both NGP, CIC and TSC interpolation schemes, and
compare the results with the corresponding theoretical value. The result was 2.35
RMS error for NGP and 2.33 CIC while 2.30 for TSC.
In the scenario where the particles are placed very close (for example, one at
(0.25, 16, 16) and the other at (0.75, 16, 16)), The result was 0.16 RMS error for NGP
and 0.16 for CIC while 0.144 for TSC.
Higher-order interpolation schemes like TSC provide more accurate force calcula-
tions compared to NGP and CIC, particularly when particles are very close, where
lower-order methods exhibit significantly larger errors.

3.2.2 Force accuracy test - II


The accuracy of the force calculations using these interpolation schemes is demon-
strated in Figure 2. For this test, we divided a unit grid cell into subcells of length
1/12. A particle was placed at the center of each subcell, and the force exerted by
the particle was computed at several positions lying within a series of spherical shells
centered around it. By averaging the force over all positions within each shell, as
well as over all subcell centers, we obtained the mean force at each separation dis-
tance. The deviations from this mean reflect the effects of anisotropy and the lack of
translational invariance introduced by the mesh.

27
Figure 3.2: figure between ln r vs ln(Fr )

While all methods deviate from the theoretical curve near the center, TSC per-
forms best, followed by CIC and NGP, indicating reduced numerical error. But as
TSC is computationally expensive we prefer CIC over TSC.

3.3 Energy Conservation


3.3.1 Energy conservation Test - I
The Newtonian energy conservation equation when generalized to an expanding cos-
mological background becomes,
d 4 dU
(a T ) + a =0
dt dt
after integrating, Z
4
a T + aU − U da = C
Z
a T + U + a2 T da = C ′
3

The Layzer-Irvine equation has been establishing itself as one of the most renowned
equations of modern cosmology with its many applications including the determina-
tion of the matter density, cluster mass and size, and the galaxy peculiar velocity field.
In simulations, C and C’ is approximately constant if energy is properly conserved.

28
Figure 3.3: fig between a vs C(layzer irvine constant) for a simulation from a = 1 to a =
2. grid size = 64, ∆a = 0.004

Fig 3 shows the variation of the Layzer-Irvine constant (C) with the scale factor (a)
for CIC and NGP schemes. Ideally, C should remain conserved over time. However,
the NGP scheme shows larger deviations and oscillations due to its poorer force
resolution and particle noise, especially at smaller scales. In contrast, the CIC scheme
provides smoother and more accurate force calculations, leading to better energy
conservation. The difference arises because CIC distributes mass over multiple grid
points, reducing discreteness noise, while NGP assigns mass to a single grid point,
causing higher errors in force and energy estimation.

3.3.2 Energy conservation Test - II


In cosmological simulations, transforming the time variable from the scale factor a
to a rescaled variable p = aα is a widely used technique to simplify the equations of
motion and improve numerical stability. This transformation helps in decoupling the
rapid expansion of the universe from the local dynamics of particles, thus avoiding

numerical stiffness caused by the Hubble term H = a
The choice of α depends on the
cosmological era and is made such that it flattens the variation of dynamical quan-
tities, allowing larger and more stable time steps during integration. This technique
also helps in preserving energy conservation better in N-body simulations and sym-

29
plectic integrators by reducing the sensitivity of equations to the fast-changing scale
factor, especially during early times when a is very small.
Our equation of motion becomes,
dX V
= α+2
dp αa E(a)

dV 3 1
=− α+1
∇ϕ
dp 2α a E(a)

Figure 3.4: in figure α values are 0.1, 0.5, 1, 1.5 in order of upper left, bottom left, upper
right and bottom right

from fig 4. alpha value of 0.5 leads to lower error compared to others. Choosing
α = 2/3 as the integration variable provides the best time-stepping stability for white
noise initial conditions in cosmological simulations. This choice balances the expan-
sion rate and the growth of structures, leading to smoother evolution and reducing
numerical errors during integration, especially in the early stages of the universe.

3.4 Effect of Force Resolution


3.4.1 One dimensional perturbation test
The evolution of a one-dimensional plane-wave perturba- tion provides an instructive
test of the N-body codes. Using Zeldovich’s formulation, the initial conditions are
given by ,

A
xzi = qi + cos(2πkqz ) (3.1)
2πk

30
viz = x˙zi

where qi are the unperturbed positions and k is an integer triple (0,0,1). In


one dimension, equation 3.1 is an exact solution of the equation of motion in the
continuum limit until A = 1, at which point infinite density occurs at the locations
where sin(2πkqz ) = 1. A is proportional to the growth factor of linear density
fluctuations: A ∝ a in an Ω = 1 universe.

a NGP CIC
xrms vrms xrms vrms
k=1
1.6 0.05929 7.07171 0.01927 2.11174
2.2 0.05227 13.02026 0.06647 9.63665
2.8 0.00351 16.10387 0.06832 14.61592
3.4 0.01376 17.09654 0.02235 17.35748
4.0 0.01951 16.45971 0.01702 18.92648
k=2
1.6 0.04625 7.07535 0.00631 1.01552
2.2 0.05147 13.01162 0.03058 6.57157
2.8 0.02131 16.11662 0.04301 12.44312
3.4 0.04444 17.06609 0.02348 16.04670
4.0 0.04049 16.60244 0.02788 18.43541
k=4
1.6 0.03664 7.11097 0.00316 0.50776
2.2 0.04513 12.97750 0.01486 3.71452
2.8 0.03762 16.12799 0.01639 9.87354
3.4 0.02144 17.11787 0.01600 14.08616
4.0 0.01178 16.62001 0.03119 17.25121

Table 3.1: Comparison of xrms and vrms for NGP and CIC at different values of k
and a.

To test our A-body codes against this solution, we have run a series of simulations
using a 163 mesh with one particle per cell. The unperturbed coordinates, qi , were
taken to be the cell centers, and the perturbation was applied in the z-direction. The
initial value of A was chosen to be 0.25, so equation (3.1) should remain valid until
a = 4.0. The results, for three values of kz, are given in Table, where we list the rms
deviations of the particle positions and velocities from the exact solution,
qX
∆xrms = (xi − xzi )2

31
qX
∆vrms = (vi − viz )2

For all values of kz, the NGP scheme leads to much larger deviations from the exact
solution than the CIC scheme. This is because the forces on the particles in the NGP
scheme vary discontinuously with time. For example, for kz = 2, there are no forces
on the particles initially because the particle dis- placements are smaller than half a
mesh cell. For kz = 4, the forces remain zero for the entire duration of the run. The
CIC scheme, in which the forces vary continuously with time, provides a much more
accurate de- scription. Since it does not take much more computing time than the
NGP scheme, it is to be preferred in most practical applications.
This comparison shows that even with a high degree of force resolution, one re-
quires several particles (≥ 4) per wave- length to reduce the errors in the positions,
∆xrms , down to a few percent. To get results of comparable accuracy using the CIC
scheme, one also requires several mesh cells (≥ 8) per wavelength.

3.4.2 3 dimensional perturbation test


In this subsection, we describe tests of the effects of force resolution using a set of
N -body simulations containing 323 particles. These simulations correspond to the
“pancake” models, which were initialized with a flat power spectrum and a sharp
cutoff for k > kmax . The initial conditions were generated by displacing particles
from a 323 grid according to the specified power spectrum.

kX
max
A ⃗k
xi = q i + cos(2π⃗k.⃗q + ϕk ) (3.2)
kp ,kq ,kr =−kmax
2π |k 2 |

where the ϕk are randomly assigned phases. In these experi- ments we took kmax
D E 21
= 2 and set the initial amplitude of the fluctuations so that δρ
ρ
= 0.22
Figure 5 and 6 shows a two-dimensional projection of the particle positions at a =
3 and at a = 10.0. This figure shows that large-scale structures (sheets and filaments)
are quite well reproduced in the low resolution pancake models. As the resolution is
increased, the dense knots at the intersections of sheets and filaments become more
concentrated and change shape significantly.
The two-point correlation function, ξ(r), is a fundamental statistical tool used to
quantify the clustering properties of particles in cosmological simulations. It measures

32
Figure 3.5: Figure shows the final evolution of particles after a = 3.

Figure 3.6: Figure shows the final evolution of particles after a = 8.

33
Figure 3.7: figure is between lnζ vs ln r the blue dots are for 323 and the red one is for 163

the excess probability, relative to a random distribution, of finding a pair of particles


separated by a distance r. Mathematically, it is defined such that the probability of
finding a particle within a volume element dV at a distance r from another particle
is given by dP = n[1 + ξ(r)]dV , where n is the mean number density of particles.
A positive value of ξ(r) indicates clustering at the scale r, while a negative value
signifies a tendency toward uniformity or anti-clustering. In this work, we compute
the two-point correlation function to investigate the spatial distribution of particles
in the simulations and to study the effect of varying force resolution on the clustering
properties of the system.

DD(r) − 2DR(r) + RR(r)


ζ(r) = (3.3)
RR(r)

• ζ(r) = 0 : No correlation between particles at separation r. The distribution is


random.

• ζ(r) > 0 : Positive correlation between particles at separation r. Particles are


more clustered than random distribution.

34
Figure 3.8: Particle position at center. this figure shows a slice of the potential grid.

• ζ(r) < 0 : Negative correlation between particles at separation r. Particles are


more uniformly distributed or repel each other compared to random distribu-
tion.

3.5 Telegraph equation


3.5.1 Static density tests
In this test, we analyze the evolution of a single particle placed at the center of
the simulation box for the telegraph equation. The primary aim of this test is to
study how the potential field evolves in response to a localized particle distribution.
The resulting potential field, as shown in Fig. 8 and Fig. 9, exhibits a radially
symmetric pattern centered around the particle. This test serves as a useful check for
the correctness of the numerical solution of the telegraph equation, ensuring that the
generated potential field behaves as expected in the presence of a central particle. Any
deviation from the expected pattern would indicate numerical instability or errors in
the solution scheme.
Another important test for validating the Poisson solver method is to check its
behavior for a uniformly distributed density field. In this case, since the density
is constant everywhere, the resulting gravitational potential field should ideally be

35
Figure 3.9: fig for particle at center position.

zero or constant, as there are no density fluctuations to generate any gradients in


the potential. Our results confirm that the Poisson solver correctly produces a zero
potential field for a uniform density distribution, thus verifying the accuracy and
consistency of the method in handling this special case.

3.5.2 Gaussian density test


In this test we generate a Gaussian random field given by,
 
|x − x0 |
ρ(x) = ρ0 exp −
2σ 2

Where ρ0 is the peak density, x0 is the Center position and σ is the standard
deviation. The analytical potential field is given by,
3
ρ(2π) 2 σ 3
 
|x − x0 |
ϕ(x) = − erf √
|x − x0 | 2σ
The analytical solution assumes an infinite space, whereas our simulation is con-
fined within periodic boundaries. This mismatch can lead to errors near the bound-
aries. To minimize such effects, we choose ρ0 = 1 and σ = 1, ensuring that the
Gaussian density peak remains narrow and localized away from the boundaries.
We have run the simulation with poisson solver and telegraph equation solver
function and compare it with analytical solution, the result gives,
Both methods give comparable results in terms of L2 error and maximum error,
indicating similar accuracy. However, the Poisson solver is slightly faster in terms of
computation time compared to the Telegraph solver when 1 core is used.

36
Poisson Solver Telegraph Solver(100 iterations)
L2 Error 2.103 2.128
Max Error 0.845 0.893
Time(s) 0.0028 0.0034

The Telegraph solver is slightly slower than the Poisson solver because it is an
iterative method and requires multiple iterations to converge to the solution, whereas
the Poisson solver directly solves the equation using Fourier methods. However, the
Telegraph solver is preferred in scenarios where a time-dependent evolution of the
potential field is required or when solving in non-periodic or more complex boundary
conditions where direct Fourier-based Poisson solvers are not applicable. It also
provides more flexibility in handling dynamic systems and localized interactions.

3.5.3 Compairing Total Force with Poisson Solver


Since the Telegraph solver evolves the potential field dynamically over time, unlike the
Poisson solver which gives an instantaneous solution, we expect the force computed
from the Telegraph solver to gradually build up as the potential evolves. Therefore,
at early time steps, the force may be small, but as the simulation progresses and the
potential reaches its final state, the force is expected to increase almost linearly over
time until it saturates.
In this test, we have used a 323 grid size simulation setup with a time step of
da = 0.004. All particles were placed at the center of their respective grid cells,
except for the particle at (16.5, 16.5, 16.5), which was slightly displaced to (16.8,
16.8, 16.8). This configuration creates a nearly uniform density field with a small
perturbation at the center. The simulation was started with an initial scale factor
of a = 1. For the Poisson solver, we evolved the system up to a = 2, while for the
Telegraph solver, the evolution was carried out till a = 5. We observed that the total
force calculated using the Poisson solver was initially very high, indicating that the
Poisson solver provides an instantaneous response to the perturbation. In contrast,
for the Telegraph solver, the total force started from zero and gradually increased as
the scale factor grew. Since we have taken the propagation speed cg = 1, the evolution
of the Telegraph solver is much slower compared to the Poisson solver, requiring the
simulation to run for larger values of a to reach a comparable force response.

37
Figure 3.10: Fig shows plot between Total Force against scale factor

Figure 3.11: Fig shows plot between error vs iteration value

3.5.4 Iteration vs Error


Figure 3.11 shows the variation of RMS error with respect to the number of iterations
for the Telegraph solver, using a Gaussian density field. We observe that as the num-
ber of iterations increases, the error decreases smoothly, indicating the convergence
of the method.
Initially, the error is relatively large due to the solver starting from zero potential,
but with increasing iterations, the solution progressively matches the Poisson solu-
tion more closely. The convergence is slow but steady, as expected from a wave-like
evolution of the potential in the Telegraph equation. This behavior demonstrates the
iterative nature of the Telegraph solver, where increasing the number of iterations

38
Figure 3.12: Fig shows Error vs Kappa value

improves accuracy but also increases computational cost.


From the above figure, we can observe that the error keeps decreasing with the
number of iterations in the Telegraph solver. However, after a certain point, the rate
of decrease in error becomes very slow. This suggests that increasing the number of
iterations beyond a certain limit does not significantly improve accuracy but adds to
the computational cost. Therefore, it is important to choose an optimal number of
iterations that provides a good balance between accuracy and efficiency. In this case,
choosing around 100-120 iterations seems to be a reasonable choice as beyond this
the reduction in error is very minimal.

3.5.5 kappa vs Error


To test the optimal value of κ (the damping coefficient in the telegraph equation),
we fix the number of iterations to 100 and vary κ over a range of values fig 3.12.
We compare the telegraph solver’s potential with the Poisson solution and calculate
the error for each κ. We observe that the error is minimum when κ = 0, as there
is no damping and the wave propagates without any loss, closely resembling the
Poisson solution. However, in a realistic physical scenario, κ should not be zero, as
it controls the damping of the potential evolution and ensures stability in dynamic
systems. Thus, while κ = 0 gives the lowest error mathematically, a small non-zero
κ is preferred to maintain physical consistency and avoid unphysical oscillations or
instabilities in simulations
The parameter κ in the telegraph equation controls the damping of the potential
field. Its choice is crucial for balancing accuracy and physical realism.

39
Case 1: κ = 0

When κ = 0, there is no damping in the system. This results in a purely wave-like


behavior, where the solution converges faster, and the error is minimized (close to
the Poisson solution). However, this is not physically realistic, as in real systems,
signals do not propagate indefinitely without damping. This can lead to oscillations
and noise in evolving systems.

Case 2: Very Large κ

If κ is chosen to be very large, the system becomes heavily damped. While this
suppresses oscillations, it also slows down the evolution of the potential field, requiring
more iterations for convergence. Moreover, it might not properly capture the transient
behavior of the system.

Optimal Choice of κ

A good estimate for κ is given by:

κ ≈ cg × kmax

where cg is the propagation speed used in the telegraph equation, and kmax is the
highest wavenumber that fits in the grid, given by:
π
kmax =
∆x
where ∆x is the grid spacing.

In Our Case

Given cg = 1 and ∆x = 1, we have:

kmax ≈ π

Thus, an optimal choice for κ lies in the range:

κ∼1−3

The choice of κ in the telegraph solver plays an important role in determining the
accuracy and physical behavior of the solution. Although κ = 0 gives the lowest error,

40
it is not physically realistic as it allows undamped wave propagation, which may lead
to oscillations in a dynamic system. A small non-zero κ introduces necessary damping
that suppresses unphysical oscillations while allowing reasonable convergence speed.
An optimal choice of κ is often taken as κ ∼ cg kmax , where cg is the propagation
speed and kmax is the maximum wavenumber of the system. In our case, with cg = 1
and grid spacing ∆x = 1, we get kmax ≈ π, suggesting κ in the range of 1 to 3
is suitable. This range provides a good balance between accuracy, stability, and
physical relevance, ensuring fast enough convergence without introducing significant
unphysical behavior. Higher κ values improve stability but slow down convergence,
while lower values reduce error but risk instability.

41
Chapter 4

Program

4.1 Introduction
This document describes the methods of the ParticleMeshSimulation class, which
implements a particle-mesh simulation for cosmological structure formation. The
class combines particle dynamics with mesh-based field calculations to simulate the
evolution of matter under gravity.

4.2 Class Methods


4.2.1 Initialization
• init (self, grid size, num particles): Initializes the simulation with
a given grid size and number of particles. Sets up arrays for positions, veloc-
ities, density grid, potential grid, and force grid. Also initializes cosmological
parameters.

4.2.2 Initial Conditions


• initial positions grid center(self): Places particles on a uniform grid
centered in each cell. Positions are modulo the grid size to enforce periodic
boundary conditions.

• zeldovich(self, delta a=0.01): Implements the Zel’dovich approximation


for setting up initial conditions. Generates a Gaussian random field based on
the power spectrum, computes displacements and velocities, and applies them
to particles.

42
4.2.3 Cosmology Calculations
• hubble(self, a=None): Computes the Hubble parameter at scale factor a
using H(a) = H0 E(a).

• E(self, a): Computes the dimensionless Hubble parameter E(a) = Ωm a−3 + Ωk a−2 + ΩΛ .

• growth factor(self): Returns the linear growth factor (currently simplified


to D(a) = a).

• power spectrum(self, ks): Computes the matter power spectrum P (k) using
Eisenstein & Hu transfer functions, normalized to σ8 .

4.2.4 Mass Assignment


• mass assign(self, scheme): Assigns particle masses to the grid using one of
three schemes:

– Nearest Grid Point (NGP): Mass assigned to nearest cell


– Cloud-In-Cell (CIC): Mass distributed to 8 nearest cells
– Triangular Shaped Cloud (TSC): Mass distributed to 27 nearest cells

4.2.5 Poisson Solvers


• solve poisson(self): Solves Poisson’s equation ∇2 Φ = δ in Fourier space
using the standard Green’s function −1/k 2 .

• solve poisson 2(self): Alternative Poisson solver using finite-difference rep-


resentation in Fourier space.

• compute laplacian(self, field): Computes the Laplacian of a field using


FFT.

• solve telegraph(self, da, kappa=2.5, c g=1.0, max iter=100, tolerance=1e-4):


Solves the telegraph equation for potential evolution, including damping and fi-
nite propagation speed effects.

43
4.2.6 Force Calculations
• compute forces(self): Computes forces from the potential grid using finite
differences with periodic boundary conditions.

• interpolate forces(self, scheme): Interpolates forces from the grid to par-


ticle positions using NGP, CIC, or TSC scheme.

4.2.7 Time Integration


• leapfrog(self, delta a, scheme): Performs a leapfrog integration step with
time step ∆a, using the specified force interpolation scheme.

4.2.8 Energy Calculations


• kinetic(self): Computes total kinetic energy of particles.

• potential(self): Computes total potential energy from the density and po-
tential grids.

4.2.9 Visualization
• visualize(self, title extra=""): Creates a 2D scatter plot of particle po-
sitions.

• visualize potential(self, slice index=None, projection=’2d’): Plots


a 2D slice or projection of the potential field.

4.2.10 Analysis
• compute power spectrum(self, delta x, n bins=20): Computes the power
spectrum of a density field δx by binning Fourier modes.

44
Chapter 5

Conclusion

The ParticleMeshSimulation class provides a robust implementation of a particle-


mesh (PM) scheme for cosmological simulations, combining particle-based dynamics
with grid-based field calculations to model large-scale structure formation efficiently.
By leveraging Fourier methods for solving Poisson’s equation and employing inter-
polation schemes like CIC and TSC, the class achieves a balance between accuracy
and computational performance. Key features include the Zel’dovich approximation
for generating initial conditions, cosmological calculations for expansion history, and
leapfrog integration for time evolution, ensuring self-consistent gravitational interac-
tions.
The class supports multiple analysis tools, such as power spectrum computation
and energy diagnostics, enabling quantitative comparisons with theoretical predic-
tions. Visualization methods allow for intuitive inspection of particle distributions
and potential fields, aiding in debugging and interpretation. While the implementa-
tion focuses on standard ΛCDM cosmology, the modular design permits extensions,
such as modified gravity or additional physics, via the telegraph equation solver or
alternative Poisson kernels.
A notable strength is the handling of periodic boundary conditions and Fourier-
space operations, which are critical for cosmological simulations. However, the fixed
grid resolution and simplified growth factor assumption may limit accuracy in highly
nonlinear regimes. Future improvements could include adaptive time-stepping, higher-
order force interpolation, or hybrid PM-tree methods for small-scale precision. Over-
all, this class serves as a versatile foundation for studying structure formation, demon-
strating the power of particle-mesh techniques in computational cosmology.

45
Bibliography

[1] S. Aarseth. “N-body simulations (gravitational)”. In: Scholarpedia 2.9 (2007),


p. 2111. url: http://www.scholarpedia.org/article/N-body_simulations_
(gravitational).
[2] J.S. Bagla. “Cosmological N-body simulation: Techniques, scope and status”.
In: Current Science 88.7 (2005), pp. 1088–1100.
[3] E. Bertschinger. “Cosmological Dynamics: Course 1 from Vlasov to N-body”.
In: arXiv preprint astro-ph/0101009 (2001). url: https://arxiv.org/abs/
astro-ph/0101009.
[4] E. Bertschinger. “Simulations of Structure Formation in the Universe”. In: arXiv
preprint astro-ph/0303175 (2003). url: https://ned.ipac.caltech.edu/
level5/March03/Bertschinger/Bert1.html.
[5] J. Binney and S. Tremaine. Galactic Dynamics. 2nd. Princeton, NJ: Princeton
University Press, 2008. isbn: 9780691130279.
[6] C.K. Birdsall and A.B. Langdon. “Particle-in-cell simulations”. In: Plasma
Physics via Computer Simulation (1991).
[7] Planck Collaboration, N. Aghanim, et al. “Planck 2018 results. VI. Cosmological
parameters”. In: Astronomy & Astrophysics 641 (2020), A6. doi: 10 . 1051 /
0004-6361/201833910. url: https://arxiv.org/abs/1807.06209.
[8] Scott Dodelson and Fabian Schmidt. Modern Cosmology. 2nd. Academic Press,
2020. isbn: 9780128159487.
[9] G. Efstathiou et al. “Numerical Techniques for Large Cosmological N-Body Sim-
ulations”. In: The Astrophysical Journal Supplement Series 57 (1985), pp. 241–
260.

46
[10] Masahiro Hirai, Shin Mineshige, and Kazunari Shibata. “An Improved Poisson
Solver for Self-Gravity Using the Telegraph Equation”. In: Publications of the
Astronomical Society of Japan (2002).
[11] R. W. Hockney and J. W. Eastwood. Computer Simulation Using Particles.
New York: Taylor & Francis, 1981. isbn: 9780852743928.
[12] Roger W. Hockney and James W. Eastwood. Computer Simulation Using Par-
ticles. CRC Press, 1988. isbn: 9780852743928.
[13] R. A. James. “Correcting for the alias effect when measuring the power spec-
trum”. In: Monthly Notices of the Royal Astronomical Society 179 (1977), pp. 15–
18.
[14] Aurobinda Majhi. N-body. https://github.com/aurobinda824/pm. 2025.
[15] Rajesh Mondal. N-body. https : / / github . com / rajeshmondal18 / N - body.
2021.
[16] P.J.E. Peebles. The Large-Scale Structure of the Universe. Princeton University
Press, 1980. isbn: 9780691082400.
[17] S. Prunet et al. “Starting Cosmological Simulations from the Big Bang: Phase-
Space Initial Conditions for N-Body Simulations”. In: The Astrophysical Jour-
nal Supplement Series 178.1 (2008), pp. 179–188.
[18] Hannes R Rüter, Volker Springel, and Rüdiger Pakmor. “An improved Poisson
solver for self-gravity in astrophysical fluid simulations”. In: Monthly Notices of
the Royal Astronomical Society 527.1 (2018), pp. 471–486.
[19] Volker Springel. “The cosmological simulation code GADGET-2”. In: Monthly
Notices of the Royal Astronomical Society 364.4 (2005). https://arxiv.org/
abs/astro-ph/0411105, pp. 1105–1134.
[20] Volker Springel et al. “Galaxy Formation in a ΛCDM Cosmology”. In: Nature
435 (2005), pp. 629–636.
[21] Gustavo Yepes. Introduction to N-body simulations. https://workshops.ift.
uam-csic.es/uploads/charla/275/Yepes_nbody.pdf. 2015.

47

You might also like