Unit System

These parameters control the units used for a simulation:

UnitLength_in_cm

This sets the internal length unit in cm/h, where H_0 = 100 h km/sec/Mpc. For example, the standard choice of 3.085678e21 sets the length unit to \(1.0 \, \rm{kpc/h}\).

UnitMass_in_g

This sets the internal mass unit in g/h, where H_0 = 100 h km/sec/Mpc. For example, the standard choice of 1.989e43 sets the mass unit to \(10^{10} M_\odot/\rm{h}\).

UnitVelocity_in_cm_per_s

This sets the internal velocity unit in cm/sec. For example, the standard choice of 1e5 sets the velocity unit to \(1.0 \, \rm{km/sec}\). Note that the specification of UnitLength_in_cm, UnitMass_in_g, and UnitVelocity_in_cm_per_s also determines the internal unit of time.

GravityConstantInternal

The numerical value of the gravitational constant G in internal units depends on the system of units you choose. For example, for the choices above, G=43007.1 in internal units. For GravityConstantInternal=0, the code calculates the value corresponding to the physical value of G automatically. However, you might want to set G yourself. For example, by specifying: GravityConstantInternal=1, UnitLength_in_cm=1, UnitMass_in_g=1, and UnitVelocity_in_cm_per_s=1, one obtains a natural system of units. Note that the code will nevertheless try to use the correct value of the Hubble constant in this case, so you should not set GravityConstantInternal in cosmological integrations.

Unit metadata in output

Some information about the physical unit can be stored in the hdf5 output. The unit is stored as a bunch of hdf5 attributes on each dataset which has unit information available.

The length_scaling, mass_scaling, and velocity_scaling attributes describe how the quantity has to change if the length, mass and velocity units are changed, i.e. if the quantity has to be multiplied with 0.01^n when you go from cm to meter, length_scaling would be set to n. a_scaling and h_scaling are just the exponents of the scaling with the cosmological a and h factors. The attribute to_cgs gives the factor to convert the output to cgs units (excluding a and h factors).

Note

Almost every unit can be described with these 6 numbers. A bit more tricky is the temperature unit in Kelvin. Either, the unit system needs to be extend with another scaling factor, or one adopts a system of units with the Boltzmann constant \(k_B\) equal to 1 and set the to_cgs factor for Kelvin quantities to the real value of \(k_B\). Also to be addressed: magnitudes.

To enable unit output, the function init_unit must be called after init_field in io_fields.c. Examples are:

init_units(IO_SFR, 0.0, 0.0, -1., 1.0, 1.0, SOLAR_MASS/SEC_PER_YEAR);
/* Msun/yr */

init_units(IO_GFM_AGN_RADIATION, 0.0, 0.0, -3.0, 1.0, 3.0, 1.0);
/* bolometric intensity in physical cgs units of erg/s/cm^2 */

Some python code that can handle the output for unit conversions and guessing the usual name can be found in inspector gadget (unit.py). This part of the code does not depend on any other inspector gadget related code and should be fairly easy to portable to other i/o libraries. The unit class represent a unit and handles conversion/guessing a common name for a set of unit parameters. The Quantity class is derived from numpy.ndarray and is a numpy array with unit information. This class tries to carry on unit information through most mathematical operations. The idea is to not alter the outcome of any operation and just augment the result with some unit information. I.e. if you add up 1 meter with 1 centimetre you end up with 2 and a unit of none instead of 1.01 m. The file can be found at: