Ok, now open loop is working, sc mass changed to state, and other updates

This commit is contained in:
Connor
2021-09-21 22:14:49 -06:00
parent 982440c976
commit eaae54ac59
16 changed files with 320 additions and 373 deletions

View File

@@ -1,28 +1,27 @@
@testset "Monotonic Basin Hopping" begin
using PlotlyJS, NLsolve
using PlotlyJS, NLsolve, Dates
println("Testing Monotonic Basin Hopper")
# Initial Setup
sc = Sc("test")
a = rand(15000:1.:40000)
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.75T
n = 10
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"])
# T_craft = hcat(repeat([0.6], n), repeat([0.], n), repeat([0.], n))
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.mass,
sc,
prop_time,
μs["Earth"])
nominal_path, normal_mass, final = prop(hcat(Tx, Ty, Tz), start, sc, μs["Earth"], prop_time)
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
@@ -33,14 +32,13 @@
0.0,
prop_time,
n,
num_iters=5,
search_patience_lim=50,
drill_patience_lim=100,
search_patience_lim=25,
drill_patience_lim=50,
verbose=true)
# Test and plot
@test converged(best)
transit, best_masses, calc_final = prop(tanh.(best.zero), start, sc, μs["Earth"], prop_time)
@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]
@@ -53,21 +51,62 @@
colors=["#FFFFFF", "#FF4444","#44FF44","#4444FF"]),
"../plots/mbh_best.html")
i = 0
best_mass = best_masses[end]
nominal_mass = normal_mass[end]
best_mass = calc_final[end]
nominal_mass = final[end]
masses = []
for candidate in archive
@test converged(candidate)
path2, cand_ms, calc_final = prop(tanh.(candidate.zero), start, sc, μs["Earth"], prop_time)
push!(masses, cand_ms[end])
@test norm(calc_final - final) < 1e-4
@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 (sc.mass - best_mass) < 1.1 * (sc.mass - nominal_mass)
@show best_mass
@show nominal_mass
@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