Click here to Skip to main content
12,446,146 members (25,550 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked

Monte Carlo Simulation for Testing Cosmological Models

, 3 May 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Source code for the paper titled "A Monte Carlo simulation framework for testing cosmological models"


A galactic survey encompasses a collection of observable galaxies with respective redshifts that have been obtained for a given spectroscopic area of the sky. Using a cosmological model, we can convert the redshifts into light-travel times and, by slicing the survey into small redshift buckets, compute a curve of galactic density over time.

Because foreground galaxies obstruct the images of more distant galaxies, we simulate the theoretical galactic density curve using an average galactic radius. By comparing the galactic density curves of the simulation with that of the survey, we can assess the cosmologies.

We use the simulation to generate a uniform distribution of galaxies for each redshift bucket. We then compute the number of visible galaxies (i.e., those that are not covered by foreground galaxies) to derive the simulated galactic density curve. Our method requires only a cosmological model that relates distances to redshifts, a behavior for the galactic density, and the average galactic radius versus redshifts.


In the research paper "A Monte Carlo simulation for testing cosmological models", we consider two distinct cosmologies: the de Sitter flat-universe cosmology and the dichotomous cosmology.

The de Sitter cosmology is a solution to the Friedmann equation for an empty universe, without matter, dominated by a repulsive cosmological constant Lambda corresponding to a positive vacuum energy density.

The dichotomous cosmology consists of a static material world and an expanding luminous world.

For both cosmologies, the Hubble parameter is a physical constant which does not vary over time.

Using the Code

The class GalaxyCount.cs does the job. The class Galaxy.cs is used to represent a galaxy. This class holds the position of the galaxy using astronomical spherical coordinates, and also has the associated radius of the galaxy.

In the header of GalaxyCount.cs, we specify both the galactic density and the average galactic radius at present time.

In the method generateBucket(), we need to specify the behavior for the galactic density versus redshift.

For the dichotomous cosmology, the galactic density is constant over time.
//Behavior for the galactic density in the dichotomous cosmology
double densityZ = density0;

For the expanding Universe theory, the density increases by a factor (1+z)3 when looking back in the past.

// Behavior for the galactic density in the expanding Universe cosmology
double densityZ = Math.Pow(1+z,3)*density0;

We iterate from redshift z1 to redshift zn, and generate Ni galaxies for each redshift bucket, and then determine for each galaxy whether it is obscured by foreground galaxies. Using this procedure, we obtain the simulated galactic counts for each redshift bucket.

The number of galaxies that we need to generate for each redshift bucket is determined as follows:

//Spectroscopic area of the simulation
specArea = 180.0 / Math.PI * (Math.Sin(theta_max) - Math.Sin(theta_min)) * (phi_max-phi_min) * 180.0 / Math.PI;
//Factor to convert volume of the spherical shell to the spectroscopic area of the simulation
nu = 4 * Math.PI * Math.Pow(180.0 / Math.PI, 2)/specArea;

//Volume of the spherical shell
double volume = 4.0/3.0*Math.PI*(Math.Pow(getDistance(z),3)-Math.Pow(getDistance(zprevious),3)); 
// Density function, which is equal to the present galactic density for 
// the dichotomous cosmology, and density0*(1+z)^3 for the expanding Universe cosmology.
double densityZ = density0; //Math.Pow(1+z,3)*density0 for the expanding cosmology
// Number of galaxies to generate for a given redshift bucket 
int numberGalaxies = (int)(densityZ*volume/nu);

For each galaxy, we generate the declination and right ascension angles with a uniform distribution. The radial distance is set to the light-travel time at redshift zi.

To determine if galaxy B is hidden by foreground galaxy A, we need to check whether the actual distance between the projection of galaxy A into the plan of B and galaxy B itself is larger or smaller than the critical distance. If it is smaller, then galaxy B is determined to be hidden. Otherwise, B is visible.

//The actual distance between the projection of galaxy A into the plan of B and galaxy B itself.
public double galaxyDistance(Galaxy a, Galaxy b, double r)
double dist = Math.Sqrt(Math.Pow(r*Math.Cos(a.Theta)*Math.Cos(a.Phi)-
return dist;

Because galactic surveys are obtained using an automated device, and an algorithm cannot identify a galaxy that is not isolated from other sources of light, the critical distance is calculated as follows:

//Critical distance to determine if galaxy B is hidden by galaxy A
public double criticalDistance(Galaxy a, Galaxy b)
   return b.Radius + b.R / a.R * a.Radius;

Mathematical details for the algorithm are described in the article "A Monte Carlo simulation framework for testing cosmological models".



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Yuri Heymann
Switzerland Switzerland
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160811.3 | Last Updated 3 May 2014
Article Copyright 2014 by Yuri Heymann
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid