Table of Contents
This is an old revision of the document!
Modeling a star
This article shows how to build a static stellar model by numerically integrating the seven equations of stellar structure using the program STATSTAR (Python-3 version). The code integrates inward from the stellar surface, layer by layer, until a self-consistent structure is found. It provides a direct computational implementation of the equations developed in Equations of stellar structure.
What STATSTAR does
STATSTAR numerically integrates the primary stellar-structure equations:
- Hydrostatic equilibrium: \( \displaystyle \frac{dP}{dr} = -\rho\,\frac{GM}{r^2} \) - Mass conservation: \( \displaystyle \frac{dM}{dr} = 4\pi r^2\rho \) - Energy generation: \( \displaystyle \frac{dL}{dr} = 4\pi r^2\rho\,\epsilon \) - Temperature gradient: chosen locally as either
\( \displaystyle \left(\frac{dT}{dr}\right)_{\!\mathrm{rad}} = -\frac{3\kappa\rho L}{16\pi a c\,T^3 r^2} \)
or
\( \displaystyle \left(\frac{dT}{dr}\right)_{\!\mathrm{ad}} \) if convection dominates.
The secondary equations provide the local thermodynamic closure:
- Equation of state (EOS): \( P = \rho kT / \mu m_p \) - Saha equation: sets the ionization balance, and hence \(\mu\) and \(\kappa\).
Each integration step uses these relations to update pressure, temperature, mass, and luminosity as the radius decreases. The method of integration is fourth-order Runge–Kutta for stability and accuracy.
Inputs you provide
When STATSTAR starts, it requests the following input parameters:
- Mass \(M\) in units of \(M_\odot\) - Luminosity \(L\) in units of \(L_\odot\) - Effective temperature \(T_{\!eff}\) (K) - Hydrogen mass fraction \(X\) - Metal mass fraction \(Z\) (helium is then \(Y = 1 - X - Z\))
These define the global properties and composition of the star, serving as the outer boundary conditions for integration.
Files and version
The Python-3 code is distributed as statstar_python3.py. Its companion output files are:
- starmodl.dat — detailed shell-by-shell structure (radius, \(M_r\), \(L_r\), \(T\), \(P\), \(\rho\), \(\kappa\), \(\epsilon\), …) - statstar.out — summary of the run, including success or failure messages
The program is derived from the original FORTRAN version but updated for modern Python environments.
Numerical workflow (per shell)
For each thin spherical shell:
- Compute auxiliary quantities (\(\rho, \kappa, \epsilon\)) using the EOS and Saha equations. - Evaluate derivatives \(dP/dr,\ dM/dr,\ dL/dr,\ dT/dr\). - Advance one step inward using the Runge–Kutta scheme. - Check for physical consistency (e.g., positive pressure, monotonic behavior). - Repeat until the center is reached or the run terminates.
Starting, stepping, and stopping
- Initialization: The program constructs the outermost layer from your \(L,\ T_{\!eff}\), and composition, then begins stepping inward (\(dr < 0\)). - Integration: Steps proceed through hundreds of thin shells using the Runge–Kutta algorithm. - Termination:
- Successful runs end with
- *“CONGRATULATIONS, I THINK YOU FOUND IT!”, indicating a plausible stellar center. - Failed runs stop early if a physical quantity becomes non-realistic (e.g., negative density or implausible temperature). ===== Example input ===== A near-solar model can be reproduced with: - \( M = 1.0\,M_\odot \) - \( L = 0.86\,L_\odot \) - \( T_{\!eff} = 5500\,\mathrm{K} \) - \( X = 0.70 \) - \( Z = 0.008 \) The resulting model integrates inward through a few hundred shells, generating profiles of temperature, pressure, and density. ===== Reading the output ===== A physically consistent model should show: - radius \(r \to 0\) smoothly toward the center - monotonically increasing \(P®\) and \(\rho®\) inward - a central temperature \(T_c \sim 10^7\) K for a solar-type star - no discontinuities or sign changes in \(M®\) or \(L®\) If the center is too cool or the run fails to converge, adjust \(T_{\!eff}\) or the step size and re-run. ===== Physical assumptions ===== STATSTAR solves the static, one-dimensional, spherically symmetric equations for a star in hydrostatic and thermal equilibrium. Assumptions include: - Composition is uniform throughout the star. - Rotation, magnetic fields, and time evolution are neglected. - Heat transfer switches automatically between radiative and convective regimes. - The EOS and opacity relations are idealized but sufficient for main-sequence models. Only certain combinations of \1)
