def test13(self): solsys = new_solar_system() mercury = Mercury() mercury.particles.add_particles(solsys) idpos1 = [ (p.position - q.position) for p in mercury.particles[1:10] for q in mercury.particles[1:10] ] mercury.evolve_model(11.8618|units.yr) edpos1 = [ (p.position - q.position) for p in mercury.particles[1:10] for q in mercury.particles[1:10] ] mercury.stop() centre, orbiters = new_solar_system_for_mercury() mercury = MercuryWayWard() mercury.central_particle.add_particles(centre) mercury.orbiters.add_particles(orbiters) idpos2 = [ (p.position - q.position) for p in mercury.orbiters[0:9] for q in mercury.orbiters[0:9] ] mercury.evolve_model(11.8618|units.yr) edpos2 = [ (p.position - q.position) for p in mercury.orbiters[0:9] for q in mercury.orbiters[0:9] ] mercury.stop() for d1,d2 in zip(idpos1,idpos2): self.assertAlmostEqual(d1,d2, 7) for d1,d2 in zip(edpos1,edpos2): self.assertAlmostEqual(d1,d2, 7)
def test17(self): solsys = new_solar_system() mercury = Mercury() mercury.particles.add_particles(solsys) mercury.evolve_model(5.|units.yr) mercury.evolve_model(10.|units.yr) dpos1=mercury.particles[0].position-mercury.particles[5].position mercury.stop() mercury = Mercury() mercury.particles.add_particles(solsys) mercury.evolve_model(5.|units.yr) mercury.particles.x+=1 | units.AU mercury.particles.y+=2 | units.AU mercury.particles.z+=3 | units.AU mercury.particles.vx+=10. | units.kms mercury.particles.vy+=20. | units.kms mercury.particles.vz+=30. | units.kms mercury.evolve_model(10.|units.yr) dpos2=mercury.particles[0].position-mercury.particles[5].position mercury.stop() self.assertAlmostEqual(dpos1, dpos2, 12)
def test16(self): solsys = new_solar_system() solsys.x-=1.| units.AU p=datamodel.Particles(3) p.mass=[1,2,3] | units.MSun p.x=[1,10,100] | units.AU p.y=[0,0,-10] | units.AU p.z=[0,0,10] | units.AU from amuse.community.huayno.interface import Huayno from amuse.units import nbody_system conv=nbody_system.nbody_to_si(1. | units.AU, 1.| units.MSun) h = Huayno(conv) h.particles.add_particles(solsys) ax1,ay1,az1=h.get_gravity_at_point(p.x*0.,p.x,p.y,p.z) mercury = Mercury() mercury.particles.add_particles(solsys) ax2,ay2,az2=mercury.get_gravity_at_point(p.x*0.,p.x,p.y,p.z) self.assertAlmostRelativeEqual(ax1,ax2,12) self.assertAlmostRelativeEqual(ay1,ay2,12) self.assertAlmostRelativeEqual(az1,az2,12)
def test18(self): solsys = new_solar_system() mercury = Mercury() mercury.initialize_code() self.assertEqual(mercury.parameters.integrator,10) mercury.parameters.integrator=2 self.assertEqual(mercury.parameters.integrator,2) mercury.stop()
def test3(self): solsys = new_solar_system() mercury = Mercury() mercury.initialize_code() mercury.particles.add_particles(solsys) mercury.commit_particles() start_pos = mercury.orbiters[2].position mercury.evolve_model(365.14|units.day) self.assertAlmostEqual(mercury.orbiters[2].position, start_pos, 1) mercury.stop()
def test11(self): solsys = new_solar_system() mercury = Mercury() self.assertEqual(mercury.parameters.timestep, 8 | units.day) mercury.parameters.timestep = 1 | units.day self.assertEqual(mercury.parameters.timestep, 1 | units.day) mercury.particles.add_particles(solsys) start_pos = mercury.particles[5].position mercury.evolve_model(11.8618|units.yr) self.assertAlmostEqual(mercury.particles[5].position, start_pos, 1) mercury.stop()
def test11(self): solsys = new_solar_system() mercury = Mercury() self.assertEquals(mercury.parameters.timestep, 8 | units.day) mercury.parameters.timestep = 1 | units.day self.assertEquals(mercury.parameters.timestep, 1 | units.day) mercury.particles.add_particles(solsys) start_pos = mercury.particles[5].position mercury.evolve_model(11.8618|units.yr) self.assertAlmostEqual(mercury.particles[5].position, start_pos, 1) mercury.stop()
def main(): filename = "SunAndEarth.hdf" ss = new_solar_system() star = ss[0] planet = ss[3] converter = nbody_system.nbody_to_si(star.mass, planet.position.length()) ###BOOKLISTSTART### star_gravity = ph4(converter) star_gravity.particles.add_particle(star) planet_gravity = ph4(converter) planet_gravity.particles.add_particle(planet) channel_from_star_to_framework = star_gravity.particles.new_channel_to(ss) channel_from_planet_to_framework = planet_gravity.particles.new_channel_to( ss) gravity = bridge.Bridge(use_threading=False) gravity.add_system(star_gravity, (planet_gravity, )) gravity.add_system(planet_gravity, (star_gravity, )) ###BOOKLISTSTOP### write_set_to_file(ss, filename, 'hdf5', append_to_file=Fale) Etot_init = gravity.kinetic_energy + gravity.potential_energy Etot_prev = Etot_init gravity.timestep = 1 | units.day time = zero dt = 10 | units.day t_end = 100 | units.yr while time < t_end: time += dt gravity.evolve_model(time) Etot_prev_se = gravity.kinetic_energy + gravity.potential_energy channel_from_star_to_framework.copy() channel_from_planet_to_framework.copy() write_set_to_file(ss, filename, 'hdf5') Ekin = gravity.kinetic_energy Epot = gravity.potential_energy Etot = Ekin + Epot print "T=", time, print "E= ", Etot, "Q= ", Ekin / Epot, print "dE=", (Etot_init - Etot) / Etot, "ddE=", (Etot_prev - Etot) / Etot Etot_prev = Etot gravity.stop()
def main(): filename = "SunAndEarth.hdf" ss = new_solar_system() star = ss[0] planet = ss[3] converter=nbody_system.nbody_to_si(star.mass,planet.position.length()) ###BOOKLISTSTART### star_gravity = ph4(converter) star_gravity.particles.add_particle(star) planet_gravity = ph4(converter) planet_gravity.particles.add_particle(planet) channel_from_star_to_framework = star_gravity.particles.new_channel_to(ss) channel_from_planet_to_framework = planet_gravity.particles.new_channel_to(ss) gravity = bridge.Bridge(use_threading=False) gravity.add_system(star_gravity, (planet_gravity,) ) gravity.add_system(planet_gravity, (star_gravity,) ) ###BOOKLISTSTOP### write_set_to_file(ss, filename, 'hdf5', append_to_file=Fale) Etot_init = gravity.kinetic_energy + gravity.potential_energy Etot_prev = Etot_init gravity.timestep = 1|units.day time = zero dt = 10|units.day t_end = 100 | units.yr while time < t_end: time += dt gravity.evolve_model(time) Etot_prev_se = gravity.kinetic_energy + gravity.potential_energy channel_from_star_to_framework.copy() channel_from_planet_to_framework.copy() write_set_to_file(ss, filename, 'hdf5') Ekin = gravity.kinetic_energy Epot = gravity.potential_energy Etot = Ekin + Epot print "T=", time, print "E= ", Etot, "Q= ", Ekin/Epot, print "dE=", (Etot_init-Etot)/Etot, "ddE=", (Etot_prev-Etot)/Etot Etot_prev = Etot gravity.stop()
def test12(self): solsys = new_solar_system() mercury = Mercury() mercury.parameters.timestep = 1. | units.day mercury.particles.add_particles(solsys) start_pos = mercury.particles[5].position mercury.evolve_model(11.8618|units.yr) self.assertAlmostEqual(mercury.particles[5].position, start_pos, 1) mercury.particles.remove_particles(mercury.particles[1:5]) self.assertAlmostEqual(mercury.particles[1].position, start_pos, 1) start_pos = mercury.particles[1].position mercury.evolve_model(2*11.8618|units.yr) self.assertAlmostEqual(mercury.particles[1].position, start_pos, 1) mercury.stop()
def make_solar_system(iplanet_min, iplanet_max): ss = new_solar_system() star = ss[ss.name == "SUN"] star.type = "star" star.id = 0 planets = ss[iplanet_min:iplanet_max] planets.type = "planet" for i in range(len(planets)): planets[i].id = i converter = nbody_system.nbody_to_si(ss.mass.sum(), 1 | units.au) solar_system = Particles(0) solar_system.add_particles(star) solar_system.add_particles(planets) solar_system.move_to_center() determine_orbital_elements(solar_system) return solar_system
def test15(self): solsys = new_solar_system() solsys.x-=1.| units.AU p=datamodel.Particles(3) p.mass=[1,2,3] | units.MSun p.x=[1,10,100] | units.AU p.y=[0,0,-10] | units.AU p.z=[0,0,10] | units.AU pe=p.potential_energy_in_field(solsys) mercury = Mercury() mercury.particles.add_particles(solsys) pot=mercury.get_potential_at_point(p.x*0.,p.x,p.y,p.z) self.assertAlmostRelativeEqual((pot*p.mass).sum(),pe,12)
def test21(self): solsys = new_solar_system() mercury = Mercury() mercury.initialize_code() names=["elements_file","close_encounters_file","info_file", "bigbody_file","smallbody_file","integration_parameters_file","restart_file"] for name in names: self.assertEqual(getattr(mercury.parameters,name),"/dev/null") for name in names: setattr(mercury.parameters,name,os.path.join(mercury.output_directory,name)) for name in names: self.assertEqual(getattr(mercury.parameters,name),os.path.join(mercury.output_directory,name)) mercury.stop()
def test2(self): print "Test 2: testing new_solar_system" particles = new_solar_system() print particles expected_attributes = set( ["name", "mass", "radius", "x", "y", "z", "vx", "vy", "vz"]) self.assertEqual(set(particles.get_attribute_names_defined_in_store()), expected_attributes) self.assertAlmostEqual(particles.center_of_mass(), [0, 0, 0] | units.m, in_units=units.AU) self.assertAlmostEqual(particles.center_of_mass_velocity(), [0, 0, 0] | units.m / units.s, in_units=units.AUd) # Particles are in center-of-mass(-velocity) coordinates, move them to heliocentric coordinates: self.assertTrue(particles[0].name == "SUN") particles.position -= particles[0].position particles.velocity -= particles[0].velocity # Data from Carroll & Ostlie, An introduction to modern astrophysics, 1996 eccentricity = numpy.asarray([ 0.2056, 0.0068, 0.0167, 0.0934, 0.0483, 0.0560, 0.0461, 0.0097, 0.2482 ]) semimajor_axis = [ 0.3871, 0.7233, 1.0000, 1.5237, 5.2028, 9.5388, 19.1914, 30.0611, 39.5294 ] | units.AU self.assertAlmostRelativeEqual( particles[2:-1].position.lengths_squared(), semimajor_axis[1:-1]**2, 1) # Somewhat more complicated test for more eccentric orbiters Mercury and Pluto: expected = (constants.G * (particles[1:].mass + particles[0].mass) * semimajor_axis * (1 - eccentricity**2)).sqrt() self.assertAlmostRelativeEqual( particles[1:].position.cross(particles[1:].velocity).lengths(), expected, 2)
def create_system(): system = new_solar_system() system = system[system.mass > 10**-5 | units.MSun] # Takes gas giants and Sun only system.move_to_center() sun = Particles(1) sun.name = "Sun" sun.mass = 1.0 | units.MSun sun.radius = 1.0 | units.RSun sun.position = (0, 0, 0) | units.AU sun.velocity = (0, 0, 0) | units.kms sun.density = 3*sun.mass/(4*np.pi*sun.radius**3) names = ["Jupiter", "Saturn", "Uranus", "Neptune"] masses = [317.8, 90, 15, 17] | units.MEarth radii = [0.10049, 0.083703, 0.036455, 0.035392] | units.RSun semis = [5.4, 7.1, 10.5, 13] | units.AU #[3.5, 4.9, 6.4, 8.4] trues = [0, 90, 180, 270]| units.deg#np.random.uniform(0, 360, 4) | units.deg longs = np.random.uniform(0, 360, 4) | units.deg args = np.random.uniform(0, 360, 4) | units.deg for i in range(4): orbital_elements = get_orbital_elements_from_binary(system[0]+ system[i+1], G=constants.G) eccentricity, inclination = 0, orbital_elements[5] sun_and_plan = new_binary_from_orbital_elements(sun[0].mass, masses[i], semis[i], 0, trues[i], inclination, longs[i], args[i], G=constants.G) planet = Particles(1) planet.name = system[i+1].name planet.mass = system[i+1].mass planet.radius = system[i+1].radius # This is purely non-zero for collisional purposes planet.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) planet.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) planet.density = 3*planet.mass/(4*np.pi*planet.radius**3) sun.add_particle(planet) return sun
def create_post_tack_giants_system(): #Create the present day solar system and keep only the sun and the giants present_day_solar_system = new_solar_system() present_day_solar_system = present_day_solar_system[present_day_solar_system.mass > 10**-5 | units.MSun] # Takes gas giants and Sun only present_day_solar_system.move_to_center() #Create a post_tack_giants_system by first recreating the sun. post_tack_giants_system = Particles(1) post_tack_giants_system[0].name = "Sun" post_tack_giants_system[0].mass = 1.0 | units.MSun post_tack_giants_system[0].radius = 1.0 | units.RSun post_tack_giants_system[0].position = (0, 0, 0) | units.AU post_tack_giants_system[0].velocity = (0, 0, 0) | units.kms #The post tack orbital elements for the planets as below a = np.array([5.4, 7.1, 10.5, 13]) | units.AU true_anomalies = np.random.uniform(0, 360, 4) | units.deg long_of_ascending_node = np.random.uniform(0, 360, 4) | units.deg args_of_periapsis = np.random.uniform(0, 360, 4) | units.deg #Create the four planets as binaries with the sun and add them to the post_tack_giants_system for i in range(4): orbital_elements = get_orbital_elements_from_binary(present_day_solar_system[0]+ present_day_solar_system[i+1], G=constants.G) inclination = orbital_elements[5] #Make sure we have a sensable inclination for the giants sun_and_planet = new_binary_from_orbital_elements(post_tack_giants_system.mass[0], present_day_solar_system[i+1].mass, a[i], 0, true_anomalies[i], inclination, long_of_ascending_node[i], args_of_periapsis[i], G=constants.G) planet = Particles(1) planet.name = present_day_solar_system[i+1].name planet.mass = present_day_solar_system[i+1].mass planet.radius = present_day_solar_system[i+1].radius planet.position = (sun_and_planet[1].x-sun_and_planet[0].x, sun_and_planet[1].y-sun_and_planet[0].y, sun_and_planet[1].z-sun_and_planet[0].z) planet.velocity = (sun_and_planet[1].vx-sun_and_planet[0].vx, sun_and_planet[1].vy-sun_and_planet[0].vy, sun_and_planet[1].vz-sun_and_planet[0].vz) post_tack_giants_system.add_particle(planet) return post_tack_giants_system
def test2(self): print "Test 2: testing new_solar_system" particles = new_solar_system() print particles expected_attributes = set(["name", "mass", "radius", "x", "y", "z", "vx", "vy", "vz"]) self.assertEqual(set(particles.get_attribute_names_defined_in_store()), expected_attributes) self.assertAlmostEqual(particles.center_of_mass(), [0, 0, 0] | units.m, in_units = units.AU) self.assertAlmostEqual(particles.center_of_mass_velocity(), [0, 0, 0] | units.m/units.s, in_units = units.AUd) # Particles are in center-of-mass(-velocity) coordinates, move them to heliocentric coordinates: self.assertTrue(particles[0].name == "SUN") particles.position -= particles[0].position particles.velocity -= particles[0].velocity # Data from Carroll & Ostlie, An introduction to modern astrophysics, 1996 eccentricity = numpy.asarray([0.2056, 0.0068, 0.0167, 0.0934, 0.0483, 0.0560, 0.0461, 0.0097, 0.2482]) semimajor_axis = [0.3871, 0.7233, 1.0000, 1.5237, 5.2028, 9.5388, 19.1914, 30.0611, 39.5294] | units.AU self.assertAlmostRelativeEqual(particles[2:-1].position.lengths_squared(), semimajor_axis[1:-1]**2, 1) # Somewhat more complicated test for more eccentric orbiters Mercury and Pluto: expected = (constants.G * (particles[1:].mass + particles[0].mass) * semimajor_axis * (1 - eccentricity**2)).sqrt() self.assertAlmostRelativeEqual(particles[1:].position.cross(particles[1:].velocity).lengths(), expected, 2)
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 MWG_evolver(complete_post_tack_system, converter, N_objects, potential, end_time, time_step): #Initialise the gravity code and add the particles to it gravity_code = Huayno(converter) gravity_code.particles.add_particles(complete_post_tack_system) channel = gravity_code.particles.new_channel_to(complete_post_tack_system) gravity_bridge = 0 gravity_bridge = bridge.Bridge(use_threading=False) gravity_bridge.add_system(gravity_code, (potential,)) gravity_bridge.timestep = 100 |units.yr times = np.arange(0., end_time, time_step) | units.yr #All time steps to which we want to evolve the model #--------------------------------------------------------------------------------------------------------- #Here we define the planetary orbital parameters that should be returned to if the planets start moving too much current_sma = np.array([0, 0, 0, 0]) | units.AU correct_sma = np.array([5.4, 7.1, 10.5, 13]) | units.AU inclinations = np.array([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] #------------------------------------------------------------------------------------------------------------ dead_comets = [] #Here all 'dead' comets are stored #Below the evolving starts for i in tqdm(range(len(times))): gravity_bridge.evolve_model(times[i]) channel.copy() #--------------------------------------------------------------------------------------------------------------- #Here we check if the planetary orbits are still 'correct' and act for three degrees of incorrectness. for j in range(4): current_sma[j] = sma_determinator(gravity_code.particles[0], gravity_code.particles[j+1]) for l in range(4): if abs(current_sma[l]/correct_sma[l]) > 1.25 or abs(current_sma[l]/correct_sma[l]) < 0.75: #The orbits are too much perturbed, so we end the simulation return elif abs(current_sma[l]/correct_sma[l]) > 1.05 or abs(current_sma[l]/correct_sma[l]) < 0.95: #The orbits are slightly perturbed, so we redefinie them print("Here", complete_post_tack_system[l+1].name, "was redefined") binary = Particles(0) binary.add_particle(gravity_code.particles[0]) binary.add_particle(gravity_code.particles[l+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_plan = new_binary_from_orbital_elements(1 | units.MSun, orbital_params[1], #We keep the current angles, but change the a, e and i back correct_sma[l], 0, true_anomaly, inclinations[l], ascending_node, pericenter, G=constants.G) gravity_code.particles[l+1].position = (sun_and_plan[1].x+gravity_code.particles[0].x, sun_and_plan[1].y+gravity_code.particles[0].y, sun_and_plan[1].z+gravity_code.particles[0].z) gravity_code.particles[l+1].velocity = (sun_and_plan[1].vx+gravity_code.particles[0].vx, sun_and_plan[1].vy+gravity_code.particles[0].vy, sun_and_plan[1].vz+gravity_code.particles[0].vz) else: #The orbits do not need changing pass #---------------------------------------------------------------------------------------------------------------------- #Once we checked for the orbital correctness, we can save data if i%4000 == 0: write_set_to_file(gravity_code.particles, directory + 'MWG_run' + str(run_number) +'_time=' + str(np.log10(times[i].value_in(units.yr)))[0:5] + '.hdf5', format='hdf5', overwrite_file = True) #-------------------------------------------------------------------------------------------------------------------- #Here we look for 'escaped' and 'out of bounds' comets out_of_bounds, escaped_comets = [], [] for i in range(len(gravity_code.particles)): if (gravity_code.particles[i].position-gravity_code.particles[0].position).length() > 500 | units.AU: escaped_comets.append(gravity_code.particles[i]) if (gravity_code.particles[i].position-gravity_code.particles[0].position).length() > 250000 | units.AU: out_of_bounds.append(gravity_code.particles[i]) dead_comets.append(gravity_code.particles[i]) for particle in out_of_bounds: #Out of bounds comets are removed completely complete_post_tack_system.remove_particle(particle) complete_post_tack_system.synchronize_to(gravity_code.particles) if i%100 == 0: print("The amount of currently escaped comets is ", len(escaped_comets)) print("The amount of dead comets is ", len(dead_comets)) for m in range(4): print(complete_post_tack_system[m+1].name, " is at ", (gravity_code.particles[m+1].position-gravity_code.particles[0].position).length().in_(units.AU)) gravity_code.stop() write_set_to_file(gravity_code.orbiters, directory + 'MWG_run' + str(run_number) +'_final.hdf5', format='hdf5', overwrite_file = True) return complete_post_tack