temporary point on the inner loop wrapper

This commit is contained in:
Connor
2021-09-02 21:40:19 -06:00
parent 4d180f577a
commit 9298a7a6f3
19 changed files with 96 additions and 23 deletions

View File

@@ -0,0 +1,50 @@
@testset "Find Closest" begin
println("Testing NLP solver")
using NLsolve, PlotlyJS
# Initial Setup
sc = Sc("test")
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
# 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,
sc.mass,
sc,
prop_time,
μs["Earth"])
final = prop(hcat(Tx, Ty, Tz), start, sc, μs["Earth"], prop_time)[3]
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),
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)
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)
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]
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
end
end

View File

@@ -0,0 +1,13 @@
@testset "Inner Loop" begin
println("Testing Inner Loop")
using Dates
phase1 = Phase("Earth", "Mars", 3600*24*365*1.5, 5., 2.)
phase2 = Phase("Mars", "Jupiter", 3600*24*365*3.5, 2., 0.1)
inner_loop(DateTime(2024,3,5), 0.3, 0.4, [phase1, phase2])
@test true
end

View File

@@ -0,0 +1,31 @@
@testset "Laguerre-Conway" begin
println("Testing LaGuerre-Conway")
using Thesis: laguerre_conway
# Test that the propagator produces good periodic orbits (forwards and backwards)
for T in rand(3600*1.5:3600*4, (5))
start = oe_to_xyz([ (μs["Earth"]*(T/(2π))^2)^(1/3), rand(0.01:0.01:0.5), rand(0.01:0.01:0.45π), 0., 0., 1. ], μs["Earth"])
orbit = start
for _ in 1:5
i = 0.
while i < T
orbit = laguerre_conway(orbit, μs["Earth"], 1.)
i += 1
end
@test i T
@test norm(orbit - start) < 1e-2
end
for _ in 1:5
i = 0.
while i > -T
orbit = laguerre_conway(orbit, μs["Earth"], -1.)
i -= 1
end
@test i -T
@test norm(orbit - start) < 1e-2
end
end
end

View File

@@ -0,0 +1,70 @@
@testset "Monotonic Basin Hopping" begin
println("Testing Monotonic Basin Hopper")
# Initial Setup
sc = Sc("test")
a = rand(15000:1.:40000)
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
# 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))
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)
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,
num_iters=5,
patience_level=50,
verbose=true)
# Test and plot
@test converged(best)
transit, best_masses, calc_final = prop(tanh.(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 = best_masses[end]
nominal_mass = normal_mass[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
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
end

View File

@@ -0,0 +1,41 @@
@testset "Propagator" begin
println("Testing propagator")
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"])
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
# 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
# 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
end