Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
Comrade = "99d987ce-9a1e-4df8-bc0b-1ea019aa547b"
DisplayAs = "0b91fe84-8a4c-11e9-3e1d-67c38462b6d6"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand Down
2 changes: 0 additions & 2 deletions gpu_examples/Project.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
Krang = "54806c32-d51a-438d-8447-e0041be2fbfb"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
79 changes: 29 additions & 50 deletions gpu_examples/coordinate-example-metal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,84 @@ using Metal

curr_theme = Theme(
Axis = (
xticksvisible = false,
xticksvisible = false,
xticklabelsvisible = false,
yticksvisible = false,
yticklabelsvisible = false,
aspect = 1,
),
Heatmap = (rasterize = true,),
aspect=1
),
Heatmap = (
rasterize=true,
)
)
set_theme!(merge!(curr_theme, theme_latexfonts()))

metric = Krang.Kerr(0.99f0); # Kerr metric with a spin of 0.99
θo = 45.0f0 * π / 180; # inclination angle of the observer. θo ∈ (0, π)
θo = 45f0 * π / 180; # inclination angle of the observer. θo ∈ (0, π)
sze = 400; # resolution of the screen is sze x sze
rmin = Krang.horizon(metric); # minimum radius to be ray traced
rmax = 10.0f0; # maximum radius to be ray traced
ρmax = 15.0f0; # horizontal and vertical limits of the screen
rmax = 10f0; # maximum radius to be ray traced
ρmax = 15f0; # horizontal and vertical limits of the screen

# Create Figure
fig = Figure(resolution = (700, 700));
fig = Figure(resolution=(700, 700));
axes_list = [
[
Axis(
fig[i, 1],
title = (i == 1 ? "Regularized Time" : ""),
titlesize = 20,
ylabel = (i == 1 ? L"n=0" : i == 2 ? L"n=1" : L"n=2"),
ylabelsize = 20,
),
Axis(fig[i, 2], title = (i == 1 ? "Radius" : ""), titlesize = 20),
Axis(fig[i, 3], title = (i == 1 ? "Azimuth" : ""), titlesize = 20),
] for i = 1:3
Axis(fig[i, 1], title=(i==1 ? "Regularized Time" : ""), titlesize=20, ylabel=(i==1 ? L"n=0" : i==2 ? L"n=1" : L"n=2"), ylabelsize=20),
Axis(fig[i, 2], title=(i==1 ? "Radius" : ""), titlesize=20),
Axis(fig[i, 3], title=(i==1 ? "Azimuth" : ""), titlesize=20),
] for i in 1:3
]


# Initialize Camera and Pre-Allocate Memory for data to be plotted
coordinates = (zeros(sze, sze) for _ = 1:3)
coordinates = (zeros(sze, sze) for _ in 1:3)
camera = Krang.SlowLightIntensityCamera(metric, θo, -ρmax, ρmax, -ρmax, ρmax, sze);
colormaps = (:afmhot, :afmhot, :hsv)
colorrange = ((-20, 20), (0, rmax), (0, 2π))

function coordinate_point(
pix::Krang.AbstractPixel,
geometry::Krang.ConeGeometry{T,A},
) where {T,A}
function coordinate_point(pix::Krang.AbstractPixel, geometry::Krang.ConeGeometry{T,A}) where {T, A}
n, rmin, rmax = geometry.attributes
θs = geometry.opening_angle

coords = ntuple(j -> zero(T), Val(4))

isindir = false
for _ = 1:2 # Looping over isindir this way is needed to get Metal to work
isindir = false
for _ in 1:2 # Looping over isindir this way is needed to get Metal to work
isindir ⊻= true
ts, rs, θs, ϕs = emission_coordinates(pix, geometry.opening_angle, isindir, n)
ts, rs, θs, ϕs = emission_coordinates(pix, geometry.opening_angle, isindir, n)
if rs ≤ rmin || rs ≥ rmax
continue
end
coords = (ts, rs, θs, ϕs)
end
return coords
return coords
end

θs = (75 * π / 180) # opening angle of the cone
geometry = Krang.ConeGeometry(θs, (0, rmin, rmax))
coordinate_point.(MtlArray(camera.screen.pixels), Ref(geometry))

# Draw Function
# This function draws the coordinates associated with the n=0,1,2 subimages of a cone with opening angle θs.
function draw!(axes_list, camera, coordinates, rmin, rmax, θs)
times, radii, azimuths = coordinates
times, radii, azimuths = coordinates
map(axes -> empty!.(axes), axes_list)

geometries = (Krang.ConeGeometry(θs, (i, rmin, rmax)) for i = 0:2)

geometries = (Krang.ConeGeometry(θs, (i, rmin, rmax)) for i in 0:2)
for (i, geometry) in enumerate(geometries)
rendered_scene =
Array(coordinate_point.(MtlArray(camera.screen.pixels), Ref(geometry)))
rendered_scene = Array(coordinate_point.(MtlArray(camera.screen.pixels), Ref(geometry)))
for I in CartesianIndices(rendered_scene)
times[I] = rendered_scene[I][1]
radii[I] = rendered_scene[I][2]
azimuths[I] = rendered_scene[I][4]
end
coordinates = (times, radii, mod2pi.(azimuths))
for j = 1:3
heatmap!(
axes_list[i][j],
coordinates[j],
colormap = colormaps[j],
colorrange = colorrange[j],
)
coordinates = (times, radii, mod2pi.(azimuths ))
for j in 1:3
heatmap!(axes_list[i][j], coordinates[j], colormap = colormaps[j], colorrange=colorrange[j])
end
end
end

# Create the animation of Cone of Emission Coordinates
recording = CairoMakie.record(
fig,
"coordinate.gif",
range(0.0f0, 1.0f0π, length = 180),
framerate = 12,
) do θs
recording = CairoMakie.record(fig, "coordinate.gif", range(0f0, 1f0π, length=180), framerate=12) do θs
draw!(axes_list, camera, coordinates, rmin, rmax, θs)
end

130 changes: 56 additions & 74 deletions gpu_examples/mino-time-example-metal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,101 +4,83 @@ using Metal
GLMk.Makie.inline!(true)

metric = Krang.Kerr(0.99f0); # Kerr spacetime with 0.99 spin
θo = 85.0f0 * π / 180; # Observer inclination angle with respect to spin axis
θo = 85f0 * π / 180; # Observer inclination angle with respect to spin axis
sze = 200; # Number of pixels along each axis of the screen
ρmax = 5.0f0; # Size of the screen
ρmax = 5f0; # Size of the screen

camera = Krang.SlowLightIntensityCamera(metric, θo, -ρmax, ρmax, -ρmax, ρmax, sze);

curr_theme = GLMk.Theme(# Makie theme
fontsize = 20,
Axis = (
xticksvisible = false,
xticklabelsvisible = false,
yticksvisible = false,
yticklabelsvisible = false,
leftspinevisible = false,
rightspinevisible = false,
topspinevisible = false,
bottomspinevisible = false,
titlefontsize = 30,
fontsize=20,
Axis=(
xticksvisible=false,
xticklabelsvisible=false,
yticksvisible=false,
yticklabelsvisible=false,
leftspinevisible=false,
rightspinevisible=false,
topspinevisible=false,
bottomspinevisible=false,
titlefontsize=30,
),
)

GLMk.set_theme!(GLMk.merge(curr_theme, GLMk.theme_latexfonts()))

fig = GLMk.Figure(resolution = (500, 600));

recording =
GLMk.record(fig, "raytrace.gif", range(0.1f0, 3.0f0, length = 290), framerate = 15) do τ
GLMk.empty!(fig)

coordinates = Array(
((x, τ) -> emission_coordinates(x, τ)[1:4]).(MtlArray(camera.screen.pixels), τ),
)
time = [i[1] for i in coordinates]
radius = [i[2] for i in coordinates]
inclination = [i[3] for i in coordinates]
azimuth = mod2pi.([i[4] for i in coordinates])

data = (time, radius, inclination, azimuth)
titles = (
GLMk.L"\text{Regularized Time }(t_s)",
GLMk.L"\text{Radius }(r_s)",
GLMk.L"\text{Inclination }(\theta_s)",
GLMk.L"\text{Azimuth } (\phi_s)",
fig = GLMk.Figure(resolution=(500, 600));

recording = GLMk.record(fig, "raytrace.gif", range(0.1f0, 3f0, length=290), framerate=15) do τ
GLMk.empty!(fig)

coordinates = Array(((x, τ)->emission_coordinates(x, τ)[1:4]).(MtlArray(camera.screen.pixels), τ))
time = [i[1] for i in coordinates]
radius = [i[2] for i in coordinates]
inclination = [i[3] for i in coordinates]
azimuth = mod2pi.([i[4] for i in coordinates])

data = (time, radius, inclination, azimuth)
titles = (GLMk.L"\text{Regularized Time }(t_s)", GLMk.L"\text{Radius }(r_s)", GLMk.L"\text{Inclination }(\theta_s)", GLMk.L"\text{Azimuth } (\phi_s)")
colormaps = (:afmhot, :afmhot, :afmhot, :hsv)
colorrange = ((-20, 20), (0, 10), (0,π), (0, 2π))
indices = ((1,1), ())

for i in 1:4
hm = GLMk.heatmap!(
GLMk.Axis(getindex(fig, (i > 2 ? 2 : 1), (iszero(i%2) ? 3 : 1)); aspect=1, title=titles[i]),
data[i],
colormap=colormaps[i],
colorrange=colorrange[i]
)
colormaps = (:afmhot, :afmhot, :afmhot, :hsv)
colorrange = ((-20, 20), (0, 10), (0, π), (0, 2π))
indices = ((1, 1), ())

for i = 1:4
hm = GLMk.heatmap!(
GLMk.Axis(
getindex(fig, (i > 2 ? 2 : 1), (iszero(i % 2) ? 3 : 1));
aspect = 1,
title = titles[i],
),
data[i],
colormap = colormaps[i],
colorrange = colorrange[i],
)
cb = GLMk.Colorbar(
fig[(i > 2 ? 2 : 1), (iszero(i % 2) ? 3 : 1)+1],
hm;
labelsize = 30,
ticklabelsize = 20,
)
end

ax = GLMk.Axis(fig[3, 1:3], height = 60)
GLMk.hidedecorations!(ax)
GLMk.text!(ax, 0, 100; text = GLMk.L"θ_o=%$(Int(floor(θo*180/π)))^\circ")
GLMk.rowgap!(fig.layout, 1, GLMk.Fixed(0))
cb = GLMk.Colorbar(fig[(i > 2 ? 2 : 1), (iszero(i%2) ? 3 : 1)+1], hm; labelsize=30, ticklabelsize=20)
end

ax = GLMk.Axis(fig[3, 1:3], height=60)
GLMk.hidedecorations!(ax)
GLMk.text!(ax,0,100; text=GLMk.L"θ_o=%$(Int(floor(θo*180/π)))^\circ")
GLMk.rowgap!(fig.layout, 1, GLMk.Fixed(0))
end

# ![image](raytrace.gif)

camera = Krang.SlowLightIntensityCamera(metric, θo, -3, 3, -3, 3, 4);

fig = GLMk.Figure()
ax = GLMk.Axis3(fig[1, 1], aspect = (1, 1, 1))
GLMk.xlims!(ax, (-3, 3))
GLMk.ylims!(ax, (-3, 3))
GLMk.zlims!(ax, (-3, 3))
lines_to_plot =
Krang.generate_rays(MtlArray(camera.screen.pixels), 5_000; A = MtlArray) |> Array

sphere = GLMk.Sphere(GLMk.Point(0.0, 0.0, 0.0), horizon(metric))
GLMk.mesh!(ax, sphere, color = :black) # Sphere to represent black hole

for i = 1:4
for j = 1:4
GLMk.lines!(ax, lines_to_plot[i, j, :, :])
ax = GLMk.Axis3(fig[1,1], aspect=(1,1,1))
GLMk.xlims!(ax, (-3, 3))
GLMk.ylims!(ax, (-3, 3))
GLMk.zlims!(ax, (-3, 3))
lines_to_plot = Krang.generate_rays(MtlArray(camera.screen.pixels), 5_000; A=MtlArray) |> Array

sphere = GLMk.Sphere(GLMk.Point(0.0,0.0,0.0), horizon(metric))
GLMk.mesh!(ax, sphere, color=:black) # Sphere to represent black hole

for i in 1:4;
for j in 1:4;
GLMk.lines!(ax, lines_to_plot[i,j,:,:])
end
end
fig

GLMk.save("mino_time_rays.png", fig)

# ![Photons trajectories around Kerr black hole in Boyer-Lindquist Coordinates](mino_time_rays.png)
# ![Photons trajectories around Kerr black hole in Boyer-Lindquist Coordinates](mino_time_rays.png)
2 changes: 1 addition & 1 deletion notebook_examples/mino-time-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"GLMk.ylims!(ax, (-3, 3))\n",
"GLMk.zlims!(ax, (-3, 3))\n",
"lines_to_plot = []\n",
"lines_to_plot = Krang.generate_ray_cartesian.(camera.screen.pixels, 5_000)\n",
"lines_to_plot = Krang.generate_ray.(camera.screen.pixels, 5_000)\n",
"\n",
"sphere = GLMk.Sphere(GLMk.Point(0.0,0.0,0.0), horizon(metric))\n",
"GLMk.mesh!(ax, sphere, color=:black) # Sphere to represent black hole\n",
Expand Down
2 changes: 1 addition & 1 deletion notebook_examples/raytracing-mesh-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"\n",
"GLMk.hidedecorations!(ax)\n",
"sphere = GLMk.Sphere(GLMk.Point(0.0,0.0,0.0), horizon(metric)) # Sphere to represent black hole\n",
"lines_to_plot = Krang.generate_ray_cartesian.(camera.screen.pixels, 100) # 100 is the number of steps to take along the ray\n",
"lines_to_plot = Krang.generate_ray.(camera.screen.pixels, 100) # 100 is the number of steps to take along the ray\n",
"\n",
"img = zeros(sze, sze)\n",
"recording = GLMk.record(fig, \"mesh.mp4\", 1:sze*sze, framerate=120) do i\n",
Expand Down
Loading
Loading