# Simulating a Black Hole!

Black holes are among the most difficult to understand objects in the universe, but the main defining feature of black holes -- that objects inside a certain distance from them will never escape -- is something that isn't too hard to demonstrate if we take the slingshot with gravity activity and make one crucial change: objects can only be launched up to some maximum speed. As you can probably guess, that maximum speed is the speed of light. In real life that speed would be $3 \cdot 10^8 \, m/s$ but in our code we don't absolutely have to use this value and in the Slingshot with Gravity activity, we didn't actually use $G = 6.67 \cdot 10^{-11}$ for the gravitational constant. To make sure the strength of gravity wasn't crazy weak or crazy strong in our simulation, we chose G = 100. Likewise we will choose c = 50 for the speed of light. The reason for doing this is that in STEMcoding we assume that the 750x500 pixel sketch is actually 750 meters x 500 meters in extent. In order to see interesting stuff on that scale we have to make gravity stronger, and we need to slow down the speed of light so we can actually see what's going on.

Play around with this code! If you look closely at the behavior you will notice a key difference between this code and the slignshot with gravity code. In both versions you can click and drag (or touch and drag) to launch a projectile. The longer you drag, the larger velocity that it will be launched. But unlike the slinghshot with gravity version, the initial speed is limited to 50. So if you click and drag the velocity arrow too long, the program will make it shorter but in that same direction. This is not noticable unless you drag the arrow across most of the screen and let go, but it is definitely happening. (If I had more time I would configure the program to limit the length of the arrow before you let go and launch the object.)

By limiting the speed that the object can be launched, we of course limit the ability for the object to get away from the massive object (a.k.a. black hole) and within a certain radius one finds that objects launched at the max speed will never escape to very far distances away from the massive object. The program assumes a mass of 3 for the object in question, but this remains true for light (which would be mass of zero). I would not recommend changing the mass in the program to zero, because it would produce divide by zero errors, but if you change it to mass of 1 and 0.1 and 0.01 you will find that the program gives exactly the same behavior.

The program as it exists is a bit of a hack, because it is simulating Newtonian gravity (as we did to demonstrate that $1/r^2$ forces produce elliptical orbits in slingshot with gravity) but we have approximated relativity (a.k.a nothing can travel faster than the speed of light) by putting a cap on the max initial speed. We can use this to demonstrate that this cap prevents objects within a certain radius from escaping the black hole, but there are lots of relativity things that this code doesn't include. For example, if you launch an object from far away towards the black hole at the max speed, the black hole would speed it up even further. If we were talking about a real object in the universe, the black hole would only be able to increase the speed of the object from, say, 99% of the speed of light to 99.9% of the speed of light. And if it was a flashlight you're shining into a black hole, not even a black hole can make light travel faster than the speed of light, if that makes any sense. But if we're launching things from close to the black hole outward, then the speed is always less than or equal to what the launch speed so the fact that our code isn't sophisticated enough to prevent things from moving faster than the speed of light then this is not a big deal and it turns out that the radius where things can't escape in our simulation is the same as what you would expect from a more sophisticated model.

As we will show in just a second, the radius that things moving at the speed of light cannot escape a black hole is given by this equation: $$R = \frac{2 G M}{c^2}$$

where $G$ is the gravitational constant, $M$ is the mass of the black hole and $c$ is the speed of light. $R$ is the "event horizon" of the black hole. The name "event horizon" means that information about any "events" that occur within this radius can never get communicated to people who are much further away from the black hole. It is essentially the radius where you can no longer post to twitter. You can still read twitter no problem if someone is kind enough to broadcast a signal into the black hole, but your posting and re-tweeting days will be over.

This radius is marked on the simulation and the initial position of the object is set (x = 445, 250) to be just INSIDE this radius. So it gets launched at high speeds, but it can't quite get away from the gravitational field of the black hole and it turns around. You can modify the code to set the initial position for example to be (x = 460, y = 250) which is just outside the radius and you will notice that the object can move very far away from the black hole and never really turn around.

The thing I like about this code is that the only place where $2 GM/c^2$ shows up is where we tell the program to draw a circle. There is no if statement that checks whether or not the initial distance from the black hole is less than this radius in order to apply a different algorithm for each case. Instead, this boundary naturally emerges because we are calculating the velocities, acceleration and change of position of the object correctly (mic drop!).

Simulating this system correctly means a variety of things, and it means that total energy should be conserved in the system. $$KE + PE = E_{\rm tot}$$

As usual the kinetic energy is $KE = (1/2)m v^2$, and because our object is in a gravitational field this means $PE = - G Mm / r$ so we get $$\frac{1}{2} m v^2 - \frac{G M m}{r} = E_{\rm tot}$$

Let's say that the object does move very far away from the black hole. This would imply that $r \approx \infty$ and $G M m/\infty = 0$ so we would be left with $$KE - 0 = E_{\rm tot}$$

Since the kinetic energy is always positive (because $m > 0$ and $v^2 > 0$), this means the total energy ($E_{\rm tot}$) is positive if the object is able to get infinitely far away from the black hole.

If the object can't get infinitely far away from the black hole then the opposite is true: $E_{\rm tot}$ would be negative and the object would be "bound" to the black hole.

So let's figure out how much velocity we would need to just barely escape the black hole. Set $E_{\rm tot} = 0$ and solve for $v$. $$\frac{1}{2} m v^2 - \frac{ GM m }{r} = 0$$ $$v^2 = \frac{G Mm / r}{(1/2)m} = \frac{2 G M} { r}$$ $$v = \sqrt{\frac{2 G M }{r}}$$

This velocity is called the "escape velocity". If you use the mass and radius of the earth you get something like 11.2 km/s for how fast you have to be moving to escape the earth's gravity and move very far away from it (in other words not be "bound" to the earth's gravity).

But we also know from relativity that the universe has a maximum speed limit, which is the speed of light. If we are standing on some kind of dense planet or star with a large mass and a small radius, there are situations where the escape velocity would exceed the speed of light and even if you shined a flashlight from the surface of this planet would the light be able to get away. Exactly how high it would go before turning around is something you can try to calculate, but it's definitely not getting large distances away from the place you are standing. You can try this out in the code but launching objects radially away from the black hole instead of tangential to it. You will indeed find that objects launched from inside a certain radius never escape. This turns out to be true even for light and in the expression above, the mass of the object cancelled out, which is good because the mass of a particle of light is zero.

So we could set $v = c$ in the equation above (where $c$ is the speed of light) and if we knew how large this super-dense planet or star we're standing on was, we could figure out how massive this planet would have to be before not even light rays can escape. Or we can say that we know the mass of the object, but we want to know at what radius ($r$) we would be too close to its center for light to get out. This latter scenario is the one most relevant to our code. Let's go ahead and solve for $r$ then assuming $v = c$ $$c = \sqrt{\frac{2 G M}{r}}$$ $$c^2 = \frac{2 G M}{r}$$ $$r = \frac{2 G M}{c^2}$$

There you have it! The Schwarzchild radius, a.k.a. event horizon, of the black hole.

Aside: Schwarzchild was the first person to derive this formula (and he did it the complicated relativity way but it turned out to be the same as the Newtonian way which I just showed you). Initially, Schwarzchild thought that this was the radius that space and time broke down some how (think: end of 2001 a space odyessy or the end of Interstellar). Only later did Lemaitre and students working with Oppenheimer realize that in fact, no, this is not where space-time breaks down. It's just the boundary between where things can and can't escape. You can see this in running the program. Nothing dramatic happens at this radius, it's just the dividing line between objects that can and can't escape if they are launched at the speed of light.

In closing, it is worth emphasizing again that the code is not explictly making sure this radius is where this transition occurs. Instead, the code is iterating the velocities, accelerations and position of the object over time. It does this well enough that energy is conserved as it should be, and because energy is conserved, the dynamics agree with this consideration from energy conservation.

This is still a long way from the cool-looking simulations people have done of the black hole at the center of the galaxy, but this is at least part of the way there!