Currently working on refactor, much work to do

This commit is contained in:
Connor
2021-09-25 16:10:02 -06:00
parent 7d0037f38d
commit af545ba1a7
23 changed files with 286 additions and 353 deletions

View File

@@ -1,50 +0,0 @@
@testset "Find Closest" begin
println("Testing NLP solver")
using NLsolve, PlotlyJS
# 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 = 5T
n = 200
# A simple orbit raising
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,
prop_time,
μs["Earth"])
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 converge
Tx, Ty, Tz = conv_T(repeat([0.89], n), repeat([0.], n), repeat([0.], n),
start,
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 result.converged
path1 = prop(zeros((100,3)), start, sc, μs["Earth"], T)[1]
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, 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 result.converged
@test norm(calc_final[1:6] - final[1:6]) < 1e-4
end
end

View File

@@ -5,26 +5,29 @@
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"])
μ = Earth.μ
for T in rand(3600*1.5:3600*4, 5)
e = rand(0.0:0.01:0.75)
i = rand(0.0:0.01:0.499π)
start = [ oe_to_xyz([ (μ*(T/(2π))^2)^(1/3), e, i, 0., 0., 1. ], μ); 12_000. ]
orbit = start
for _ in 1:5
i = 0.
while i < T
orbit = laguerre_conway(orbit, μs["Earth"], 1.)
orbit = laguerre_conway(orbit, 1., Earth)
i += 1
end
@test i T
@test norm(orbit - start) < 1e-2
@test norm(orbit[1:6] - start[1:6]) < 1e-2
end
for _ in 1:5
i = 0.
while i > -T
orbit = laguerre_conway(orbit, μs["Earth"], -1.)
orbit = laguerre_conway(orbit, -1., Earth)
i -= 1
end
@test i -T
@test norm(orbit - start) < 1e-2
@test norm(orbit[1:6] - start[1:6]) < 1e-2
end
end

View File

@@ -0,0 +1,39 @@
@testset "Phase" begin
println("Testing NLP solver")
using NLsolve, PlotlyJS
# Initial Setup
T = rand( 2hour : second : 12hour)
revs = 5
n = 10revs
start_mass = 12_000.
# A simple orbit raising
start = gen_orbit(T, start_mass, Earth)
thrust = spiral(0.9, n, start, test_sc, revs*T, Earth)
final = prop(thrust, start, test_sc, revs*T, Earth)[2]
new_T = 2π * ( xyz_to_oe(final, Earth.μ)[1]^3 / Earth.μ )
# This should be close enough to converge
thrust_guess = spiral(0.88, n, start, test_sc, revs*T, Earth)
result = solve_phase(start, final, test_sc, revs*T, thrust_guess, Earth)
calc_path, calc_final = prop(result.zero, start, test_sc, revs*T, Earth)
# Test
@test converged(result)
@test norm(calc_final[1:6] - final[1:6]) < 1e-5
# Plot
paths = Pathlist()
push!(paths, prop(start, T, Earth),
calc_path,
prop(calc_final, T, Earth),
prop(final, T, Earth) )
fig = plot_orbits(paths, Earth,
labels=["init", "transit", "post-transit", "final"],
colors=["#FFF","#F44","#4F4","#44F"])
savefig(fig, "../plots/nlp_test.html")
end

View File

@@ -6,26 +6,19 @@
# Set up
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)
start = gen_orbit(rand(.5year : hour : 2year), start_mass)
stepsize = rand(hour : second : 6hour)
# Test that Laguerre-Conway is the default propagator for spacecrafts
craft = Sc("no_thrust")
state = prop_one([0., 0., 0.], start, craft, μs["Earth"], stepsize)
@test laguerre_conway(start, μs["Earth"], stepsize) state[1:6]
state = prop_one([0., 0., 0.], start, no_thrust, stepsize)
@test laguerre_conway(start, stepsize) state[1:6]
@test state[7] == start_mass
# Test that mass is reduced properly
craft = Sc("test")
state = prop_one([1., 0., 0.], start, craft, μs["Earth"], stepsize)
@test state[7] == start_mass - craft.mass_flow_rate*stepsize
state = prop_one([1., 0., 0.], start, bepi, stepsize)
@test state[7] == start_mass - bepi.mass_flow_rate*stepsize
# Test that a bad ΔV throws an error
@test_throws ErrorException prop_one([1.5, 0., 0.], start, craft, μs["Earth"], stepsize)
@test_throws Thesis.PropOne_Error prop_one([1.5, 0., 0.], start, bepi, stepsize)
end