A lot of progress on the propagator
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using LinearAlgebra
|
||||
using LinearAlgebra, JuMP, Ipopt
|
||||
|
||||
include("constants.jl")
|
||||
include("conversions.jl")
|
||||
include("spacecraft.jl")
|
||||
include("sft.jl")
|
||||
include("laguerre-conway.jl")
|
||||
include("propagator.jl")
|
||||
|
||||
36
julia/propagator.jl
Normal file
36
julia/propagator.jl
Normal file
@@ -0,0 +1,36 @@
|
||||
"""
|
||||
This function propagates the spacecraft forward in time 1 Sim-Flanagan step (of variable length of time),
|
||||
applying a thrust in the center.
|
||||
"""
|
||||
function prop_one(ΔV_unit::Vector{Float64},
|
||||
state::Vector{Float64},
|
||||
duty_cycle::Float64,
|
||||
num_thrusters::Int,
|
||||
max_thrust::Float64,
|
||||
mass::Float64,
|
||||
mass_flow_rate::Float64,
|
||||
μ::Float64,
|
||||
time::Float64)
|
||||
|
||||
if norm(ΔV_unit) > 1.
|
||||
throw(ErrorException("ΔV input is too high"))
|
||||
end
|
||||
halfway = laguerre_conway(state, μ, time/2)
|
||||
halfway[4:6] += ΔV_unit * max_ΔV(duty_cycle, num_thrusters, max_thrust, time, 0., mass)
|
||||
return laguerre_conway(halfway, μ, time/2), mass - mass_flow_rate*norm(ΔV_unit)*time
|
||||
|
||||
end
|
||||
|
||||
"""
|
||||
A convenience function for using spacecraft. Note that this function outputs a sc instead of a mass
|
||||
"""
|
||||
function prop_one(ΔV_unit::Vector{Float64},
|
||||
state::Vector{Float64},
|
||||
craft::sc,
|
||||
μ::Float64,
|
||||
time::Float64)
|
||||
state, mass = prop_one(ΔV_unit, state, craft.duty_cycle, craft.num_thrusters, craft.max_thrust,
|
||||
craft.mass, craft.mass_flow_rate, μ, time)
|
||||
return state, sc(mass, craft.mass_flow_rate, craft.max_thrust, craft.num_thrusters, craft.duty_cycle)
|
||||
end
|
||||
|
||||
17
julia/spacecraft.jl
Normal file
17
julia/spacecraft.jl
Normal file
@@ -0,0 +1,17 @@
|
||||
struct sc
|
||||
mass::Float64
|
||||
mass_flow_rate::Float64
|
||||
max_thrust::Float64
|
||||
num_thrusters::Int
|
||||
duty_cycle::Float64
|
||||
end
|
||||
|
||||
function sc(name::String)
|
||||
if name == "test"
|
||||
return sc(1000., 0.01, 0.1, 2, 1.)
|
||||
elseif name == "no_thrust"
|
||||
return sc(1000., 0.01, 0., 0, 0.)
|
||||
else
|
||||
throw(ErrorException("Bad sc name"))
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,8 @@
|
||||
@testset "Laguerre-Conway" begin
|
||||
|
||||
# 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), 0.1, 0.1, 0., 0., 1. ], μs["Earth"])
|
||||
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.
|
||||
@@ -11,5 +13,15 @@
|
||||
@test i ≈ T
|
||||
@test orbit ≈ start
|
||||
end
|
||||
for _ in 1:5
|
||||
i = 0.
|
||||
while i > -T
|
||||
orbit = laguerre_conway(orbit, μs["Earth"], -1.)
|
||||
i -= 1
|
||||
end
|
||||
@test i ≈ -T
|
||||
@test orbit ≈ start
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
33
julia/test/propagator.jl
Normal file
33
julia/test/propagator.jl
Normal file
@@ -0,0 +1,33 @@
|
||||
@testset "Propagator" begin
|
||||
|
||||
# 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")
|
||||
state, craft = prop_one([0., 0., 0.], start, craft, μs["Earth"], stepsize)
|
||||
@test laguerre_conway(start, μs["Earth"], stepsize) ≈ state
|
||||
@test craft.mass == 1000.
|
||||
|
||||
# Test that mass is reduced properly
|
||||
craft = sc("test")
|
||||
start_mass = craft.mass
|
||||
state, craft = prop_one([1., 1., 1.]/√(3), 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., 1., -1.], start, craft, μs["Earth"], stepsize)
|
||||
|
||||
end
|
||||
19
julia/test/spacecraft.jl
Normal file
19
julia/test/spacecraft.jl
Normal file
@@ -0,0 +1,19 @@
|
||||
@testset "Spacecraft Construction" begin
|
||||
|
||||
# Test that the standard spacecrafts can be created
|
||||
craft = sc("test")
|
||||
@test craft.mass == 1000.
|
||||
@test craft.mass_flow_rate == 0.01
|
||||
@test craft.max_thrust == 0.1
|
||||
@test craft.num_thrusters == 2
|
||||
@test craft.duty_cycle == 1.
|
||||
|
||||
craft = sc("no_thrust")
|
||||
@test craft.mass == 1000.
|
||||
@test craft.mass_flow_rate == 0.01
|
||||
@test craft.max_thrust == 0.
|
||||
@test craft.num_thrusters == 0
|
||||
@test craft.duty_cycle == 0.
|
||||
|
||||
|
||||
end
|
||||
@@ -5,12 +5,16 @@ using LinearAlgebra
|
||||
# Includes
|
||||
include("../constants.jl")
|
||||
include("../conversions.jl")
|
||||
include("../spacecraft.jl")
|
||||
include("../sft.jl")
|
||||
include("../laguerre-conway.jl")
|
||||
include("../propagator.jl")
|
||||
|
||||
# Tests
|
||||
@testset verbose=true "All Tests" begin
|
||||
@testset "All Tests" begin
|
||||
include("spacecraft.jl")
|
||||
include("laguerre-conway.jl")
|
||||
include("propagator.jl")
|
||||
end
|
||||
|
||||
print()
|
||||
|
||||
Reference in New Issue
Block a user