Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: SVector as common currency #83

Merged
merged 4 commits into from
Feb 15, 2023
Merged
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: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Gradus"
uuid = "c5b7b928-ea15-451c-ad6f-a331a0f3e4b7"
authors = ["fjebaker <[email protected]>"]
version = "0.2.3"
version = "0.2.4"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
3 changes: 3 additions & 0 deletions src/Gradus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export AbstractMetricParams,
AbstractIntegrationParameters,
IntegrationParameters

# export static arrays too
export SVector, @SVector

"""
abstract type AbstractPointFunction

Expand Down
15 changes: 2 additions & 13 deletions src/tracing/constraints.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
# vectors of vectors
function constrain_all(m::AbstractMetricParams, us, vs, μ)
function constrain_all(m::AbstractMetricParams, us::AbstractArray{<:StaticVector}, vs::AbstractArray{<:StaticVector}, μ)
@inbounds for i in eachindex(vs)
vs[i] = constrain_all(m, us[i], vs[i], μ)
end
vs
end

function constrain_all(
m::AbstractMetricParams{T},
u::AbstractVector{T},
v::AbstractVector{T},
μ,
) where {T<:Number}
v[1] = constrain(m, u, v, μ = μ)
v
end

function constrain_all(
@inline function constrain_all(
m::AbstractMetricParams{T},
u::StaticVector{S,T},
v::StaticVector{S,T},
Expand All @@ -25,7 +15,6 @@ function constrain_all(
# mut = MVector{S,T}(v)
# mut[1] = constrain(m, u, v, μ = μ)
# SVector{S,T}(mut)
#
# this results in no performance gain over the above, but i think it
# reads nicer
@inbounds SVector{S,T}(constrain(m, u, v, μ = μ), v[2], v[3], v[4])
Expand Down
6 changes: 3 additions & 3 deletions src/tracing/method-implementations/auto-diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ inv(metric)
g4 = g_comp[4],
g5 = g_comp[5]

(
SVector{5}(
(g2 * g3 * g4) / (g1 * g2 * g3 * g4 - (g5^2) * g2 * g3),
(g1 * g3 * g4 - (g5^2) * g3) / (g1 * g2 * g3 * g4 - (g5^2) * g2 * g3),
(g1 * g2 * g4 - (g5^2) * g2) / (g1 * g2 * g3 * g4 - (g5^2) * g2 * g3),
Expand Down Expand Up @@ -176,7 +176,7 @@ jacobian = (j0, j1_mat, j2_mat, j0)
v3 = v[3],
v4 = v[4]

(
SVector{4}(
-2(0.5gi5 * j14 + 0.5gi1 * j15) * v2 * v4 -
2(0.5gi1 * j11 + 0.5gi5 * j15) * v1 * v2 -
2(0.5gi1 * j21 + 0.5gi5 * j25) * v1 * v3 -
Expand Down Expand Up @@ -229,7 +229,7 @@ Limitations:
end
end

function constrain(
@inline function constrain(
m::AbstractAutoDiffStaticAxisSymmetricParams{T},
u,
v;
Expand Down
20 changes: 0 additions & 20 deletions src/tracing/tracing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,6 @@ function integrator_problem(
ODEProblem{false}(f, u_init, time_domain, IntegrationParameters(StatusCodes.NoStatus))
end

function integrator_problem(
m::AbstractMetricParams{T},
pos::AbstractVector{T},
vel::AbstractVector{T},
time_domain,
) where {T}
u_init = vcat(pos, vel)

function f!(du, u::AbstractVector{T}, p, λ) where {T}
@inbounds let x = @view(u[1:4]), v = @view(u[5:8])
dv = SVector{4,T}(geodesic_eq(m, x, v))

du[1:4] .= v
du[5:8] .= dv
end
end

ODEProblem{true}(f!, u_init, time_domain, IntegrationParameters(StatusCodes.NoStatus))
end

# single position and single velocity
function __tracegeodesics(
m::AbstractMetricParams{T},
Expand Down
13 changes: 2 additions & 11 deletions src/tracing/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@

Map impact parameters `α` and `β` to a velocity vector at some position `u` in the given metric `m`.
"""
function map_impact_parameters(
m::AbstractMetricParams{T},
u::AbstractVector{T},
α::N,
β::N,
) where {T,N<:Number}
[T(0.0), impact_parameters_to_vel(m, u, α, β)...]
end

function map_impact_parameters(
m::AbstractMetricParams{T},
u::SVector{S,T},
Expand All @@ -31,9 +22,9 @@ function map_impact_parameters(
curried.(α, β)
end

function impact_parameters_to_vel(m::AbstractMetricParams{T}, u, α, β) where {T}
@inline function impact_parameters_to_vel(m::AbstractMetricParams{T}, u, α, β) where {T}
mcomp = metric_components(m, @view(u[2:3]))
T(-1.0), -β / mcomp[3], -α / √(mcomp[3] * mcomp[4])
end

export map_impact_parameters, impact_parameters_to_vel
export map_impact_parameters
16 changes: 0 additions & 16 deletions test/smoke-tests/tracegeodesics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,6 @@ using StaticArrays
end
end

@testset "regular-arrays" begin
u = Float64[0.0, 100.0, deg2rad(85), 0.0]
# arbitrary single velocity vector
v = Float64[0.0, -1.0, -0.0, -3.5e-6]
for m in [
KerrMetric(),
JohannsenMetric(),
KerrSpacetimeFirstOrder(),
MorrisThorneWormhole(),
]
test_single(m, u, v)
test_many(m, u, v)
@test true
end
end

@testset "corona-models" begin
# only implemented for KerrMetric at the moment
# because of the vector to local sky methods
Expand Down