def add_comet_objects(pre_tack_giants_system, N_objects, comet_positions, comet_velocities): for i in tqdm(range(N_objects)): comet = Particles(1) comet.name = "OORT_" + str(i) comet.mass = 0.0 | units.MSun #Take massless test particles comet.radius = 0.0 | units.RSun comet.position = (comet_positions[i, 0], comet_positions[i, 1], comet_positions[i, 2]) comet.velocity = (comet_velocities[i, 0], comet_velocities[i, 1], comet_velocities[i, 2]) comet.density = 0.0 | (units.MSun / (units.RSun**3)) pre_tack_giants_system.add_particle(comet) z_comp = np.arctan( 100 / 8500. ) #Determining the z-component of the sun's trajectory around the galactic center for i in range(len(pre_tack_giants_system) ): #adding the sun's trajectory around the galactic center pre_tack_giants_system[i].position += (1, 0, 0) * (8.5 | units.kpc) pre_tack_giants_system[i].velocity += (0, np.sqrt(1 - z_comp**2), z_comp) * (220 | units.kms) return pre_tack_giants_system
def resolve_collision(collision_detection, gravity_code, bodies, time): print("Well, we have an actual collision between two or more objects.") print("This happened at time=", time.in_(units.yr)) for ci in range(len(collision_detection.particles(0))): # Multiple pairs of collisions could take place in one timestep encountering_particles = Particles(particles=[collision_detection.particles(0)[ci], collision_detection.particles(1)[ci]]) colliding_objects = encountering_particles.get_intersecting_subset_in(bodies) merge_two_bodies(bodies, colliding_objects) bodies.synchronize_to(gravity_code.particles) # Update bodies to contain 1 particle instead of 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 add_comet_objects(pre_tack_giants_system, N_objects, comet_positions, comet_velocities): for i in tqdm(range(N_objects)): comet = Particles(1) comet.name = "OORT_" + str(i) comet.mass = 0.0 | units.MSun #Take massless test particles comet.radius = 0.0 | units.RSun comet.position = (comet_positions[i, 0], comet_positions[i, 1], comet_positions[i, 2]) comet.velocity = (comet_velocities[i, 0], comet_velocities[i, 1], comet_velocities[i, 2]) comet.density = 0.0 | (units.MSun / (units.RSun**3)) pre_tack_giants_system.add_particle(comet) return pre_tack_giants_system
def add_comet_objects(system, N_objects, rand_pos, rand_vel): for i in tqdm(range(N_objects)): oort = Particles(1) oort.name = "OORT_" + str(i) oort.mass = 0.0 | units.MSun oort.radius = (2.3 | units.km).in_(units.RSun) # This is purely non-zero for collisional purposes oort.position = (rand_pos[i, 0], rand_pos[i, 1], rand_pos[i, 2]) oort.velocity = (rand_vel[i, 0], rand_vel[i, 1], rand_vel[i, 2]) system.add_particle(oort) for particle in system: #So that Mercury will work particle.density = 3*particle.mass/(4*np.pi*particle.radius**3) return system
def merge_two_bodies(bodies, particles_in_encounter): com_pos = particles_in_encounter.center_of_mass() com_vel = particles_in_encounter.center_of_mass_velocity() d = (particles_in_encounter[0].position - particles_in_encounter[1].position) v = (particles_in_encounter[0].velocity - particles_in_encounter[1].velocity) print("Actually merger occurred:") print("Two objects (M=",particles_in_encounter.mass.in_(units.MSun), ") collided with d=", d.length().in_(units.au)) #time.sleep(10) new_particle=Particles(1) new_particle.mass = particles_in_encounter.total_mass() new_particle.position = com_pos new_particle.velocity = com_vel new_particle.radius = ((particles_in_encounter.radius**3).sum())**(1./3.) # New radius cannot simply be summed bodies.add_particles(new_particle) bodies.remove_particles(particles_in_encounter)
def body_init_sun_jupiter(): particles = Particles(2) sun = particles[0] sun.mass = 1.0 | units.MSun sun.radius = 1.0 | units.RSun sun.position = (855251, -804836, -3186) | units.km sun.velocity = (7.893, 11.894, 0.20642) | (units.m / units.s) jupiter = particles[1] jupiter.mass = 1.0 | units.MJupiter jupiter.radius = 1.0 | units.RJupiter jupiter.position = (-4.9829, 2.062, -0.10990) | units.AU jupiter.velocity = (-5.158, -11.454, 0.13558) | units.kms particles.move_to_center() return particles
def new_field_stars( N, width=10 | units.parsec, height=10 | units.parsec, depth=100 | units.parsec, massdistribution="salpeter", agespread=3 | units.Gyr, seed=1701, ): np.random.seed(seed) stars = Particles(N) stars.x = (np.random.random(N) - 0.5) * width stars.y = (np.random.random(N) - 0.5) * height stars.z = (np.random.random(N) - 0.02) * depth if massdistribution == "salpeter": stars.mass = new_salpeter_mass_distribution(N) return stars