4

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
  • 28,229
  • 41
  • 68
  • 131
Kid A
  • 176
  • 2
    Consider to spell out acronym. – Qmechanic Apr 19 '23 at 23:53
  • TOV stands for Tolman Oppenheimer and Volkoff: https://en.wikipedia.org/wiki/Tolman%E2%80%93Oppenheimer%E2%80%93Volkoff_equation Related: https://physics.stackexchange.com/q/69953/226902 and https://physics.stackexchange.com/q/680628/226902 – Quillo Apr 20 '23 at 00:14
  • 1
    Isn't that dm/dr = 4πρ r² ? – KP99 Apr 20 '23 at 00:44
  • 3
    What's wrong with using standard RK4 methods for this coupled problem? – Kyle Kanos Apr 20 '23 at 01:36
  • @KyleKanos I was tempted to say the same thing... but I am not so sure anymore. We can't naively integrate from r=0 because we don't know the density at the center (yet). We can't integrate from the outer radius because we don't know the total mass. Is that what the OP is asking? Am I missing something? – FlatterMann Apr 20 '23 at 01:53
  • 2
    Not sure why this was considered a homework like question. That many important equations can only be solved numerically is a fact. Is that off-topic? Where should people ask questions about numerical methods in physics? Math SE? – FlatterMann Apr 20 '23 at 07:12
  • @KyleKanos Nothings wrong with that I just need to know $d\rho/dr$ based on the equation of state $P(\rho)$ and I am asking if my approach is correct. – Kid A Apr 20 '23 at 07:39
  • @FlatterMann I don't have any homework regarding this subject tbh, this is just for fun. – Kid A Apr 20 '23 at 07:49
  • 2
    @FlatterMann sadly, there seem to be several people on this site who are under the mistaken impression that comp-physics type questions are off-topic. I am nominating this for re-opening because it shouldn't have been closed in the first place, since it seems to be following the expected rules in the comp-phys tag info. – Kyle Kanos Apr 20 '23 at 12:23
  • @KyleKanos Understood. Thanks for supporting this question. I would like to hear the solution, too. I am just guessing right now. My last numerical methods class was a lifetime ago and I never had to solve a problem like that. All the numerical equations in my life were straight forward integrations. – FlatterMann Apr 20 '23 at 12:27
  • Related: https://physics.stackexchange.com/q/761948/226902, https://physics.stackexchange.com/q/774502/226902 – Quillo Aug 02 '23 at 16:46
  • @Quillo Thanks but the first question you tagged is also mine :) – Kid A Aug 11 '23 at 20:16

2 Answers2

3

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
  • 28,229
  • 41
  • 68
  • 131
  • This was really helpful and changed my mindset about the whole project. Thank you. On the other hand is there a way to inverse any function given by the user? I thought about using mathematica file that solves it and then return it into cpp. Do you think that would work? – Kid A Apr 22 '23 at 15:43
  • 2
    @KidA For any arbitrary user defined-function, the most adaptable/extensible way would be to implement a root-finding algorithm (e.g., Brent's method or Secant method) for the inverse function. – Kyle Kanos Apr 22 '23 at 18:46
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
  • 5,273
FlatterMann
  • 2,968
  • I don't think that this is the answer to my question, beside the numerical method I just asked a simple question regarding derivatvies. – Kid A Apr 20 '23 at 07:38
  • 2
    @KidA maybe you want to look in https://physics.stackexchange.com/a/679431. For static perfect fluid sphere Einstein equations become linear differential equations. Imposing EOS $p(\rho)$ means additional non-linear equation on metric coefficients. – JanG Apr 20 '23 at 08:22
  • 1
    While GR is the theory of gravitation and not matter (see https://physics.stackexchange.com/a/683771/281096) the finding of spacetime (metric) that fits to some EOS does not seem right to me. – JanG Apr 20 '23 at 08:50