profiles.density.KingDensityProfile.compute_enclosed_mass#
- KingDensityProfile.compute_enclosed_mass(r: unyt_array | unyt_quantity, units: str | Unit | None = None, **kwargs) unyt_array | unyt_quantity #
Numerically compute the enclosed mass \(M(r)\) within radius \(r\).
The enclosed mass is given by:
\[M(r) = 4 \pi \int_0^r \rho(r') \, r'^2 \, dr',\]where \(\rho(r)\) is the spherically symmetric density profile.
- Parameters:
r (
unyt_quantity
orunyt_array
) – Radius or array of radii at which to compute enclosed mass. Must carry length units (e.g., kpc, pc).units (
str
orUnit
, optional) – Desired output units for mass. If not provided, output units follow from the profile parameters.**kwargs – Additional arguments passed to
scipy.integrate.quad()
.
- Returns:
mass – Enclosed mass at each radius with appropriate units.
- Return type:
Notes
Assumes spherical symmetry.
Uses
scipy.integrate.quad()
for numerical integration.Units are handled automatically using
unyt
.
Examples
Compute enclosed mass for a Hernquist profile:
import numpy as np import unyt from pisces.profiles.density import ( HernquistDensityProfile, ) profile = HernquistDensityProfile( rho_0=0.05 * unyt.Msun / unyt.kpc**3, r_s=10 * unyt.kpc, ) radii = np.logspace(-1, 2, 100) * unyt.kpc mass = profile.compute_enclosed_mass( radii, units="Msun" ) print(mass)