Small improvements
This commit is contained in:
@@ -23,7 +23,7 @@ function laguerre_conway(state::Vector{<:Real}, time::Float64, primary::Body=Sun
|
||||
sign = dF >= 0 ? 1 : -1
|
||||
ΔE_new = ΔE - n*F / ( dF + sign * √(abs((n-1)^2*dF^2 - n*(n-1)*F*d2F )))
|
||||
i += 1
|
||||
if i > 100 throw(LaGuerreConway_Error("LaGuerre-Conway did not converge!")) end
|
||||
if i > 100 throw(LaGuerreConway_Error()) end
|
||||
end
|
||||
F = 1 - a/r0_mag * (1-cos(ΔE))
|
||||
G = a * σ0/ √(μ) * (1-cos(ΔE)) + r0_mag * √(a) / √(μ) * sin(ΔE)
|
||||
@@ -42,7 +42,7 @@ function laguerre_conway(state::Vector{<:Real}, time::Float64, primary::Body=Sun
|
||||
sign = dF >= 0 ? 1 : -1
|
||||
ΔH_new = ΔH - n*F / ( dF + sign * √(abs((n-1)^2*dF^2 - n*(n-1)*F*d2F )))
|
||||
i += 1
|
||||
if i > 100 throw(LaGuerreConway_Error("LaGuerre-Conway did not converge!")) end
|
||||
if i > 100 throw(LaGuerreConway_Error()) end
|
||||
end
|
||||
F = 1 - a/r0_mag * (1-cos(ΔH))
|
||||
G = a * σ0/ √(μ) * (1-cos(ΔH)) + r0_mag * √(-a) / √(μ) * sin(ΔH)
|
||||
|
||||
@@ -34,7 +34,8 @@ function solve_mission( guess::Mission_Guess,
|
||||
launch_window::Vector{DateTime},
|
||||
latest_arrival::DateTime;
|
||||
tol=1e-10,
|
||||
verbose::Bool=false )
|
||||
verbose::Bool=false,
|
||||
print_level=0 )
|
||||
|
||||
# First we define our starting point
|
||||
x0 = Vector(guess)
|
||||
@@ -58,29 +59,39 @@ function solve_mission( guess::Mission_Guess,
|
||||
# - That the ending position matches (if final leg)
|
||||
# - That the ending mass is acceptable (if final leg)
|
||||
i = 0
|
||||
for flyby in flybys
|
||||
phase_params = x[ 5 + (3n+7) * i : 5 + (3n+7) * (i+1) - 1 ]
|
||||
v∞_in = phase_params[1:3]
|
||||
v∞_out = phase_params[4:6]
|
||||
tof = phase_params[7]
|
||||
thrusts = reshape(phase_params[8:end], (n,3))
|
||||
current_planet = flyby
|
||||
time += tof
|
||||
goal = state(current_planet, time, v∞_in)
|
||||
final = prop(reshape(thrusts, (n,3)), start, guess.sc, tof)[2]
|
||||
if flyby != flybys[end]
|
||||
g[1+8i:6+8i] .= (final[1:6] .- goal[1:6]) .* [1., 1., 1., 10_000., 10_000., 10_000.]
|
||||
g[7+8i] = (norm(v∞_out) - norm(v∞_in)) * 10_000.
|
||||
δ = acos( ( v∞_in ⋅ v∞_out ) / ( norm(v∞_in) * norm(v∞_out) ) )
|
||||
g[8+8i] = (current_planet.μ/(v∞_in ⋅ v∞_in)) * ( 1/sin(δ/2) - 1 ) - current_planet.r
|
||||
else
|
||||
g[8*(length(flybys)-1)+1:8*(length(flybys)-1)+3] .= final[1:3] .- goal[1:3]
|
||||
g[8*(length(flybys)-1)+4] = final[7] - guess.sc.dry_mass
|
||||
try
|
||||
for flyby in flybys
|
||||
phase_params = x[ 5 + (3n+7) * i : 5 + (3n+7) * (i+1) - 1 ]
|
||||
v∞_in = phase_params[1:3]
|
||||
v∞_out = phase_params[4:6]
|
||||
tof = phase_params[7]
|
||||
thrusts = reshape(phase_params[8:end], (n,3))
|
||||
current_planet = flyby
|
||||
time += tof
|
||||
goal = state(current_planet, time, v∞_in)
|
||||
final = prop(reshape(thrusts, (n,3)), start, guess.sc, tof)[2]
|
||||
if flyby != flybys[end]
|
||||
g[1+8i:6+8i] .= (final[1:6] .- goal[1:6]) .* [1., 1., 1., 10_000., 10_000., 10_000.]
|
||||
g[7+8i] = (norm(v∞_out) - norm(v∞_in)) * 10_000.
|
||||
δ = acos( ( v∞_in ⋅ v∞_out ) / ( norm(v∞_in) * norm(v∞_out) ) )
|
||||
g[8+8i] = (current_planet.μ/(v∞_in ⋅ v∞_in)) * ( 1/sin(δ/2) - 1 ) - current_planet.r
|
||||
else
|
||||
g[8*(length(flybys)-1)+1:8*(length(flybys)-1)+3] .= final[1:3] .- goal[1:3]
|
||||
g[8*(length(flybys)-1)+4] = final[7] - guess.sc.dry_mass
|
||||
end
|
||||
start = state(current_planet, time, v∞_out, final[7])
|
||||
mass = final[7]
|
||||
i += 1
|
||||
end
|
||||
return 1.0
|
||||
catch e
|
||||
if isa(e,LaGuerreConway_Error)
|
||||
g[1:8*(length(flybys)-1)+4] .= 1e10
|
||||
return 1e10
|
||||
else
|
||||
rethrow()
|
||||
end
|
||||
start = state(current_planet, time, v∞_out, final[7])
|
||||
i += 1
|
||||
end
|
||||
return 1.0
|
||||
end
|
||||
|
||||
max_time = Dates.datetime2unix(latest_arrival) - Dates.datetime2unix(launch_window[1])
|
||||
@@ -90,9 +101,9 @@ function solve_mission( guess::Mission_Guess,
|
||||
g_low, g_high = constraint_bounds(guess)
|
||||
ipopt_options = Dict("constr_viol_tol" => tol,
|
||||
"acceptable_constr_viol_tol" => 100tol,
|
||||
"max_iter" => 10_000,
|
||||
"max_cpu_time" => 300.,
|
||||
"print_level" => 0)
|
||||
"max_iter" => 100_000,
|
||||
"max_cpu_time" => 60.,
|
||||
"print_level" => print_level)
|
||||
options = Options(solver=IPOPT(ipopt_options), derivatives=ForwardFD())
|
||||
|
||||
x, _, info = minimize(optimizer!, x0, num_constraints, lower_x, upper_x, g_low, g_high, options)
|
||||
@@ -101,6 +112,9 @@ function solve_mission( guess::Mission_Guess,
|
||||
if info in [:Solve_Succeeded, :Solved_To_Acceptable_Level]
|
||||
return Mission(x, guess.sc, guess.start_mass, flybys)
|
||||
else
|
||||
g = zeros(num_constraints)
|
||||
optimizer!(g,x)
|
||||
println(g)
|
||||
return guess
|
||||
end
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ function prop(ΔVs::Matrix{T},
|
||||
end
|
||||
end
|
||||
for j in 1:7 push!(states[j], state[j]) end
|
||||
state[7] >= craft.dry_mass || throw(Mass_Error(state[7]))
|
||||
end
|
||||
|
||||
return states, state
|
||||
|
||||
Reference in New Issue
Block a user