Code Monkey home page Code Monkey logo

zigularity's Introduction

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.

zigularity's People

Contributors

fjebaker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.