Built the population member gen function

This commit is contained in:
Connor
2021-09-22 22:21:00 -06:00
parent eaae54ac59
commit 80e352059e
7 changed files with 147 additions and 63 deletions

View File

@@ -5,76 +5,78 @@
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.
# 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"])
# # 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)
# # 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)
# # 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)
# # 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, "J2000"); 1e5]
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]
final = [1.62914115303947e8, 1.33709639408102e8, 5.690490452749867e7, -16.298522963602757, 15.193294491415365, 6.154820267250081, 1.0001e8]
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