Slow but steady progress on the mbh

This commit is contained in:
Connor
2021-09-26 00:01:50 -06:00
parent 49eff02cd0
commit 26ddb43a5d
8 changed files with 420 additions and 191 deletions

View File

@@ -4,111 +4,42 @@
println("Testing Monotonic Basin Hopper")
# Initial Setup
# sc = Sc("test")
# a = rand(50_000:1.:100_000)
# e = rand(0.01:0.01:0.5)
# i = rand(0.01:0.01:π/6)
# T = 2π*√(a^3/μs["Earth"])
# prop_time = 0.5T
# n = 20
# start_mass = 10_000.
# # A simple orbit raising
# start = [oe_to_xyz([ a, e, i, 0., 0., 0. ], μs["Earth"]); start_mass]
# Tx, Ty, Tz = conv_T(repeat([0.8], n), repeat([0.], n), repeat([0.], n),
# start,
# sc,
# prop_time,
# μs["Earth"])
# nominal_path, final = prop(hcat(Tx, Ty, Tz), start, sc, μs["Earth"], prop_time)
# new_T = 2π*√(xyz_to_oe(final, μs["Earth"])[1]^3/μs["Earth"])
# # Find the best solution
# best, archive = mbh(start,
# final,
# sc,
# μs["Earth"],
# 0.0,
# prop_time,
# n,
# search_patience_lim=25,
# drill_patience_lim=50,
# verbose=true)
# # Test and plot
# @test best.converged
# transit, calc_final = prop(best.zero, start, sc, μs["Earth"], prop_time)
# initial_path = prop(zeros((100,3)), start, sc, μs["Earth"], T)[1]
# after_transit = prop(zeros((100,3)), calc_final, sc, μs["Earth"], new_T)[1]
# final_path = prop(zeros((100,3)), final, sc, μs["Earth"], new_T)[1]
# savefig(plot_orbits([initial_path, nominal_path, final_path],
# labels=["initial", "nominal transit", "final"],
# colors=["#FF4444","#44FF44","#4444FF"]),
# "../plots/mbh_nominal.html")
# savefig(plot_orbits([initial_path, transit, after_transit, final_path],
# labels=["initial", "transit", "after transit", "final"],
# colors=["#FFFFFF", "#FF4444","#44FF44","#4444FF"]),
# "../plots/mbh_best.html")
# i = 0
# best_mass = calc_final[end]
# nominal_mass = final[end]
# masses = []
# for candidate in archive
# @test candidate.converged
# path2, calc_final = prop(candidate.zero, start, sc, μs["Earth"], prop_time)
# push!(masses, calc_final[end])
# @test norm(calc_final[1:6] - final[1:6]) < 1e-4
# end
# @test best_mass == maximum(masses)
# # This won't always work since the test is reduced in fidelity,
# # but hopefully will usually work:
# @test (start_mass - best_mass) < 1.1 * (start_mass - nominal_mass)
# Now let's test a sun case. This should be pretty close to begin with
start_mass = 10_000.
launch_date = DateTime(2016,3,28)
launch_j2000 = utc2et(Dates.format(launch_date,"yyyy-mm-ddTHH:MM:SS"))
earth_start = [spkssb(ids["Earth"], launch_j2000, "ECLIPJ2000"); start_mass]
earth_speed = earth_start[4:6]
v∞ = 3.0*earth_speed/norm(earth_speed)
start = earth_start + [zeros(3); v∞; 0.0]
tof = 3600*24*30*10.75
mars_state = [spkssb(Thesis.ids["Mars"], launch_j2000+tof, "ECLIPJ2000"); start_mass]
final = mars_state + [ zeros(3); [-1.1, -3., -2.6]; 0.0 ]
a = xyz_to_oe(final, μs["Sun"])[1]
T = 2π*(a^3/μs["Sun"])
n = 20
# First we test the random mission guess generator
flybys = [Earth, Venus, Jupiter]
launch_window = ( DateTime(2021,12,25), DateTime(2025,12,25) )
max_C3 = 10.
max_v∞ = 8.
latest_arrival = DateTime(2035,12,25)
random_guess = Thesis.mission_guess(flybys, bepi, 12_000., launch_window, max_C3, max_v∞, latest_arrival)
@test typeof(random_guess) == Mission_Guess
# But we'll plot to see
beginning_path = prop(zeros(100,3), start, Sc("test"), μs["Sun"], tof)[1]
ending_path = prop(zeros(100,3), final, Sc("test"), μs["Sun"], T)[1]
savefig(plot_orbits([beginning_path, ending_path],
labels=["initial", "ending"],
colors=["#F2F", "#2F2"]),
"../plots/mbh_sun_initial.html")
# Now we solve and plot the new case
best, archive = mbh(start,
final,
Sc("test"),
μs["Sun"],
0.0,
tof,
n,
search_patience_lim=25,
drill_patience_lim=50,
verbose=true)
solved_path, solved_state = prop(best.zero, start, Sc("test"), μs["Sun"], tof)
ending_path = prop(zeros(100,3), final, Sc("test"), μs["Sun"], T)[1]
savefig(plot_orbits([solved_path, ending_path],
labels=["best", "ending"],
colors=["#C2F", "#2F2"]),
"../plots/mbh_sun_solved.html")
# We'll just make sure that this at least converged correctly
@test norm(solved_state[1:6] - final[1:6]) < 1e-4
# Then the perturb function
mission_guess = Thesis.perturb(test_mission)
@test mission_guess.launch_date != test_mission.launch_date
@test mission_guess.launch_v∞ != test_mission.launch_v∞
for i in 1:2
@test mission_guess.phases[i].v∞_in != test_mission.phases[i].v∞_in
@test mission_guess.phases[i].δ != test_mission.phases[i].δ
@test mission_guess.phases[i].tof != test_mission.phases[i].tof
end
@test !mission_guess.converged
# # Then the inner loop builder function
mission = Thesis.inner_loop_solve(test_mission_guess)
@test !mission.converged
# For the valid case we need to use a lambert's solver
# TODO: This is probably not acceptable for how close I have to be
leave = DateTime(1992,11,19)
arrive = DateTime(1993,4,1)
time_leave = utc2et(Dates.format(leave,"yyyy-mm-ddTHH:MM:SS"))
time_arrive = utc2et(Dates.format(arrive,"yyyy-mm-ddTHH:MM:SS"))
earth_state = [spkssb(Earth.id, time_leave, "ECLIPJ2000"); 0.0]
venus_state = [spkssb(Venus.id, time_arrive, "ECLIPJ2000"); 0.0]
v∞_out, v∞_in, tof = Thesis.lamberts(Earth, Venus, leave, arrive)
phase = Phase(Venus, 1.0001v∞_in, 0.2, tof, 0.0*ones(20,3))
mission_guess = Mission_Guess(bepi, 12_000., leave, v∞_out, [phase])
mission = Thesis.inner_loop_solve(mission_guess)
@test mission.converged
end

View File

@@ -4,10 +4,18 @@ using LinearAlgebra
using SPICE
using Thesis
@testset "All Tests" begin
include("plotting.jl")
include("inner_loop/laguerre-conway.jl")
include("inner_loop/propagator.jl")
include("inner_loop/phase.jl")
# include("inner_loop/monotonic_basin_hopping.jl")
try
furnsh("../../spice_files/naif0012.tls")
furnsh("../../spice_files/de430.bsp")
catch
furnsh("spice_files/naif0012.tls")
furnsh("spice_files/de430.bsp")
end
@testset "All Tests" begin
# include("plotting.jl")
# include("inner_loop/laguerre-conway.jl")
# include("inner_loop/propagator.jl")
# include("inner_loop/phase.jl")
include("inner_loop/monotonic_basin_hopping.jl")
end