The Tolman-Oppenheimer-Volkoff (TOV) equations describe the structure of a spherically symmetric, static star in general relativity, such as a neutron star. The equations relate the pressure ( P(r) ), mass ( M(r) ), and energy density ( \epsilon(r) ) as a function of radius ( r ). The standard form is:
Below is a minimal Python implementation using a polytropic equation of state (EoS) as an example. You can substitute your own EoS as needed.
python
import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt
# Physical constants (cgs units)
G = 6.67430e-8 # Gravitational constant [cm^3 g^-1 s^-2]
c = 2.99792458e10 # Speed of light [cm/s]
Msun = 1.98847e33 # Solar mass [g]
# Polytropic EoS parameters (example: n=1, K=1e5)
K = 1e5 # Polytropic constant [cgs]
gamma = 2.0 # Polytropic index
def eos_pressure_to_density(P):
# Polytropic EoS: P = K * rho^gamma => rho = (P/K)^(1/gamma)
return (P / K) ** (1.0 / gamma)
def tov_rhs(r, y):
P, M = y
if P <= 0:
return [0, 0]
rho = eos_pressure_to_density(P)
eps = rho * c**2
dPdr = -G * eps * M / r**2 * (1 + P / eps) * (1 + 4 * np.pi * r**3 * P / (M * c**2)) / (1 - 2 * G * M / (r * c**2))
dMdr = 4 * np.pi * r**2 * eps / c**2
return [dPdr, dMdr]
def solve_tov(Pc, r_max=2e6, dr=100):
# Initial conditions
r0 = 1e-10 # Avoid division by zero at r=0
M0 = 1e-10 # Small initial mass
y0 = [Pc, M0]
r_points = np.arange(r0, r_max, dr)
sol = solve_ivp(tov_rhs, [r0, r_max], y0, t_eval=r_points, method='RK45', rtol=1e-6, atol=1e-8)
P = sol.y
M = sol.y[1]
R_star = sol.t[P > 0][-1] if np.any(P > 0) else 0
M_star = M[P > 0][-1] if np.any(P > 0) else 0
return R_star, M_star, sol
# Example: Compute mass-radius curve for a range of central pressures
Pc_values = np.logspace(23, 26, 20) # Central pressures [dyne/cm^2]
R_values = []
M_values = []
for Pc in Pc_values:
R, M, _ = solve_tov(Pc)
R_values.append(R / 1e5) # Convert cm to km
M_values.append(M / Msun) # Convert g to solar masses
plt.plot(R_values, M_values)
plt.xlabel('Radius (km)')
plt.ylabel('Mass (M$_\odot$)')
plt.title('Neutron Star Mass-Radius Relation (Polytropic EoS)')
plt.grid()
plt.show()
How to Use:
Adjust the polytropic EoS parameters (K, gamma) or replace the eos_pressure_to_density function with your own EoS.
The code integrates the TOV equations from the center (small ( r )) outward until the pressure drops to zero, which defines the stellar surface.
The resulting plot shows the mass-radius relation for neutron stars with the chosen EoS.
References for Further Study:
For more advanced EoS and data-driven approaches, see open-source projects like [PYTOV][1], [TOVsolver][7], and Jupyter notebook examples[2][3][4].
For a detailed explanation of the equations and their physical meaning, see [6][8].
Note: This code is a minimal, illustrative example. For realistic neutron star modeling, use a physically motivated EoS and carefully handle units throughout the calculation[1][2][7][8].