Skip to content

Itsy-bitsy-teeny-weeny-black-hole-visualisation-machiney.

License

Notifications You must be signed in to change notification settings

fjebaker/zigularity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zigularity

Itsy-bitsy-teeny-weeny-black-hole-visualisation-machiney

A little long weekend project: relativistic ray tracing in Zig, visualizing thin accretion discs around a Kerr black hole with a handful of configurable parameters:

  • observer position
  • disc inner and outer radius
  • black hole mass and spin
git clone https://github.com/fjebaker/zigularity
cd zigularity
zigmod fetch
zig build -Drelease-fast

Default is to try and calculate the coordinate-time of each traced photon (pixel) -- darker colours indicate things further away to give a slight semblance of three-dimensionality. The program should output something similar to this:

thin-disc-example

The program will write the output to a plain-text file "disc.data", which may be plotted with your plotting package of choice. As an example, here is a little bit of Python:

import matplotlib.pyplot as plt
import numpy as np

with open("disc.data") as f:
    data = f.read()

image = []
for line in data.split("\n"):
    row = line.split(",")[:-1]
    if row:
        image.append(row)

img = np.array(image, dtype=float)

plt.imshow(
    img.transpose(), 
    # only want to color close to the black hole
    vmin = 900, 
    vmax = 1100,
    cmap = "Greys"
)
plt.show()

It can also be used to calculate the so-called shadow of a black hole, which traces the apparent shape of the event horizon:

shadow-spinning

Or for a non-spinning black hole:

shadow-non-spinning

Todo

  • fix bad pixels bugs
  • severely clean and refactor the code
  • interpolate on integrator callback to smoothen the disc
  • (stretch) multi-threading cus it's a wee bit slow Not available on self-hosted Zig compiler yet.

Dependencies

Requires nektro/zigmod to install dependencies:

About

I write relativistic ray tracing codes as part of my research, feel free to take a look (~:

Relativistic ray-tracing is similar to regular ray-tracing, except that the trajectory of light may be altered due to the locally curved spacetime under strong gravity (see gravitional lensing). The trajectories may be traced by solving the geodesic equation -- a 2nd order ODE system which can be quite stiff -- however certain formulations of curved space permit a 1st order set of equations.

One such spacetime is the spacetime of the Kerr metric, describing a black hole with angular momentum. This metric is parameterised by a black hole mass $M$ and spin $a$, and is axis-symmetric about the spin axis and unchanging with time.

This code implements equations from Bardeen et al. (1972) and Fanton et al. (1997) to construct the 1st order equations, and integrates them using a simple adaptive Runge-Kutta algorithm.

About

Itsy-bitsy-teeny-weeny-black-hole-visualisation-machiney.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages