profiles.density.PseudoIsothermalDensityProfile.compute_gravitational_field#

PseudoIsothermalDensityProfile.compute_gravitational_field(r: unyt_array | unyt_quantity, units: str | Unit | None = None, G: unyt_quantity | None = None, **kwargs) unyt_array | unyt_quantity#

Numerically compute the gravitational field \(g(r)\) at radius \(r\).

The radial gravitational field in a spherically symmetric potential is

\[g(r) = -\frac{G M(r)}{r^2},\]

where \(M(r)\) is the enclosed mass at radius \(r\) and \(G\) is the gravitational constant.

Parameters:
  • r (unyt_quantity or unyt_array) – Radius or array of radii at which to compute the gravitational field. Must carry length units (e.g. kpc, pc).

  • units (str or Unit, optional) – Desired output units for the gravitational field. If not provided, the natural units implied by G and the profile parameters are used.

  • G (unyt_quantity, optional) – Gravitational constant to use. Defaults to unyt.physical_constants.gravitational_constant.

  • **kwargs – Additional arguments passed to compute_enclosed_mass().

Returns:

g – Gravitational field at each input radius with appropriate units.

Return type:

unyt_quantity or unyt_array

Notes

  • This method always returns the magnitude of the inward field (negative sign included).

  • Assumes spherical symmetry.

Examples

Compute the gravitational field for an Einasto profile:

import numpy as np
import unyt
from pisces.profiles.density import (
    EinastoDensityProfile,
)

profile = EinastoDensityProfile(
    rho_0=0.01 * unyt.Msun / unyt.kpc**3,
    r_s=20 * unyt.kpc,
    alpha=0.2,
)

radii = np.logspace(0, 2, 50) * unyt.kpc
g = profile.compute_gravitational_field(
    radii, units="km/s**2"
)
print(g)