Ok, now open loop is working, sc mass changed to state, and other updates
This commit is contained in:
@@ -6,45 +6,45 @@
|
||||
|
||||
# Initial Setup
|
||||
sc = Sc("test")
|
||||
fresh_sc = copy(sc)
|
||||
a = rand(25000:1.:40000)
|
||||
e = rand(0.01:0.01:0.05)
|
||||
i = rand(0.01:0.01:π/6)
|
||||
T = 2π*√(a^3/μs["Earth"])
|
||||
prop_time = T
|
||||
n = 10
|
||||
prop_time = 5T
|
||||
n = 200
|
||||
|
||||
# A simple orbit raising
|
||||
start = oe_to_xyz([ a, e, i, 0., 0., 0. ], μs["Earth"])
|
||||
Tx, Ty, Tz = conv_T(repeat([0.6], n), repeat([0.], n), repeat([0.], n),
|
||||
start_mass = 10_000.
|
||||
start = [ oe_to_xyz([ a, e, i, 0., 0., 0. ], μs["Earth"]); start_mass ]
|
||||
Tx, Ty, Tz = conv_T(repeat([0.9], n), repeat([0.], n), repeat([0.], n),
|
||||
start,
|
||||
sc.mass,
|
||||
sc,
|
||||
prop_time,
|
||||
μs["Earth"])
|
||||
final = prop(hcat(Tx, Ty, Tz), start, sc, μs["Earth"], prop_time)[3]
|
||||
final = prop(hcat(Tx, Ty, Tz), start, copy(sc), μs["Earth"], prop_time)[2]
|
||||
new_T = 2π*√(xyz_to_oe(final, μs["Earth"])[1]^3/μs["Earth"])
|
||||
|
||||
# This should be close enough to 0.6 for convergence
|
||||
Tx, Ty, Tz = conv_T(repeat([0.59], n), repeat([0.01], n), repeat([0.], n),
|
||||
# This should be close enough to converge
|
||||
Tx, Ty, Tz = conv_T(repeat([0.89], n), repeat([0.], n), repeat([0.], n),
|
||||
start,
|
||||
sc.mass,
|
||||
sc,
|
||||
prop_time,
|
||||
μs["Earth"])
|
||||
result = nlp_solve(start, final, sc, μs["Earth"], 0.0, prop_time, hcat(Tx, Ty, Tz))
|
||||
|
||||
# Test and plot
|
||||
@test converged(result)
|
||||
@test result.converged
|
||||
path1 = prop(zeros((100,3)), start, sc, μs["Earth"], T)[1]
|
||||
path2, mass, calc_final = prop(tanh.(result.zero), start, sc, μs["Earth"], prop_time)
|
||||
path2, calc_final = prop(result.zero, start, sc, μs["Earth"], prop_time)
|
||||
path3 = prop(zeros((100,3)), calc_final, sc, μs["Earth"], new_T)[1]
|
||||
path4 = prop(zeros((100,3)), final, sc, μs["Earth"], new_T)[1]
|
||||
path4 = prop(zeros((100,3)), final, fresh_sc, μs["Earth"], new_T)[1]
|
||||
savefig(plot_orbits([path1, path2, path3, path4],
|
||||
labels=["initial", "transit", "after transit", "final"],
|
||||
colors=["#FFFFFF","#FF4444","#44FF44","#4444FF"]),
|
||||
"../plots/find_closest_test.html")
|
||||
if converged(result)
|
||||
@test norm(calc_final - final) < 1e-4
|
||||
if result.converged
|
||||
@test norm(calc_final[1:6] - final[1:6]) < 1e-4
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,28 +2,73 @@
|
||||
|
||||
println("Testing Inner Loop")
|
||||
|
||||
using Dates
|
||||
using Dates, SPICE, PlotlyJS
|
||||
|
||||
sc = Sc("test")
|
||||
|
||||
phase1 = Phase("Earth",
|
||||
"Mars",
|
||||
3600*24*365*1.85,
|
||||
[1., 0.3, 0.],
|
||||
[3., 3., 0.])
|
||||
launch_date = DateTime(2016,3,28)
|
||||
launch_j2000 = utc2et(Dates.format(launch_date,"yyyy-mm-ddTHH:MM:SS"))
|
||||
leg1_tof = 3600*24*30*10.75
|
||||
leg2_tof = 3600*24*365*5.5
|
||||
v∞s = [ [0.34251772594197877, -2.7344726708862477, -1.1854707164631975],
|
||||
[-1.1, -3., -2.6],
|
||||
[3.5, 3.5, √(5^2 - 2*3.5^2)],
|
||||
[0.3, 1., 0.] ]
|
||||
p1 = "Mars"
|
||||
p2 = "Saturn"
|
||||
start_mass = 10_000.
|
||||
|
||||
phase2 = Phase("Mars",
|
||||
"Jupiter",
|
||||
3600*24*365*3.5,
|
||||
[2., 3.7416573867739413, 0.],
|
||||
[0.3, 1., 0.])
|
||||
phase1 = Phase("Earth", p1, leg1_tof, v∞s[1], v∞s[2])
|
||||
phase2 = Phase(p1, p2, leg2_tof, v∞s[3], v∞s[4])
|
||||
|
||||
result = inner_loop(DateTime(2024,3,5),
|
||||
sc,
|
||||
[phase1, phase2],
|
||||
verbose=true,
|
||||
mbh_specs=(5,50,100))
|
||||
# For finding the best trajectories
|
||||
earth_state = [spkssb(Thesis.ids["Earth"], launch_j2000, "J2000"); start_mass]
|
||||
p1_state = [spkssb(Thesis.ids[p1], launch_j2000+leg1_tof, "J2000"); start_mass]
|
||||
p2_state = [spkssb(Thesis.ids[p2], launch_j2000+leg1_tof+leg2_tof, "J2000"); start_mass]
|
||||
earth = prop(zeros(100,3), earth_state, sc, μs["Sun"], 3600*24*365.)[1]
|
||||
p1_path = prop(zeros(100,3), p1_state, sc, μs["Sun"], 3600*24*365*2.)[1]
|
||||
p2_path = prop(zeros(100,3), p2_state, sc, μs["Sun"], 3600*24*365*8.)[1]
|
||||
leg1, leg1_final = prop(zeros(400,3),
|
||||
earth_state+[zeros(3);v∞s[1];start_mass],
|
||||
copy(sc),
|
||||
μs["Sun"],
|
||||
leg1_tof)
|
||||
leg2, leg2_final = prop(zeros(400,3),
|
||||
p1_state+[zeros(3);v∞s[3];start_mass],
|
||||
copy(sc),
|
||||
μs["Sun"],
|
||||
leg2_tof)
|
||||
savefig(plot_orbits( [earth, p1_path, p2_path, leg1, leg2],
|
||||
primary="Sun",
|
||||
labels=["Earth", p1, p2, "Leg 1", "Leg 2"],
|
||||
title="Inner Loop without thrusting",
|
||||
colors=["#0000FF", "#FF0000", "#FFFF00", "#FF00FF", "#00FFFF"] ),
|
||||
"../plots/inner_loop_before.html")
|
||||
|
||||
@test result == "One path did not converge"
|
||||
# The first leg should be valid
|
||||
fresh_sc = copy(sc)
|
||||
mass, thrusts = inner_loop( launch_date,
|
||||
sc,
|
||||
start_mass,
|
||||
[phase1],
|
||||
verbose=true,
|
||||
mbh_specs=(25,50) )
|
||||
@test sc.mass > sc.dry_mass
|
||||
path, final = prop(thrusts[1], earth_state+[zeros(3);v∞s[1]], fresh_sc, μs["Sun"], leg1_tof)
|
||||
@test final ≈ p1_state + [zeros(3); v∞s[2]]
|
||||
savefig(plot_orbits( [earth, p1_path, path],
|
||||
primary="Sun",
|
||||
labels=["Earth", p1, "Leg 1"],
|
||||
title="Inner Loop with thrusting",
|
||||
colors=["#0000FF", "#FF0000", "#FF00FF"] ),
|
||||
"../plots/inner_loop_after.html")
|
||||
|
||||
# The second one was too hard to figure out on my own, so I'm letting it fail
|
||||
@test_throws ErrorException inner_loop( launch_date,
|
||||
sc,
|
||||
start_mass,
|
||||
[phase1, phase2],
|
||||
verbose=true,
|
||||
mbh_specs=(10,10) )
|
||||
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,37 +5,27 @@
|
||||
using Thesis: prop_one
|
||||
|
||||
# Set up
|
||||
start = oe_to_xyz([ (μs["Earth"]*(rand(3600*1.5:0.01:3600*4)/(2π))^2)^(1/3),
|
||||
rand(0.01:0.01:0.5),
|
||||
rand(0.01:0.01:0.45π),
|
||||
0.,
|
||||
0.,
|
||||
1. ], μs["Earth"])
|
||||
start_mass = 10_000.
|
||||
start = [oe_to_xyz([ (μs["Earth"]*(rand(3600*1.5:0.01:3600*4)/(2π))^2)^(1/3),
|
||||
rand(0.01:0.01:0.5),
|
||||
rand(0.01:0.01:0.45π),
|
||||
0.,
|
||||
0.,
|
||||
1. ], μs["Earth"]); start_mass]
|
||||
stepsize = rand(100.0:0.01:500.0)
|
||||
|
||||
# Test that Laguerre-Conway is the default propagator
|
||||
propped = prop_one([0., 0., 0.], start, 0., 0, 0., 1000., 0.1, μs["Earth"], stepsize)
|
||||
@test laguerre_conway(start, μs["Earth"], stepsize) ≈ propped[1]
|
||||
|
||||
# Test that Laguerre-Conway is the default propagator for spacecrafts
|
||||
craft = Sc("no_thrust")
|
||||
start_mass = craft.mass
|
||||
state, craft = prop_one([0., 0., 0.], start, craft, μs["Earth"], stepsize)
|
||||
@test laguerre_conway(start, μs["Earth"], stepsize) ≈ state
|
||||
@test craft.mass == start_mass
|
||||
state = prop_one([0., 0., 0.], start, craft, μs["Earth"], stepsize)
|
||||
@test laguerre_conway(start, μs["Earth"], stepsize) ≈ state[1:6]
|
||||
@test state[7] == start_mass
|
||||
|
||||
# Test that mass is reduced properly
|
||||
craft = Sc("test")
|
||||
start_mass = craft.mass
|
||||
state, craft = prop_one([1., 0., 0.], start, craft, μs["Earth"], stepsize)
|
||||
@test craft.mass == start_mass - craft.mass_flow_rate*stepsize
|
||||
state = prop_one([1., 0., 0.], start, craft, μs["Earth"], stepsize)
|
||||
@test state[7] == start_mass - craft.mass_flow_rate*stepsize
|
||||
|
||||
# Test that a bad ΔV throws an error
|
||||
# craft = Sc("test")
|
||||
# start_mass = craft.mass
|
||||
# @test_throws ErrorException prop_one([1.5, 0., 0.], start, craft, μs["Earth"], stepsize)
|
||||
|
||||
# Test that a full propagation doesn't take too long
|
||||
|
||||
@test_throws ErrorException prop_one([1.5, 0., 0.], start, craft, μs["Earth"], stepsize)
|
||||
|
||||
end
|
||||
|
||||
@@ -7,15 +7,16 @@
|
||||
# First some setup
|
||||
sc = Sc("test")
|
||||
T = rand(3600*2:0.01:3600*4)
|
||||
start = oe_to_xyz([ (μs["Earth"]*(T/(2π))^2)^(1/3),
|
||||
0.1,
|
||||
π/4,
|
||||
0.,
|
||||
0.,
|
||||
1. ], μs["Earth"])
|
||||
n = 100
|
||||
ΔVs = repeat([0.5, 0., 0.]', outer=(n,1))
|
||||
path = prop(ΔVs, start, sc, μs["Earth"], 3T)[1]
|
||||
start = [oe_to_xyz([ (μs["Earth"]*(T/(2π))^2)^(1/3),
|
||||
0.1,
|
||||
π/4,
|
||||
0.,
|
||||
0.,
|
||||
1. ], μs["Earth"]); 10_000.]
|
||||
revs = 30
|
||||
n = revs*100
|
||||
ΔVs = repeat([0.9, 0., 0.]', outer=(n,1))
|
||||
path = prop(ΔVs, start, copy(sc), μs["Earth"], revs*T)[1]
|
||||
p = plot_orbits([path])
|
||||
savefig(p,"../plots/plot_test.html")
|
||||
@test typeof(p) == PlotlyJS.SyncPlot
|
||||
|
||||
@@ -4,17 +4,25 @@
|
||||
|
||||
# Test that the standard spacecraft can be created
|
||||
craft = Sc("test")
|
||||
@test craft.mass == 10000.
|
||||
@test craft.mass_flow_rate == 0.01
|
||||
@test craft.max_thrust == 0.05
|
||||
@test craft.num_thrusters == 2
|
||||
@test craft.duty_cycle == 1.
|
||||
@test craft.dry_mass == 9000.
|
||||
@test craft.mass_flow_rate == craft.max_thrust/(0.00981*2000)
|
||||
@test craft.max_thrust == 0.00025
|
||||
@test craft.num_thrusters == 50
|
||||
@test craft.duty_cycle == 0.9
|
||||
|
||||
craft = Sc("no_thrust")
|
||||
@test craft.mass == 10000.
|
||||
@test craft.dry_mass == 9000.
|
||||
@test craft.mass_flow_rate == 0.01
|
||||
@test craft.max_thrust == 0.
|
||||
@test craft.num_thrusters == 0
|
||||
@test craft.duty_cycle == 0.
|
||||
|
||||
# Test that the standard spacecraft can be copied
|
||||
new_craft = copy(craft)
|
||||
@test new_craft.dry_mass == craft.dry_mass
|
||||
@test new_craft.mass_flow_rate == craft.mass_flow_rate
|
||||
@test new_craft.max_thrust == craft.max_thrust
|
||||
@test new_craft.num_thrusters == craft.num_thrusters
|
||||
@test new_craft.duty_cycle == craft.duty_cycle
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user