Made the switch to SNOW. Working well
This commit is contained in:
@@ -157,8 +157,8 @@ function inner_loop_solve(guess::Mission_Guess)
|
||||
time += phase.tof
|
||||
goal = spkssb(phase.planet.id, time, "ECLIPJ2000") + [zeros(3); phase.v∞_in]
|
||||
result = solve_phase( start, goal, guess.sc, phase.tof, phase.thrust_profile)
|
||||
converged(result) || return Bad_Mission() # Drop if it's not working
|
||||
corrected_phase = Phase(phase.planet, phase.v∞_in, phase.δ, phase.tof, result.zero)
|
||||
result.converged || return Bad_Mission(result.info) # Drop if it's not working
|
||||
corrected_phase = Phase(phase.planet, phase.v∞_in, phase.δ, phase.tof, result.sol)
|
||||
push!(corrected_phases, corrected_phase)
|
||||
mass_used = mass_consumption(guess.sc, corrected_phase)
|
||||
if i != length(guess.phases)
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
using NLsolve
|
||||
using SNOW
|
||||
|
||||
export solve_phase
|
||||
|
||||
struct Result
|
||||
converged::Bool
|
||||
info::Symbol
|
||||
sol::Matrix{Float64}
|
||||
end
|
||||
|
||||
"""
|
||||
This function will take a single phase (so an initial state, and a final state) and an initial guess
|
||||
to the thrust profile and use an NLP solver to find the nearest thrust profile to that initial guess
|
||||
@@ -13,26 +19,40 @@ function solve_phase( start::Vector{Float64},
|
||||
tof::Float64,
|
||||
x0::Matrix{Float64},
|
||||
primary::Body=Sun;
|
||||
tol=1e-6,
|
||||
num_iters=1_000 )
|
||||
tol=1e-8,
|
||||
verbose::Bool=false )
|
||||
n = size(x0)[1]
|
||||
|
||||
function f!(F,x)
|
||||
function f!(g,x)
|
||||
try
|
||||
F .= 0.0
|
||||
F[1:6, 1] .= prop(tanh.(x), start, craft, tof, primary)[2][1:6] .- final[1:6]
|
||||
g[1:6] .= prop(reshape(x,(n,3)), start, craft, tof, primary)[2][1:6]
|
||||
return 1.
|
||||
catch e
|
||||
# If the error is due to something natural, just imply a penalty
|
||||
if isa(e, Mass_Error) || isa(e, PropOne_Error)
|
||||
F .= 10000000.0
|
||||
if isa(e,LaGuerreConway_Error) || isa(e, Mass_Error) || isa(e, PropOne_Error)
|
||||
return 10_000.
|
||||
else
|
||||
rethrow()
|
||||
rethrow
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result = nlsolve(f!, atanh.(x0), ftol=tol, autodiff=:forward, iterations=num_iters)
|
||||
if converged(result) result.zero = tanh.(result.zero) end
|
||||
|
||||
return result
|
||||
lower_x = -1 * ones(3n)
|
||||
upper_x = ones(3n)
|
||||
num_constraints = 6
|
||||
ipopt_options = Dict("constr_viol_tol" => tol,
|
||||
"acceptable_constr_viol_tol" => 1e-4,
|
||||
"max_iter" => 10_000,
|
||||
"max_cpu_time" => 30.,
|
||||
"print_level" => 0)
|
||||
# if verbose ipopt_options["print_level"] = 5 end
|
||||
options = Options(solver=IPOPT(ipopt_options),
|
||||
derivatives=ForwardAD())
|
||||
x, _, info = minimize(f!, vec(x0), num_constraints, lower_x, upper_x, final[1:6], final[1:6], options)
|
||||
if info in [:Solve_Succeeded, :Solved_To_Acceptable_Level]
|
||||
return Result(true, info, reshape(x,(n,3)))
|
||||
else
|
||||
if verbose println(info) end
|
||||
return Result(false, info, x0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user