def test_particles(galaxy, n_halo, n_bulge, n_disk): _dsk = Particles(len(galaxy)) _dsk.mass = galaxy.mass _dsk.position = galaxy.position _dsk.velocity = galaxy.velocity disk = _dsk[n_bulge:n_halo] return disk
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 displace_galaxy(galaxy, rotation_mat, translation_vector, radial_velocity, transverse_velocity): widgets = [ 'Adjusting relative velocities and orientations: ', pbwg.AnimatedMarker(), pbwg.EndMsg() ] with pbar.ProgressBar(widgets=widgets, fd=sys.stdout) as progress: displaced_galaxy = Particles(len(galaxy)) displaced_galaxy.mass = galaxy.mass displaced_galaxy.position = galaxy.position displaced_galaxy.velocity = galaxy.velocity for body in displaced_galaxy: body.position = ([ body.x.value_in(units.kpc), body.y.value_in(units.kpc), body.z.value_in(units.kpc) ] @ rotation_mat) | units.kpc body.velocity = ([ body.vx.value_in(units.kms), body.vy.value_in(units.kms), body.vz.value_in(units.kms) ] @ rotation_mat) | units.kms displaced_galaxy.position += translation_vector displaced_galaxy.velocity += radial_velocity displaced_galaxy.velocity += transverse_velocity return displaced_galaxy
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 get_ps_from_yt(pltfile, particle_type="all"): """Take a FLASH plotfile and return an AMUSE particle set. Keyword arguments: pltfile -- The FLASH hdf5 plot or checkpoint file. Note a plotfile means there must also be a particle file with the same ID number. particle_type -- the type of particle that you want from FLASH. Can be: star -- active FLASH particle type sink -- sink FLASH particle type any other string or none returns all particle types. The default is all Returns: stars -- An AMUSE particle set. """ import yt ds = yt.load(pltfile) dd = ds.all_data() all_parts_mass = dd['particle_mass'].in_units('Msun') all_parts_pos = dd['particle_position'].in_units('cm') all_parts_vel = dd['particle_velocity'].in_units('cm/s') if (particle_type == 'star' or particle_type == 'stars'): # Index for only the star particles, and not including sink particles. mass_ind = np.where(dd['particle_type'].v == 1) elif (particle_type == 'sink' or particle_type == 'sinks'): mass_ind = np.where(dd['particle_type'].v == 2) else: mass_ind = np.arange(len(all_parts_mass)) all_parts_mass = all_parts_mass[mass_ind] all_parts_pos = all_parts_pos[mass_ind] all_parts_vel = all_parts_vel[mass_ind] num_parts = len(all_parts_mass.v) stars = Particles(num_parts) stars.mass = all_parts_mass.v | u.MSun stars.position = all_parts_pos.v | u.cm stars.velocity = all_parts_vel.v | u.cm/u.s stars.index_of_the_particle = range(num_parts) return stars
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