def test5(self): centre, orbiters = new_solar_system_for_mercury() mercury = MercuryWayWard() self.assertEqual(mercury.get_name_of_current_state(), 'UNINITIALIZED') mercury.initialize_code() self.assertEqual(mercury.get_name_of_current_state(), 'INITIALIZED') mercury.commit_parameters() self.assertEqual(mercury.get_name_of_current_state(), 'EDIT') mercury.central_particle.add_particles(centre) self.assertEqual(mercury.get_name_of_current_state(), 'EDIT') mercury.orbiters.add_particles(orbiters) self.assertEqual(mercury.get_name_of_current_state(), 'EDIT') mercury.commit_particles() self.assertEqual(mercury.get_name_of_current_state(), 'RUN') start_pos = mercury.orbiters[2].position mercury.evolve_model(365.14|units.day) self.assertEqual(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[2].position, start_pos, 1) mercury.cleanup_code() self.assertEqual(mercury.get_name_of_current_state(), 'END') mercury.stop()
def test14(self): centre, orbiters = new_solar_system_for_mercury() oneyear = 365.14 | units.day halfyear = oneyear / 2.0 mercury = MercuryWayWard() mercury.initialize_code() mercury.commit_parameters() mercury.central_particle.add_particles(centre) mercury.orbiters.add_particles(orbiters) start_pos = mercury.orbiters[2].position mercury.evolve_model(halfyear) central_particles = mercury.central_particle.copy() orbiters = mercury.orbiters.copy() mercury.stop() mercury = MercuryWayWard() mercury.initialize_code() mercury.parameters.begin_time = halfyear mercury.commit_parameters() mercury.central_particle.add_particles(centre) mercury.orbiters.add_particles(orbiters) mercury.evolve_model(oneyear) self.assertAlmostEqual(mercury.orbiters[2].position, start_pos, 1) mercury.stop()
def test5(self): centre, orbiters = new_solar_system_for_mercury() mercury = MercuryWayWard() self.assertEquals(mercury.get_name_of_current_state(), 'UNINITIALIZED') mercury.initialize_code() self.assertEquals(mercury.get_name_of_current_state(), 'INITIALIZED') mercury.commit_parameters() self.assertEquals(mercury.get_name_of_current_state(), 'EDIT') mercury.central_particle.add_particles(centre) self.assertEquals(mercury.get_name_of_current_state(), 'EDIT') mercury.orbiters.add_particles(orbiters) self.assertEquals(mercury.get_name_of_current_state(), 'EDIT') mercury.commit_particles() self.assertEquals(mercury.get_name_of_current_state(), 'RUN') start_pos = mercury.orbiters[2].position mercury.evolve_model(365.14|units.day) self.assertEquals(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[2].position, start_pos, 1) mercury.cleanup_code() self.assertEquals(mercury.get_name_of_current_state(), 'END') mercury.stop()
def test0(self): centre, orbiter = self.sun_and_earth() mercury = MercuryWayWard() #,debugger='xterm') mercury.initialize_code() mercury.central_particle.add_particles(centre) mercury.orbiters.add_particles(orbiter) mercury.commit_particles() self.assertAlmostEqual(mercury.central_particle.j4, .0 | units.AU**4) self.assertAlmostEqual(mercury.central_particle.mass, 1.98892e+30 | units.kg, 3) self.assertAlmostEqual(mercury.central_particle.mass, 1.0 | units.MSun, 3) self.assertEquals(mercury.get_number_of_orbiters(), 1) self.assertEquals(mercury.orbiters.position, [[1, 0, 0]] | units.AU) self.assertEquals(mercury.orbiters.density, 1.0 | units.g / units.cm**3) self.assertEquals(mercury.orbiters.angular_momentum, [[1.0, 0.0, 0.0]] | units.MSun * units.AU**2 / units.day) mercury.evolve_model(365.24 | units.day) self.assertAlmostEqual(mercury.orbiters.position, [[1.0, 0.0, 0.0]] | units.AU, 1) self.assertAlmostEqual( mercury.kinetic_energy + mercury.potential_energy, mercury.total_energy, 3) mercury.stop()
def integrate_and_store(): sun, planets = Solarsystem.new_solarsystem() #timerange = units.day(numpy.arange(20, 120 * 365.25, 12)) timerange = Vq.arange(20 | units.day, 120 | units.yr, 10 | units.day) pdb.set_trace() instance = MercuryWayWard() instance.initialize_code() instance.central_particle.add_particles(sun) instance.orbiters.add_particles(planets) instance.commit_particles() channels = instance.orbiters.new_channel_to(planets) err = instance.evolve_model(10 | units.day) pdb.set_trace() channels.copy() planets.savepoint(10 | units.day) pdb.set_trace() for time in timerange: err = instance.evolve_model(time) channels.copy() planets.savepoint(time) instance.stop() pdb.set_trace()
def test2(self): centre, orbiters = new_solar_system_for_mercury() mercury = MercuryWayWard() mercury.initialize_code() mercury.central_particle.add_particles(centre) mercury.orbiters.add_particles(orbiters) mercury.commit_particles() start_pos = mercury.orbiters[2].position mercury.evolve_model(16.|units.day) self.assertEqual(mercury.get_time(),16.|units.day) mercury.stop()
def planetplot(): sun, planets = new_solar_system_for_mercury() timerange = units.day(numpy.arange(0, 120 * 365.25, 12)) instance = MercuryWayWard() instance.initialize_code() instance.central_particle.add_particles(sun) instance.orbiters.add_particles(planets) instance.commit_particles() channels = instance.orbiters.new_channel_to(planets) for time in timerange: err = instance.evolve_model(time) channels.copy() planets.savepoint(time) instance.stop() for planet in planets: t, x = planet.get_timeline_of_attribute_as_vector("x") t, y = planet.get_timeline_of_attribute_as_vector("y") plot(x, y,'.') native_plot.show()
def planetplot(): sun, planets = new_solar_system_for_mercury() timerange = units.day(numpy.arange(0, 120 * 365.25, 12)) instance = MercuryWayWard() instance.initialize_code() instance.central_particle.add_particles(sun) instance.orbiters.add_particles(planets) instance.commit_particles() channels = instance.orbiters.new_channel_to(planets) for time in timerange: err = instance.evolve_model(time) channels.copy() planets.savepoint(time) instance.stop() for planet in planets: t, x = planet.get_timeline_of_attribute_as_vector("x") t, y = planet.get_timeline_of_attribute_as_vector("y") plot(x, y, '.') native_plot.show()
def test10(self): centre, orbiters = new_solar_system_for_mercury() mercury = MercuryWayWard() mercury.central_particle.add_particles(centre) self.assertEqual(mercury.get_name_of_current_state(), 'EDIT') mercury.orbiters.add_particles(orbiters[4:5]) self.assertEqual(mercury.get_name_of_current_state(), 'EDIT') start_pos = mercury.orbiters[0].position mercury.evolve_model(11.8618|units.yr) self.assertEqual(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1) mercury.orbiters.add_particles(orbiters[0:4]) self.assertEqual(mercury.get_name_of_current_state(), 'UPDATE') self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1) start_pos = mercury.orbiters[0].position mercury.evolve_model(2*11.8618|units.yr) self.assertEqual(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1)
def test10(self): centre, orbiters = new_solar_system_for_mercury() mercury = MercuryWayWard() mercury.central_particle.add_particles(centre) self.assertEquals(mercury.get_name_of_current_state(), 'EDIT') mercury.orbiters.add_particles(orbiters[4:5]) self.assertEquals(mercury.get_name_of_current_state(), 'EDIT') start_pos = mercury.orbiters[0].position mercury.evolve_model(11.8618|units.yr) self.assertEquals(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1) mercury.orbiters.add_particles(orbiters[0:4]) self.assertEquals(mercury.get_name_of_current_state(), 'UPDATE') self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1) start_pos = mercury.orbiters[0].position mercury.evolve_model(2*11.8618|units.yr) self.assertEquals(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1)
def test0(self): centre, orbiter = self.sun_and_earth() mercury = MercuryWayWard()#,debugger='xterm') mercury.initialize_code() mercury.central_particle.add_particles(centre) mercury.orbiters.add_particles(orbiter) mercury.commit_particles() self.assertAlmostEqual(mercury.central_particle.j4, .0|units.AU**4) self.assertAlmostEqual(mercury.central_particle.mass, 1.98892e+30 |units.kg, 3) self.assertAlmostEqual(mercury.central_particle.mass, 1.0 |units.MSun, 3) self.assertEquals(mercury.get_number_of_orbiters(),1) self.assertEquals(mercury.orbiters.position, [[1,0,0]] | units.AU) self.assertEquals(mercury.orbiters.density, 1.0|units.g/units.cm**3 ) self.assertEquals(mercury.orbiters.angular_momentum, [[1.0, 0.0, 0.0]] | units.MSun*units.AU**2/units.day) mercury.evolve_model(365.24 | units.day) self.assertAlmostEqual(mercury.orbiters.position, [[1.0, 0.0, 0.0]] | units.AU, 1) self.assertAlmostEqual(mercury.kinetic_energy+mercury.potential_energy,mercury.total_energy,3) mercury.stop()
def test8(self): centre, orbiters = new_solar_system_for_mercury() mercury = MercuryWayWard()#debugger="gdb") self.assertEquals(mercury.get_name_of_current_state(), 'UNINITIALIZED') mercury.initialize_code() self.assertEquals(mercury.get_name_of_current_state(), 'INITIALIZED') mercury.commit_parameters() self.assertEquals(mercury.get_name_of_current_state(), 'EDIT') mercury.central_particle.add_particles(centre) self.assertEquals(mercury.get_name_of_current_state(), 'EDIT') mercury.orbiters.add_particles(orbiters[0:5]) self.assertEquals(mercury.get_name_of_current_state(), 'EDIT') mercury.commit_particles() self.assertEquals(mercury.get_name_of_current_state(), 'RUN') start_pos = mercury.orbiters[4].position mercury.evolve_model(11.8618|units.yr) self.assertEquals(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[4].position, start_pos, 1) mercury.orbiters.remove_particles(orbiters[0:4]) self.assertEquals(mercury.get_name_of_current_state(), 'UPDATE') mercury.recommit_particles() self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1) start_pos = mercury.orbiters[0].position mercury.evolve_model(2*11.8618|units.yr) self.assertEquals(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1) mercury.cleanup_code() self.assertEquals(mercury.get_name_of_current_state(), 'END') mercury.stop()
def test8(self): centre, orbiters = new_solar_system_for_mercury() mercury = MercuryWayWard()#debugger="gdb") self.assertEqual(mercury.get_name_of_current_state(), 'UNINITIALIZED') mercury.initialize_code() self.assertEqual(mercury.get_name_of_current_state(), 'INITIALIZED') mercury.commit_parameters() self.assertEqual(mercury.get_name_of_current_state(), 'EDIT') mercury.central_particle.add_particles(centre) self.assertEqual(mercury.get_name_of_current_state(), 'EDIT') mercury.orbiters.add_particles(orbiters[0:5]) self.assertEqual(mercury.get_name_of_current_state(), 'EDIT') mercury.commit_particles() self.assertEqual(mercury.get_name_of_current_state(), 'RUN') start_pos = mercury.orbiters[4].position mercury.evolve_model(11.8618|units.yr) self.assertEqual(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[4].position, start_pos, 1) mercury.orbiters.remove_particles(orbiters[0:4]) self.assertEqual(mercury.get_name_of_current_state(), 'UPDATE') mercury.recommit_particles() self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1) start_pos = mercury.orbiters[0].position mercury.evolve_model(2*11.8618|units.yr) self.assertEqual(mercury.get_name_of_current_state(), 'EVOLVED') self.assertAlmostEqual(mercury.orbiters[0].position, start_pos, 1) mercury.cleanup_code() self.assertEqual(mercury.get_name_of_current_state(), 'END') mercury.stop()
def planetplot(): sun, planets = new_solar_system_for_mercury() initial = 12.2138 | units.Gyr final = 12.3300 | units.Gyr step = 10000.0 | units.yr timerange = VectorQuantity.arange(initial, final, step) gd = MercuryWayWard() gd.initialize_code() # gd.stopping_conditions.timeout_detection.disable() gd.central_particle.add_particles(sun) gd.orbiters.add_particles(planets) gd.commit_particles() se = SSE() # se.initialize_code() se.commit_parameters() se.particles.add_particles(sun) se.commit_particles() channelp = gd.orbiters.new_channel_to(planets) channels = se.particles.new_channel_to(sun) for time in timerange: err = gd.evolve_model(time-initial) channelp.copy() # planets.savepoint(time) err = se.evolve_model(time) channels.copy() gd.central_particle.mass = sun.mass print( sun[0].mass.value_in(units.MSun), time.value_in(units.Myr), planets[4].x.value_in(units.AU), planets[4].y.value_in(units.AU), planets[4].z.value_in(units.AU) ) gd.stop() se.stop() for planet in planets: t, x = planet.get_timeline_of_attribute_as_vector("x") t, y = planet.get_timeline_of_attribute_as_vector("y") plot(x, y, '.') native_plot.gca().set_aspect('equal') native_plot.show()
def planetplot(): sun, planets = new_solar_system_for_mercury() initial = 12.2138 | units.Gyr final = 12.3300 | units.Gyr step = 10000.0 | units.yr timerange = VectorQuantity.arange(initial, final, step) gd = MercuryWayWard() gd.initialize_code() # gd.stopping_conditions.timeout_detection.disable() gd.central_particle.add_particles(sun) gd.orbiters.add_particles(planets) gd.commit_particles() se = SSE() # se.initialize_code() se.commit_parameters() se.particles.add_particles(sun) se.commit_particles() channelp = gd.orbiters.new_channel_to(planets) channels = se.particles.new_channel_to(sun) for time in timerange: err = gd.evolve_model(time - initial) channelp.copy() # planets.savepoint(time) err = se.evolve_model(time) channels.copy() gd.central_particle.mass = sun.mass print( (sun[0].mass.value_in(units.MSun), time.value_in(units.Myr), planets[4].x.value_in(units.AU), planets[4].y.value_in(units.AU), planets[4].z.value_in(units.AU))) gd.stop() se.stop() for planet in planets: t, x = planet.get_timeline_of_attribute_as_vector("x") t, y = planet.get_timeline_of_attribute_as_vector("y") plot(x, y, '.') native_plot.gca().set_aspect('equal') native_plot.show()
def vanilla_evolver(particle_system, converter, N_objects, end_time, time_step): names = ['Sun', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'] gravity_code = MercuryWayWard() gravity_code.initialize_code() gravity_code.central_particle.add_particle(particle_system[0]) gravity_code.orbiters.add_particles(particle_system[1:]) gravity_code.commit_particles ch_g2l = gravity_code.particles.new_channel_to(particle_system) times = np.arange(0., end_time, time_step) | units.yr dead_comets = [] #--------------------------------------------------------------------------------------------------------- sma = [0, 0, 0, 0] | units.AU correct_sma = [5.4, 7.1, 10.5, 13] | units.AU eccentricities = [0, 0, 0, 0] inclinations = [0, 0, 0, 0] | units.deg system = new_solar_system() system = system[system.mass > 10**-5 | units.MSun] # Takes gas giants and Sun only system.move_to_center() for k in range(4): orbital_elements = get_orbital_elements_from_binary(system[0]+ system[k+1], G=constants.G) inclinations[k] = orbital_elements[5] #------------------------------------------------------------------------------------------------------------ for i in tqdm(range(len(times))): gravity_code.evolve_model(times[i]) ch_g2l.copy() #--------------------------------------------------------------------------------------------------------------- for j in range(4): sma[j] = sma_determinator(gravity_code.central_particle, gravity_code.orbiters[j]) for l in range(4): if abs(sma[l]/correct_sma[l]) > 1.25 or abs(sma[l]/correct_sma[l]) < 0.75: return elif abs(sma[l]/correct_sma[l]) > 1.05 or abs(sma[l]/correct_sma[l]) < 0.95: print("Here", names[l+1], "was redefined") binary = Particles(0) binary.add_particle(gravity_code.central_particle) binary.add_particle(gravity_code.orbiters[l]) orbital_params = get_orbital_elements_from_binary(binary, G = constants.G) true_anomaly, ascending_node, pericenter = orbital_params[4].in_(units.deg), orbital_params[6].in_(units.deg), orbital_params[7].in_(units.deg) sun_and_plan = new_binary_from_orbital_elements(1 | units.MSun, orbital_params[1], correct_sma[l], eccentricities[l], true_anomaly, inclinations[l], ascending_node, pericenter, G=constants.G) gravity_code.particles[l+1].position = (sun_and_plan[1].x-sun_and_plan[0].x, sun_and_plan[1].y-sun_and_plan[0].y, sun_and_plan[1].z-sun_and_plan[0].z) gravity_code.particles[l+1].velocity = (sun_and_plan[1].vx-sun_and_plan[0].vx, sun_and_plan[1].vy-sun_and_plan[0].vy, sun_and_plan[1].vz-sun_and_plan[0].vz) else: pass #---------------------------------------------------------------------------------------------------------------------- if i%1000 == 0: write_set_to_file(gravity_code.orbiters, directory + 'Vanilla_run16_time=' + str(np.log10(times[i].value_in(units.yr)))[0:5] + '.hdf5', format='hdf5', overwrite_file = True) out_of_bounds, escaped_comets = [], [] for i in range(len(particle_system)): if particle_system[i].position.length() > 500 | units.AU: escaped_comets.append(particle_system[i].name) if particle_system[i].position.length() > 250000 | units.AU: out_of_bounds.append(particle_system[i]) dead_comets.append(particle_system[i]) for particle in out_of_bounds: particle_system.remove_particle(particle) particle_system.synchronize_to(gravity_code.particles) print("The amount of currently escaped comets is ", len(escaped_comets)) print("The amount of dead comets is ", len(dead_comets)) print("The planetary positions are ", gravity_code.orbiters[0].position.length().in_(units.AU), gravity_code.orbiters[1].position.length().in_(units.AU), gravity_code.orbiters[2].position.length().in_(units.AU), gravity_code.orbiters[3].position.length().in_(units.AU)) gravity_code.stop() write_set_to_file(gravity_code.orbiters, directory + 'Vanilla_run16_final.hdf5', format='hdf5', overwrite_file = True) return particle_system
def vanilla_tack_evolver(complete_pre_tack_system, converter, N_objects, times, save_file_times): #Initialise the gravity code and add the particles to it gravity_code = MercuryWayWard(converter) gravity_code.initialize_code() gravity_code.central_particle.add_particle(complete_pre_tack_system[0]) gravity_code.orbiters.add_particles(complete_pre_tack_system[1:]) gravity_code.commit_particles channel = gravity_code.particles.new_channel_to(complete_pre_tack_system) #---------------------------------------------------------------------------------------------------- #Here we define the 'correct' sma's for the different migrations. Also, the initial #planetary inclinations are stored for later use. initial_sma = np.array([3.5, 4.5, 6.013, 8.031]) | units.AU saturn_sma = np.array([1.5, 4.5, 6.013, 8.031]) | units.AU outward_sma = np.array([1.5, 1.5 * ((3 / 2)**(2 / 3)), 6.013, 8.031]) | units.AU post_tack_sma = np.array([5.4, 7.1, 10.5, 13.]) | units.AU current_sma = [3.5, 4.5, 6.013, 8.031] | units.AU inclinations = [0, 0, 0, 0] | units.deg for k in range(4): orbital_elements = get_orbital_elements_from_binary( complete_pre_tack_system[0] + complete_pre_tack_system[k + 1], G=constants.G) inclinations[k] = orbital_elements[5] #---------------------------------------------------------------------------------------------------- #Here we define the parameters used in the 'semi_major_axis_next_step' functions #The sma's are based on exact resonances. The time_scales are taken from literature. #The 0 values will be changed during the evolution of the model. #pre_resonant is used in the outward migration, when jupiter and saturn are #already in resonance with eachother, so that pre_resonant = True a_start = [1.5, 1.5 * ((3 / 2)**(2 / 3)), 0, 0] | units.AU a_end = [ 5.4, 5.4 * ((3 / 2)**(2 / 3)), 5.4 * ((3 / 2)**(2 / 3) * (9 / 5)**(2 / 3)), 5.4 * ((3 / 2)**(2 / 3) * (5 / 2)**(2 / 3)) ] | units.AU time_start = [1.025 * 10**5, 1.025 * 10**5, 0, 0] | units.yr time_scale = [5 * 10**5, 5 * 10**5, 0, 0] | units.yr resonances = [2 / 3, 3 / 2, 9 / 5, 5 / 2] pre_resonant = [False, False, True, True] outward_migration_started = False dead_comets = [] #---------------------------------------------------------------------------------------------------- #Below, the evolution starts. for i in tqdm(range(len(times) - 1)): gravity_code.evolve_model(times[i]) channel.copy() #Save the model when we want it to if times[i] in save_file_times: write_set_to_file( gravity_code.orbiters, directory + 'Vanilla_Tack_run' + str(run_number) + '_time=' + str(np.log10(times[i].value_in(units.yr)))[0:5] + '.hdf5', format='hdf5', overwrite_file=True) #For each timestep determine the current sma's for j in range(4): current_sma[j] = sma_determinator(gravity_code.central_particle, gravity_code.orbiters[j]) #----------------------------------------------------------------------------------------------------- #This chunk of code describes the inward migration of jupiter #The first orbiter and the second particle in the gravity_code. if times[i] < 10**5 | units.yr: #This pushes Jupiter slightly inward sma_next_step = semi_major_axis_next_step_in_jup( times[i + 1], 10**5 | units.yr, 3.5 | units.AU, 1.5 | units.AU) binary = Particles(0) binary.add_particle(gravity_code.central_particle) binary.add_particle(gravity_code.orbiters[0]) orbital_params = get_orbital_elements_from_binary(binary, G=constants.G) true_anomaly, ascending_node, pericenter = orbital_params[4].in_( units.deg), orbital_params[6].in_( units.deg), orbital_params[7].in_(units.deg) sun_and_planet = new_binary_from_orbital_elements( 1 | units.MSun, orbital_params[1], sma_next_step, 0, true_anomaly, inclinations[0], ascending_node, pericenter, G=constants.G) gravity_code.particles[1].position = (sun_and_planet[1].x - (0 | units.AU), sun_and_planet[1].y - (0 | units.AU), sun_and_planet[1].z - (0 | units.AU)) gravity_code.particles[1].velocity = (sun_and_planet[1].vx - (0 | units.kms), sun_and_planet[1].vy - (0 | units.kms), sun_and_planet[1].vz - (0 | units.kms)) #During the tack, the masses of the planets increase towards their current values gravity_code.particles[2].mass *= 2**(1.5 / (10**5)) gravity_code.particles[3].mass *= 1.2**(1.5 / (10**5)) gravity_code.particles[4].mass *= 1.2**(1.5 / (10**5)) #This keeps the other planets in place for j in range(3): binary = Particles(0) binary.add_particle(gravity_code.central_particle) binary.add_particle(gravity_code.orbiters[j + 1]) orbital_params = get_orbital_elements_from_binary( binary, G=constants.G) true_anomaly, ascending_node, pericenter = orbital_params[ 4].in_(units.deg), orbital_params[6].in_( units.deg), orbital_params[7].in_(units.deg) sun_and_planet = new_binary_from_orbital_elements( 1 | units.MSun, orbital_params[1], initial_sma[1 + j], 0, true_anomaly, inclinations[j + 1], ascending_node, pericenter, G=constants.G) gravity_code.particles[j + 2].position = (sun_and_planet[1].x - (0 | units.AU), sun_and_planet[1].y - (0 | units.AU), sun_and_planet[1].z - (0 | units.AU)) gravity_code.particles[j + 2].velocity = ( sun_and_planet[1].vx - (0 | units.kms), sun_and_planet[1].vy - (0 | units.kms), sun_and_planet[1].vz - (0 | units.kms)) #------------------------------------------------------------------------------------------------------------ #This chunk of code describes the inward migration of saturn elif 1 * 10**5 | units.yr <= times[i] < 1.025 * 10**5 | units.yr: #This pushes Saturn slightly inward sma_next_step = semi_major_axis_next_step_in_sat( times[i + 1], 2.5 * 10**3 | units.yr, 4.5 | units.AU, 1.5 * ((3 / 2)**(2 / 3)) | units.AU) binary = Particles(0) binary.add_particle(gravity_code.central_particle) binary.add_particle(gravity_code.orbiters[1]) orbital_params = get_orbital_elements_from_binary(binary, G=constants.G) true_anomaly, ascending_node, pericenter = orbital_params[4].in_( units.deg), orbital_params[6].in_( units.deg), orbital_params[7].in_(units.deg) sun_and_planet = new_binary_from_orbital_elements( 1 | units.MSun, orbital_params[1], sma_next_step, 0, true_anomaly, inclinations[1], ascending_node, pericenter, G=constants.G) gravity_code.particles[2].position = (sun_and_planet[1].x - (0 | units.AU), sun_and_planet[1].y - (0 | units.AU), sun_and_planet[1].z - (0 | units.AU)) gravity_code.particles[2].velocity = (sun_and_planet[1].vx - (0 | units.kms), sun_and_planet[1].vy - (0 | units.kms), sun_and_planet[1].vz - (0 | units.kms)) gravity_code.particles[2].mass *= 1.5**(0.5 / (2500)) gravity_code.particles[3].mass *= (17.15 / 6)**(0.5 / (5 * 10**5)) gravity_code.particles[4].mass *= (14.54 / 6)**(0.5 / (5 * 10**5)) #This keeps the other planets in place for j in [0, 2, 3]: binary = Particles(0) binary.add_particle(gravity_code.central_particle) binary.add_particle(gravity_code.orbiters[j]) orbital_params = get_orbital_elements_from_binary( binary, G=constants.G) true_anomaly, ascending_node, pericenter = orbital_params[ 4].in_(units.deg), orbital_params[6].in_( units.deg), orbital_params[7].in_(units.deg) sun_and_planet = new_binary_from_orbital_elements( 1 | units.MSun, orbital_params[1], saturn_sma[j], 0, true_anomaly, inclinations[j], ascending_node, pericenter, G=constants.G) gravity_code.particles[j + 1].position = (sun_and_planet[1].x - (0 | units.AU), sun_and_planet[1].y - (0 | units.AU), sun_and_planet[1].z - (0 | units.AU)) gravity_code.particles[j + 1].velocity = ( sun_and_planet[1].vx - (0 | units.kms), sun_and_planet[1].vy - (0 | units.kms), sun_and_planet[1].vz - (0 | units.kms)) #------------------------------------------------------------------------------------------------------------ #This chunk of code describes the outward migration of all planets elif 1.025 * 10**5 | units.yr <= times[i] < 6 * 10**5 | units.yr: #This bit checks if uranus and neptune already should start migrating for k in range(4): if pre_resonant[k] == True: if current_sma[k] / current_sma[1] < (resonances[k])**(2 / 3): pre_resonant[k] = False a_start[k] = current_sma[k] time_start[k] = times[i] time_scale[k] = (6 * 10**5 | units.yr) - times[i] #If pre_resonant == False, pushes the planet outward. If true, keeps it in place for l in range(4): if pre_resonant[l] == False: sma_next_step = semi_major_axis_next_step_out( times[i + 1], time_start[l], a_end[l], a_start[l], time_scale[l]) binary = Particles(0) binary.add_particle(gravity_code.central_particle) binary.add_particle(gravity_code.orbiters[l]) orbital_params = get_orbital_elements_from_binary( binary, G=constants.G) true_anomaly, ascending_node, pericenter = orbital_params[ 4].in_(units.deg), orbital_params[6].in_( units.deg), orbital_params[7].in_(units.deg) sun_and_planet = new_binary_from_orbital_elements( 1 | units.MSun, orbital_params[1], sma_next_step, 0, true_anomaly, inclinations[l], ascending_node, pericenter, G=constants.G) gravity_code.particles[l + 1].position = ( sun_and_planet[1].x - (0 | units.AU), sun_and_planet[1].y - (0 | units.AU), sun_and_planet[1].z - (0 | units.AU)) gravity_code.particles[l + 1].velocity = ( sun_and_planet[1].vx - (0 | units.kms), sun_and_planet[1].vy - (0 | units.kms), sun_and_planet[1].vz - (0 | units.kms)) else: binary = Particles(0) binary.add_particle(gravity_code.central_particle) binary.add_particle(gravity_code.orbiters[l]) orbital_params = get_orbital_elements_from_binary( binary, G=constants.G) true_anomaly, ascending_node, pericenter = orbital_params[ 4].in_(units.deg), orbital_params[6].in_( units.deg), orbital_params[7].in_(units.deg) sun_and_planet = new_binary_from_orbital_elements( 1 | units.MSun, orbital_params[1], outward_sma[l], 0, true_anomaly, inclinations[l], ascending_node, pericenter, G=constants.G) gravity_code.particles[l + 1].position = ( sun_and_planet[1].x - (0 | units.AU), sun_and_planet[1].y - (0 | units.AU), sun_and_planet[1].z - (0 | units.AU)) gravity_code.particles[l + 1].velocity = ( sun_and_planet[1].vx - (0 | units.kms), sun_and_planet[1].vy - (0 | units.kms), sun_and_planet[1].vz - (0 | units.kms)) gravity_code.particles[3].mass *= (17.15 / 6)**(15 / (5 * 10**5)) gravity_code.particles[4].mass *= (14.54 / 6)**(15 / (5 * 10**5)) #------------------------------------------------------------------------------------------------------------ else: #--------------------------------------------------------------------------------------------------------------- for l in range(4): if abs(current_sma[l] / post_tack_sma[l]) > 1.25 or abs( current_sma[l] / post_tack_sma[l] ) < 0.75: #The orbits are too much perturbed, so we end the simulation return elif abs(current_sma[l] / post_tack_sma[l]) > 1.05 or abs( current_sma[l] / post_tack_sma[l] ) < 0.95: #The orbits are slightly perturbed, so we redefinie them print("Here", complete_pre_tack_system[l + 1].name, "was redefined") binary = Particles(0) binary.add_particle(gravity_code.central_particle) binary.add_particle(gravity_code.orbiters[l]) orbital_params = get_orbital_elements_from_binary( binary, G=constants.G) true_anomaly, ascending_node, pericenter = orbital_params[ 4].in_(units.deg), orbital_params[6].in_( units.deg), orbital_params[7].in_(units.deg) sun_and_planet = new_binary_from_orbital_elements( 1 | units.MSun, orbital_params[1], post_tack_sma[l], 0, true_anomaly, inclinations[l], ascending_node, pericenter, G=constants.G) gravity_code.particles[l + 1].position = ( sun_and_planet[1].x - (0 | units.AU), sun_and_planet[1].y - (0 | units.AU), sun_and_planet[1].z - (0 | units.AU)) gravity_code.particles[l + 1].velocity = ( sun_and_planet[1].vx - (0 | units.kms), sun_and_planet[1].vy - (0 | units.kms), sun_and_planet[1].vz - (0 | units.kms)) else: pass #---------------------------------------------------------------------------------------------------------------------- #Here we look for 'escaped' and 'out of bounds' comets out_of_bounds, escaped_comets = [], [] for i in range(len(gravity_code.orbiters)): if gravity_code.orbiters[i].position.length() > 500 | units.AU: escaped_comets.append(gravity_code.orbiters[i]) if gravity_code.orbiters[i].position.length( ) > 250000 | units.AU: out_of_bounds.append(gravity_code.orbiters[i]) dead_comets.append(gravity_code.orbiters[i]) for particle in out_of_bounds: complete_pre_tack_system.remove_particle(particle) complete_pre_tack_system.synchronize_to(gravity_code.particles) if i % 1000 == 0: print("The amount of currently escaped comets is ", len(escaped_comets)) print("The amount of dead comets is ", len(dead_comets)) if i % 1000 == 0: print("The sma's are: ", current_sma[0], current_sma[1], current_sma[2], current_sma[3]) gravity_code.stop() return complete_pre_tack_system