Exemple #1
0
 def test1(self):
     print "Testing GalactICsInterface initialization"
     instance = GalactICsInterface(**default_options)
     self.assertEqual(instance.initialize_code(), 0)
     self.assertEqual(instance.set_output_path(instance.get_output_directory()), 0)
     self.assertEqual(instance.set_generate_bulge_flag(False), 0)
     self.assertEqual(instance.set_generate_disk_flag(False), 0)
     self.assertEqual(instance.set_order_of_multipole_expansion(0), 0)
     self.assertEqual(instance.commit_parameters(), 0)
     self.assertEqual(instance.cleanup_code(), 0)
     instance.stop()
Exemple #2
0
 def test1(self):
     print "Testing GalactICsInterface initialization"
     instance = GalactICsInterface(**default_options)
     self.assertEqual(instance.initialize_code(), 0)
     self.assertEqual(instance.set_output_path(instance.get_output_directory()), 0)
     self.assertEqual(instance.set_generate_bulge_flag(False), 0)
     self.assertEqual(instance.set_generate_disk_flag(False), 0)
     self.assertEqual(instance.set_order_of_multipole_expansion(0), 0)
     self.assertEqual(instance.commit_parameters(), 0)
     self.assertEqual(instance.cleanup_code(), 0)
     instance.stop()
Exemple #3
0
    def test4(self):
        print "Testing GalactICsInterface generate_particles"
        number_of_particles_halo = 1000
        instance = GalactICsInterface(**default_options)
        self.assertEquals(instance.initialize_code(), 0)
        self.assertEquals(instance.set_output_path(instance.get_output_directory()), 0)
        self.assertEquals(instance.set_halo_number_of_particles(number_of_particles_halo), 0)
        self.assertEquals(instance.set_generate_bulge_flag(False), 0)
        self.assertEquals(instance.set_generate_disk_flag(False), 0)
        self.assertEquals(instance.set_order_of_multipole_expansion(0), 0)
        self.assertEquals(instance.commit_parameters(), 0)

        self.assertEquals(instance.get_number_of_particles_updated().values(), [0, 0])
        self.assertEquals(instance.generate_particles(), 0)
        self.assertEquals(instance.get_number_of_particles_updated().values(), [number_of_particles_halo, 0])

        masses, errors = instance.get_mass(range(number_of_particles_halo))
        self.assertEquals(errors, numpy.zeros(number_of_particles_halo))
        self.assertAlmostRelativeEquals(masses, numpy.ones(number_of_particles_halo) * masses[0])
        total_mass = masses.sum()

        expected_mean_pos = numpy.array([73.768384103536604, 76.03533643054962, 75.176319462463255])
        expected_mean_vel = numpy.array([0.92904859858192501, 0.94953939936682585, 0.92897711758688095])

        x_positions, y_positions, z_positions, errors = instance.get_position(range(number_of_particles_halo))
        self.assertEquals(errors, numpy.zeros(number_of_particles_halo))
        self.assertAlmostEquals(
            numpy.array([numpy.mean(x_positions), numpy.mean(y_positions), numpy.mean(z_positions)]),
            numpy.array([0.0] * 3),
            5,
        )
        self.assertAlmostRelativeEquals(
            numpy.array([numpy.mean(abs(x_positions)), numpy.mean(abs(y_positions)), numpy.mean(abs(z_positions))]),
            expected_mean_pos,
            4,
        )

        x_velocities, y_velocities, z_velocities, errors = instance.get_velocity(range(number_of_particles_halo))
        self.assertEquals(errors, numpy.zeros(number_of_particles_halo))
        self.assertAlmostEquals(
            numpy.array([numpy.mean(x_velocities), numpy.mean(y_velocities), numpy.mean(z_velocities)]),
            numpy.array([0.0] * 3),
        )
        self.assertAlmostRelativeEquals(
            numpy.array([numpy.mean(abs(x_velocities)), numpy.mean(abs(y_velocities)), numpy.mean(abs(z_velocities))]),
            expected_mean_vel,
            4,
        )

        self.assertEquals(instance.cleanup_code(), 0)
        instance.stop()
Exemple #4
0
    def test4(self):
        print "Testing GalactICsInterface generate_particles"
        number_of_particles_halo = 1000
        instance = GalactICsInterface(**default_options)
        self.assertEquals(instance.initialize_code(), 0)
        self.assertEquals(instance.set_output_path(instance.get_output_directory()), 0)
        self.assertEquals(instance.set_halo_number_of_particles(number_of_particles_halo), 0)
        self.assertEquals(instance.set_generate_bulge_flag(False), 0)
        self.assertEquals(instance.set_generate_disk_flag(False), 0)
        self.assertEquals(instance.set_order_of_multipole_expansion(0), 0)
        self.assertEquals(instance.commit_parameters(), 0)
        
        self.assertEquals(instance.get_number_of_particles_updated().values(), [0, 0])
        self.assertEquals(instance.generate_particles(), 0)
        self.assertEquals(instance.get_number_of_particles_updated().values(), [number_of_particles_halo, 0])

        
        
        masses, errors = instance.get_mass(range(number_of_particles_halo))
        self.assertEquals(errors, numpy.zeros(number_of_particles_halo))
        self.assertAlmostRelativeEquals(masses, numpy.ones(number_of_particles_halo)*masses[0])
        total_mass = masses.sum() 
        
        if platform.processor() == 'ppc64le':
            # on ppc64le, the model generation has small differences from intel
            # change expected pos
            expected_mean_pos = numpy.array([73.5628, 76.251034, 75.53434])
        else:
            expected_mean_pos = numpy.array([73.768384103536604, 76.03533643054962, 75.176319462463255])

        expected_mean_vel = numpy.array([0.92904859858192501, 0.94953939936682585, 0.92897711758688095])
            
        x_positions, y_positions, z_positions, errors = instance.get_position(range(number_of_particles_halo))
        self.assertEquals(errors, numpy.zeros(number_of_particles_halo))
        self.assertAlmostEquals(numpy.array([numpy.mean(x_positions), numpy.mean(y_positions), 
            numpy.mean(z_positions)]), numpy.array([0.0]*3), 5)
        self.assertAlmostRelativeEquals(numpy.array([numpy.mean(abs(x_positions)), numpy.mean(abs(y_positions)), 
            numpy.mean(abs(z_positions))]), expected_mean_pos, 3)
        
        x_velocities, y_velocities, z_velocities, errors = instance.get_velocity(range(number_of_particles_halo))
        self.assertEquals(errors, numpy.zeros(number_of_particles_halo))
        self.assertAlmostEquals(numpy.array([numpy.mean(x_velocities), numpy.mean(y_velocities), 
            numpy.mean(z_velocities)]), numpy.array([0.0]*3))
        self.assertAlmostRelativeEquals(numpy.array([numpy.mean(abs(x_velocities)), numpy.mean(abs(y_velocities)), 
            numpy.mean(abs(z_velocities))]), expected_mean_vel, 2)
        
        self.assertEquals(instance.cleanup_code(), 0)
        instance.stop()