74 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Julia
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Julia
		
	
	
	
	
	
| @testset "Inner Loop" begin
 | |
| 
 | |
|   println("Testing Inner Loop")
 | |
| 
 | |
|   using Dates, SPICE, PlotlyJS
 | |
| 
 | |
|   sc = Sc("test")
 | |
| 
 | |
|   launch_date = DateTime(2016,3,28)
 | |
|   launch_j2000 = utc2et(Dates.format(launch_date,"yyyy-mm-ddTHH:MM:SS"))
 | |
|   leg1_tof = 3600*24*30*10.75
 | |
|   leg2_tof = 3600*24*365*5.5
 | |
|   v∞s = [ [0.34251772594197877, -2.7344726708862477, -1.1854707164631975],
 | |
|           [-1.1, -3., -2.6],
 | |
|           [3.5, 3.5, √(5^2 - 2*3.5^2)],
 | |
|           [0.3, 1., 0.] ]
 | |
|   p1 = "Mars"
 | |
|   p2 = "Saturn"
 | |
|   start_mass = 10_000.
 | |
| 
 | |
|   phase1 = Phase("Earth", p1, leg1_tof, v∞s[1], v∞s[2])
 | |
|   phase2 = Phase(p1, p2, leg2_tof, v∞s[3], v∞s[4])
 | |
| 
 | |
|   # For finding the best trajectories
 | |
|   earth_state = [spkssb(Thesis.ids["Earth"], launch_j2000, "ECLIPJ2000"); start_mass]
 | |
|   p1_state = [spkssb(Thesis.ids[p1], launch_j2000+leg1_tof, "ECLIPJ2000"); start_mass]
 | |
|   p2_state = [spkssb(Thesis.ids[p2], launch_j2000+leg1_tof+leg2_tof, "ECLIPJ2000"); start_mass]
 | |
|   earth = prop(zeros(100,3), earth_state, sc, μs["Sun"], 3600*24*365.)[1]
 | |
|   p1_path = prop(zeros(100,3), p1_state, sc, μs["Sun"], 3600*24*365*2.)[1]
 | |
|   p2_path = prop(zeros(100,3), p2_state, sc, μs["Sun"], 3600*24*365*8.)[1]
 | |
|   leg1, leg1_final = prop(zeros(400,3),
 | |
|                           earth_state+[zeros(3);v∞s[1];start_mass],
 | |
|                           copy(sc),
 | |
|                           μs["Sun"],
 | |
|                           leg1_tof)
 | |
|   leg2, leg2_final = prop(zeros(400,3),
 | |
|                           p1_state+[zeros(3);v∞s[3];start_mass],
 | |
|                           copy(sc),
 | |
|                           μs["Sun"],
 | |
|                           leg2_tof)
 | |
|   savefig(plot_orbits(  [earth, p1_path, p2_path, leg1, leg2],
 | |
|                 primary="Sun",
 | |
|                 labels=["Earth", p1, p2, "Leg 1", "Leg 2"],
 | |
|                 title="Inner Loop without thrusting",
 | |
|                 colors=["#0000FF", "#FF0000", "#FFFF00", "#FF00FF", "#00FFFF"]  ),
 | |
|          "../plots/inner_loop_before.html")
 | |
| 
 | |
|   # The first leg should be valid
 | |
|   fresh_sc = copy(sc)
 | |
|   thrusts = inner_loop( launch_date,
 | |
|                         sc,
 | |
|                         start_mass,
 | |
|                         [phase1],
 | |
|                         verbose=true,
 | |
|                         mbh_specs=(25,50) )
 | |
|   path, final = prop(thrusts[1], earth_state+[zeros(3);v∞s[1];0.0], Sc("test"), μs["Sun"], leg1_tof)
 | |
|   @test final[1:6] ≈ p1_state[1:6] + [zeros(3); v∞s[2]]
 | |
|   savefig(plot_orbits(  [earth, p1_path, path],
 | |
|                 primary="Sun",
 | |
|                 labels=["Earth", p1, "Leg 1"],
 | |
|                 title="Inner Loop with thrusting",
 | |
|                 colors=["#0000FF", "#FF0000", "#FF00FF"]  ),
 | |
|           "../plots/inner_loop_after.html")
 | |
| 
 | |
|   # The second one was too hard to figure out on my own, so I'm letting it fail
 | |
|   @test_throws ErrorException inner_loop( launch_date,
 | |
|                                           sc,
 | |
|                                           start_mass,
 | |
|                                           [phase1, phase2],
 | |
|                                           verbose=true,
 | |
|                                           mbh_specs=(10,10) )
 | |
| 
 | |
| end
 | 
