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 merge_two_particles(gravity, particles_in_encounter): new_particle = Particles(1) new_particle.mass = particles_in_encounter.total_mass() new_particle.position = particles_in_encounter.center_of_mass() new_particle.velosity = particles_in_encounter.center_of_mass_velocity() new_particle.radius = particles_in_encounter.radius.sum() gravity.particles.add_particles(new_particle) gravity.particles.remove_particles(particles_in_encounter)
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_pre_tack_giants_system(): #Create a pre_tack_giants_system by first recreating the sun. pre_tack_giants_system = Particles(1) pre_tack_giants_system[0].name = "Sun" pre_tack_giants_system[0].mass = 1.0 | units.MSun pre_tack_giants_system[0].radius = 1.0 | units.RSun pre_tack_giants_system[0].position = (0, 0, 0) | units.AU pre_tack_giants_system[0].velocity = (0, 0, 0) | units.kms pre_tack_giants_system[0].density = 3 * pre_tack_giants_system[0].mass / ( 4 * np.pi * pre_tack_giants_system[0].radius**3) #The pre tack orbital elements for the planets as below names = ["Jupiter", "Saturn", "Uranus", "Neptune"] masses = np.array([317.8, 30, 5, 5]) | units.MEarth radii = np.array([0.10049, 0.083703, 0.036455, 0.035392]) | units.RSun a = np.array([3.5, 4.5, 6.013, 8.031]) | units.AU inclinations = np.random.uniform(-5, 5, 4) | units.deg true_anomalies = np.random.uniform(0, 360, 4) | units.deg longs_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 pre_tack_giants_system for i in range(4): sun_and_planet = new_binary_from_orbital_elements( pre_tack_giants_system[0].mass, masses[i], a[i], 0, true_anomalies[i], inclinations[i], longs_of_ascending_node[i], args_of_periapsis[i], G=constants.G) planet = Particles(1) planet.name = names[i] planet.mass = masses[i] planet.radius = radii[ i] # This is purely non-zero for collisional purposes planet.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)) planet.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)) planet.density = 3 * planet.mass / (4 * np.pi * planet.radius**3) pre_tack_giants_system.add_particle(planet) return pre_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 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