Outline

8. Numerical Solutions

We assume independent variables 0 < m < M and t,
and dependent variables r, ρ, T, l, and X (the vector of nuclear composition, which will evolve as the star ages).
The "four" equations for stellar structure assuming quiescent aging are:

r 2ρdr = dm
central boundary condition: r = 0 at m = 0.

dl = ε dm
central boundary condition: l = 0 at m = 0.
Gravitational and Nuclear energy generation: ε = ε (ρ, T, X ) ergs/gram.

dP = −Gmρ dr /r 2 or
r 4dP = −Gm dm
surface boundary condition: P = 0 at m = M.
Equation of State: P = P (ρ, T, X ).

Radiative layers
64π 2r 4ac T 3dT = − 3κ l dm
surface boundary condition: T = 0 at m = M.
Mean opacity: κ = κ (ρ, T, X ) cm2/gram.

Convective layers
P dT = T(1−1/γ) dP
surface boundary condition: set by radiative boundaries.
And r, P, T, and l continuous across convective-radiative interfaces.
(Note: ρ and X need not be continuous, although denser layers cannot reside above less dense layers.)
Adiabatic constant: γ = γ (ρ, T, X )

The four equations and the continuity requirements across interfaces suggest that P might be a better dependent variable than ρ, but we are so used to writing the coefficients as functions of ρ and T that I have chosen ρ for the tracked variable. If the equation of state has the form P = Po (ρ/ρo) β (T/To) α, then dP/P = β dρ/ρ + α dT/T.

Polytropes
If we can write the equation of state as P = Po (ρ/ρo) 1+1/n, then the first two equations form a complete set, and we can solve them independently from the temperature structure. Such a system is said to be a polytrope of index n. Often polytropes are good approximations to real stars, and make good initial models for the iterative schemes described below.

Numerical Solutions
Computationally one calculates values of the dependent variables on a predetermined (or adaptive) grid of m-values. We choose m rather than r for the grid since we know the total mass M but not the radius R. Ideally, we will want to choose combinations of variables and/or particular schemes of gridding to make the problem more linear and account for wide variations of pressure and density and rapid changes near the surface. Refer to the literature if you are so inclined. As an example, lets replace m with (M − ζ) /M, and write the equations in terms of logarithmic variables. Then all combinations of terms are dimensionless fractions, and equal steps in ln (ζ ) favor the surface where state variables change rapidly.

Define ym as the vector of dependent variables (ln rm, ln lm, ln ρm, ln Tm) at grid point m (assume the Xm are part of the coefficient functions). The elements of ym are yj,m, 1 ≤ j ≤ 4. Then we may write all four equations as the vector equation

Ι · dy = f ( y) d lnζ

e.g.

x1x 0 0 0 d ln r ζ M /4πr 3ρ
0 x1x 00 d ln l ζ M ε /l
00 xβx xαx xx d ln ρ x=x ζ MGm/4πr 4P d lnζ
000 1 d ln T 3ζ Mκ l /64π 2r 4acT 4
00 βad 1 − αad 0

Terms in the continuity equation have been highlighted for example.
Note that the matrix Ι is nearly the identity matrix (empty except ones on the diagonal; it would be the identity matrix if we choose P as a dependent variable and have no convection). It is independent of state variables although α and β are depth-dependent and will vary slightly from iteration to iteration.
We may replace each differential equation with a difference equation:

Ι · dy = f ( y) d lnζ xxxx Ιm+1/2 · (ym+1ym) = fm+1/2 Δlnζ,

where the subscript m+1/2 indicates the value of the function halfway between m and m+1, usually taken as the average of the values at m and m+1.

The transcontinental railroad method (my nomenclature)
When these equations were first solved numerically either by hand or on mechanical desk calculators, the prefered process was to assume values of the unknown variables at the two boundaries, and integrate outward from the center and inward from the surface with the intention of matching the solutions at some mid-point. Let's say that the matching errors at any one iteration i are Δri, Δli, ΔPi, and ΔTi. The idea is to adjust the four unknown boundary values until all four mid-point variables are continuous.

Make small changes in each boundary value Tc, ρc, ls, rs, one at a time, and deduce the 16 partial derivatives ∂Δri /∂Tc, etc.
Then solve the four equations in four unknowns

(∂Δri /∂Tc) δTc + (∂Δri /∂ρc) δρc + (∂Δri /∂ls) δls + (∂Δri /∂rs) δTs = −Δri ,
etc.

for the corrections δTc, etc. to apply to the boundary values in order to get a better solution. Iterate as needed. How many grad students on how many calculators will it take to solve this problem in a finite time?

Newton-Raphson iteration
With fast and accurate computers, the prefered method now (which allows for obscure and difficult contributions to the transfer coefficients) is Newton-Raphson iteration. Interiors astronomers call it the Henyey method after Louis Henyey, the first to apply it to structural problems. Atmospheres astronomers call it complete linearization, using a term popularized by Dimitri Mihalas. The idea is to start with some guestimate solution (e.g. a polytrope or a model for a similar star) and calculate corrections throughout the model that bring one closer to a true solution.

Begin by replacing every variable yj;m with (yj;m + δyj;m), where in this new form yj;m is the present iteration value and δyj;m is the correction required to reach the true solution. Also write the vector elements fj;m as the first order expansion fj;m [1 + ∑ k (∂ln fj;m /∂yk) δyk;m]. As an example, the f-element ( − ζ M ε /l ) becomes

f2;m xx (− ζm M εm /lm ) (1 + λ δlnρm + ν δlnTm − δlnlm )

where λ and ν are the power exponents for ρ and T, respectively, of the energy generation ε (now one sees why we use power laws). Equation j may now be written

k Ιj,k;m+1/2 (yk;m+1 + δyk;m+1yk;m − δyk;m) =
0.5 { fj;m+1 [1 + ∑ k (∂ln fj;m+1 /∂yk) δyk;m+1] + fj;m [1 + ∑ k (∂ln fj;m /∂yk) δyk;m]} Δlnζ

Collect all δy terms on the left and all known terms on the right, and express in vector form:

Ιm+1/2 · (δym+1δym) − 0.5 (Fm+1 · δym+1 + Fm · δym) Δlnζ = fm+1/2 ΔlnζΙm+1/2 · (ym+1ym) .

Here the matrices Fm contain the 16 fj;m ∂ln fj;m /∂yk values. Notice that the right-hand side consists of the inhomogeneous error source terms, and reduces to zero (one hopes) at iteration convergence. The left-hand side consists of only linear terms containing the desired corrections δym.

We have one such vector equation for each depth point. In total, there are 4×M linear equations in that many unknowns, where M is the number of depths. With today's computers, it is not dificult to do a direct inversion of a 1000×1000 matrix, so we could solve this set by brute force for a model containing up to 200-300 depths. However, in so doing we would be accomplishing a large number of multiplications of zero times zero. We can be much more elegant, doing only those calculations which are necessary.

First, split the vector equation into two parts depending on the location of the boundary conditions. For j = 1,2, write the difference equation for depth m over m and m+1 as above. At depth m = M, replace the difference equation with the boundary conditions δln rM = 0 and δln lM = 0, since we already know the values of r and l here. (Note that ln(0) is a pretty big negative number; one will need to end the model just short of the center and assume negligible but non-zero values for r and l.) For j = 3,4, write the difference equation for depth m over m and m−1. At depth m = 1, replace the difference equation with the boundary conditions δln ρ1 = 0 and δln T1 = 0, since we already know the values of ρ and T here. (With similar caveats on logarithmic values.) Then the "brute force matrix" of variable coefficients that we need to invert looks like:
Non-zero elements are blue (equations j = 1,2) and green (equations j = 3,4). The pink elements are zero, but fill out elements still necessary for the computation. This kind of matrix is called block tri-diagonal, and many mathematics packages have routines for inverting such matrices. It pictures a series of linear equations that may be written

Am · δym−1 + Bm · δymCm · δym+1 = qm ,

where Am, Bm, and Cm are 4×4 matrices and qm is the 4-vector of errors at depth m.

Assume a recursion relation

δym−1 = Dm · δym + pm

and substitute into the ABCq equation:

Am · (Dm · δym + pm) + Bm · δymCm · δym+1 = qm .

Now solve for δym:

δym = (BmAm · Dm)−1 (Cm · δym+1 + Am · pm + qm).

By comparison with the recursion relation above, we may write:

Dm+1 = (BmAm · Dm)−1 Cm,
pm+1 = (BmAm · Dm)−1 (qm + Am · pm).

The numerical solution then proceeds thusly: starting at m = 1 (where Am = 0) begin sequentially storing the recursion coefficients Dm+1 and pm+1 (we will not need D1 and p1). At m = M, the ABCq equation looks like the recursion relation:

AM · δyM−1 + BM · δyM = qM
AM · δyM−1 + AM · DM · δyM = − AM · pM .

Subtract these two equations and solve for δyM:

δyM = (BMAM · DM)−1 (qM + AM · pM)

Now we may back-substitute through the recursion relation using the stored coefficients, and we are done. Iterate as necessary.

While the Henyey method may seem much more computationally intensive than the transcontinental railroad method (and it is), it is much more robust. There are situations where very small changes in the 'unknown' boundary values result in very large (even infinite) fluctuations at some pre-determined matching boundary. Also, the TCR method does not handle discontinuities in X and ρ very well, since it doesn't 'know' what to expect on the other side. Radiative-convective boundaries present a similar though less severe problem. In the Henyey method, each grid-point is 'aware' of all the other grid points through the accumulation of the recursion coefficients.

Time integration
As long as dynamic terms are small, we may assume a sequence of hydrostatic models. The lagrangian acceleration d 2r/dt 2 = − 4π r 2P/∂mg. At some point in the aging process no sequential hydrostatic model will satisfy the relation d 2r/dt 2 << g for all levels. An equivalent check is dr/dt << vsound. Pulsation may be setting in, high luminosity may be driving rapid mass loss, the core may be initiating catastophic collapse, etc. Prior to that point, hydrostatic aging still implicitly involves time through the evolution of X, and may explicitly involve time through the expansion/contraction term in the luminosity equation.

For nuclear evolution, one only need advance the aging with time steps that match the changing concentrations of interest. The forward integration usually may proceed explicitly; that is, future times may be calculated from present and recent past times. For example,
Xj,n = Xj,n−1 + Δt dXj /dt |n−1 + 0.5 Δt (dXj /dt |n−1dXj /dt |n−2).

Nuclear evolution is accompanied by structural change, through the change in mean molecular weight/particle number.

Implicit formulae
Implicit time integration makes use of data at the time step being calculated, and is more robust than explicit integration for the same reason that Newton-Raphson methods are more robust than the TCR method. Consider the energy equation with the expansion/contraction term:

dl = (εnuc + εgrav) dm = [εnucP (d lnP/dt − Γ1 d lnρ/dt) /ρ3 − 1)] dm .

Expressing the time terms in difference form (we will leave it to the reader to follow through with the space differencing)

dln = {εnuc;nPn [(lnPn − lnPn−1) /Δt − Γ1;n (lnρn − lnρn−1) /Δt] /ρn3;n − 1)} dm .

Terms on the right hand side are all understood functions of our state variables at time iteration n, except for some added known information from n−1.

Notice that iteration n−1 data enters only through the explicit time difference quantities lnPn−1 and lnρn−1 (and the values of Xj,n necessary to determine εnuc;n). All other coefficients and terms including dln are evaluated at interation n. This notation is referred to as backward differencing. One might think that greater accuracy would be acheived if we used some form of centered differencing; i.e. if we wrote all the subscript-n factors as the average of values at n and n−1. The result would still be a straightforward equation for variables at n, although there would be more 'constant' terms from n−1. In practice, however, the simpler backward difference form is used because it quickly damps out small fluctuations arising from numerical instabilities.

Dynamic aging
In one-dimensional calculations (spherical symmetry) dynamic terms enter the equation of motion (what used to be hydrostatic equilibrium) when sequential 'hydrostatic' models no longer meet the conditions of static equilibrium. We will not discuss these terms further here.