Skip to content

Commit

Permalink
✨ Add multithreaded simultaneous init and prop
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisbr committed Jun 19, 2024
1 parent e816385 commit dbf8e98
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/api/Propagators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,38 @@ function propagate(prop, Δt::Number, args...; kwargs...)
return r_i, v_i, orbp
end

"""
propagate(::Val{:propagator}, vt::AbstractVector, args...; kwargs...) -> Vector{SVector{3, T}}, Vector{SVector{3, T}}, OrbitPropagator{Tepoch, T}
Initialize the orbit `propagator` and propagate the orbit for every instant defined in `vt`
[s] from the initial orbit epoch. The initialization arguments `args...` and `kwargs...`
(except for `ntasks`) are the same as in the initialization function
[`Propagators.init`](@ref).
!!! note
`T` is the propagator number type. For more information, see [`Propagators.init`](@ref).
# Keywords
- `ntasks::Integer`: Number of parallel tasks to propagate the orbit. If it is set to a
number equal or lower than 1, the function will propagate the orbit sequentially.
(**Default** = `Threads.nthreads()`)
# Returns
- `Vector{SVector{3, T}}`: Array with the position vectors [m] in the inertial frame at each
propagation instant defined in `vt`.
- `Vector{SVector{3, T}}`: Array with the velocity vectors [m / s] in the inertial frame at
each propagation instant defined in `vt`.
- [`OrbitPropagator{Tepoch, T}`](@ref): Structure with the initialized propagator.
"""
function propagate(prop, vt::AbstractVector, args...; kwargs...)
orbp = Propagators.init(prop, args...; kwargs...)
vr_i, vv_i = Propagators.propagate!(orbp, vt)
return vr_i, vv_i, orbp
end

"""
propagate!(orbp::OrbitPropagator{Tepoch, T}, t::Number) where {Tepoch, T} -> SVector{3, T}, SVector{3, T}
Expand Down
18 changes: 18 additions & 0 deletions test/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ end
@test ret[k][1] == r[k]
@test ret[k][2] == v[k]
end

# == Simultaneous Initialization and Propagation ===============================

ret = Propagators.propagate!.(orbp, 1:1:100)
r, v, orbp = Propagators.propagate(Val(:J2), 1:1:100, orb; j2c = j2c)

@test length(r) == 100
@test length(v) == 100
@test r isa Vector{SVector{3, T}}
@test v isa Vector{SVector{3, T}}
@test orbp isa OrbitPropagatorJ2{Float64, T}
@test Propagators.last_instant(orbp) == 100.0

for k in 1:100
@test ret[k][1] == r[k]
@test ret[k][2] == v[k]
end

end
end
end
Expand Down

0 comments on commit dbf8e98

Please sign in to comment.