Cosmological Simulations 1: Generating your own slice of the Cosmic Web

Cosmic Web. Image created by author

It was a warm winter afternoon and I was having chai and samosa with my friends in the college ground. A conversation stirred about how the structures formed by the neurons inside the human brain and the vast structure of the universe were similar. I rememeber how fascinated I was with this picture. From that day, I have been interested in learning how to generate the vast cosmic webs besides their working and structures. In this article, I will plot the density field of the Cold Dark Matter over typical scales that we use in cosmology.

First, some cliché but indispensible definitions along with some really great tools we will be needing.

  1. Universe: The vast OBSERVABLE space around us that we can see directly is what consitutes the Universe for us. [Note: Seeing in astronomy is the same as seeing in daily life except that astronomers have enhanced vision. They can see well beyond the visible spectrum of light to which you and I are limited to]. The light from the regions beyond this has yet to arrive to us (thanks to Einstein!) and that is why we keep seeing more and more of the Universe every second as this light keeps on reaching us.
  2. Dark Matter: What you, I and everything you can imagine is made up of, is Matter. Ordinary matter, to be more precise. The same matter that we learnt about in elementary classes (Matter is what everything around us is made up of!). Ironically, not everything is made up of THIS matter. The entire universe contains only 5% of this ordinary matter. 68% of the Universe is made of Dark Energy (Let’s not go into that right now! My fingers can take only so much!) and the remaining 27% is the Dark Matter. This Dark Matter is considered to be the difficult and obnoxious one. It does not reflect, absorb or emit light (hence dark) but it is right there. Now, the Dark Matter itself can be Hot and Cold (and Warm too!) and the Cold one is all we are interested in right now. It is this Cold Dark Matter (CDM) that have sluggish velocities and act via gravity only to make the Universe what it is. CDM is the primary seed for the structure formation in the Universe.
  3. Large Scale Structure: If you stand at any point in the universe and look at any direction in the space, you won’t find what you see to be the same. Well, you will! You would just need to see a little bit farther. Just around 100 Mpc (World’s fastest traveler light would take just 326 million years to travel that distance!) If you see around you at this scale, you will find the Universe around every direction at any point to be more or less the same. This is called the Principle of Homogeneity which states that the Universe is more or less the same at large scales. Now, at this scale, there are distinct features inthe Universe. There are some long thread-like structures that are nearly 200 to 500 million light years long and contain ionized gas regions, some big clusters of matter (what kind of matter?) and wayyyyyy more empty (underdense to be precise) regions called cosmic voids. What these clusters consist of, you ask? Groups of groups of galaxies! So, Large Scale Structure of the Universe refers to the patterns of galaxies and matter on very large scales, much larger than the individual galaxies and just as ordinary matter attract each other through the Newton’s law of Gravitation, these galaxies also draw closer to each other and from a homogeneous Universe at earlier times, give rise to the structure we see today.
  4. Cosmological Simulations: Consider 1 million Cold Dark Matter particles inside a big cubical volume of, say 500 Mpc/h at some initial redshift of 9. By particles, I mean galaxies and by redshift 9, I mean the time when the Universe was 1/(9+1) i.e. one-tenth of its presence size. Using the laws of gravity alone, this initial Universe is evolved over time to the current redshift i.e. 0 [Note: 1/(0+1) i.e. when the Universe is as big in size as it is today, so right now!] So, what we will have as an output is the updated positions of these million particles/galaxies along with their IDs (we need to label them, otherwise it will be a big mess of who is who!), velocities and accelerations. This data is called a Cosmological Simulation and this is the data that we will need to plot our Cold Dark Matter web.

So, let’s create our very own slice of a cosmic web.

I will be using the publicly available QUIJOTE¹ cosmological simulations which is a suite of 44,100 N-body simulations and a set of tools in Python called Pylians² that contains the commonly employed routines to read and analyse cosmological simulations. A single realization at redshift 0 with a fiducial cosmology will be used. There can be a number of cosmological simulations of the same Universe, each with a different random seed, just like multiple ensembles of the same thermodynamic system. Each of these ensembles is called a realization of our Universe. Fiducial cosmology means a standard cosmological model with some fixed parameters against which we can compare a variety of simulations with tweaked parameters. One important aspect of our fiducial cosmology is the absence of massive neutrinos [Note: Neutrinos are the second most abundant particles in the Universe after photons or radiation]. The simulation consists of 512³ Cold Dark Matter particles evolved in a simulation box of size 1000 Mpc/h from a initial redshift of 127 to the current epoch.

Considering you have properly installed the Pylians library in your machine, the first step would be to import the necessary libraries:

readsnap and readgadget read the simulation snapshot and MAS_library computes the density field. A typical comsological simulation can be in ASCII, RAMSES or GADGET file format.

Next, some parameters will be set

path directs to the snapshot of a fiducial cosmology for realization 1 and redshift 0 (snap_004 is redshift 0, snap_003 is redshift 0.5 and so on. Read Quijote documentation for more details). CIC or Cloud-In-Cell is a type of particle mesh algorithm that determines the interpolation scheme used to assign densities to grid cells. The number of pixels in the image will be grid². boxsize is the edge length of our simulation box which is a 1000 Mpc/h. Some types of simulations use a spherical region instead of a cubical volume. threads are the number of processor threads we want to use for our computation. Linear scale will be used to plot the density field. ptypes is the particle type, where 1 refers to Cold Dark Matter, 2 is Neutrinos, 3 is for Stars, etc. The particular region of the box whose density field we want to visualize is given by the axes limits in the last three lines.

Now, we will compute the overdensity of our region. Overdensity refers to the amount of fluctuation in the density of the matter at a particular point, from the average density of the simulation region.

So, the overdensity tells us about the cold dark matter density fluctuations in the Universe.

In line 1, the positions of all 512³ particles is read. The initial positions are in kpc and are converted to Mpc by dividing by 1000. These positions are explicitly stored in numpy arrays in line 2. Then, the particles that fall in our simulation region are selected on the basis of their indices in line 3 and the positions are updated in line 4. We then renormalize the coordinates and project the positions on a 2D plane. MASL.MA then computes the density field of the particles and then we compute the overdensity field by the formula stated above.

The final step now is to plot the density field. Let’s create an elaborate function for plotting this field

Finally, we plot the field

And voilà! We have our very own slice of a Cosmic Web.

This is what the Universe looks like at the current stage. We can clearly see the long filaments that are the thread-like structures distributed throughout the image. The clusters that are joined by these filaments contain several thousand galaxies. Galaxy clusters and filaments are among the largest known structures in the Universe. This is how the Universe evolved from a nearly uniform density field to the present state of structure and life.

Galaxy redshift surveys contain the information of the matter distribution in the Universe in the form of galaxy clusters, filaments and voids. The properties of this distribution contain information about the Dark Matter, Dark Energy and the laws of gravity. Various properties of these distribution like Power Spectrum, Void Abundance Function, Bispectrum, etc. can be analyzed³ and compared with the simulations.

Cosmological simulations are an indispensible and powerful tool at the hands of cosmologists and astrophysicists to obtain accurate and rigorous theoretical predictions in order to maximize the information that can be retrieved from the galaxy redshift surveys.

(Special thanks to Elena Giusarma, Mauricio Hurtado and Francisco-Villaescusa Navarro)

Thanks for reading! Comments or criticism is most welcome.

[1] Francisco Villaescusa-Navarro et al 2020 ApJS 250 2, The Quijote Simulations

[2] Francisco Villaescusa-Navarro, Pylians3,

[3] Giusarma et al, Learning Neutrino Effects in Cosmology with Convolutional Neural Netwroks, arXiv:1910.04255

I am a PhD Physics student at Michigan Tech University. I love Programming, Netflix, Books and Gym. I do poetry and study the physics of the Universe

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store