profiles.density.EinastoDensityProfile.compute_fractional_mass_radius#
- EinastoDensityProfile.compute_fractional_mass_radius(rmin: float | unyt_quantity, rmax: float | unyt_quantity, fraction: float = 0.5, units: str | Unit | None = 'kpc', **kwargs)#
Find the radius enclosing a given fraction of the total mass.
Solves numerically for radius \(r_f\) such that:
\[M(r_f) = f \times M_{\mathrm{tot}}\]where \(f\) is the desired mass fraction.
- Parameters:
rmin (
float
orunyt_quantity
) – Lower bound for the radius search interval.rmax (
float
orunyt_quantity
) – Upper bound for the radius search interval.fraction (
float
, optional) – Mass fraction to enclose, between 0 and 1. Default is 0.5 (half-mass radius).units (
str
orUnit
, optional) – Units for rmin and rmax. Default iskpc
.**kwargs – Additional arguments passed to
compute_enclosed_mass()
andcompute_total_mass()
.
- Returns:
radius – Radius enclosing the specified mass fraction.
- Return type:
- Raises:
ValueError – If the mass fraction is outside (0, 1) or search bounds are invalid.
Examples
import unyt from pisces.profiles.density import ( HernquistDensityProfile, ) profile = HernquistDensityProfile( rho_0=0.05 * unyt.Msun / unyt.kpc**3, r_s=10 * unyt.kpc, ) half_mass_radius = ( profile.compute_fractional_mass_radius( 0.1, 100, fraction=0.5, units="kpc" ) ) print(f"Half-mass radius: {half_mass_radius:.2f}")