diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f582bf1..c2a867c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,4 +25,10 @@ unit-test-job: - julia/plots/plot_test_planet_move.html - julia/plots/plot_test_planet_no_move.html - julia/plots/plot_test_planet_solar_system.html + - julia/test/missions/nlp_1_phase + - julia/test/missions/nlp_2_phase + - julia/test/missions/nlp_5_phase + - julia/test/missions/mbh_1_phase + - julia/test/missions/mbh_2_phase + - julia/test/missions/mbh_5_phase expire_in: 10 weeks diff --git a/julia/src/mission.jl b/julia/src/mission.jl index 3aeee51..a311ace 100644 --- a/julia/src/mission.jl +++ b/julia/src/mission.jl @@ -1,6 +1,7 @@ export Phase, Mission_Guess, Mission, Bad_Mission export test_phase1, test_phase2 export test_mg +export store export Vector struct Phase @@ -178,3 +179,44 @@ end Bad_Mission(s::String) = Bad_Mission(s,false) Bad_Mission(s::Symbol) = Bad_Mission(String(s),false) +function Base.write(io::IO, m::Mission) + write(io, m.sc) + write(io, "Launch Mass: $(m.start_mass)\n") + write(io, "Launch Date: $(m.launch_date)\n") + write(io, "Launch V∞: $(m.launch_v∞)\n") + i = 1 + for phase in m.phases + write(io, "Phase $(i):\n") + write(io, "\tPlanet: $(phase.planet.name)\n") + write(io, "\tV∞_in: $(phase.v∞_in)\n") + write(io, "\tV∞_out: $(phase.v∞_out)\n") + write(io, "\ttime of flight: $(phase.tof)\n") + write(io, "\tthrust profile: $(phase.thrust_profile)\n") + i += 1 + end + write(io, "\n") + write(io, "Mass Used: $(m.start_mass - prop(m)[7])\n") + write(io, "Launch C3: $(m.launch_v∞ ⋅ m.launch_v∞)\n") + write(io, "||V∞_in||: $(norm(m.phases[end].v∞_in))\n") +end + +function store(m::Union{Mission, Mission_Guess}, filename::AbstractString) + open(filename, "w") do file + write(file, filename) + write(file, "---------------------------\n") + write(file, "\n") + write(file, m) + end +end + +function store(ms::Union{Vector{Mission}, Vector{Mission_Guess}}, filename::AbstractString) + open(filename, "w") do file + write(file, filename) + write(file, "\n") + for m in ms + write(file, "---------------------------\n") + write(file, m) + write(file, "\n\n\n") + end + end +end diff --git a/julia/src/spacecraft.jl b/julia/src/spacecraft.jl index c647680..96e6821 100644 --- a/julia/src/spacecraft.jl +++ b/julia/src/spacecraft.jl @@ -1,6 +1,7 @@ export Sc, test_sc, bepi, no_thrust mutable struct Sc + name::AbstractString dry_mass::Float64 mass_flow_rate::Float64 max_thrust::Float64 @@ -8,6 +9,16 @@ mutable struct Sc duty_cycle::Float64 end -const test_sc = Sc(8000., 0.00025/(2000*0.00981), 0.00025, 50, 0.9) -const bepi = Sc(2000., 2*0.00025/(2800*0.00981), 0.00025, 2, 0.9) -const no_thrust = Sc(0., 0.01, 0., 0, 0.) +function Base.write(io::IO, sc::Sc) + write(io, "Spacecraft: $(sc.name)\n") + write(io, "\tdry_mass: $(sc.dry_mass)\n") + write(io, "\tmass_flow_rate: $(sc.mass_flow_rate)\n") + write(io, "\tmax_thrust: $(sc.max_thrust)\n") + write(io, "\tnum_thrusters: $(sc.num_thrusters)\n") + write(io, "\tduty_cycle: $(sc.duty_cycle)\n") +end + +const test_sc = Sc("test", 8000., 0.00025/(2000*0.00981), 0.00025, 50, 0.9) +const bepi = Sc("bepi", 2000., 2*0.00025/(2800*0.00981), 0.00025, 2, 0.9) +const no_thrust = Sc("no thrust", 0., 0.01, 0., 0, 0.) + diff --git a/julia/test/inner_loop/monotonic_basin_hopping.jl b/julia/test/inner_loop/monotonic_basin_hopping.jl index fd872a1..c3977ae 100644 --- a/julia/test/inner_loop/monotonic_basin_hopping.jl +++ b/julia/test/inner_loop/monotonic_basin_hopping.jl @@ -28,20 +28,24 @@ launch_window = DateTime(1992,11,1), DateTime(1992,12,1) latest_arrival = DateTime(1993,6,1) planets = [ Earth, Venus ] - best, archive = mbh(planets, launch_window, latest_arrival, 2, 3) + best, archive = mbh(planets, launch_window, latest_arrival, 10, 5) @test typeof(best) == Mission p = plot(best, title="MBH Test Solution") savefig(p,"../plots/mbh_test_1_phase.html") + store(best, "missions/mbh_1_phase_best") + store(archive, "missions/mbh_1_phase_archive") # Now for a more complicated two-phase mission, with a bigger date range # This is known to have a solution though planets = [Earth, Venus, Mars] launch_window = DateTime(2021,6,1), DateTime(2022,6,1) latest_arrival = DateTime(2024,1,1) - best, archive = mbh(planets, launch_window, latest_arrival, 10, 3) + best, archive = mbh(planets, launch_window, latest_arrival, 20, 5) @test typeof(best) == Mission p = plot(best, title="MBH Test Solution") savefig(p,"../plots/mbh_test_2_phase.html") + store(best, "missions/mbh_2_phase_best") + store(archive, "missions/mbh_2_phase_archive") # Now for a real stress test - the old ten-year, 5-phase Jovian mission # This is known to have a solution... tough to find though @@ -49,9 +53,11 @@ planets = [Earth, Venus, Earth, Mars, Earth, Jupiter] launch_window = DateTime(2023,4,1), DateTime(2023,7,1) latest_arrival = DateTime(2033,1,1) - best, archive = mbh(planets, launch_window, latest_arrival, 100, 3) + best, archive = mbh(planets, launch_window, latest_arrival, 200, 10) @test typeof(best) == Mission p = plot(best, title="MBH Test Solution") savefig(p,"../plots/mbh_test_5_phase.html") + store(best, "missions/mbh_5_phase_best") + store(archive, "missions/mbh_5_phase_archive") end diff --git a/julia/test/inner_loop/nlp_solver.jl b/julia/test/inner_loop/nlp_solver.jl index 2db034b..fbd7a25 100644 --- a/julia/test/inner_loop/nlp_solver.jl +++ b/julia/test/inner_loop/nlp_solver.jl @@ -22,6 +22,7 @@ # Now we can plot the results to check visually p = plot(m, title="NLP Test Solution") savefig(p,"../plots/nlp_test_1_phase.html") + store(m, "missions/nlp_1_phase") # Now we can look at a slightly more complicated trajectory flybys = [Earth, Venus, Mars] @@ -42,6 +43,7 @@ @test typeof(m) == Mission p = plot(m, title="NLP Test Solution (2 Phases)") savefig(p,"../plots/nlp_test_2_phase.html") + store(m, "missions/nlp_2_phase") # Here is the final, most complicated, trajectory to test flybys = [Earth, Venus, Earth, Mars, Earth, Jupiter] @@ -67,5 +69,6 @@ @test typeof(m) == Mission p = plot(m, title="NLP Test Solution (5 Phases)") savefig(p,"../plots/nlp_test_5_phase.html") + store(m, "missions/nlp_5_phase") end diff --git a/julia/test/runtests.jl b/julia/test/runtests.jl index 390f23e..1f16d54 100644 --- a/julia/test/runtests.jl +++ b/julia/test/runtests.jl @@ -14,9 +14,9 @@ catch end @testset "All Tests" begin - # include("plotting.jl") - # include("inner_loop/laguerre-conway.jl") - # include("inner_loop/propagator.jl") - # include("inner_loop/nlp_solver.jl") + include("plotting.jl") + include("inner_loop/laguerre-conway.jl") + include("inner_loop/propagator.jl") + include("inner_loop/nlp_solver.jl") include("inner_loop/monotonic_basin_hopping.jl") end