51 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Julia
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Julia
		
	
	
	
	
	
| @testset "Find Closest" begin
 | |
| 
 | |
|   println("Testing NLP solver")
 | |
| 
 | |
|   using NLsolve, PlotlyJS
 | |
| 
 | |
|   # Initial Setup
 | |
|   sc = Sc("test")
 | |
|   fresh_sc = copy(sc)
 | |
|   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 = 5T
 | |
|   n = 200
 | |
| 
 | |
|   # A simple orbit raising
 | |
|   start_mass = 10_000.
 | |
|   start = [ oe_to_xyz([ a, e, i, 0., 0., 0. ], μs["Earth"]); start_mass ]
 | |
|   Tx, Ty, Tz = conv_T(repeat([0.9], n), repeat([0.], n), repeat([0.], n),
 | |
|                       start,
 | |
|                       sc,
 | |
|                       prop_time,
 | |
|                       μs["Earth"])
 | |
|   final = prop(hcat(Tx, Ty, Tz), start, copy(sc), μs["Earth"], prop_time)[2]
 | |
|   new_T = 2π*√(xyz_to_oe(final, μs["Earth"])[1]^3/μs["Earth"])
 | |
| 
 | |
|   # This should be close enough to converge
 | |
|   Tx, Ty, Tz = conv_T(repeat([0.89], n), repeat([0.], n), repeat([0.], n),
 | |
|                       start,
 | |
|                       sc,
 | |
|                       prop_time,
 | |
|                       μs["Earth"])
 | |
|   result = nlp_solve(start, final, sc, μs["Earth"], 0.0, prop_time, hcat(Tx, Ty, Tz))
 | |
| 
 | |
|   # Test and plot
 | |
|   @test result.converged
 | |
|   path1 = prop(zeros((100,3)), start, sc, μs["Earth"], T)[1]
 | |
|   path2, calc_final = prop(result.zero, start, sc, μs["Earth"], prop_time)
 | |
|   path3 = prop(zeros((100,3)), calc_final, sc, μs["Earth"], new_T)[1]
 | |
|   path4 = prop(zeros((100,3)), final, fresh_sc, μs["Earth"], new_T)[1]
 | |
|   savefig(plot_orbits([path1, path2, path3, path4],
 | |
|                       labels=["initial", "transit", "after transit", "final"],
 | |
|                       colors=["#FFFFFF","#FF4444","#44FF44","#4444FF"]),
 | |
|                       "../plots/find_closest_test.html")
 | |
|   if result.converged
 | |
|     @test norm(calc_final[1:6] - final[1:6]) < 1e-4
 | |
|   end
 | |
| 
 | |
| end
 | 
