def bb79_cloud_evolve(N=50000, Mcloud=1. | units.MSun, Rcloud=3.2e16 | units.cm, omega=1.56e-12 | units.rad / units.s, density_perturb=0.5, t_total=8.3e11 | units.s): # mean density of the cloud rho_uni = Mcloud / (4. / 3. * numpy.pi * Rcloud**3) print(" ** mean density = ", rho_uni.in_(units.g / units.cm**3)) # free fall time of the cloud t_ff = numpy.sqrt(3. * numpy.pi / (32. * units.constants.G * rho_uni)) print(" ** free-fall time = ", t_ff.in_(units.yr)) conv = nbody_system.nbody_to_si(Mcloud, Rcloud) sph = Fi(conv) # the initial conditions of BB79 parts_bb79 = bb79_cloud(targetN=N, omega=omega, rho_perturb=0.5, ethep_ratio=0.25, convert_nbody=conv, base_grid=body_centered_grid_unit_cube).result sph.gas_particles.add_particles(parts_bb79) sph.parameters.use_hydro_flag = True sph.parameters.isothermal_flag = True sph.parameters.integrate_entropy_flag = False sph.parameters.gamma = 1 sph.parameters.verbosity = 0 sph.parameters.timestep = 0.1 * t_ff print( "**evolving to time: (end time = ~ {0:.3f} t_ff)".format(t_total / t_ff)) # setting snapshots to be plotted nplot = 10 if nplot > 1: plot_timestep = t_total / (nplot - 1) else: plot_timestep = t_total # evolution of the cloud for i in range(nplot): ttarget = i * plot_timestep t_tff = ttarget / t_ff sph.evolve_model(ttarget) plot_i = "bb79_rho_{0:03d}.png".format(i) tt_tff = "{0:.3f}".format(t_tff) title_i = "$%s\,t_{\mathrm{ff}}$" % (tt_tff) print("\t {0:.3f} t_ff -> {1}".format(t_tff, plot_i)) plot_sph_rho(sph, N=300, grid_size=0.025 | units.parsec, plot_name=plot_i, plot_title=title_i) sph.stop()
def bb79_cloud_evolve(N=50000, Mcloud=1. | units.MSun, Rcloud=3.2e16 | units.cm, omega=1.56e-12 | units.rad/units.s, density_perturb=0.5, t_total=8.3e11 | units.s): # mean density of the cloud rho_uni = Mcloud / (4./3.*numpy.pi*Rcloud**3) print(" ** mean density = ", rho_uni.in_(units.g/units.cm**3)) # free fall time of the cloud t_ff = numpy.sqrt(3.*numpy.pi / (32.*units.constants.G*rho_uni)) print(" ** free-fall time = ", t_ff.in_(units.yr)) conv = nbody_system.nbody_to_si(Mcloud, Rcloud) sph = Fi(conv) # the initial conditions of BB79 parts_bb79 = bb79_cloud(targetN=N, omega=omega, rho_perturb=0.5, ethep_ratio=0.25, convert_nbody=conv, base_grid=body_centered_grid_unit_cube).result sph.gas_particles.add_particles(parts_bb79) sph.parameters.use_hydro_flag = True sph.parameters.isothermal_flag = True sph.parameters.integrate_entropy_flag = False sph.parameters.gamma = 1 sph.parameters.verbosity = 0 sph.parameters.timestep = 0.1*t_ff print( "**evolving to time: (end time = ~ {0:.3f} t_ff)".format(t_total/t_ff)) # setting snapshots to be plotted nplot = 10 if nplot > 1: plot_timestep = t_total / (nplot - 1) else: plot_timestep = t_total # evolution of the cloud for i in range(nplot): ttarget = i*plot_timestep t_tff = ttarget / t_ff sph.evolve_model(ttarget) plot_i = "bb79_rho_{0:03d}.png".format(i) tt_tff = "{0:.3f}".format(t_tff) title_i = "$%s\,t_{\mathrm{ff}}$" % (tt_tff) print("\t {0:.3f} t_ff -> {1}".format(t_tff, plot_i)) plot_sph_rho(sph, N=300, grid_size=0.025 | units.parsec, plot_name=plot_i, plot_title=title_i) sph.stop()
def test1(self): numpy.random.seed(1234) mc = bb79_cloud(targetN=1000).result self.assertEqual(len(mc), 1000) ek = mc.kinetic_energy() ep = mc.potential_energy(G=nbody_system.G) eth = mc.thermal_energy() self.assertAlmostEqual(eth / ep, -0.25, 2) self.assertAlmostEqual(ek / ep, -0.2, 2)
def test1(self): numpy.random.seed(1234) mc=bb79_cloud(targetN=1000).result self.assertEqual(len(mc),1000) ek=mc.kinetic_energy() ep=mc.potential_energy(G=nbody_system.G) eth=mc.thermal_energy() self.assertAlmostEqual(eth/ep, -0.25, 2) self.assertAlmostEqual(ek/ep, -0.2, 2)
def test2(self): numpy.random.seed(1234) convert = nbody_system.nbody_to_si(1. | units.MSun, 3.2e16 | units.cm) mc = bb79_cloud(targetN=1000, convert_nbody=convert).result self.assertEqual(len(mc), 1000) ek = mc.kinetic_energy() ep = mc.potential_energy() eth = mc.thermal_energy() self.assertAlmostEqual(eth / ep, -0.25, 2) self.assertAlmostEqual(ek / ep, -0.2, 2)
def test2(self): numpy.random.seed(1234) convert=nbody_system.nbody_to_si(1. | units.MSun,3.2e16| units.cm) mc=bb79_cloud(targetN=1000,convert_nbody=convert).result self.assertEqual(len(mc),1000) ek=mc.kinetic_energy() ep=mc.potential_energy() eth=mc.thermal_energy() self.assertAlmostEqual(eth/ep, -0.25, 2) self.assertAlmostEqual(ek/ep, -0.2, 2)