NLP seems to be doing pretty well
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
export Phase, Mission_Guess, Mission, Bad_Mission
|
||||
export test_phase1, test_phase2
|
||||
export test_mg, test_mission
|
||||
export test_mg
|
||||
export Vector
|
||||
|
||||
struct Phase
|
||||
@@ -11,7 +11,7 @@ struct Phase
|
||||
thrust_profile::Matrix{Float64}
|
||||
end
|
||||
|
||||
const test_phase1 = Phase(Venus, [9., 10., 0.], [10., 9, 0.], 1.30464e7, zeros(20,3))
|
||||
const test_phase1 = Phase(Venus, [√20., -√80., 0.], [√50., -√50., 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]
|
||||
|
||||
@@ -46,12 +46,6 @@ function Mission_Guess(sc::Sc, mass::Float64, date::DateTime, v∞::Vector{Float
|
||||
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
|
||||
@@ -101,6 +95,32 @@ function Base.Vector(g::Mission_Guess)
|
||||
return result
|
||||
end
|
||||
|
||||
function lowest_mission_vector(launch_window::Vector{DateTime}, num_phases::Int, n::Int)
|
||||
result = Vector{Float64}()
|
||||
push!(result, Dates.datetime2unix(launch_window[1]))
|
||||
push!(result, -10*ones(3)...)
|
||||
for i in 1:num_phases
|
||||
push!(result, -10*ones(3)...)
|
||||
push!(result, -10*ones(3)...)
|
||||
push!(result, 86_400.0)
|
||||
push!(result, -1 * ones(n,3)...)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function highest_mission_vector(launch_window::Vector{DateTime}, mission_length::Float64, num_phases::Int, n::Int)
|
||||
result = Vector{Float64}()
|
||||
push!(result, Dates.datetime2unix(launch_window[2]))
|
||||
push!(result, 10*ones(3)...)
|
||||
for i in 1:num_phases
|
||||
push!(result, 10*ones(3)...)
|
||||
push!(result, 10*ones(3)...)
|
||||
push!(result, mission_length)
|
||||
push!(result, ones(n,3)...)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
const test_mg = Mission_Guess(bepi, 12_000., DateTime(1992,11,19), [-3.4,1.2,0.1], test_phases)
|
||||
|
||||
struct Mission
|
||||
@@ -113,27 +133,47 @@ struct Mission
|
||||
end
|
||||
|
||||
"""
|
||||
Constructor for a mission. Generally mission guesses are converged
|
||||
Constructor for a mission. Generally mission guesses are converged, so we check everything
|
||||
"""
|
||||
function Mission(sc::Sc, mass::Float64, date::DateTime, v∞::Vector{Float64}, phases::Vector{Phase})
|
||||
function Mission(sc::Sc, mass::Float64, date::DateTime, v∞::Vector{Float64}, phases::Vector{Phase};
|
||||
force=false)
|
||||
# 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())
|
||||
if !force
|
||||
time = date
|
||||
current_planet = Earth
|
||||
start = state(current_planet, time, v∞, mass)
|
||||
for phase in phases
|
||||
final = prop(phase.thrust_profile, start, sc, phase.tof)[2]
|
||||
mass = final[7]
|
||||
mass > sc.dry_mass || throw(Mass_Error(mass - mass_used))
|
||||
current_planet = phase.planet
|
||||
time += Dates.Second(floor(phase.tof))
|
||||
p_pos = state(current_planet, time)[1:3]
|
||||
abs(norm(final[1:3] - p_pos)) < √30_000. || throw(Planet_Match_Error(final[1:3], p_pos))
|
||||
v∞_in, v∞_out = phase.v∞_in, phase.v∞_out
|
||||
if phase != phases[end]
|
||||
abs(norm(v∞_in) - norm(v∞_out)) < 0.005 || 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
|
||||
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)
|
||||
|
||||
"""
|
||||
BE CAREFUL!! This just makes a guess converged, whether true or not
|
||||
"""
|
||||
function Mission(g::Mission_Guess)
|
||||
return Mission(g.sc, g.start_mass, g.launch_date, g.launch_v∞, g.phases, force=true)
|
||||
end
|
||||
|
||||
function Mission(x::Vector{Float64}, sc::Sc, mass::Float64, flybys::Vector{Body})
|
||||
guess = Mission_Guess(x, sc, mass, flybys::Vector{Body})
|
||||
return Mission(guess)
|
||||
end
|
||||
|
||||
struct Bad_Mission
|
||||
message::String
|
||||
converged::Bool
|
||||
|
||||
Reference in New Issue
Block a user