Skip to content

Commit

Permalink
🔧 Improve simultaneously init and prop
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ronisbr committed Jun 19, 2024
1 parent 2d4e228 commit 474cde3
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 262 deletions.
12 changes: 0 additions & 12 deletions src/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/api/Propagators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
34 changes: 0 additions & 34 deletions src/api/j2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 0 additions & 34 deletions src/api/j2osc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 0 additions & 35 deletions src/api/j4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 0 additions & 35 deletions src/api/j4osc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 0 additions & 75 deletions src/api/sgp4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 0 additions & 34 deletions src/api/twobody.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 474cde3

Please sign in to comment.