From dbf8e98545bcf48490d9a2601a7b7d299e071cbc Mon Sep 17 00:00:00 2001 From: Ronan Arraes Jardim Chagas Date: Wed, 19 Jun 2024 04:19:14 -0300 Subject: [PATCH] :sparkles: Add multithreaded simultaneous init and prop --- src/api/Propagators.jl | 32 ++++++++++++++++++++++++++++++++ test/api.jl | 18 ++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/api/Propagators.jl b/src/api/Propagators.jl index e8591f4..84fe0af 100644 --- a/src/api/Propagators.jl +++ b/src/api/Propagators.jl @@ -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} diff --git a/test/api.jl b/test/api.jl index 5cbdda1..e5a3adf 100644 --- a/test/api.jl +++ b/test/api.jl @@ -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