astronomix.units.unit_helpers#

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.

Module Contents#

Classes#

CodeUnits

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

API#

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

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).

Initialization

Define the code-unit system from three astropy-valued base units.

Args:

unit_length: The code length, e.g. 3 * u.parsec. unit_mass: The code mass, e.g. 1e5 * u.M_sun. unit_velocity: The code velocity, e.g. 1 * u.km / u.s.

init_from_unit_params(UnitMass_in_g, UnitVelocity_in_cm_per_s)[source]#

Build a CodeUnits from raw CGS unit magnitudes.

Args:

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.

get_temperature_from_internal_energy(internal_energy, gamma=5 / 3, 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.

Args:

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.

print_simulation_parameters(final_time_wanted)[source]#

Print the base and derived code units in physical units.

Args:
final_time_wanted: A target physical time, reported in code-time

units for convenience when choosing a run length.