Skip to content

Commit

Permalink
Updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
cadojo committed Sep 23, 2023
1 parent 9e46858 commit 132ca56
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 54 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@

_Common astrodynamics calculations, with units!_

> **Warning**
>
> This package is being split into constituent packages, including
> [`AstrodynamicalModels.jl`](https://github.com/cadojo/AstrodynamicalModels.jl,)
> [`AstrodynamicalModels.jl`](https://github.com/cadojo/AstrodynamicalModels.jl),
> [`AstrodynamicalSolvers.jl`](https://github.com/cadojo/AstrodynamicalModels.jl),
> and more. Eventually `GeneralAstrodynamics.jl` will be a super-package, which
> re-exports all of the functionality in its constituent packages. For now, this
> package passes tests, but is really slow. By using the constituent packages
> directly, you may find a 1000x speedup! Eventually the slow interfaces in this
> package will be replaced by the fast interfaces in the constituent packages.
> Look out for `v1.0`!
## JuliaCon Talk

Check out `GeneralAstrodynamics` in action at JuliaCon 2021! The talk
Expand Down
42 changes: 31 additions & 11 deletions art/stable.jl
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
using GeneralAstrodynamics
using DifferentialEquations, Plots

L1 = halo(EarthMoon, Az = 0.01, L=1)
L2 = halo(EarthMoon, Az = 0.01, L=2)
using Logging
debuglogger = ConsoleLogger(stderr, Logging.Debug)

with_logger(debuglogger) do
return L1 = halo(EarthMoon, Az = 0.01, L = 1)
end

# L2 = halo(EarthMoon, Az = 0.01, L = 2)

M1 = manifold(
L1...,
L1...,
duration = 1.95 * L1.period,
eps = -1e-7,
eps = -1e-7,
trajectories = 14,
direction = Val{:unstable},
)

M2 = manifold(
L2...,
L2...,
duration = 2.1 * L2.period,
eps = 1e-7,
eps = 1e-7,
trajectories = 14,
direction = Val{:unstable},
)

artsy = (;
artsy = (;
aspect_ratio = 1.0,
background = :transparent,
grid = false,
axis = nothing,
xlabel = "",
xlabel = "",
ylabel = "",
zlabel = "",
border = :none,
title = "",
dpi = 600,
)

plot(M1; vars=:XY, artsy..., palette = :seaborn_colorblind, linestyle = :solid, linewidth = 1)
plot!(M2; vars=:XY, artsy..., palette = :seaborn_colorblind, linestyle = :solid, linewidth = 1)
plot(
M1;
vars = :XY,
artsy...,
palette = :seaborn_colorblind,
linestyle = :solid,
linewidth = 1,
)
plot!(
M2;
vars = :XY,
artsy...,
palette = :seaborn_colorblind,
linestyle = :solid,
linewidth = 1,
)

let xyz = GeneralAstrodynamics.Calculations.secondary_position(massparameter(L1.orbit))
x, y, z = xyz
scatter!([x], [y]; markersize=4, label=:none, color = :black, marker = :x)
scatter!([x], [y]; markersize = 4, label = :none, color = :black, marker = :x)
end
110 changes: 67 additions & 43 deletions src/Propagation/Halos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@
"""
Returns the Monodromy Matrix for a Halo orbit.
"""
function monodromy(orbit::CR3BPOrbit, T; verify=true, reltol = 1e-14, abstol = 1e-14)
initial = Orbit(CartesianStateWithSTM(state(orbit)), system(orbit), epoch(orbit); frame=frame(orbit))
final = propagate(initial, T; reltol=reltol, abstol=abstol, save_everystep=false)[end]

function monodromy(orbit::CR3BPOrbit, T; verify = true, reltol = 1e-14, abstol = 1e-14)
initial = Orbit(
CartesianStateWithSTM(state(orbit)),
system(orbit),
epoch(orbit);
frame = frame(orbit),
)
final =
propagate(initial, T; reltol = reltol, abstol = abstol, save_everystep = false)[end]

if verify && !(state(initial)[1:6] final[1:6])
throw(ErrorException("The provided `orbit` is not periodic!"))
end

SMatrix{6,6}(final[7:end]...) |> Matrix
return SMatrix{6,6}(final[7:end]...) |> Matrix
end

"""
Returns true if a `RestrictedThreeBodySystem` is numerically periodic.
"""
function isperiodic(orbit::CR3BPOrbit, T; reltol = 1e-14, abstol = 1e-14)
final = propagate(orbit, T; reltol=reltol, abstol=abstol, save_everystep=false)[end]
return state(orbit)[1:6] final[1:6]
final =
propagate(orbit, T; reltol = reltol, abstol = abstol, save_everystep = false)[end]
return state(orbit)[1:6] final[1:6]
end


Expand Down Expand Up @@ -53,36 +60,40 @@ available online.
- [Dr. Mireles Code](http://cosweb1.fau.edu/~jmirelesjames/notes.html)
- [Rund, 2018](https://digitalcommons.calpoly.edu/theses/1853/).
"""
function halo(μ; Az=0.0, L=1, hemisphere=:northern,
tolerance=1e-8, max_iter=100,
reltol=1e-14, abstol=1e-14,
nan_on_fail = true, disable_warnings = false)

r₀, v₀, Τ = analyticalhalo(μ; Az=Az, ϕ=0.0, L=L, hemisphere=hemisphere)
r₀ = r₀[1,:]
v₀ = v₀[1,:]
τ = Τ/2
function halo(
μ;
Az = 0.0,
L = 1,
hemisphere = :northern,
tolerance = 1e-8,
max_iter = 100,
reltol = 1e-14,
abstol = 1e-14,
nan_on_fail = true,
disable_warnings = false,
)

r₀, v₀, Τ = analyticalhalo(μ; Az = Az, ϕ = 0.0, L = L, hemisphere = hemisphere)
r₀ = r₀[1, :]
v₀ = v₀[1, :]
τ = Τ / 2
δu = Vector{typeof(τ)}(undef, 6)
Id = Matrix(I(6))

for i 1:max_iter

problem = ODEProblem(
CR3BPFunction(; stm=true),
vcat(r₀, v₀, Id...),
(0.0, τ),
(μ,)
)
problem =
ODEProblem(CR3BPFunction(; stm = true), vcat(r₀, v₀, Id...), (0.0, τ), (μ,))

retcode, rₛ, vₛ, Φ = let
sols = solve(problem, Vern9(); reltol=reltol, abstol=abstol)
final = sols.u[end]
retcode, rₛ, vₛ, Φ = let
sols = solve(problem, Vern9(); reltol = reltol, abstol = abstol)
final = sols.u[end]
sols.retcode, final[1:3], final[4:6], SMatrix{6,6}(final[7:end]...)
end

CR3BPFunction()(δu, vcat(rₛ, vₛ), (μ,), NaN)
∂vₛ = δu[4:6]

# All code in this `if, else, end` block is ported from
# Dr. Mireles' MATLAB code, which is available on his
# website: http://cosweb1.fau.edu/~jmirelesjames/notes.html.
Expand All @@ -91,36 +102,44 @@ function halo(μ; Az=0.0, L=1, hemisphere=:northern,
# http://cosweb1.fau.edu/~jmirelesjames/hw5Notes.pdf
if Az 0
F = @SMatrix [
Φ[4,1] Φ[4,5] ∂vₛ[1];
Φ[6,1] Φ[6,5] ∂vₛ[3];
Φ[2,1] Φ[2,5] vₛ[2]
Φ[4, 1] Φ[4, 5] ∂vₛ[1]
Φ[6, 1] Φ[6, 5] ∂vₛ[3]
Φ[2, 1] Φ[2, 5] vₛ[2]
]

xᵪ = SVector(r₀[1], v₀[2], τ) - inv(F) * SVector(vₛ[1], vₛ[3], rₛ[2])
correction = -1 * (inv(F) * SVector(vₛ[1], vₛ[3], rₛ[2]))
@debug "Differential Correction: $correction"

xᵪ = SVector(r₀[1], v₀[2], τ) + correction

r₀[1] = xᵪ[1]
v₀[2] = xᵪ[2]
τ = xᵪ[3]
τ = xᵪ[3]
else
F = @SMatrix [
Φ[4,3] Φ[4,5] ∂vₛ[1];
Φ[6,3] Φ[6,5] ∂vₛ[3];
Φ[2,3] Φ[2,5] vₛ[2]
Φ[4, 3] Φ[4, 5] ∂vₛ[1]
Φ[6, 3] Φ[6, 5] ∂vₛ[3]
Φ[2, 3] Φ[2, 5] vₛ[2]
]

xᵪ = SVector(r₀[3], v₀[2], τ) - inv(F) * SVector(vₛ[1], vₛ[3], rₛ[2])
correction = -1 * (inv(F) * SVector(vₛ[1], vₛ[3], rₛ[2]))
@debug "Differential Correction: $correction"

xᵪ = SVector(r₀[3], v₀[2], τ) + correction

r₀[3] = xᵪ[1]
v₀[2] = xᵪ[2]
τ = xᵪ[3]
τ = xᵪ[3]
end

if abs(vₛ[1]) tolerance && abs(vₛ[3]) tolerance
break;
break
elseif τ > 5 * one(τ)
error("Unreasonably large halo period, , ending iterations.")
elseif i == max_iter
error("Desired tolerance was not reached, and iterations have hit the maximum number of iterations: $max_iter.")
error(
"Desired tolerance was not reached, and iterations have hit the maximum number of iterations: $max_iter.",
)
end
end

Expand All @@ -132,14 +151,19 @@ end
A `halo` wrapper! Returns a `CircularRestrictedThreeBodyOrbit`.
Returns a tuple: `halo_orbit, halo_period`.
"""
function halo(sys::CR3BPParameters, epoch=TAIEpoch(now()); Az=0.0, kwargs...)
function halo(sys::CR3BPParameters, epoch = TAIEpoch(now()); Az = 0.0, kwargs...)

if Az isa Unitful.Length
Az = Az / lengthunit(sys)
end

r,v,T = halo(massparameter(sys); Az = Az, kwargs...)
cart = CartesianState(vcat(r,v); lengthunit=lengthunit(sys), timeunit=timeunit(sys), angularunit=angularunit(sys))
r, v, T = halo(massparameter(sys); Az = Az, kwargs...)
cart = CartesianState(
vcat(r, v);
lengthunit = lengthunit(sys),
timeunit = timeunit(sys),
angularunit = angularunit(sys),
)
orbit = Orbit(cart, sys)
return (; orbit=orbit, period=T)
return (; orbit = orbit, period = T)
end

0 comments on commit 132ca56

Please sign in to comment.