def gas_particles(self): array = [] for x in self.codes: if hasattr(x, "gas_particles"): array.append(x.gas_particles) if len(array) == 0: raise AttributeError elif len(array) == 1: return array[0] return datamodel.ParticlesSuperset(array)
def particles(self): arr=[] for x in self.systems: if hasattr(x,"particles"): arr.append(x.particles) particles=datamodel.ParticlesSuperset(arr) return TransformedParticles(particles, ["x","y","vx","vy"], self.transform_rotating_to_inertial, ["x","y","vx","vy"], self.transform_inertial_to_rotating, )
def test7(self): print("Testing HDF5 io with a ParticlesSuperset") if os.path.exists("test_unit.hdf5"): os.remove("test_unit.hdf5") set1 = datamodel.Particles(2) set2 = datamodel.Particles(2) superset = datamodel.ParticlesSuperset([set1, set2]) superset.mass = [1.0, 2.0, 3.0, 4.0] | units.kg superset.radius = [3.0, 4.0, 5.0, 6.0] | units.m superset.position = [[1,2,3], [3,5,6], [3,2,1], [-3,-5,-6]] | units.m superset.velocity = [[1,2,3], [3,5,6], [3,2,1], [-3,-5,-6]] | units.m / units.s io.write_set_to_file(superset, "test_unit.hdf5","hdf5") y = io.read_set_from_file("test_unit.hdf5","hdf5") self.assertAlmostEqual(superset.mass, y.mass, 8) self.assertAlmostEqual(superset.radius, y.radius, 8) self.assertAlmostEqual(superset.position, y.position,8) self.assertAlmostEqual(superset.velocity, y.velocity,8) os.remove("test_unit.hdf5")
def gas_particles(self): arr=[] for x in self.systems: if hasattr(x,"gas_particles"): arr.append(x.gas_particles) return datamodel.ParticlesSuperset(arr)
def Run(N_CORES, DM_halo_r_limit, star_disk_R_limit, star_disk_z_limit, star_bulge_r_limit): start_time = time.time() Print("Generating dark matter halo...", start_time) DM_halo_particles = gen_particles_Einasto(N=10**2, mass=2 * 10**12, N_CORES=N_CORES, r_limit=DM_halo_r_limit) Print("Generating disk stars...", start_time) star_disk_particles = gen_particles_exp_sech(N=10**2, mass=4 * 10**10, N_CORES=N_CORES, R_limit=star_disk_R_limit, z_limit=star_disk_z_limit) Print("Generating bulge stars...", start_time) star_bulge_particles = gen_particles_Jaffe(N=10**1, mass=2 * 10**10, N_CORES=N_CORES, r_limit=star_bulge_r_limit) Print("Generating disc gas...", start_time) gas_disk_particles = gen_particles_exp_sech(N=10**2, mass=1 * 10**10, N_CORES=N_CORES, R_limit=star_disk_R_limit, z_limit=star_disk_z_limit) Print("Generating halo gas...", start_time) gas_halo_particles = gen_particles_Einasto(N=10**2, mass=1 * 10**10, N_CORES=N_CORES, r_limit=star_disk_R_limit * 2) for p in datamodel.ParticlesSuperset( [gas_disk_particles.as_set(), gas_halo_particles.as_set()]): p.u = 1 | units.km**2 / units.s**2 Print("Assigning velocities to non-halo particles...", start_time) assign_star_velocities( datamodel.ParticlesSuperset([ star_disk_particles, star_bulge_particles, gas_disk_particles, gas_halo_particles ]), datamodel.ParticlesSuperset([ star_disk_particles, star_bulge_particles, gas_disk_particles, gas_halo_particles, DM_halo_particles ]), 2 * math.sqrt(star_disk_R_limit**2 + star_disk_z_limit**2)) Print("Assigning velocities to halo particles...", start_time) assign_halo_velocities( datamodel.ParticlesSuperset([DM_halo_particles, gas_halo_particles])) Print("Initializing Gadget2 code...", start_time) SE = Gadget2(number_of_workers=N_CORES - 1) Gadget_config(SE) Print("Adding particles to the code...", start_time) SE.dm_particles.add_particles(DM_halo_particles) SE.dm_particles.add_particles(star_disk_particles) SE.dm_particles.add_particles(star_bulge_particles) SE.gas_particles.add_particles(gas_disk_particles) SE.gas_particles.add_particles(gas_halo_particles) #io.write_set_to_file(SE.particles, 'output.dat', 'gadget') Print("Starting the simulation...", start_time) for t in np.arange(0, 1000, 1): SE.evolve_model(t | units.Myr) Plots(SE.dm_particles, SE.gas_particles, t) Print("Timestep " + str(t + 1) + ", screenshots saved!", start_time)