113 lines
4.3 KiB
Julia
113 lines
4.3 KiB
Julia
@testset "Monotonic Basin Hopping" begin
|
|
|
|
using PlotlyJS, NLsolve, Dates
|
|
|
|
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
|
|
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, "J2000"); 1e5]
|
|
earth_speed = earth_start[4:6]
|
|
v∞ = 3.0*earth_speed/norm(earth_speed)
|
|
start = earth_start + [zeros(3); v∞; 0.0]
|
|
final = [1.62914115303947e8, 1.33709639408102e8, 5.690490452749867e7, -16.298522963602757, 15.193294491415365, 6.154820267250081, 1.0001e8]
|
|
tof = 3600*24*30*10.75
|
|
a = xyz_to_oe(final, μs["Sun"])[1]
|
|
T = 2π*√(a^3/μs["Sun"])
|
|
n = 20
|
|
|
|
# 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
|
|
|
|
|
|
end
|