temporary point on the inner loop wrapper
This commit is contained in:
70
julia/test/inner_loop/monotonic_basin_hopping.jl
Normal file
70
julia/test/inner_loop/monotonic_basin_hopping.jl
Normal file
@@ -0,0 +1,70 @@
|
||||
@testset "Monotonic Basin Hopping" begin
|
||||
|
||||
println("Testing Monotonic Basin Hopper")
|
||||
|
||||
# Initial Setup
|
||||
sc = Sc("test")
|
||||
a = rand(15000:1.:40000)
|
||||
e = rand(0.01:0.01:0.5)
|
||||
i = rand(0.01:0.01:π/6)
|
||||
T = 2π*√(a^3/μs["Earth"])
|
||||
prop_time = 0.75T
|
||||
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.8], n), repeat([0.], n), repeat([0.], n),
|
||||
start,
|
||||
sc.mass,
|
||||
sc,
|
||||
prop_time,
|
||||
μs["Earth"])
|
||||
nominal_path, normal_mass, final = prop(hcat(Tx, Ty, Tz), start, sc, μs["Earth"], prop_time)
|
||||
new_T = 2π*√(xyz_to_oe(final, μs["Earth"])[1]^3/μs["Earth"])
|
||||
|
||||
# Find the best solution
|
||||
best, archive = mbh(start,
|
||||
final,
|
||||
sc,
|
||||
μs["Earth"],
|
||||
0.0,
|
||||
prop_time,
|
||||
n,
|
||||
num_iters=5,
|
||||
patience_level=50,
|
||||
verbose=true)
|
||||
|
||||
# Test and plot
|
||||
@test converged(best)
|
||||
transit, best_masses, calc_final = prop(tanh.(best.zero), start, sc, μs["Earth"], prop_time)
|
||||
initial_path = prop(zeros((100,3)), start, sc, μs["Earth"], T)[1]
|
||||
after_transit = prop(zeros((100,3)), calc_final, sc, μs["Earth"], new_T)[1]
|
||||
final_path = prop(zeros((100,3)), final, sc, μs["Earth"], new_T)[1]
|
||||
savefig(plot_orbits([initial_path, nominal_path, final_path],
|
||||
labels=["initial", "nominal transit", "final"],
|
||||
colors=["#FF4444","#44FF44","#4444FF"]),
|
||||
"../plots/mbh_nominal.html")
|
||||
savefig(plot_orbits([initial_path, transit, after_transit, final_path],
|
||||
labels=["initial", "transit", "after transit", "final"],
|
||||
colors=["#FFFFFF", "#FF4444","#44FF44","#4444FF"]),
|
||||
"../plots/mbh_best.html")
|
||||
i = 0
|
||||
best_mass = best_masses[end]
|
||||
nominal_mass = normal_mass[end]
|
||||
masses = []
|
||||
for candidate in archive
|
||||
@test converged(candidate)
|
||||
path2, cand_ms, calc_final = prop(tanh.(candidate.zero), start, sc, μs["Earth"], prop_time)
|
||||
push!(masses, cand_ms[end])
|
||||
@test norm(calc_final - final) < 1e-4
|
||||
end
|
||||
@test best_mass == maximum(masses)
|
||||
|
||||
# This won't always work since the test is reduced in fidelity,
|
||||
# but hopefully will usually work:
|
||||
@test (sc.mass - best_mass) < 1.1 * (sc.mass - nominal_mass)
|
||||
@show best_mass
|
||||
@show nominal_mass
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user