From 474cde379b91b82d58b0c40f0581b4afea8be828 Mon Sep 17 00:00:00 2001 From: Ronan Arraes Jardim Chagas Date: Wed, 19 Jun 2024 03:57:02 -0300 Subject: [PATCH] :wrench: Improve simultaneously init and prop Our tests indicate that we have no need to define custom functions to simultaneously initialize and propagate. We can use the API functions with virtually no penalty. --- src/API.md | 12 ------- src/api/Propagators.jl | 14 ++++++-- src/api/j2.jl | 34 ------------------- src/api/j2osc.jl | 34 ------------------- src/api/j4.jl | 35 -------------------- src/api/j4osc.jl | 35 -------------------- src/api/sgp4.jl | 75 ------------------------------------------ src/api/twobody.jl | 34 ------------------- 8 files changed, 11 insertions(+), 262 deletions(-) diff --git a/src/API.md b/src/API.md index f9612d3..26b6425 100644 --- a/src/API.md +++ b/src/API.md @@ -180,18 +180,6 @@ Propagators.name(orbp) to return its name. The system uses this information to display the object using the function `show`. If the function is not provided, the structure name is used by default. -### Simultaneous Initialization and Propagation (Optional) - -If the propagator supports, it can overload the functions: - -```julia -Propagators.propagate(t, args...; kwargs...) -``` - -that simultaneously initialize and propagate the orbit to the instant `t` [s] after the -input elements. `args...` and `kwargs...` must be the same as in the initialization function -`Propagators.init`. - ### Fitting Mean Elements (Optional) The propagator can implement the following functions to fit a set of osculating state diff --git a/src/api/Propagators.jl b/src/api/Propagators.jl index bca81e7..61e190d 100644 --- a/src/api/Propagators.jl +++ b/src/api/Propagators.jl @@ -111,21 +111,29 @@ structure name is used: `typeof(orbp) |> string`. name(orbp::OrbitPropagator) = typeof(orbp) |> string """ - propagate(::Val{:propagator}, Δt::Number, args...; kwargs...) + propagate(::Val{:propagator}, Δt::Number, args...; kwargs...) -> SVector{3, T}, SVector{3, T}, OrbitPropagator Initialize the orbit `propagator` and propagate the orbit by `t` [s] from the initial orbit epoch. The initialization arguments `args...` and `kwargs...` 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). + # Returns - `SVector{3, T}`: Position vector [m] represented in the inertial frame at propagation instant. - `SVector{3, T}`: Velocity vector [m / s] represented in the inertial frame at propagation instant. -- [`OrbitPropagator`](@ref): Structure with the initialized parameters. +- [`OrbitPropagator{Tepoch, T}`](@ref): Structure with the initialized propagator. """ -function propagate end +function propagate(prop, Δt::Number, args...; kwargs...) + orbp = Propagators.init(prop, args...; kwargs...) + r_i, v_i = Propagators.propagate!(orbp, Δt) + return r_i, v_i, orbp +end """ propagate!(orbp::OrbitPropagator{Tepoch, T}, t::Number) where {Tepoch, T} -> SVector{3, T}, SVector{3, T} diff --git a/src/api/j2.jl b/src/api/j2.jl index 61baf3a..9156a27 100644 --- a/src/api/j2.jl +++ b/src/api/j2.jl @@ -171,40 +171,6 @@ function Propagators.init!(orbp::OrbitPropagatorJ2, orb₀::KeplerianElements) return nothing end -""" - Propagators.propagate(Val(:J2), Δt::Number, orb₀::KeplerianElements; kwargs...) -> SVector{3, T}, SVector{3, T}, OrbitPropagatorJ2 - -Initialize the J2 propagator structure using the input elements `orb₀` [SI units] and -propagate the orbit until the time Δt [s]. - -!!! note - - The type used in the propagation will be the same as used to define the constants in the - structure `j2c`. - -# Keywords - -- `j2c::J2PropagatorConstants{T}`: J2 orbit propagator constants (see - [`J2PropagatorConstants`](@ref)). (**Default** = `j2c_egm2008`) - -# Returns - -- `SVector{3, T}`: Position vector [m] represented in the inertial frame at propagation - instant. -- `SVector{3, T}`: Velocity vector [m / s] represented in the inertial frame at propagation - instant. -- [`OrbitPropagatorJ2`](@ref): Structure with the initialized parameters. -""" -function Propagators.propagate( - ::Val{:J2}, - Δt::Number, - orb₀::KeplerianElements; - j2c::J2PropagatorConstants = j2c_egm2008 -) - r_i, v_i, j2d = j2(Δt, orb₀; j2c = j2c) - return r_i, v_i, OrbitPropagatorJ2(j2d) -end - function Propagators.propagate!(orbp::OrbitPropagatorJ2, t::Number) # Auxiliary variables. j2d = orbp.j2d diff --git a/src/api/j2osc.jl b/src/api/j2osc.jl index 60d24be..e62ae7b 100644 --- a/src/api/j2osc.jl +++ b/src/api/j2osc.jl @@ -171,40 +171,6 @@ function Propagators.init!(orbp::OrbitPropagatorJ2Osculating, orb₀::KeplerianE return nothing end -""" - Propagators.propagate(Val(:J2osc), Δt::Number, orb₀::KeplerianElements; kwargs...) -> SVector{3, T}, SVector{3, T}, OrbitPropagatorJ2Osculating - -Initialize the J2 osculating propagator structure using the input elements `orb₀` [SI units] -and propagate the orbit until the time Δt [s]. - -!!! note - - The type used in the propagation will be the same as used to define the constants in the - structure `j2c`. - -# Keywords - -- `j2c::J2PropagatorConstants{T}`: J2 orbit propagator constants (see - [`J2PropagatorConstants`](@ref)). (**Default** = `j2c_egm2008`) - -# Returns - -- `SVector{3, T}`: Position vector [m] represented in the inertial frame at propagation - instant. -- `SVector{3, T}`: Velocity vector [m / s] represented in the inertial frame at propagation - instant. -- [`OrbitPropagatorJ2Osculating`](@ref): Structure with the initialized parameters. -""" -function Propagators.propagate( - ::Val{:J2osc}, - Δt::Number, - orb₀::KeplerianElements; - j2c::J2PropagatorConstants = j2c_egm2008 -) - r_i, v_i, j2oscd = j2osc(Δt, orb₀; j2c = j2c) - return r_i, v_i, OrbitPropagatorJ2Osculating(j2oscd) -end - function Propagators.propagate!(orbp::OrbitPropagatorJ2Osculating, t::Number) # Auxiliary variables. j2oscd = orbp.j2oscd diff --git a/src/api/j4.jl b/src/api/j4.jl index 4890883..8f9150c 100644 --- a/src/api/j4.jl +++ b/src/api/j4.jl @@ -172,41 +172,6 @@ function Propagators.init!(orbp::OrbitPropagatorJ4, orb₀::KeplerianElements) return nothing end -""" - Propagators.propagate(Val(:J4), Δt::Number, orb₀::KeplerianElements; kwargs...) -> SVector{3, T}, SVector{3, T}, OrbitPropagatorJ4 - -Initialize the J4 propagator structure using the input elements `orb₀` and propagate the -orbit until the time Δt [s]. - -!!! note - - The type used in the propagation will be the same as used to define the constants in the - structure `j4c`. - -# Keywords - -- `j4c::J4PropagatorConstants{T}`: J4 orbit propagator constants (see - [`J4PropagatorConstants`](@ref)). - (**Default** = `j4c_egm2008`) - -# Returns - -- `SVector{3, T}`: Position vector [m] represented in the inertial frame at propagation - instant. -- `SVector{3, T}`: Velocity vector [m / s] represented in the inertial frame at propagation - instant. -- [`OrbitPropagatorJ4`](@ref): Structure with the initialized parameters. -""" -function Propagators.propagate( - ::Val{:J4}, - Δt::Number, - orb₀::KeplerianElements; - j4c::J4PropagatorConstants = j4c_egm2008 -) - r_i, v_i, j4d = j4(Δt, orb₀; j4c = j4c) - return r_i, v_i, OrbitPropagatorJ4(j4d) -end - function Propagators.propagate!(orbp::OrbitPropagatorJ4, t::Number) # Auxiliary variables. j4d = orbp.j4d diff --git a/src/api/j4osc.jl b/src/api/j4osc.jl index b186208..b7fe0cb 100644 --- a/src/api/j4osc.jl +++ b/src/api/j4osc.jl @@ -174,41 +174,6 @@ function Propagators.init!(orbp::OrbitPropagatorJ4Osculating, orb₀::KeplerianE return nothing end -""" - Propagators.propagate(Val(:J4osc), Δt::Number, orb₀::KeplerianElements; kwargs...) -> SVector{3, T}, SVector{3, T}, OrbitPropagatorJ4Osculating - -Initialize the J4 osculating propagator structure using the input elements `orb₀` and -propagate the orbit until the time Δt [s]. - -!!! note - - The type used in the propagation will be the same as used to define the constants in the - structure `j4c`. - -# Keywords - -- `j4c::J4PropagatorConstants{T}`: J4 orbit propagator constants (see - [`J4PropagatorConstants`](@ref)). - (**Default** = `j4c_egm2008`) - -# Returns - -- `SVector{3, T}`: Position vector [m] represented in the inertial frame at propagation - instant. -- `SVector{3, T}`: Velocity vector [m / s] represented in the inertial frame at propagation - instant. -- [`OrbitPropagatorJ4Osculating`](@ref): Structure with the initialized parameters. -""" -function Propagators.propagate( - ::Val{:J4osc}, - Δt::Number, - orb₀::KeplerianElements; - j4c::J4PropagatorConstants = j4c_egm2008 -) - r_i, v_i, j4oscd = j4osc(Δt, orb₀; j4c = j4c) - return r_i, v_i, OrbitPropagatorJ4Osculating(j4oscd) -end - function Propagators.propagate!(orbp::OrbitPropagatorJ4Osculating, t::Number) # Auxiliary variables. j4oscd = orbp.j4oscd diff --git a/src/api/sgp4.jl b/src/api/sgp4.jl index 2654c9d..bcf98f7 100644 --- a/src/api/sgp4.jl +++ b/src/api/sgp4.jl @@ -377,81 +377,6 @@ function Propagators.init!( return nothing end -""" - Propagators.propagate(Val(:SGP4), Δt::Number, epoch::Number, n₀::Number, e₀::Number, i₀::Number, Ω₀::Number, ω₀::Number, M₀::Number, bstar::Number; kwargs...) - Propagators.propagate(Val(:SGP4), Δt::Number, tle::TLE; kwargs...) - -Initialize the SGP4 propagator structure using the input arguments and propagate the orbit -until the time Δt [s]. - -!!! note - - The type used in the propagation will be the same as used to define the constants in the - structure `sgp4c`. - -# Arguments - -- `epoch::Number`: Epoch of the orbital elements [Julian Day]. -- `n₀::Number`: SGP type "mean" mean motion at epoch [rad/s]. -- `e₀::Number`: "Mean" eccentricity at epoch. -- `i₀::Number`: "Mean" inclination at epoch [rad]. -- `Ω₀::Number`: "Mean" longitude of the ascending node at epoch [rad]. -- `ω₀::Number`: "Mean" argument of perigee at epoch [rad]. -- `M₀::Number`: "Mean" mean anomaly at epoch [rad]. -- `bstar::Number`: Drag parameter (B*). -- `tle::TLE`: Two-line elements used for the initialization. - -# Keywords - -- `sgp4c::Sgp4Constants{T}`: SGP4 orbit propagator constants (see `Sgp4Constants`). - (**Default** = `sgp4c_wgs84`) - -# Returns - -- `SVector{3, T}`: Position vector [m] represented in the inertial frame at propagation - instant. -- `SVector{3, T}`: Velocity vector [m / s] represented in the inertial frame at propagation - instant. -- [`OrbitPropagatorSgp4`](@ref): Structure with the initialized parameters. -""" -function Propagators.propagate( - ::Val{:SGP4}, - Δt::Number, - tle::TLE; - sgp4c::Sgp4Constants = sgp4c_wgs84 -) - r_i, v_i, sgp4d = sgp4(Δt / 60, tle; sgp4c = sgp4c) - return 1000r_i, 1000v_i, OrbitPropagatorSgp4(sgp4d) -end - -function Propagators.propagate( - ::Val{:SGP4}, - Δt::Number, - epoch::Number, - n₀::Number, - e₀::Number, - i₀::Number, - Ω₀::Number, - ω₀::Number, - M₀::Number, - bstar::Number; - sgp4c::Sgp4Constants = sgp4c_wgs84 -) - r_i, v_i, sgp4d = sgp4( - Δt / 60, - epoch, - 60n₀, - e₀, - i₀, - Ω₀, - ω₀, - M₀, - bstar; - sgp4c = sgp4c - ) - return 1000r_i, 1000v_i, OrbitPropagatorSgp4(sgp4d) -end - function Propagators.propagate!(orbp::OrbitPropagatorSgp4, t::Number) # Auxiliary variables. sgp4d = orbp.sgp4d diff --git a/src/api/twobody.jl b/src/api/twobody.jl index 71ef05e..d1b7ff0 100644 --- a/src/api/twobody.jl +++ b/src/api/twobody.jl @@ -50,40 +50,6 @@ function Propagators.init!(orbp::OrbitPropagatorTwoBody, orb₀::KeplerianElemen return nothing end -""" - Propagators.propagate(Val(:TwoBody), Δt::Number, orb₀::KeplerianElements; kwargs...) -> SVector{3, T}, SVector{3, T}, OrbitPropagatorTwoBody - -Initialize the two-body propagator structure using the input elements `orb₀` and propagate -the orbit until the time Δt [s]. - -!!! note - - The type used in the propagation will be the same as used to define the gravitational - constant `m0`. - -# Keywords - -- `m0::T`: Standard gravitational parameter of the central body [m³ / s²]. - (**Default** = `tbc_m0`) - -# Returns - -- `SVector{3, T}`: Position vector [m] represented in the inertial frame at propagation - instant. -- `SVector{3, T}`: Velocity vector [m / s] represented in the inertial frame at propagation - instant. -- [`OrbitPropagatorTwoBody`](@ref): Structure with the initialized parameters. -""" -function Propagators.propagate( - ::Val{:TwoBody}, - Δt::Number, - orb₀::KeplerianElements; - m0::Number = tbc_m0 -) - r_i, v_i, tbd = twobody(Δt, orb₀; m0 = m0) - return r_i, v_i, OrbitPropagatorTwoBody(tbd) -end - function Propagators.propagate!(orbp::OrbitPropagatorTwoBody, t::Number) # Auxiliary variables. tbd = orbp.tbd