Skip to content

Units and Constants

munan edited this page Apr 17, 2023 · 3 revisions

Constants

Physical constants in c.g.s. are stored in units/units.hpp under the Constants namespace. The currently defined constants are as follows.

static const Real grav_const_cgs       = 6.67259e-8;
static const Real solar_mass_cgs       = 1.9891e+33;
static const Real solar_lum_cgs        = 3.8268e+33;
static const Real yr_cgs               = 3.155815e+7;
static const Real million_yr_cgs       = 3.155815e+13;
static const Real pc_cgs               = 3.085678e+18;
static const Real kpc_cgs              = 3.085678e+21;
static const Real km_s_cgs             = 1.0e+5;
static const Real hydrogen_mass_cgs    = 1.6733e-24;
static const Real radiation_aconst_cgs = 7.5646e-15;
static const Real k_boltzmann_cgs      = 1.380658e-16;
static const Real speed_of_light_cgs   = 2.99792458e+10;
static const Real echarge_cgs          = 4.80320427e-10;
static const Real kelvin_cgs           = 1;

Units

The Units class is declared in units/units.hpp.

The unit systems

The Units constructor is called at the very beginning of the Mesh constructor and takes ParameterInput as an argument. The unit system is set by choosing one of the default unit systems or providing a custom MLT unit system. If the <units> block in the input file is not specified, the code will use the default ism unit system. The resulting MLT units will be set in the runtime and stored in the parameter input. There are two possible use cases:

  • Choose preset unit systems. Now, we provide ism and galaxy. If one wants to add additional unit systems, units/units.cpp has to be modified. If the unit system is set to one of the preset unit systems, additional input parameters, mass_cgs, length_cgs, and time_cgs, will be simply ignored.

    <units>
    unit_system = ism
    
  • Choose custom and set MLT units explicitly.

    <units>
    unit_system = custom
    mass_cgs = 1
    length_cgs = 1
    time_cgs = 1
    

ISM units

Our favorite the ISM default unit system is defined by

    code_length_cgs_ = Constants::pc_cgs;
    code_mass_cgs_ = 1.4*Constants::hydrogen_mass_cgs*CUBE(code_length_cgs_);
    code_time_cgs_ = Constants::pc_cgs/Constants::km_s_cgs;

such that

  • code density in cgs = 1.4m_H/cm^3
  • code length in cgs = pc
  • code velocity in cgs = km/s

Galaxy units

As an example, we provide galaxy unit system defined by

    code_length_cgs_ = Constants::kpc_cgs;
    code_mass_cgs_ = 1.4*Constants::hydrogen_mass_cgs*CUBE(code_length_cgs_);
    code_time_cgs_ = Constants::million_yr_cgs;

Units members

Under the hood, the Units constructor calls Units::SetUnitsConstants() to set useful conversion factors.

  • Here is the list of conversion factors to be multiplied to convert the physical variables in the code units to get them in the cgs units.

      Real code_mass_cgs, code_length_cgs, code_time_cgs;
    
      Real code_volume_cgs, code_density_cgs, code_velocity_cgs;
      Real code_energydensity_cgs, code_pressure_cgs;
      Real code_magneticfield_cgs;
      Real code_temperature_mu_cgs; // T/mu

    For example, if one wants to convert input pressure/k_B in c.g.s to code units, one can do this.

      pressure_code = pok_cgs * Constants::k_boltzmann / punit->code_pressure cgs
  • Similarly, the conversion factors of c.g.s. units to code units are also provided:

      Real gram_code, cm_code, second_code, dyne_code, erg_code, kelvin_code;

    In fact, gram_code = 1/code_mass_cgs; i.e., if the input mass is provided in units of gram, one can convert it to code mass in two ways.

      mass_code = mass * gram_code = mass/code_mass_cgs

    Note that kelvin_code is set to 1, not set to 1/code_temperature_cgs

  • Finally, we provide a set of physical constants in the code units.

    // physical constants in code units
    Real grav_const_code;
    Real solar_mass_code;
    Real solar_lum_code;
    Real yr_code;
    Real million_yr_code;
    Real pc_code;
    Real kpc_code;
    Real km_s_code;
    Real hydrogen_mass_code;
    Real radiation_aconst_code; // aR
    Real k_boltzmann_code; // k_B
    Real speed_of_light_code;
    Real echarge_code;
    Real bethe_code; // 1.e51 erg

    i.e., we applied appropriate unit conversion

    grav_const_code = Constants::grav_const_cgs
                       *cm_code*cm_code*cm_code/(gram_code*second_code*second_code);

Units class pointer

Now, the default Units class constructed in the Mesh constructor is passed to MeshBlock. For example, in a MeshBlock member function, one can use the Units class by

  • punit
  • pmy_mesh->punit

They point to the same Units class.

Temperature Units

Since the temperature conversion depends on the mean molecular weight mu, at this stage, we set a conversion factor code_temperature_mu_cgs for $$T/\mu\equiv (P/\rho)(m_H/k_B)$$ i.e., there is no punit->code_temperature_cgs.

Clone this wiki locally