astronomix.units.unit_helpers module#

Conversion between simulation code units and physical units.

The simulation works in dimensionless code units defined by a chosen unit length, unit mass and unit velocity. CodeUnits builds the derived code units (time, density, pressure, energy, magnetic field) from those three base units and offers convenience conversions back to physical quantities. When post-processing with Paicos these helpers are not needed.

class astronomix.units.unit_helpers.CodeUnits(unit_length, unit_mass, unit_velocity)[source]#

Bases: object

Derived code-unit system built from a base length, mass and velocity.

From the three base units every other code unit (time, density, pressure, energy, magnetic field) follows by dimensional analysis. The magnetic field is stored as B / sqrt(mu_0), which has units of sqrt(pressure).

get_temperature_from_internal_energy(internal_energy, gamma=1.6666666666666667, hydrogen_abundance=0.76)[source]#

Convert specific internal energy (code units) to a temperature.

Uses the ideal-gas relation T = (gamma - 1) u mu m_H / k_B with the mean molecular weight derived from the hydrogen abundance.

Parameters:
  • internal_energy – The specific internal energy in code units.

  • gamma – The adiabatic index of the gas.

  • hydrogen_abundance – The hydrogen mass fraction, used to set the mean molecular weight.

Returns:

The temperature as an astropy quantity in kelvin.

init_from_unit_params(UnitMass_in_g, UnitVelocity_in_cm_per_s)[source]#

Build a CodeUnits from raw CGS unit magnitudes.

Parameters:
  • UnitLength_in_cm – The code length in centimetres.

  • UnitMass_in_g – The code mass in grams.

  • UnitVelocity_in_cm_per_s – The code velocity in cm/s.

Returns:

The corresponding CodeUnits instance.

print_simulation_parameters(final_time_wanted)[source]#

Print the base and derived code units in physical units.

Parameters:

final_time_wanted – A target physical time, reported in code-time units for convenience when choosing a run length.