Currently working on refactor, much work to do
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
39
julia/test/inner_loop/phase.jl
Normal file
39
julia/test/inner_loop/phase.jl
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -4,21 +4,32 @@
|
||||
|
||||
using PlotlyJS
|
||||
|
||||
# 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"]); 10_000.]
|
||||
# Plot an earth plot
|
||||
T = rand(2hour : 1 : 4hour)
|
||||
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")
|
||||
|
||||
start = gen_orbit(T, 12_000., Earth)
|
||||
thrust = spiral(0.9, n, start, test_sc, revs*T, Earth)
|
||||
path = prop(thrust, start, test_sc, revs*T, Earth)[1]
|
||||
|
||||
p = plot_orbits([path], Earth)
|
||||
savefig(p,"../plots/plot_test_earth.html")
|
||||
@test typeof(p) == PlotlyJS.SyncPlot
|
||||
|
||||
# Now change a little bit and plot around the Sun
|
||||
# This also checks that the spacecraft are configured right:
|
||||
# They really shouldn't run out of fuel in 4 years
|
||||
T = rand(year : hour : 4year)
|
||||
tof = 4year
|
||||
start = gen_orbit(T, 12_000.)
|
||||
thrust = spiral(0.9, n, start, bepi, tof)
|
||||
sun_paths = Vector{Vector{Vector{Float64}}}()
|
||||
push!(sun_paths, prop(zeros(100,3), start, bepi, tof)[1])
|
||||
push!(sun_paths, prop(thrust, start, bepi, tof)[1])
|
||||
p = plot_orbits(sun_paths)
|
||||
savefig(p,"../plots/plot_test_sun.html")
|
||||
@test typeof(p) == PlotlyJS.SyncPlot
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -4,24 +4,13 @@ using LinearAlgebra
|
||||
using SPICE
|
||||
using Thesis
|
||||
|
||||
try
|
||||
furnsh("../../SPICE/naif0012.tls")
|
||||
furnsh("../../SPICE/de430.bsp")
|
||||
catch
|
||||
furnsh("SPICE/naif0012.tls")
|
||||
furnsh("SPICE/de430.bsp")
|
||||
end
|
||||
|
||||
# Tests
|
||||
@testset "All Tests" begin
|
||||
include("spacecraft.jl")
|
||||
include("plotting.jl")
|
||||
include("inner_loop/laguerre-conway.jl")
|
||||
include("inner_loop/propagator.jl")
|
||||
include("inner_loop/find_closest.jl")
|
||||
include("inner_loop/monotonic_basin_hopping.jl")
|
||||
include("inner_loop/inner_loop.jl")
|
||||
include("outer_loop.jl")
|
||||
include("inner_loop/phase.jl")
|
||||
# include("inner_loop/monotonic_basin_hopping.jl")
|
||||
end
|
||||
|
||||
print()
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
@testset "Spacecraft Construction" begin
|
||||
|
||||
println("Testing spacecraft")
|
||||
|
||||
# Test that the standard spacecraft can be created
|
||||
craft = Sc("test")
|
||||
@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.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