profiles.density.BaseSphericalDensityProfile.compute_total_mass#

BaseSphericalDensityProfile.compute_total_mass(units: str | Unit | None = None, **kwargs) unyt_quantity[source]#

Numerically compute the total mass of the profile by integrating to infinity.

\[M_{\mathrm{tot}} = 4 \pi \int_0^\infty \rho(r) \, r^2 \, dr\]

If the profile has finite total mass, this method returns its value. Divergent profiles will raise a RuntimeError.

Parameters:
  • units (str or Unit, optional) – Desired output units for mass. Defaults to units implied by the profile parameters.

  • **kwargs – Additional arguments passed to scipy.integrate.quad().

Returns:

mass – Total mass with correct units.

Return type:

unyt_quantity

Raises:

RuntimeError – If the integral fails to converge or the result is infinite/NaN.

Examples

import unyt
from pisces.profiles.density import (
    PlummerDensityProfile,
)

profile = PlummerDensityProfile(
    M=1e11 * unyt.Msun, r_s=5 * unyt.kpc
)
total_mass = profile.compute_total_mass(
    units="Msun"
)

print(f"Total mass: {total_mass:.3e}")