Exemplo n.º 1
0
 def test3(self):
     print "Testing the user interface, random base_distribution_type"
     number_of_particles = 10000
     test_grid = self.setup_simple_grid()
     sph_particles = convert_grid_to_SPH(test_grid, number_of_particles, 
         base_distribution_type = "random", seed = 12345)
     self.assertEqual(len(sph_particles), number_of_particles)
     self.assertAlmostEqual(sph_particles.mass.sum(),  1.5 | units.kg)
     self.assertAlmostEqual(sph_particles.velocity,  [3.0, 4.0, 0.0] | units.m/units.s)
     self.assertAlmostEqual(sph_particles.u,  1.0 | (units.m/units.s)**2)
     # For 'random', the number of particles in a cell should scale only on average 
     # with the amount of mass in the cell:
     self.assertAlmostRelativeEqual(
         ((1.5 | units.kg)/number_of_particles * numpy.histogramdd(
             sph_particles.position.value_in(units.m), bins=(4,3,2))[0]).sum(), 
         (test_grid.rho*test_grid.cellsize().prod()).sum(), 
         places = 2
     )
     self.assertRaises(AssertionError, 
         self.assertAlmostRelativeEqual,
             (1.5 | units.kg)/number_of_particles * numpy.histogramdd(sph_particles.position.value_in(units.m), bins=(4,3,2))[0], 
             test_grid.rho*test_grid.cellsize().prod(), 
             places = 2,
     )
     self.assertAlmostEqual(sph_particles.h_smooth,  (50.0/number_of_particles)**(1.0/3) | units.m)
Exemplo n.º 2
0
def main(stellar_mass, stellar_radius, core_mass, core_radius, t_end, dt_diag, resolution):
    grid_size = 10 * stellar_radius
    grid = initialize_grid(stellar_mass, stellar_radius, core_mass, core_radius,
                           resolution, grid_size)
    if False:
        hydro = initialize_grid_code(resolution, grid_size)
        cth = grid.new_channel_to(hydro.grid)
        cth.copy()
        hydro.initialize_grid()
        run_grid_code(hydro, grid, t_end, dt_diag)
    else:
        converter = nbody_system.nbody_to_si(1|units.MSun, 1|units.RSun)
        hydro = Gadget2(converter, number_of_workers=4)
        from amuse.ext.grid_to_sph import convert_grid_to_SPH
        particles = convert_grid_to_SPH(grid, number_of_sph_particles=100000)
        #hydro.particles.add_particles(particles)
        #channel = hydro.gas_particles.new_channel_to(particles)
        #hydro.evolve_model(20|units.s)
        #pyplot.scatter(particles.x.value_in(units.RSun), particles.y.value_in(units.RSun))
        #pyplot.show()
        #R = 1|units.RSun
        #particles = particles.select(lambda x, y, z: x>R and y>R and z>R,["x", "y", "z"])
        #print particles
        print "N=", len(particles)

        run_sph_code(hydro, particles, t_end, dt_diag)
Exemplo n.º 3
0
def main(stellar_mass, stellar_radius, core_mass, core_radius, t_end, dt_diag,
         resolution):
    grid_size = 10 * stellar_radius
    grid = initialize_grid(stellar_mass, stellar_radius, core_mass,
                           core_radius, resolution, grid_size)
    if False:
        hydro = initialize_grid_code(resolution, grid_size)
        cth = grid.new_channel_to(hydro.grid)
        cth.copy()
        hydro.initialize_grid()
        run_grid_code(hydro, grid, t_end, dt_diag)
    else:
        converter = nbody_system.nbody_to_si(1 | units.MSun, 1 | units.RSun)
        hydro = Gadget2(converter, number_of_workers=4)
        from amuse.ext.grid_to_sph import convert_grid_to_SPH
        particles = convert_grid_to_SPH(grid, number_of_sph_particles=10000)
        #hydro.particles.add_particles(particles)
        #channel = hydro.gas_particles.new_channel_to(particles)
        #hydro.evolve_model(20|units.s)
        #pyplot.scatter(particles.x.value_in(units.RSun), particles.y.value_in(units.RSun))
        #pyplot.show()
        #R = 1|units.RSun
        #particles = particles.select(lambda x, y, z: x>R and y>R and z>R,["x", "y", "z"])
        #print particles
        print "N=", len(particles)

        run_sph_code(hydro, particles, t_end, dt_diag)
Exemplo n.º 4
0
 def test3(self):
     print "Testing the user interface, random base_distribution_type"
     number_of_particles = 10000
     test_grid = self.setup_simple_grid()
     sph_particles = convert_grid_to_SPH(test_grid,
                                         number_of_particles,
                                         base_distribution_type="random",
                                         seed=12345)
     self.assertEqual(len(sph_particles), number_of_particles)
     self.assertAlmostEqual(sph_particles.mass.sum(), 1.5 | units.kg)
     self.assertAlmostEqual(sph_particles.velocity,
                            [3.0, 4.0, 0.0] | units.m / units.s)
     self.assertAlmostEqual(sph_particles.u, 1.0 | (units.m / units.s)**2)
     # For 'random', the number of particles in a cell should scale only on average
     # with the amount of mass in the cell:
     self.assertAlmostRelativeEqual(
         ((1.5 | units.kg) / number_of_particles *
          numpy.histogramdd(sph_particles.position.value_in(units.m),
                            bins=(4, 3, 2))[0]).sum(),
         (test_grid.rho * test_grid.cellsize().prod()).sum(),
         places=2)
     self.assertRaises(
         AssertionError,
         self.assertAlmostRelativeEqual,
         (1.5 | units.kg) / number_of_particles * numpy.histogramdd(
             sph_particles.position.value_in(units.m), bins=(4, 3, 2))[0],
         test_grid.rho * test_grid.cellsize().prod(),
         places=2,
     )
     self.assertAlmostEqual(sph_particles.h_smooth,
                            (50.0 / number_of_particles)**(1.0 / 3)
                            | units.m)
 def set_initial_conditions(self, instance):
     if self.name_of_the_code in self.sph_hydro_codes:
         initial_grid = self.new_grid()
         self.initialize_grid_with_shock(initial_grid)
         if self.name_of_the_code == "fi":
             initial_grid.position -= 0.5 | length
         sph_particles = convert_grid_to_SPH(initial_grid, self.number_of_particles)
         instance.gas_particles.add_particles(sph_particles)
     else:
         for x in instance.itergrids():
             inmem = x.copy()
             self.clear_grid(inmem)
             self.initialize_grid_with_shock(inmem)
             from_model_to_code = inmem.new_channel_to(x)
             from_model_to_code.copy()
         
         instance.initialize_grid()
Exemplo n.º 6
0
 def test2(self):
     print "Testing the user interface"
     number_of_particles = 10000
     test_grid = self.setup_simple_grid()
     sph_particles = convert_grid_to_SPH(test_grid, number_of_particles)
     self.assertEqual(len(sph_particles), number_of_particles)
     self.assertAlmostEqual(sph_particles.mass.sum(),  1.5 | units.kg)
     self.assertAlmostEqual(sph_particles.velocity,  [3.0, 4.0, 0.0] | units.m/units.s)
     self.assertAlmostEqual(sph_particles.u,  1.0 | (units.m/units.s)**2)
     # The number of particles in a cell should scale with the amount of mass in the cell:
     self.assertAlmostRelativeEqual(
         (1.5 | units.kg)/number_of_particles * numpy.histogramdd(
             sph_particles.position.value_in(units.m), bins=(4,3,2))[0], 
         test_grid.rho*test_grid.cellsize().prod(), 
         places = 2
     )
     self.assertAlmostEqual(sph_particles.h_smooth,  (50.0/number_of_particles)**(1.0/3) | units.m)
    def set_initial_conditions(self, instance):
        if self.name_of_the_code in self.sph_hydro_codes:
            initial_grid = self.new_grid()
            self.initialize_grid_with_shock(initial_grid)
            if self.name_of_the_code == "fi":
                initial_grid.position -= 0.5 | length
            sph_particles = convert_grid_to_SPH(initial_grid,
                                                self.number_of_particles)
            instance.gas_particles.add_particles(sph_particles)
        else:
            for x in instance.itergrids():
                inmem = x.copy()
                self.clear_grid(inmem)
                self.initialize_grid_with_shock(inmem)
                from_model_to_code = inmem.new_channel_to(x)
                from_model_to_code.copy()

            instance.initialize_grid()
Exemplo n.º 8
0
 def test2(self):
     print "Testing the user interface"
     number_of_particles = 10000
     test_grid = self.setup_simple_grid()
     sph_particles = convert_grid_to_SPH(test_grid, number_of_particles)
     self.assertEqual(len(sph_particles), number_of_particles)
     self.assertAlmostEqual(sph_particles.mass.sum(), 1.5 | units.kg)
     self.assertAlmostEqual(sph_particles.velocity,
                            [3.0, 4.0, 0.0] | units.m / units.s)
     self.assertAlmostEqual(sph_particles.u, 1.0 | (units.m / units.s)**2)
     # The number of particles in a cell should scale with the amount of mass in the cell:
     self.assertAlmostRelativeEqual(
         (1.5 | units.kg) / number_of_particles * numpy.histogramdd(
             sph_particles.position.value_in(units.m), bins=(4, 3, 2))[0],
         test_grid.rho * test_grid.cellsize().prod(),
         places=2)
     self.assertAlmostEqual(sph_particles.h_smooth,
                            (50.0 / number_of_particles)**(1.0 / 3)
                            | units.m)