diff --git a/julia/src/Thesis.jl b/julia/src/Thesis.jl index f510c67..bf0cc08 100644 --- a/julia/src/Thesis.jl +++ b/julia/src/Thesis.jl @@ -2,8 +2,13 @@ module Thesis using LinearAlgebra, ForwardDiff, PlotlyJS, SPICE - furnsh("../../SPICE/naif0012.tls") - furnsh("../../SPICE/de430.bsp") + try + furnsh("../../SPICE/naif0012.tls") + furnsh("../../SPICE/de430.bsp") + catch + furnsh("SPICE/naif0012.tls") + furnsh("SPICE/de430.bsp") + end include("./constants.jl") include("./spacecraft.jl") @@ -16,4 +21,4 @@ module Thesis include("./inner_loop/phase.jl") include("./inner_loop/inner_loop.jl") -end \ No newline at end of file +end diff --git a/julia/src/inner_loop/inner_loop.jl b/julia/src/inner_loop/inner_loop.jl index 7297a7c..fde352e 100644 --- a/julia/src/inner_loop/inner_loop.jl +++ b/julia/src/inner_loop/inner_loop.jl @@ -7,8 +7,11 @@ This is it. The outer function call for the inner loop. After this is done, there's only the outer loop left to do. And that's pretty easy. """ function inner_loop(launch_date::DateTime, + craft::Sc, phases::Vector{Phase}; - min_flyby::Float64=1000.) + min_flyby::Float64=1000., + mbh_specs=nothing, + verbose=false) # First we need to do some quick checks that the mission is well formed for i in 1:length(phases) @@ -43,14 +46,24 @@ function inner_loop(launch_date::DateTime, end time = utc2et(Dates.format(launch_date,"yyyy-mm-ddTHH:MM:SS")) + thrust_profiles = [] for phase in phases planet1_state = spkssb(ids[phase.from_planet], time, "J2000") - println(planet1_state) time += phase.time_of_flight planet2_state = spkssb(ids[phase.to_planet], time, "J2000") - println(planet2_state) + # TODO: Come up with improved method of calculating "n" + start = planet1_state + [0., 0., 0., phase.v∞_outgoing...] + final = planet2_state + [0., 0., 0., phase.v∞_incoming...] + if mbh_specs == nothing + best = mbh(start, final, craft, μs["Sun"], 0.0, phase.time_of_flight, 10, + verbose=verbose)[1] + else + best = mbh(start, final, craft, μs["Sun"], 0.0, phase.time_of_flight, 10, + verbose=verbose, num_iters=mbh_specs[1], patience_level=mbh_specs[2])[1] + end + push!(thrust_profiles, best) + craft.mass = prop(tanh.(best.zero), planet1_state, sc, μs["Sun"], prop_time)[2][end] end - - return phases[1].v∞_incoming[1] -end \ No newline at end of file + return craft.mass, thrust_profiles +end diff --git a/julia/src/inner_loop/monotonic_basin_hopping.jl b/julia/src/inner_loop/monotonic_basin_hopping.jl index e0e1a44..71c85da 100644 --- a/julia/src/inner_loop/monotonic_basin_hopping.jl +++ b/julia/src/inner_loop/monotonic_basin_hopping.jl @@ -26,8 +26,8 @@ function mbh(start::AbstractVector, t0::AbstractFloat, tf::AbstractFloat, n::Int; - num_iters=50, - patience_level::Int=400, + num_iters=25, + patience_level::Int=200, tol=1e-6, verbose=false) @@ -38,11 +38,18 @@ function mbh(start::AbstractVector, while true i += 1 if verbose print("\r",i) end + # TODO: Should this be two separate "impatience" values? impatience = 0 + println("HERE") x_star = nlp_solve(start, final, craft, μ, t0, tf, new_x(n), tol=tol) - while converged(x_star) == false + println("THERE") + while converged(x_star) == false && impatience < patience_level + impatience += 1 x_star = nlp_solve(start, final, craft, μ, t0, tf, new_x(n), tol=tol) + println(impatience) end + if impatience > patience_level break end + impatience = 0 if converged(x_star) x_current = x_star while impatience < patience_level @@ -71,4 +78,4 @@ function mbh(start::AbstractVector, return best, archive -end \ No newline at end of file +end diff --git a/julia/src/inner_loop/phase.jl b/julia/src/inner_loop/phase.jl index e246a18..ae809a2 100644 --- a/julia/src/inner_loop/phase.jl +++ b/julia/src/inner_loop/phase.jl @@ -6,4 +6,4 @@ struct Phase time_of_flight::Float64 # seconds v∞_outgoing::Vector{Float64} # Km/s v∞_incoming::Vector{Float64} # Km/s -end \ No newline at end of file +end diff --git a/julia/test/inner_loop/inner_loop.jl b/julia/test/inner_loop/inner_loop.jl index 07f976e..6a1ef8e 100644 --- a/julia/test/inner_loop/inner_loop.jl +++ b/julia/test/inner_loop/inner_loop.jl @@ -4,6 +4,8 @@ using Dates + sc = Sc("test") + phase1 = Phase("Earth", "Mars", 3600*24*365*1.5, @@ -15,8 +17,9 @@ 3600*24*365*3.5, [2., 3.7416573867739413, 0.], [0.3, 1., 0.]) - inner_loop(DateTime(2024,3,5), [phase1, phase2]) + + inner_loop(DateTime(2024,3,5), sc, [phase1, phase2], verbose=true, mbh_specs=(5,100)) @test true -end \ No newline at end of file +end diff --git a/julia/test/runtests.jl b/julia/test/runtests.jl index 5a4eaa0..e0ce16a 100644 --- a/julia/test/runtests.jl +++ b/julia/test/runtests.jl @@ -4,8 +4,13 @@ using LinearAlgebra using SPICE using Thesis -furnsh("../../SPICE/naif0012.tls") -furnsh("../../SPICE/de430.bsp") +try + furnsh("../../SPICE/naif0012.tls") + furnsh("../../SPICE/de430.bsp") +catch + furnsh("SPICE/naif0012.tls") + furnsh("SPICE/de430.bsp") +end # Tests @testset "All Tests" begin