Might change the structure again...
This commit is contained in:
@@ -1,17 +1,30 @@
|
||||
export Phase, Mission_Guess, Mission, Bad_Mission
|
||||
export test_phase1, test_phase2
|
||||
export test_mission_guess, test_mission_guess_simple
|
||||
export test_mission, test_mission_simple
|
||||
export test_mg, test_mission
|
||||
|
||||
struct Phase
|
||||
planet::Body
|
||||
v∞_in::Vector{Float64}
|
||||
δ::Float64
|
||||
v∞_out::Vector{Float64}
|
||||
tof::Float64
|
||||
thrust_profile::Matrix{Float64}
|
||||
end
|
||||
const test_phase1 = Phase(Venus, [10.4321, -6.3015, -0.01978], 0.2, 1.30464e7, zeros(20,3))
|
||||
const test_phase2 = Phase(Jupiter, [0.3, 7.1, 0.2], 2π, 3.9year, zeros(20,3))
|
||||
|
||||
const test_phase1 = Phase(Venus, [9., 10., 0.], [10., 9, 0.], 1.30464e7, zeros(20,3))
|
||||
const test_phase2 = Phase(Jupiter, [0.3, 7.1, 0.2], [0.3, 7.1, 0.2], 3.9year, zeros(20,3))
|
||||
const test_phases = [test_phase1, test_phase2]
|
||||
|
||||
"""
|
||||
A convenience function for calculating mass usage given a certain thrust profile
|
||||
"""
|
||||
function mass_consumption(sc::Sc, phase::Phase)
|
||||
weighted_thrusting_time = 0.0
|
||||
n = size(phase.thrust_profile)[1]
|
||||
for i in 1:size(phase.thrust_profile,1)
|
||||
weighted_thrusting_time += norm(phase.thrust_profile[i,:]) * phase.tof/n
|
||||
end
|
||||
return weighted_thrusting_time*sc.mass_flow_rate
|
||||
end
|
||||
|
||||
struct Mission_Guess
|
||||
sc::Sc
|
||||
@@ -21,17 +34,28 @@ struct Mission_Guess
|
||||
phases::Vector{Phase}
|
||||
converged::Bool
|
||||
end
|
||||
Mission_Guess(args...) = Mission_Guess(args..., false)
|
||||
const test_mission_guess = Mission_Guess( bepi,
|
||||
12_000.,
|
||||
DateTime(1992, 11, 19),
|
||||
[-3.4, 1.2, 0.1],
|
||||
[test_phase1, test_phase2] )
|
||||
const test_mission_guess_simple = Mission_Guess(bepi,
|
||||
12_000.,
|
||||
DateTime(1992, 11, 19),
|
||||
[-3.4, 1.2, 0.1],
|
||||
[test_phase1])
|
||||
|
||||
"""
|
||||
Constructor for a mission guess. Generally mission guesses are not converged
|
||||
"""
|
||||
function Mission_Guess(sc::Sc, mass::Float64, date::DateTime, v∞::Vector{Float64}, phases::Vector{Phase})
|
||||
# First do some checks to make sure that it's valid
|
||||
mass_used = 0
|
||||
for phase in phases
|
||||
mass_used += mass_consumption(sc, phase)
|
||||
mass - mass_used > sc.dry_mass || throw(Mass_Error(mass - mass_used))
|
||||
v∞_in, v∞_out = phase.v∞_in, phase.v∞_out
|
||||
if phase != phases[end]
|
||||
norm(v∞_in) ≈ norm(v∞_out) || throw(V∞_Error(v∞_in, v∞_out))
|
||||
δ = acos( ( v∞_in ⋅ v∞_out ) / ( norm(v∞_in) * norm(v∞_out) ) )
|
||||
periapsis = (phase.planet.μ/(v∞_in ⋅ v∞_in)) * ( 1/sin(δ/2) - 1 )
|
||||
periapsis > 1.1phase.planet.r || throw(HitPlanet_Error())
|
||||
end
|
||||
end
|
||||
Mission_Guess(sc, mass, date, v∞, phases, false)
|
||||
end
|
||||
|
||||
const test_mg = Mission_Guess(bepi, 12_000., DateTime(1992,11,19), [-3.4,1.2,0.1], test_phases)
|
||||
|
||||
struct Mission
|
||||
sc::Sc
|
||||
@@ -41,20 +65,33 @@ struct Mission
|
||||
phases::Vector{Phase}
|
||||
converged::Bool
|
||||
end
|
||||
Mission(args...) = Mission(args..., true)
|
||||
const test_mission = Mission(bepi,
|
||||
12_000.,
|
||||
DateTime(1992, 11, 19),
|
||||
[-3.4, 1.2, 0.1],
|
||||
[test_phase1, test_phase2])
|
||||
const test_mission_simple = Mission(bepi,
|
||||
12_000.,
|
||||
DateTime(1992, 11, 19),
|
||||
[4.2984, -4.3272668, 1.43752],
|
||||
[test_phase1])
|
||||
|
||||
"""
|
||||
Constructor for a mission. Generally mission guesses are converged
|
||||
"""
|
||||
function Mission(sc::Sc, mass::Float64, date::DateTime, v∞::Vector{Float64}, phases::Vector{Phase})
|
||||
# First do some checks to make sure that it's valid
|
||||
mass_used = 0
|
||||
for phase in phases
|
||||
mass_used += mass_consumption(sc, phase)
|
||||
mass - mass_used > sc.dry_mass || throw(Mass_Error(mass - mass_used))
|
||||
v∞_in, v∞_out = phase.v∞_in, phase.v∞_out
|
||||
if phase != phases[end]
|
||||
norm(v∞_in) ≈ norm(v∞_out) || throw(V∞_Error(v∞_in, v∞_out))
|
||||
δ = acos( ( v∞_in ⋅ v∞_out ) / ( norm(v∞_in) * norm(v∞_out) ) )
|
||||
periapsis = (phase.planet.μ/(v∞_in ⋅ v∞_in)) * ( 1/sin(δ/2) - 1 )
|
||||
periapsis > 1.1phase.planet.r || throw(HitPlanet_Error())
|
||||
end
|
||||
end
|
||||
Mission(sc, mass, date, v∞, phases, true)
|
||||
end
|
||||
|
||||
const test_mission = Mission(bepi, 12_000., DateTime(1992,11,19), [-3.4,1.2,0.1], test_phases)
|
||||
|
||||
struct Bad_Mission
|
||||
message::Symbol
|
||||
message::String
|
||||
converged::Bool
|
||||
end
|
||||
Bad_Mission(s) = Bad_Mission(s,false)
|
||||
Bad_Mission(s::String) = Bad_Mission(s,false)
|
||||
Bad_Mission(s::Symbol) = Bad_Mission(String(s),false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user