A numerical simulation of stellar interior dynamics, solving the coupled system of stellar structure ODEs from a star's surface inward to its core.
This project models the physical state of a star (pressure, mass, luminosity, temperature, density, opacity, and energy generation) as a function of radial depth, under the following simplifying assumptions:
-
Fixed composition throughout the star (constant mean molecular weight
$\mu$ ) -
Spherical symmetry — all quantities depend only on radius
$r$ - Two energy transport modes — radiation and convection (whichever dominates at a given depth)
The four coupled first-order ODEs solved are:
| Equation | Description |
|---|---|
| Hydrostatic equilibrium | |
| Mass continuity | |
| Luminosity gradient | |
| Temperature gradient |
At each integration step, the following are computed from the current state
-
Density (ideal gas law):
$$\rho = \frac{P,\mu, m_H}{k_B T}$$ -
Opacity (Kramers' law, bound-free absorption):
$$\kappa = 0.32,\rho\left(\frac{T}{10^6}\right)^{-3.5}$$ -
Energy generation (simplified CNO cycle):
$$\varepsilon = \varepsilon_0,\rho\times 0.70\left(\frac{T}{T_0}\right)^{20}$$
The temperature gradient switches between:
-
Radiative:
$\nabla_\text{rad} = \frac{3\kappa\rho}{16\pi ac}\frac{L_r}{r^2 T^3}$ -
Adiabatic (convective):
$\nabla_\text{adia} = \frac{1}{\gamma_\text{rat}}\frac{GM_r}{r^2}\frac{\mu m_H}{k_B}$
Convection dominates when
A standard 4th-order Runge-Kutta integrator. Shown to be insufficient for this stiff ODE system — large step sizes cause numerical blow-up.
The primary integration method. Uses the Butcher tableau to compute both a 4th- and 5th-order estimate at each step, then adapts the step size
This dramatically reduces computation time and memory use versus fixed-step RK4, and avoids the instability caused by the system's stiffness.
The state vector is represented as a NumPy array
All quantities are in CGS units:
| Constant | Value | Unit |
|---|---|---|
| cm³ g⁻¹ s⁻² | ||
| erg K⁻¹ | ||
| cm s⁻¹ | ||
| cm | ||
| g | ||
| erg s⁻¹ |
Integration starts at the stellar surface
| Variable | Value |
|---|---|
| Pressure |
|
| Enclosed mass |
|
| Luminosity |
|
| Temperature |
|
| Mean molecular weight |
The integrator returns radial profiles of:
- Pressure
- Enclosed mass
- Luminosity
- Temperature
- Density
- Opacity
- Energy generation rate
These are visualised using matplotlib subplots.
- Python 3.12+
numpymatplotlib