NLP seems to be doing pretty well
This commit is contained in:
@@ -1,36 +1,48 @@
|
||||
@testset "Phase" begin
|
||||
|
||||
using PlotlyJS: savefig
|
||||
|
||||
println("Testing NLP solver")
|
||||
|
||||
# We'll start by testing the mission_guess -> vector function
|
||||
vec = Vector(test_mg)
|
||||
@test typeof(vec) == Vector{Float64}
|
||||
|
||||
# Now we go in the other direction
|
||||
flybys = [ p.planet for p in test_mg.phases ]
|
||||
guess = Mission_Guess(vec, test_mg.sc, test_mg.start_mass, flybys)
|
||||
@test typeof(guess) == Mission_Guess
|
||||
@test guess.sc == test_mg.sc
|
||||
@test guess.start_mass == test_mg.start_mass
|
||||
@test guess.launch_date == test_mg.launch_date
|
||||
@test guess.launch_v∞ == test_mg.launch_v∞
|
||||
@test guess.converged == test_mg.converged
|
||||
for i in 1:length(guess.phases)
|
||||
@test guess.phases[i].planet == test_mg.phases[i].planet
|
||||
@test guess.phases[i].v∞_in == test_mg.phases[i].v∞_in
|
||||
@test guess.phases[i].v∞_out == test_mg.phases[i].v∞_out
|
||||
@test guess.phases[i].tof == test_mg.phases[i].tof
|
||||
@test guess.phases[i].thrust_profile == test_mg.phases[i].thrust_profile
|
||||
end
|
||||
|
||||
# Now we test an example run of the basic "inner function"
|
||||
# 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)]
|
||||
latest_arrival = DateTime(1993,6,1)
|
||||
leave, arrive = DateTime(1992,11,19), DateTime(1993,4,1)
|
||||
test_leave = DateTime(1992,11,12)
|
||||
earth_state = state(Earth, leave)
|
||||
venus_state = state(Venus, arrive)
|
||||
v∞_out, v∞_in, tof = Thesis.lamberts(Earth, Venus, leave, arrive)
|
||||
phase = Phase(Venus, v∞_in, v∞_in, tof, zeros(20,3))
|
||||
guess = Mission_Guess(bepi, 12_000., leave, v∞_out, [phase])
|
||||
g = solve_mission(guess)
|
||||
println(g)
|
||||
# We can get the thrust profile and tof pretty wrong and still be ok
|
||||
phase = Phase(Venus, 1.1v∞_in, v∞_in, 0.9*tof, 0.1*ones(20,3))
|
||||
guess = Mission_Guess(bepi, 12_000., test_leave, 0.9*v∞_out, [phase])
|
||||
m = solve_mission(guess, launch_window, latest_arrival, verbose=true)
|
||||
@test typeof(m) == Mission
|
||||
@test m.converged == true
|
||||
|
||||
# Now we can plot the results to check visually
|
||||
p = plot(m, title="NLP Test Solution")
|
||||
savefig(p,"../plots/nlp_test_1_phase.html")
|
||||
|
||||
# Now we can look at a more complicated trajectory
|
||||
flybys = [Earth, Venus, Mars]
|
||||
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}()
|
||||
launch_v∞, _, tof1 = Thesis.lamberts(flybys[1], flybys[2], dates[1], dates[2])
|
||||
println(launch_v∞)
|
||||
for i in 1:length(dates)-2
|
||||
v∞_out1, v∞_in1, tof1 = Thesis.lamberts(flybys[i], flybys[i+1], dates[i], dates[i+1])
|
||||
v∞_out2, v∞_in2, tof2 = Thesis.lamberts(flybys[i+1], flybys[i+2], dates[i+1], dates[i+2])
|
||||
push!(phases, Phase(flybys[i+1], v∞_in1, v∞_out2, tof1, 0.01*ones(20,3)))
|
||||
end
|
||||
v∞_out, v∞_in, tof = Thesis.lamberts(flybys[end-1], flybys[end], dates[end-1], dates[end])
|
||||
push!(phases, Phase(flybys[end], v∞_in, v∞_in, tof, 0.01*ones(20,3)))
|
||||
# This isn't quite right. V∞ discrepancy is too big
|
||||
guess = Mission_Guess(bepi, 12_000., dates[1], launch_v∞, phases)
|
||||
m = solve_mission(guess, launch_window, latest_arrival, verbose=true)
|
||||
p = plot(m, title="NLP Test Solution (2 Phases)")
|
||||
savefig(p,"../plots/nlp_test_2_phase.html")
|
||||
|
||||
end
|
||||
|
||||
@@ -2,34 +2,55 @@
|
||||
|
||||
println("Testing plotting features")
|
||||
|
||||
using PlotlyJS
|
||||
using PlotlyJS: savefig, SyncPlot
|
||||
|
||||
# Plot an earth plot
|
||||
T = rand(2hour : 1 : 4hour)
|
||||
revs = 30
|
||||
n = revs*100
|
||||
|
||||
start = gen_orbit(T, 12_000., Earth)
|
||||
thrust = spiral(0.9, n, start, test_sc, revs*T, Earth)
|
||||
path = prop(thrust, start, test_sc, revs*T, Earth)[1]
|
||||
|
||||
p = plot_orbits([path], Earth)
|
||||
savefig(p,"../plots/plot_test_earth.html")
|
||||
@test typeof(p) == PlotlyJS.SyncPlot
|
||||
|
||||
# Now change a little bit and plot around the Sun
|
||||
# This also checks that the spacecraft are configured right:
|
||||
# They really shouldn't run out of fuel in 4 years
|
||||
# Generate a couple of useful paths
|
||||
T = rand(year : hour : 4year)
|
||||
tof = 4year
|
||||
n = 4_000
|
||||
start = gen_orbit(T, 12_000.)
|
||||
thrust = spiral(0.9, n, start, bepi, tof)
|
||||
sun_paths = Vector{Vector{Vector{Float64}}}()
|
||||
push!(sun_paths, prop(zeros(100,3), start, bepi, tof)[1])
|
||||
push!(sun_paths, prop(thrust, start, bepi, tof)[1])
|
||||
p = plot_orbits(sun_paths)
|
||||
savefig(p,"../plots/plot_test_sun.html")
|
||||
@test typeof(p) == PlotlyJS.SyncPlot
|
||||
spiral_path = prop(thrust, start, bepi, tof)[1]
|
||||
no_thrust_path = prop(zeros(n,3), start, bepi, tof)[1]
|
||||
paths = [ spiral_path, no_thrust_path ]
|
||||
|
||||
# First let's plot a single basic path
|
||||
p = plot(spiral_path)
|
||||
savefig(p,"../plots/plot_test_path.html")
|
||||
@test typeof(p) == SyncPlot
|
||||
|
||||
# Next I just want to plot a planet both not moving...
|
||||
p = plot(Jupiter, Dates.now(), title="Jupiter")
|
||||
savefig(p,"../plots/plot_test_planet_nomove.html")
|
||||
@test typeof(p) == SyncPlot
|
||||
|
||||
# ...and moving
|
||||
p = plot(Venus, Dates.now(), 0.95period(Venus), title="Venus")
|
||||
savefig(p,"../plots/plot_test_planet_move.html")
|
||||
@test typeof(p) == SyncPlot
|
||||
|
||||
# Next I want to plot the entire solar system
|
||||
p = plot([Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto],
|
||||
Dates.now(),
|
||||
title="The Solar System")
|
||||
savefig(p,"../plots/plot_test_solar_system.html")
|
||||
@test typeof(p) == SyncPlot
|
||||
|
||||
# Next I want to plot a vector of states
|
||||
p = plot(paths,
|
||||
labels = ["No Thrust Orbit","Thrust Spiral"],
|
||||
title = "Vector of Paths Plot Test")
|
||||
savefig(p,"../plots/plot_test_paths.html")
|
||||
@test typeof(p) == SyncPlot
|
||||
|
||||
# And finally, I'd like to plot a mission guess...
|
||||
p = plot(test_mg)
|
||||
savefig(p,"../plots/plot_test_mission_guess.html")
|
||||
@test typeof(p) == SyncPlot
|
||||
|
||||
# ...and a mission
|
||||
p = plot(Mission(test_mg))
|
||||
savefig(p,"../plots/plot_test_mission.html")
|
||||
@test typeof(p) == SyncPlot
|
||||
|
||||
end
|
||||
|
||||
@@ -14,9 +14,9 @@ catch
|
||||
end
|
||||
|
||||
@testset "All Tests" begin
|
||||
# include("plotting.jl")
|
||||
# include("inner_loop/laguerre-conway.jl")
|
||||
# include("inner_loop/propagator.jl")
|
||||
include("plotting.jl")
|
||||
include("inner_loop/laguerre-conway.jl")
|
||||
include("inner_loop/propagator.jl")
|
||||
include("inner_loop/nlp_solver.jl")
|
||||
# include("inner_loop/monotonic_basin_hopping.jl")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user