Exemple #1
0
 def test6(self):
     print("Test with different masses")
     # Particles on a cubic grid with masses according to a gaussian density profile
     grid = numpy.mgrid[-1:1:21j, -1:1:21j, -1:1:21j] | units.m
     particles = Particles(9261, x=grid[0].flatten(), y=grid[1].flatten(), z=grid[2].flatten())
     peak_positions = [[0.2, -0.4, 0.3], [-0.6, 0.2, 0.7]] | units.m
     particles.mass = 2*numpy.exp(-(particles.position-peak_positions[0]).lengths_squared() / (0.1|units.m**2)) | units.kg
     particles.mass += numpy.exp(-(particles.position-peak_positions[1]).lengths_squared() / (0.1|units.m**2)) | units.kg
     self.assertAlmostEqual(particles.position[particles.mass.argmax()], peak_positions[0])
     self.assertAlmostEqual(particles[:4000].position[particles[:4000].mass.argmax()], peak_positions[1])
     
     hop = Hop(unit_converter=nbody_system.nbody_to_si(particles.mass.sum(), 1.0 | units.m))#, redirection="none")
     hop.parameters.density_method = 2
     hop.parameters.number_of_neighbors_for_local_density = 50
     hop.parameters.relative_saddle_density_threshold = True
     hop.commit_parameters()
     hop.particles.add_particles(particles)
     hop.calculate_densities()
     self.assertAlmostEqual(hop.particles.position[hop.particles.density.argmax()], peak_positions[0])
     self.assertAlmostEqual(hop.particles[:4000].position[hop.particles[:4000].density.argmax()], peak_positions[1])
     hop.do_hop()
     groups = list(hop.groups())
     self.assertEqual(len(groups), 2)
     for group, peak_position in zip(groups, peak_positions):
         self.assertAlmostEqual(group.center_of_mass(), peak_position, 1)
     hop.stop()
Exemple #2
0
 def test6(self):
     print "Test with different masses"
     # Particles on a cubic grid with masses according to a gaussian density profile
     grid = numpy.mgrid[-1:1:21j, -1:1:21j, -1:1:21j] | units.m
     particles = Particles(9261, x=grid[0], y=grid[1], z=grid[2])
     peak_positions = [[0.2, -0.4, 0.3], [-0.6, 0.2, 0.7]] | units.m
     particles.mass = 2*numpy.exp(-(particles.position-peak_positions[0]).lengths_squared() / (0.1|units.m**2)) | units.kg
     particles.mass += numpy.exp(-(particles.position-peak_positions[1]).lengths_squared() / (0.1|units.m**2)) | units.kg
     self.assertAlmostEquals(particles.position[particles.mass.argmax()], peak_positions[0])
     self.assertAlmostEquals(particles[:4000].position[particles[:4000].mass.argmax()], peak_positions[1])
     
     hop = Hop(unit_converter=nbody_system.nbody_to_si(particles.mass.sum(), 1.0 | units.m))#, redirection="none")
     hop.parameters.density_method = 2
     hop.parameters.number_of_neighbors_for_local_density = 50
     hop.parameters.relative_saddle_density_threshold = True
     hop.commit_parameters()
     hop.particles.add_particles(particles)
     hop.calculate_densities()
     self.assertAlmostEquals(hop.particles.position[hop.particles.density.argmax()], peak_positions[0])
     self.assertAlmostEquals(hop.particles[:4000].position[hop.particles[:4000].density.argmax()], peak_positions[1])
     hop.do_hop()
     groups = list(hop.groups())
     self.assertEquals(len(groups), 2)
     for group, peak_position in zip(groups, peak_positions):
         self.assertAlmostEquals(group.center_of_mass(), peak_position, 1)
     hop.stop()
Exemple #3
0
 def create_star(self):
     star = Particles(1)
     star.mass = 2|units.MSun
     star.radius = 2|units.RSun
     star.temperature = 5000|units.K
     star.position = [1, 1, 1] | units.parsec
     star.velocity = [-1000, 0, 1000] | units.ms
     star.wind_mass_loss_rate = 1e-6 | units.MSun / units.yr
     star.terminal_wind_velocity = 500 | units.ms
     return star
 def create_star(self, N=1):
     star = Particles(N)
     star.mass = 2 | units.MSun
     star.radius = 2 | units.RSun
     star.temperature = 5000 | units.K
     star.position = [1, 1, 1] | units.parsec
     star.velocity = [-1000, 0, 1000] | units.ms
     star.wind_mass_loss_rate = 1e-6 | units.MSun / units.yr
     star.initial_wind_velocity = 50 | units.ms
     star.terminal_wind_velocity = 500 | units.ms
     return star
    def create_stars_without_wind_attributes(self):
        stars = Particles(2)
        stars.mass = 2 | units.MSun
        stars.radius = 2 | units.RSun
        stars.temperature = 5000 | units.K
        stars.luminosity = 2 | units.LSun
        stars.age = 0 | units.Myr
        stars[0].position = [1, 1, 1] | units.parsec
        stars[1].position = [-1, -1, -1] | units.parsec
        stars[0].velocity = [-1000, 0, 1000] | units.ms
        stars[1].velocity = [0, 0, 0] | units.ms

        return stars
    def create_stars_without_wind_attributes(self):
        stars = Particles(2)
        stars.mass = 2 | units.MSun
        stars.radius = 2 | units.RSun
        stars.temperature = 5000 | units.K
        stars.luminosity = 2 | units.LSun
        stars.age = 0 | units.Myr
        stars[0].position = [1, 1, 1] | units.parsec
        stars[1].position = [-1, -1, -1] | units.parsec
        stars[0].velocity = [-1000, 0, 1000] | units.ms
        stars[1].velocity = [0, 0, 0] | units.ms

        return stars
Exemple #7
0
def new_cluster(number_of_stars=1000):
    masses = new_salpeter_mass_distribution(number_of_stars,
                                            mass_min=0.1 | units.MSun,
                                            mass_max=125.0 | units.MSun,
                                            alpha=-2.35)

    particles = Particles(number_of_stars)
    particles.mass = masses
    particles.x = units.parsec(random.gamma(2.0, 1.0, number_of_stars))
    particles.y = units.parsec(random.gamma(1.0, 1.0, number_of_stars))
    particles.z = units.parsec(random.random(number_of_stars))

    return particles
Exemple #8
0
def new_cluster(number_of_stars = 1000):
    masses = new_salpeter_mass_distribution(
        number_of_stars, 
        mass_min = 0.1 | units.MSun,
        mass_max = 125.0 | units.MSun, 
        alpha = -2.35
    )
    
    particles = Particles(number_of_stars)
    particles.mass = masses
    particles.x = units.parsec(random.gamma(2.0, 1.0, number_of_stars))
    particles.y = units.parsec(random.gamma(1.0, 1.0, number_of_stars))
    particles.z = units.parsec(random.random(number_of_stars))
    
    return particles
Exemple #9
0
    def test1(self):
        print "First test: adding particles, setting and getting."
        hop = Hop()
        particles = Particles(6)
        particles.mass = 1.0 | nbody_system.mass
        particles.x = [i * i for i in range(6)] | nbody_system.length
        particles.y = 0.0 | nbody_system.length
        particles.z = 0.0 | nbody_system.length

        hop.particles.add_particles(particles)

        positions = hop.particles.position
        for i in range(6):
            x, y, z = positions[i]
            self.assertEquals(x, i * i | nbody_system.length)
            self.assertEquals(y, 0 | nbody_system.length)
            self.assertEquals(z, 0 | nbody_system.length)

        hop.stop()
Exemple #10
0
 def test1(self):
     print "First test: adding particles, setting and getting."
     hop = Hop()
     particles = Particles(6)
     particles.mass = 1.0 | nbody_system.mass
     particles.x = [i*i for i in range(6)] | nbody_system.length
     particles.y = 0.0 | nbody_system.length
     particles.z = 0.0 | nbody_system.length
     
     hop.particles.add_particles(particles)
     
     positions = hop.particles.position
     for i in range(6):
         x, y, z = positions[i]
         self.assertEquals(x, i*i | nbody_system.length)
         self.assertEquals(y, 0 | nbody_system.length)
         self.assertEquals(z, 0 | nbody_system.length)
         
     hop.stop()
    def setup_supernova(self):
        numpy.random.seed(123456789)

        stars = Particles(2)
        stars.mass = [9, 10] | units.MSun
        stars[0].position = [1, 1, 1] | units.parsec
        stars[1].position = [-1, -1, -1] | units.parsec
        stars[0].velocity = [-1000, 0, 1000] | units.ms
        stars[1].velocity = [0, 0, 0] | units.ms

        stev = SeBa()
        stars = stev.particles.add_particles(stars)

        r_max = .1 | units.parsec
        star_wind = stellar_wind.new_stellar_wind(3e-5 | units.MSun,
                                                  mode="heating",
                                                  r_max=r_max,
                                                  derive_from_evolution=True,
                                                  tag_gas_source=True)
        star_wind.particles.add_particles(stars)

        return stev, star_wind, stars
Exemple #12
0
    def setup_supernova(self):
        numpy.random.seed(123456789)

        stars = Particles(2)
        stars.mass = [9, 10] | units.MSun
        stars[0].position = [1, 1, 1] | units.parsec
        stars[1].position = [-1, -1, -1] | units.parsec
        stars[0].velocity = [-1000, 0, 1000] | units.ms
        stars[1].velocity = [0, 0, 0] | units.ms

        stev = SeBa()
        stars = stev.particles.add_particles(stars)

        r_max = .1 | units.parsec
        star_wind = stellar_wind.new_stellar_wind(
            3e-5 | units.MSun,
            mode="heating",
            r_max=r_max,
            derive_from_evolution=True,
            tag_gas_source=True
            )
        star_wind.particles.add_particles(stars)

        return stev, star_wind, stars