diff --git a/julia/Project.toml b/julia/Project.toml index 01d2154..3e6ef18 100644 --- a/julia/Project.toml +++ b/julia/Project.toml @@ -4,6 +4,7 @@ authors = ["Connor Johnstone "] version = "0.1.0" [deps] +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56" diff --git a/julia/src/Thesis.jl b/julia/src/Thesis.jl index 69c5dcd..88a2fd4 100644 --- a/julia/src/Thesis.jl +++ b/julia/src/Thesis.jl @@ -6,8 +6,10 @@ module Thesis include("./spacecraft.jl") include("./conversions.jl") include("./plotting.jl") - include("./laguerre-conway.jl") - include("./propagator.jl") - include("./find_closest.jl") - include("./monotonic_basin_hopping.jl") + include("./inner_loop/laguerre-conway.jl") + include("./inner_loop/propagator.jl") + include("./inner_loop/find_closest.jl") + include("./inner_loop/monotonic_basin_hopping.jl") + include("./inner_loop/phase.jl") + include("./inner_loop/inner_loop.jl") end \ No newline at end of file diff --git a/julia/src/find_closest.jl b/julia/src/inner_loop/find_closest.jl similarity index 100% rename from julia/src/find_closest.jl rename to julia/src/inner_loop/find_closest.jl diff --git a/julia/src/inner_loop/inner_loop.jl b/julia/src/inner_loop/inner_loop.jl new file mode 100644 index 0000000..d4b7012 --- /dev/null +++ b/julia/src/inner_loop/inner_loop.jl @@ -0,0 +1,25 @@ +using Dates + +export inner_loop + +""" +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, + RLA::Float64, + DLA::Float64, + phases::Vector{Phase}) + + # First we need to do some quick checks that the mission is well formed + for i in 1:length(phases) + if i == 1 + @assert phases[i].from_planet == "Earth" + else + @assert phases[i].from_planet == phases[i-1].to_planet + @assert phases[i].v∞_outgoing == phases[i-1].v∞_incoming + end + end + + return RLA + DLA + phases[1].v∞_incoming +end \ No newline at end of file diff --git a/julia/src/laguerre-conway.jl b/julia/src/inner_loop/laguerre-conway.jl similarity index 100% rename from julia/src/laguerre-conway.jl rename to julia/src/inner_loop/laguerre-conway.jl diff --git a/julia/src/monotonic_basin_hopping.jl b/julia/src/inner_loop/monotonic_basin_hopping.jl similarity index 96% rename from julia/src/monotonic_basin_hopping.jl rename to julia/src/inner_loop/monotonic_basin_hopping.jl index dbb3c41..e0e1a44 100644 --- a/julia/src/monotonic_basin_hopping.jl +++ b/julia/src/inner_loop/monotonic_basin_hopping.jl @@ -1,3 +1,5 @@ +export mbh + function pareto(α::Float64, n::Int) s = rand((-1,1), (n,3)) r = rand(Float64, (n,3)) @@ -54,10 +56,9 @@ function mbh(start::AbstractVector, end push!(archive, x_current) end - if i >= num_iters - break - end + if i >= num_iters break end end + if verbose println() end current_best_mass = 1e8 best = archive[1] diff --git a/julia/src/inner_loop/phase.jl b/julia/src/inner_loop/phase.jl new file mode 100644 index 0000000..96a380d --- /dev/null +++ b/julia/src/inner_loop/phase.jl @@ -0,0 +1,9 @@ +export Phase + +struct Phase + from_planet::String + to_planet::String + time_of_flight::Float64 # seconds + v∞_outgoing::Float64 # Km/s + v∞_incoming::Float64 # Km/s +end \ No newline at end of file diff --git a/julia/src/propagator.jl b/julia/src/inner_loop/propagator.jl similarity index 100% rename from julia/src/propagator.jl rename to julia/src/inner_loop/propagator.jl diff --git a/julia/src/plotting.jl b/julia/src/plotting.jl index 45d5fac..129fdf0 100644 --- a/julia/src/plotting.jl +++ b/julia/src/plotting.jl @@ -18,7 +18,6 @@ end function plot_orbits(paths::Vector{Vector{Vector{Float64}}}; primary::String="Earth", - plot_theme::Symbol=:juno, labels::Vector{String}=Vector{String}(), title::String="Spacecraft Position", colors::Vector{String}=Vector{String}()) @@ -49,7 +48,7 @@ function plot_orbits(paths::Vector{Vector{Vector{Float64}}}; showscale=false, colorscale = p_colors[primary]) - layout = Layout(;title="Orbit Plot", + layout = Layout(;title=title, width=1000, height=600, paper_bgcolor="#222529", diff --git a/julia/src/spacecraft.jl b/julia/src/spacecraft.jl index a3c9169..711da0f 100644 --- a/julia/src/spacecraft.jl +++ b/julia/src/spacecraft.jl @@ -1,5 +1,4 @@ export Sc - struct Sc{T <: Real} mass::T mass_flow_rate::Float64 diff --git a/julia/test/find_closest.jl b/julia/test/inner_loop/find_closest.jl similarity index 89% rename from julia/test/find_closest.jl rename to julia/test/inner_loop/find_closest.jl index f053130..24fafd7 100644 --- a/julia/test/find_closest.jl +++ b/julia/test/inner_loop/find_closest.jl @@ -1,19 +1,20 @@ @testset "Find Closest" begin + println("Testing NLP solver") + using NLsolve, PlotlyJS # Initial Setup sc = Sc("test") - a = rand(15000:1.:40000) - e = rand(0.01:0.01:0.5) + a = rand(25000:1.:40000) + e = rand(0.01:0.01:0.05) i = rand(0.01:0.01:π/6) T = 2π*√(a^3/μs["Earth"]) - prop_time = 2T - n = 20 + prop_time = T + n = 10 # A simple orbit raising start = oe_to_xyz([ a, e, i, 0., 0., 0. ], μs["Earth"]) -# T_craft = hcat(repeat([0.6], n), repeat([0.], n), repeat([0.], n)) Tx, Ty, Tz = conv_T(repeat([0.6], n), repeat([0.], n), repeat([0.], n), start, sc.mass, @@ -23,7 +24,7 @@ final = prop(hcat(Tx, Ty, Tz), start, sc, μs["Earth"], prop_time)[3] new_T = 2π*√(xyz_to_oe(final, μs["Earth"])[1]^3/μs["Earth"]) - # This should be close enough to 0.6 + # This should be close enough to 0.6 for convergence Tx, Ty, Tz = conv_T(repeat([0.59], n), repeat([0.01], n), repeat([0.], n), start, sc.mass, diff --git a/julia/test/inner_loop/inner_loop.jl b/julia/test/inner_loop/inner_loop.jl new file mode 100644 index 0000000..3646f0d --- /dev/null +++ b/julia/test/inner_loop/inner_loop.jl @@ -0,0 +1,13 @@ +@testset "Inner Loop" begin + + println("Testing Inner Loop") + + using Dates + + phase1 = Phase("Earth", "Mars", 3600*24*365*1.5, 5., 2.) + phase2 = Phase("Mars", "Jupiter", 3600*24*365*3.5, 2., 0.1) + inner_loop(DateTime(2024,3,5), 0.3, 0.4, [phase1, phase2]) + + @test true + +end \ No newline at end of file diff --git a/julia/test/laguerre-conway.jl b/julia/test/inner_loop/laguerre-conway.jl similarity index 95% rename from julia/test/laguerre-conway.jl rename to julia/test/inner_loop/laguerre-conway.jl index 5df2b54..20a9b9d 100644 --- a/julia/test/laguerre-conway.jl +++ b/julia/test/inner_loop/laguerre-conway.jl @@ -1,4 +1,7 @@ @testset "Laguerre-Conway" begin + + println("Testing LaGuerre-Conway") + using Thesis: laguerre_conway # Test that the propagator produces good periodic orbits (forwards and backwards) diff --git a/julia/test/monotonic_basin_hopping.jl b/julia/test/inner_loop/monotonic_basin_hopping.jl similarity index 98% rename from julia/test/monotonic_basin_hopping.jl rename to julia/test/inner_loop/monotonic_basin_hopping.jl index 452053d..bda02c1 100644 --- a/julia/test/monotonic_basin_hopping.jl +++ b/julia/test/inner_loop/monotonic_basin_hopping.jl @@ -1,6 +1,6 @@ @testset "Monotonic Basin Hopping" begin - using Thesis: mbh + println("Testing Monotonic Basin Hopper") # Initial Setup sc = Sc("test") diff --git a/julia/test/propagator.jl b/julia/test/inner_loop/propagator.jl similarity index 97% rename from julia/test/propagator.jl rename to julia/test/inner_loop/propagator.jl index b985443..d66f0c1 100644 --- a/julia/test/propagator.jl +++ b/julia/test/inner_loop/propagator.jl @@ -1,5 +1,7 @@ @testset "Propagator" begin + println("Testing propagator") + using Thesis: prop_one # Set up diff --git a/julia/test/plotting.jl b/julia/test/plotting.jl index ada5689..e369885 100644 --- a/julia/test/plotting.jl +++ b/julia/test/plotting.jl @@ -1,5 +1,7 @@ @testset "Plotting" begin + println("Testing plotting features") + using PlotlyJS # First some setup diff --git a/julia/test/runtests.jl b/julia/test/runtests.jl index dc3d99d..2eecafa 100644 --- a/julia/test/runtests.jl +++ b/julia/test/runtests.jl @@ -7,11 +7,12 @@ using Thesis # Tests @testset "All Tests" begin include("spacecraft.jl") - include("laguerre-conway.jl") - include("propagator.jl") include("plotting.jl") - include("find_closest.jl") - include("monotonic_basin_hopping.jl") + include("inner_loop/laguerre-conway.jl") + include("inner_loop/propagator.jl") + include("inner_loop/find_closest.jl") + include("inner_loop/monotonic_basin_hopping.jl") + include("inner_loop/inner_loop.jl") end print() diff --git a/julia/test/spacecraft.jl b/julia/test/spacecraft.jl index 4c41d4f..236d8d0 100644 --- a/julia/test/spacecraft.jl +++ b/julia/test/spacecraft.jl @@ -1,5 +1,7 @@ @testset "Spacecraft Construction" begin + println("Testing spacecraft") + # Test that the standard spacecraft can be created craft = Sc("test") @test craft.mass == 10000. diff --git a/readme.md b/readme.md index 5e1e4e9..0aa3855 100644 --- a/readme.md +++ b/readme.md @@ -9,18 +9,31 @@ this readme as I flush out the plan a little better and then as I begin producin ## Dependencies -For now, this just generates pdf files from the markdown files that I used to take notes. If you'd -like to do that, though, you'll need: +### Generate PDFs + +To generate the PDFs (currently just the notes, but soon to include the thesis paper) you'll need: - pandoc - a working LaTeX installation - Roboto font - make +### Julia Code + +In order to run the Julia code, you'll need Julia v1.6 or higher. This project is packaged as a package, so installing the dependencies (and the project itself) is simple. Just run: + +```julia +Pkg.import(); Pkg.activate("julia"); Pkg.build() +``` + ## Installation +### Generate PDFs + To produce the pdfs, simply run: ```bash make ``` +### Julia Code +