Example #1
0
    def test3(self):

        random.seed(1001)

        print "Third test: densest neighbors and groups."

        hop = Hop()
        hop.parameters.number_of_neighbors_for_local_density = 5

        particles1 = new_plummer_model(10)
        particles2 = new_plummer_model(10)
        particles3 = new_plummer_model(10)

        particles2.position += (10, 0, 0) | nbody_system.length

        particles3.position += (0, 20, 0) | nbody_system.length

        hop.particles.add_particles(particles1)
        hop.particles.add_particles(particles2)
        hop.particles.add_particles(particles3)

        hop.calculate_densities()
        hop.do_hop()

        print hop.particles.group_id

        groups = list(hop.groups())

        self.assertEquals(len(groups), 3)

        self.assertEquals(hop.get_number_of_particles_outside_groups(), 0)

        #densities = (0,0,0) | nbody_system.density
        for index, group in enumerate(groups):
            self.assertEquals(len(group), 10)
            self.assertEquals(group.id_of_group(), index)
            #self.assertEquals(group.get_density_of_group(), densities[index])
        hop.stop()
Example #2
0
 def test3(self): 
 
     random.seed(1001)
     
     print "Third test: densest neighbors and groups."
             
     hop = Hop()
     hop.parameters.number_of_neighbors_for_local_density = 5
     
     particles1 = new_plummer_model(10)
     particles2 = new_plummer_model(10)
     particles3 = new_plummer_model(10)
     
     particles2.position += (10,0,0) | nbody_system.length
     
     particles3.position += (0,20,0) | nbody_system.length
     
     hop.particles.add_particles(particles1)
     hop.particles.add_particles(particles2)
     hop.particles.add_particles(particles3)        
     
     hop.calculate_densities()
     hop.do_hop()
     
     print hop.particles.group_id
     
     groups = list(hop.groups())
     
     self.assertEquals(len(groups), 3)
     
     self.assertEquals(hop.get_number_of_particles_outside_groups(), 0)
     
     #densities = (0,0,0) | nbody_system.density
     for index, group in enumerate(groups):
         self.assertEquals(len(group), 10)
         self.assertEquals(group.id_of_group(), index)
         #self.assertEquals(group.get_density_of_group(), densities[index])
     hop.stop()
Example #3
0
    def test4(self):
        random.seed(1001)
        print "Test 4: complicated density field."

        # A separate group below peak_density_threshold -> should be dropped
        particles0 = new_plummer_model(90,
                                       convert_nbody=nbody_system.nbody_to_si(
                                           0.9 | units.MSun, 1.0 | units.RSun))

        # A nearby group below peak_density_threshold -> should be attached to proper group
        particles1 = new_plummer_model(80,
                                       convert_nbody=nbody_system.nbody_to_si(
                                           0.8 | units.MSun, 1.0 | units.RSun))
        particles1.x += 10 | units.RSun

        # A proper group very nearby other proper group -> groups should merge
        particles2a = new_plummer_model(200,
                                        convert_nbody=nbody_system.nbody_to_si(
                                            2.0 | units.MSun,
                                            1.0 | units.RSun))
        particles2b = new_plummer_model(300,
                                        convert_nbody=nbody_system.nbody_to_si(
                                            3.0 | units.MSun,
                                            1.0 | units.RSun))
        particles2a.x += 11.0 | units.RSun
        particles2b.x += 11.2 | units.RSun

        # A separate proper group other proper group -> groups should be preserved
        particles3 = new_plummer_model(400,
                                       convert_nbody=nbody_system.nbody_to_si(
                                           4.0 | units.MSun, 1.0 | units.RSun))
        particles3.x += 20 | units.RSun

        hop = Hop(
            unit_converter=nbody_system.nbody_to_si(10.7 | units.MSun, 1.0
                                                    | units.RSun))
        hop.parameters.number_of_neighbors_for_local_density = 100
        hop.parameters.saddle_density_threshold_factor = 0.5
        hop.parameters.relative_saddle_density_threshold = True
        hop.commit_parameters()

        for set in [
                particles0, particles1, particles2a, particles2b, particles3
        ]:
            hop.particles.add_particles(set)

        hop.calculate_densities()
        hop.parameters.outer_density_threshold = 0.1 * hop.particles.density.mean(
        )
        hop.parameters.peak_density_threshold = hop.particles.density.amax(
        ) / 4.0
        hop.recommit_parameters()
        hop.do_hop()
        groups = list(hop.groups())

        self.assertEquals(len(hop.particles), 1070)
        self.assertEquals(len(groups), 2)
        self.assertEquals(
            hop.particles.select(lambda x: x < 5 | units.RSun, "x").group_id,
            -1)
        self.assertEquals(hop.get_number_of_particles_outside_groups(), 299)
        self.assertEquals(1070 - len(groups[0]) - len(groups[1]), 299)

        expected_size = [
            477, 294
        ]  # Less than [580, 400], because particles below outer_density_threshold are excluded
        expected_average_x = [11.0, 20] | units.RSun
        for index, group in enumerate(groups):
            self.assertEquals(group.id_of_group(), index)
            self.assertAlmostEquals(group.center_of_mass()[0],
                                    expected_average_x[index], 1)
            self.assertEquals(len(group), expected_size[index])

        if False:  # Make a plot
            original = hop.particles.copy()
            from amuse.plot import scatter, native_plot
            colors = ["r", "g", "b", "y", "k", "w"] * 100
            for group, color in zip(hop.groups(), colors):
                scatter(group.x, group.y, c=color)
                original -= group
            scatter(original.x, original.y, c="m", marker="s")
            native_plot.show()

        hop.stop()
Example #4
0
 def test4(self):
     random.seed(1001)
     print "Test 4: complicated density field."
     
     # A separate group below peak_density_threshold -> should be dropped
     particles0 = new_plummer_model(90, convert_nbody=nbody_system.nbody_to_si(0.9 | units.MSun, 1.0 | units.RSun))
     
     # A nearby group below peak_density_threshold -> should be attached to proper group
     particles1 = new_plummer_model(80, convert_nbody=nbody_system.nbody_to_si(0.8 | units.MSun, 1.0 | units.RSun))
     particles1.x += 10 | units.RSun
     
     # A proper group very nearby other proper group -> groups should merge
     particles2a = new_plummer_model(200, convert_nbody=nbody_system.nbody_to_si(2.0 | units.MSun, 1.0 | units.RSun))
     particles2b = new_plummer_model(300, convert_nbody=nbody_system.nbody_to_si(3.0 | units.MSun, 1.0 | units.RSun))
     particles2a.x += 11.0 | units.RSun
     particles2b.x += 11.2 | units.RSun
     
     # A separate proper group other proper group -> groups should be preserved
     particles3 = new_plummer_model(400, convert_nbody=nbody_system.nbody_to_si(4.0 | units.MSun, 1.0 | units.RSun))
     particles3.x += 20 | units.RSun
     
     hop = Hop(unit_converter=nbody_system.nbody_to_si(10.7 | units.MSun, 1.0 | units.RSun))
     hop.parameters.number_of_neighbors_for_local_density = 100
     hop.parameters.saddle_density_threshold_factor = 0.5
     hop.parameters.relative_saddle_density_threshold = True
     hop.commit_parameters()
     
     for set in [particles0, particles1, particles2a, particles2b, particles3]:
         hop.particles.add_particles(set)
     
     hop.calculate_densities()
     hop.parameters.outer_density_threshold = 0.1 * hop.particles.density.mean()
     hop.parameters.peak_density_threshold = hop.particles.density.amax() / 4.0
     hop.recommit_parameters()
     hop.do_hop()
     groups = list(hop.groups())
     
     self.assertEquals(len(hop.particles), 1070)
     self.assertEquals(len(groups), 2)
     self.assertEquals(hop.particles.select(lambda x: x < 5|units.RSun, "x").group_id, -1)
     self.assertEquals(hop.get_number_of_particles_outside_groups(), 299)
     self.assertEquals(1070 - len(groups[0]) - len(groups[1]), 299)
     
     expected_size = [477, 294] # Less than [580, 400], because particles below outer_density_threshold are excluded
     expected_average_x = [11.0, 20] | units.RSun
     for index, group in enumerate(groups):
         self.assertEquals(group.id_of_group(), index)
         self.assertAlmostEquals(group.center_of_mass()[0], expected_average_x[index], 1)
         self.assertEquals(len(group), expected_size[index])
     
     if False: # Make a plot
         original = hop.particles.copy()
         from amuse.plot import scatter, native_plot
         colors = ["r", "g", "b", "y", "k", "w"]*100
         for group, color in zip(hop.groups(), colors):
             scatter(group.x, group.y, c=color)
             original -= group
         scatter(original.x, original.y, c="m", marker="s")
         native_plot.show()
     
     hop.stop()