Fully working mbh for two phase missions!

This commit is contained in:
Connor
2021-10-11 21:53:23 -06:00
parent 504d83b390
commit a2c1aedc08
11 changed files with 106 additions and 167 deletions

View File

@@ -1,58 +1,45 @@
@testset "Monotonic Basin Hopping" begin
using PlotlyJS
using PlotlyJS: savefig
println("Testing Monotonic Basin Hopper")
# First we test the random mission guess generator
println("Testing guess generator function")
flybys = [Earth, Venus, Jupiter]
launch_window = ( DateTime(2021,12,25), DateTime(2025,12,25) )
max_C3 = 10.
max_v∞ = 8.
latest_arrival = DateTime(2030,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
# Then the perturb function
println("Testing 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].v∞_out != test_mission.phases[i].v∞_out
@test mission_guess.phases[i].tof != test_mission.phases[i].tof
"""
The cost function for the mission
"""
function easy_cost(m::Mission, C3::Float64, v∞::Float64)
norm_mass = (m.start_mass - prop(m)[7]) / m.start_mass
norm_C3 = ( m.launch_v∞ m.launch_v∞ ) / C3
norm_v∞ = norm(m.phases[end].v∞_in) / v∞
return 3norm_mass + norm_C3 + norm_v∞
end
@test !mission_guess.converged
# Mission Parameters that won't change (they're very lenient)
sc, fuel = bepi, 3_600.
c3, v∞ = 100., 20.
# Convenience function for these tests
Thesis.mbh(fbs, lw, la, sp, dp) = mbh(fbs, sc, fuel, lw, c3, v∞, la, easy_cost,
search_patience=sp, drill_patience=dp, verbose=true)
# # Then the inner loop builder function
println("Testing inner loop solver function")
mission = Thesis.inner_loop_solve(test_mg)
@test !mission.converged
# For the valid case we need to use a lambert's solver
leave, arrive = DateTime(1992,11,19), DateTime(1993,4,1)
earth_state = state(Earth, leave)
venus_state = state(Venus, arrive)
v∞_out, v∞_in, tof = Thesis.lamberts(Earth, Venus, leave, arrive)
phase = Phase(Venus, 1.01v∞_in, -1.01v∞_in, tof, 0.01*ones(20,3))
mission_guess = Mission_Guess(bepi, 12_000., leave, v∞_out, [phase])
mission = Thesis.inner_loop_solve(mission_guess)
@test mission.converged
if !mission.converged println(mission.message) end
# Now we're ready to test the whole thing!
println("Testing whole thing")
flybys = [ Earth, Venus ]
start_mass = 12_000.
launch_window = DateTime(1997, 10, 1), DateTime(1997, 10, 31)
max_C3 = 15.
max_v∞ = 20.
latest_arrival = DateTime(2001, 1, 1)
best, archive = mbh(flybys, bepi, start_mass, launch_window, max_C3, max_v∞, latest_arrival,
verbose=true)
# Again, we're going to test a simple case first
# This one seems to converge really easily, so we don't run it much
launch_window = DateTime(1992,11,1), DateTime(1992,12,1)
latest_arrival = DateTime(1993,6,1)
planets = [ Earth, Venus ]
best, archive = mbh(planets, launch_window, latest_arrival, 2, 3)
@test typeof(best) == Mission
p = plot(best, title="MBH Test Solution")
savefig(p,"../plots/mbh_test_1_phase.html")
# Now for a more complicated two-phase mission, with a bigger date range
# This is known to have a solution though
planets = [Earth, Venus, Mars]
launch_window = DateTime(2021,6,1), DateTime(2022,6,1)
latest_arrival = DateTime(2024,1,1)
best, archive = mbh(planets, launch_window, latest_arrival, 10, 3)
@test typeof(best) == Mission
p = plot(best, title="MBH Test Solution")
savefig(p,"../plots/mbh_test_2_phase.html")
end

View File

@@ -6,7 +6,7 @@
# Test the optimizer for a one-phase mission
# The lambert's solver said this should be pretty valid
launch_window = [DateTime(1992,11,1), DateTime(1992,12,1)]
launch_window = DateTime(1992,11,1), DateTime(1992,12,1)
latest_arrival = DateTime(1993,6,1)
leave, arrive = DateTime(1992,11,19), DateTime(1993,4,1)
test_leave = DateTime(1992,11,12)
@@ -25,7 +25,7 @@
# Now we can look at a slightly more complicated trajectory
flybys = [Earth, Venus, Mars]
launch_window = [DateTime(2021,10,1), DateTime(2021,12,1)]
launch_window = DateTime(2021,10,1), DateTime(2021,12,1)
latest_arrival = DateTime(2023,1,1)
dates = [DateTime(2021,11,1), DateTime(2022,3,27), DateTime(2022,8,28)]
phases = Vector{Phase}()
@@ -45,7 +45,7 @@
# Here is the final, most complicated, trajectory to test
flybys = [Earth, Venus, Earth, Mars, Earth, Jupiter]
launch_window = [DateTime(2023,1,1), DateTime(2024,1,1)]
launch_window = DateTime(2023,1,1), DateTime(2024,1,1)
latest_arrival = DateTime(2031,1,1)
dates = [DateTime(2023,5,23),
DateTime(2023,10,21),

View File

@@ -18,7 +18,4 @@
state = prop_one([1., 0., 0.], start, bepi, stepsize)
@test state[7] == start_mass - bepi.mass_flow_rate*stepsize
# Test that a bad ΔV throws an error
@test_throws Thesis.PropOne_Error prop_one([1.5, 0., 0.], start, bepi, stepsize)
end

View File

@@ -18,5 +18,5 @@ end
include("inner_loop/laguerre-conway.jl")
include("inner_loop/propagator.jl")
include("inner_loop/nlp_solver.jl")
# include("inner_loop/monotonic_basin_hopping.jl")
include("inner_loop/monotonic_basin_hopping.jl")
end