Still a lot of changes to make

This commit is contained in:
Connor
2021-09-08 11:11:00 -06:00
parent d11ad9bb13
commit e885295bd7
6 changed files with 51 additions and 18 deletions

View File

@@ -2,8 +2,13 @@ module Thesis
using LinearAlgebra, ForwardDiff, PlotlyJS, SPICE using LinearAlgebra, ForwardDiff, PlotlyJS, SPICE
furnsh("../../SPICE/naif0012.tls") try
furnsh("../../SPICE/de430.bsp") furnsh("../../SPICE/naif0012.tls")
furnsh("../../SPICE/de430.bsp")
catch
furnsh("SPICE/naif0012.tls")
furnsh("SPICE/de430.bsp")
end
include("./constants.jl") include("./constants.jl")
include("./spacecraft.jl") include("./spacecraft.jl")
@@ -16,4 +21,4 @@ module Thesis
include("./inner_loop/phase.jl") include("./inner_loop/phase.jl")
include("./inner_loop/inner_loop.jl") include("./inner_loop/inner_loop.jl")
end end

View File

@@ -7,8 +7,11 @@ This is it. The outer function call for the inner loop. After this is done,
there's only the outer loop left to do. And that's pretty easy. there's only the outer loop left to do. And that's pretty easy.
""" """
function inner_loop(launch_date::DateTime, function inner_loop(launch_date::DateTime,
craft::Sc,
phases::Vector{Phase}; phases::Vector{Phase};
min_flyby::Float64=1000.) min_flyby::Float64=1000.,
mbh_specs=nothing,
verbose=false)
# First we need to do some quick checks that the mission is well formed # First we need to do some quick checks that the mission is well formed
for i in 1:length(phases) for i in 1:length(phases)
@@ -43,14 +46,24 @@ function inner_loop(launch_date::DateTime,
end end
time = utc2et(Dates.format(launch_date,"yyyy-mm-ddTHH:MM:SS")) time = utc2et(Dates.format(launch_date,"yyyy-mm-ddTHH:MM:SS"))
thrust_profiles = []
for phase in phases for phase in phases
planet1_state = spkssb(ids[phase.from_planet], time, "J2000") planet1_state = spkssb(ids[phase.from_planet], time, "J2000")
println(planet1_state)
time += phase.time_of_flight time += phase.time_of_flight
planet2_state = spkssb(ids[phase.to_planet], time, "J2000") planet2_state = spkssb(ids[phase.to_planet], time, "J2000")
println(planet2_state) # TODO: Come up with improved method of calculating "n"
start = planet1_state + [0., 0., 0., phase.v∞_outgoing...]
final = planet2_state + [0., 0., 0., phase.v∞_incoming...]
if mbh_specs == nothing
best = mbh(start, final, craft, μs["Sun"], 0.0, phase.time_of_flight, 10,
verbose=verbose)[1]
else
best = mbh(start, final, craft, μs["Sun"], 0.0, phase.time_of_flight, 10,
verbose=verbose, num_iters=mbh_specs[1], patience_level=mbh_specs[2])[1]
end
push!(thrust_profiles, best)
craft.mass = prop(tanh.(best.zero), planet1_state, sc, μs["Sun"], prop_time)[2][end]
end end
return phases[1].v∞_incoming[1] return craft.mass, thrust_profiles
end end

View File

@@ -26,8 +26,8 @@ function mbh(start::AbstractVector,
t0::AbstractFloat, t0::AbstractFloat,
tf::AbstractFloat, tf::AbstractFloat,
n::Int; n::Int;
num_iters=50, num_iters=25,
patience_level::Int=400, patience_level::Int=200,
tol=1e-6, tol=1e-6,
verbose=false) verbose=false)
@@ -38,11 +38,18 @@ function mbh(start::AbstractVector,
while true while true
i += 1 i += 1
if verbose print("\r",i) end if verbose print("\r",i) end
# TODO: Should this be two separate "impatience" values?
impatience = 0 impatience = 0
println("HERE")
x_star = nlp_solve(start, final, craft, μ, t0, tf, new_x(n), tol=tol) x_star = nlp_solve(start, final, craft, μ, t0, tf, new_x(n), tol=tol)
while converged(x_star) == false println("THERE")
while converged(x_star) == false && impatience < patience_level
impatience += 1
x_star = nlp_solve(start, final, craft, μ, t0, tf, new_x(n), tol=tol) x_star = nlp_solve(start, final, craft, μ, t0, tf, new_x(n), tol=tol)
println(impatience)
end end
if impatience > patience_level break end
impatience = 0
if converged(x_star) if converged(x_star)
x_current = x_star x_current = x_star
while impatience < patience_level while impatience < patience_level
@@ -71,4 +78,4 @@ function mbh(start::AbstractVector,
return best, archive return best, archive
end end

View File

@@ -6,4 +6,4 @@ struct Phase
time_of_flight::Float64 # seconds time_of_flight::Float64 # seconds
v∞_outgoing::Vector{Float64} # Km/s v∞_outgoing::Vector{Float64} # Km/s
v∞_incoming::Vector{Float64} # Km/s v∞_incoming::Vector{Float64} # Km/s
end end

View File

@@ -4,6 +4,8 @@
using Dates using Dates
sc = Sc("test")
phase1 = Phase("Earth", phase1 = Phase("Earth",
"Mars", "Mars",
3600*24*365*1.5, 3600*24*365*1.5,
@@ -15,8 +17,9 @@
3600*24*365*3.5, 3600*24*365*3.5,
[2., 3.7416573867739413, 0.], [2., 3.7416573867739413, 0.],
[0.3, 1., 0.]) [0.3, 1., 0.])
inner_loop(DateTime(2024,3,5), [phase1, phase2])
inner_loop(DateTime(2024,3,5), sc, [phase1, phase2], verbose=true, mbh_specs=(5,100))
@test true @test true
end end

View File

@@ -4,8 +4,13 @@ using LinearAlgebra
using SPICE using SPICE
using Thesis using Thesis
furnsh("../../SPICE/naif0012.tls") try
furnsh("../../SPICE/de430.bsp") furnsh("../../SPICE/naif0012.tls")
furnsh("../../SPICE/de430.bsp")
catch
furnsh("SPICE/naif0012.tls")
furnsh("SPICE/de430.bsp")
end
# Tests # Tests
@testset "All Tests" begin @testset "All Tests" begin