5

I am trying to solve a system of geodesics orbital equations using python. They are coupled ordinary equations. I've tried different approaches, but they all yielded me a wrong shape (the shape should be some periodic function when plotting r and phi). Any idea on how to do this? Here are my constants

G = 4.30091252525 * (pow(10, -3)) #Gravitational constant in (parsec*km^2)/(Ms*sec^2)
c = 0.0020053761 #speed of light , AU/sec
M = 170000 #mass of the central body, in solar masses
m = 10 #mass of the orbiting body, in solar masses
rs = 2 * G * M / pow(c, 2) #Schwarzschild radius
Lz= 0.000024 #Angular momemntum
h = Lz / m #Just the constant  in equation
E= 1.715488e-007 #energy

And initial conditions are:

Y(0) = rs
Phi(0) = math.pi

Orbital equations

image

The way I tried to do it:

def rhs(t, u):
    Y, phi = u
    dY = np.sqrt((E**2 / (m**2 * c**2) - (1 - rs / Y) * (c**2 + h**2 / Y**2)))
    dphi = L / Y**2
    return [dY, dphi]

Y0 = np.array([rs,math.pi])
sol = solve_ivp(rhs, [1, 1000], Y0, method='Radau', dense_output=True)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Could you add some explanations or code comments on what the variables represent and what their units are? How many periods did you expect to cover and what was the result? // You are borderline off-topic, as this is more a physics or numerics problem, thus better suited for scicomp.SE, physics.SE or math.SE. Please, if acting on this, avoid (hidden) cross-postings. – Lutz Lehmann Mar 21 '20 at 09:15
  • How did you solve the sign in the first equation? Did you make sure that the second derivative is continuous? – Lutz Lehmann Mar 21 '20 at 11:07
  • What have you tried so far? Are you aware of [scipy.integrate](https://docs.scipy.org/doc/scipy/reference/integrate.html)? – Reti43 Mar 21 '20 at 11:17
  • Updated the post with additional information and my code! For sign, I just took a square root, since it would give me part of the solution I need. And I didn't check the second derivative for continuity. How can I do that in Python? – Mikl Ivaniuk Mar 25 '20 at 23:47
  • You are mixing length units of km, AU and parsec. The units of the angular momentum and energy are not given and might also be with mixed scales. There is no reason why the numerical results should be close to some physical expectation. – Lutz Lehmann Mar 24 '21 at 09:02

1 Answers1

5

It seems like you are looking at the spacial coordinates in an invariant plane of the geodesic equations of an object moving in Schwarzschild gravity.

One can use many different methods, which preserve as much of the underlying geometric structure of the model as possible, like symplectic geometric integrators or perturbation theory. As Lutz Lehmann pointed out in the comments, the default method for 'solve_ivp' uses as default the Dormand-Prince (4)5 stepper that utilizes the extrapolation mode, that is, the order 5 step, with the step size selection driven by the error estimate of the order 4 step.

Warning: your initial condition for Y equals Schwarzschild's radius, so these equations may fail or require special treatment (especially the time component of the equations, which you have not included here!) It may be that you have to switch to different coordinates, that remove the singularity at the even horizon. Moreover, the solutions may not be periodic curves, but quasi-periodic, so they may not close up nicely.

For a quick and dirty treatment, but possibly a fairly accurate one, I would differentiate the first equation

(dr / dtau)^2 = (E2_mc2 - c2) + (2*GM)/r - (h^2)/(r^2) + (r_schw*h^2)/(r^3)

with respect to the proper time tau, then cancel out the first derivative dr / dtau with respect to r on both sides, and end up with an equation with second derivative for the radius r on the left. Then turn this second derivative equation into a pair of first derivative equations for r and its rate of change v, i.e

dphi / dtau = h / (r^2)
  dr / dtau = v
  dv / dtau = - GM / (r^2) + h^2 / (r^3) - 3*r_schw*(h^2) / (2*r^4)

and calculate from the original equation for r and its first derivative dr / dtau an initial value for the rate of change v = dr / dtau, i.e. I would solve for v the equations with r=r0:

(v0)^2 = (E2_mc2 - c2) + (2*GM)/r0 - (h^2)/(r0^2) + (r_schw*h^2)/(r0^3)

Maybe some kind of python code like this may work:

import math
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
#from ode_helpers import state_plotter

# u = [phi, Y, V, t] or if time is excluded 
# u = [phi, Y, V]
def f(tau, u, param):
    E2_mc2, c2, GM, h, r_schw = param
    Y = u[1]
    f_phi = h / (Y**2)
    f_Y = u[2] # this is the dr / dt auxiliary equation
    f_V =  - GM / (Y**2) + h**2 / (Y**3) - 3*r_schw*(h**2) / (2*Y**4)
    #f_time = (E2_mc2 * Y) / (Y - r_schw) # this is the equation of the time coordinate
    return [f_phi, f_Y, f_V] # or [f_phi, f_Y, f_V, f_time] 

# from the initial value for r = Y0 and given energy E,  
# calculate the initial rate of change dr / dtau = V0
def ivp(Y0, param, sign):
    E2_mc2, c2, GM, h, r_schw = param
    V0 = math.sqrt((E2_mc2 - c2) + (2*GM)/Y0 - (h**2)/(Y0**2) + (r_schw*h**2)/(Y0**3))
    return sign*V0

G = 4.30091252525 * (pow(10, -3)) #Gravitational constant in (parsec*km^2)/(Ms*sec^2)
c = 0.0020053761 #speed of light , AU/sec
M = 170000 #mass of the central body, in solar masses
m = 10 #mass of the orbiting body, in solar masses
Lz= 0.000024 #Angular momemntum
h = Lz / m #Just the constant  in equation
E= 1.715488e-007 #energy

c2 = c**2
E2_mc2 = (E**2) / (c2*m**2)
GM = G*M
r_schw = 2*GM / c2

param = [E2_mc2, c2, GM, h, r_schw]
Y0 = r_schw
sign = 1 # or -1
V0 = ivp(Y0, param, sign)

tau_span = np.linspace(1, 1000, num=1000)
u0 = [math.pi, Y0, V0]
    
sol = solve_ivp(lambda tau, u: f(tau, u, param), [1, 1000], u0, t_eval=tau_span)

Double check the equations, mistakes and inaccuracies are possible.

Futurologist
  • 1,874
  • 2
  • 7
  • 9
  • I've tried this, but it gave me a constant line (plotting sol.y[0] with sol.y[1]). And I wonder whether its something I did wrong. – Mikl Ivaniuk Mar 31 '20 at 23:17
  • @MiklIvaniuk As I already warned you, what I think is the problem here is the fact that your initial condition for ``r`` equals the Schwarzschild radius, where the physics changes drastically: e.g. ``r`` coordinate "turns from spacial to temporal" and the ``t`` coordinate "turns from temporal to spacial". If you carefully check, the angle ``phi`` doesn't seem to change at all. But the first value ``sol.y[1,0] = 363620079.3597036`` and last value ``sol.y[1,-1] = 363620079.4452392`` are a bit different. Why have you chosen this particular initial condition? – Futurologist Apr 01 '20 at 19:55
  • `solve_ivp` uses as default `RK45` which is the Dormand-Prince (4)5 stepper that uses the extrapolation mode, that is, the order 5 step, with the step size selection driven by the error estimate of the order 4 step. This is not the classical fixed-step RK4. – Lutz Lehmann Mar 24 '21 at 07:35
  • @LutzLehmann Thanks for the information on Python's numerical integrator! – Futurologist Mar 24 '21 at 13:36