5

I am trying to solve the TOV equation with a given equation of state. So if

$$ \frac{dP}{dr} = TOV $$ and there we have $P(\rho)$ can we write: $$ \frac{d\rho}{dr} = TOV/\frac{dP}{d\rho} $$

these two with the differential mass $dm = 4\pi r^2 \rho\,dr$ should be solved simultaneously to give the right answer, am I right? And how do we in general solve these equations?

The TOV is the Tolman-Oppenheimer-Volkoff right-hand side of the equation: $$ \frac{dP(r)}{dr} = -\frac{G}{r^2} \left[ \frac{\rho(r) + P(r)}{c^2} \right] \left[ \frac{m(r)}{r} + \frac{4\pi r^3 P(r)}{c^2 m(r)} \right] \left[ 1 - \frac{2Gm(r)}{rc^2} \right]^{-1} $$

Kyle Kanos
  • 29,127
Kid A
  • 186

2 Answers2

4

Solving the TOV equations does indeed require simultaneously solving two ODEs: \begin{align} \frac{\mathrm{d}P}{\mathrm{d}r}&=TOV(P,\,\rho,\,m) \\ \frac{\mathrm{d}m}{\mathrm{d}r}&=4\pi\rho r^2 \end{align} However, this cannot be solved as-is because you have two equations and three unknowns (mass, pressure & density). Hence, you also need to make an assumption on the functional form of the equation of state (EOS), $P(\rho)$ which, assuming you have a nice, analytic function, can be invertible to find the density from the pressure (i.e., $\rho(P)$). A common function, for instance, is the polytrope ($P(\rho)=\kappa\rho^\gamma\leftrightarrow\rho=(P/\kappa)^{1/\gamma}$).
If your EOS is not nice, you may require finding the density from the pressure via root-finding (i.e., finding $\hat{\rho}$ s.t. $P_\text{input}-P(\hat{\rho})\simeq0$).

You then solve the system much the same way that FlatterMann describes. A somewhat simplified example in Python is below.

def eos(rho: float) -> float:
    """ equation of state """
    return k * pow(rho, gamma)

def inv_eos(p: float) -> float: """ inverse equation of state """ return pow(p / k, 1 / gamma)

def tov_integrate(y: ArrayLike, r: float) -> ArrayLike: """ integration of the TOV equation """ p, m = y[0], y[1] rho = inv_eos(p) dp_dr = TOV(p, m, rho) dm_dr = 4 * pi * r*2 rho return [dp_dr, dm_dr]

def integrate(rho_central: float) -> tuple """ integrate the system """ # set up r as the range [?, R] with N bins m = zeros(len(r)) p = zeros(len(r)) m[0] = 4 * pi * r[0]*2 rho_central p[0] = eos(rho_central) i, y = 0, [p[0], m[0]] while p[i] > 0 and i < N: y = rk4(tov_integrate, y, r[i], r[i+1] - r[i]) p[i+1] = y[0] m[i+1] = y[1] i += 1

return r, p, m

You may also want to save and return the densities for plotting purposes, but that could be determined using the EOS anyway.

Kyle Kanos
  • 29,127
1

I am almost certain this answer is wrong, but I don't have a numerical problem solving book at home and I couldn't find a quick solution on the internet (but I am sure there are plenty of descriptions on papers which deal with this problem) so I can only come up with my own recipe:

  1. Discretize the problem as a function of radii $r_i$
  2. Linearize the equations at each discrete radius. This should lead to a linear system of equations between the $P(r_i), \rho(r_i), m(r_i)$ and their first derivatives at each point. Use RK4 as Kyle Kanos suggested to estimate the derivatives using the neighboring values.
  3. Use a matrix solver to solve these equations or try to find the solution of the system iteratively

I am probably still missing something, but without actually doing it I can't see what it is. Good luck!

PS: I am almost certain that trying to diagonalize the difference equations is a marvelously crappy idea in terms of numerical stability and error propagation. I would bet that a numerical methods textbook will prescribe to transform the equations into integral equations, first, discretize that set before going all numerical on the discretized system.

Mauricio
  • 6,886
FlatterMann
  • 3,155