Code Units - N-BodyShop/changa GitHub Wiki

Understanding Units

The key constraint for units is that gasoline/ChaNGa require G = 1. Hence if you choose two out of the three possible dimensions, the third is always chosen for you. The two dimensions that are specifiable in the parameter file are mass in "dMSolUnit" and length in "dKpcUnit". The time dimension is determined from these two. A simple example is from the solar system: if the mass unit is 1 Solar mass ("dMSolUnit = 1") and the length unit is 1 AU ("dKpcUnit = 4.8481368e-09"), then the time unit is (1 year/ (2 pi)), since the Earth moves one radian in one time unit. Another example is convenient unit system for galactic dynamics: with a time unit of 1 gigayear and a length unit of 1 kiloparsec (dKpcUnit = 1), the mass unit is required to be 2.2222858e5 Solar Masses ("dMSolUnit = 2.2222858e5"). Conveniently, 1 kpc/gigayear = .9778 km/s.

Units in cosmology

For cosmology, the Hubble parameter enters as a unit, so it needs to be consistent with the other unit choices, and with G = 1. Many choices are possible, but our convention is the following:

  • Boxsize=1=length unit

  • Lengths and velocities are comoving.

  • Velocities are peculiar from the Hubble flow.

  • The critical density of the Universe in simulation units is 1.

Implications:

  • The total mass in the box in simulation units is rho/rho_crit = Omega_{matter} at z = 0.
  • From the Friedmann equation, H_0^2 = 8 pi rho_crit / 3; hence, H_0 = sqrt(8 pi/3) = 2.894405 in simulation units.
  • The velocity unit is gotten from (Hubble velocity across the box/2.894405).
  • The time unit is 2.894405/(Hubble parameter).

Examples

Omega0 = 1 Box size = 100mpc at z=0 h=0.5

(just in case you are wondering: sigma8 and P(k) are not important)

mass unit = (rho_crit in Msun/Mpc^3) times (100 Mpc)^3 = 6.398e16 solar masses

Total mass in the box = 1 code mass unit

box size = 100Mpc/(1+z)

Velocity unit= 1727.47/(1+z) = (50 100 /2.894405)/(1+z)


Omega0 = 0.3 (lambda or non lambda), Box size 100mpc at z=0, h=0.7

If H0=70Km/sec/Mpc units mass is (70/50)^2 6.938e16 = 13.6e16 Msol

Total mass in the box = Omega0 13.6e16 Msol =4.08e16

Velocity Unit: 70 100/2.894405 = 2418.46/(1+z) km/sec


Omega0 = 0.3 (lambda or non lambda), Box size 22.222mpc at z=0, h=0.7

If H0=70Km/sec/Mpc units mass is (22.222/100)^3 (70/50)^2 6.938e16 Msol = 1.492e15 msol

Total mass in the box = 4.476e14

Velocity Unit: 70 22.222/2.894405 = 537.43/(1+z) km/sec

Note: if got the units right for a given box and cosmology then the mass unit scales easily with boxsize^3 and the velocity unit is proportional to the boxsize for any other boxsizes.

Comoving Coordinates

Here be Dragons.

Going from comoving distance to physical distance is straightforward: r_phys = a r_cm. Physical velocity requires including the Hubble flow: v_phys = a (v_cm + H r_cm), where H is the hubble constant at the given redshift. Beware that v_circular is calculated differently, and therefore scales differently: v_c_phys = v_c_cm/sqrt(a). Finally, sometimes you want to know the ratio of the density to the critical density (e.g. to calculate the virial radius). This depends on cosmology. For Lambda + Matter critical Universes, we have rho/rho_c = rho_cm/(a^3 Omega_Lambda + Omega_matter), where the Omegas are present values and rho_c at the present is 1 as described above.