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()
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()
def slowtest3(self): print "Testing GalactICsInterface generate_particles" n_particles_halo = 100 n_particles_bulge = 100 n_particles_disk = 100 number_of_particles = n_particles_disk + n_particles_bulge + n_particles_halo 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(n_particles_halo), 0) self.assertEquals( instance.set_bulge_number_of_particles(n_particles_bulge), 0) self.assertEquals( instance.set_disk_number_of_particles(n_particles_disk), 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, 0]) mass_disk, mass_bulge, mass_halo = 26.578816771507263, 14.632800221443176, 1184.2350006103516 masses, errors = instance.get_mass(range(number_of_particles)) self.assertEquals(errors, numpy.zeros(number_of_particles)) self.assertAlmostRelativeEquals( masses, numpy.concatenate(( numpy.ones(n_particles_disk) * mass_disk / n_particles_disk, numpy.ones(n_particles_bulge) * mass_bulge / n_particles_bulge, numpy.ones(n_particles_halo) * mass_halo / n_particles_halo, )), 3) x_positions, y_positions, z_positions, errors = instance.get_position( range(number_of_particles)) self.assertEquals(errors, numpy.zeros(number_of_particles)) 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[:n_particles_disk])), numpy.mean(abs(y_positions[:n_particles_disk])), numpy.mean(abs(z_positions[:n_particles_disk])) ]), numpy.array( [7.3994484072923656, 7.1570298135280606, 0.33854196755215527]), 3) self.assertAlmostRelativeEquals( numpy.array([ numpy.mean( abs(x_positions[n_particles_disk:n_particles_disk + n_particles_bulge])), numpy.mean( abs(y_positions[n_particles_disk:n_particles_disk + n_particles_bulge])), numpy.mean( abs(z_positions[n_particles_disk:n_particles_disk + n_particles_bulge])) ]), numpy.array( [1.244429082274437, 1.1639373835548759, 0.8550614269822836]), 3) self.assertAlmostRelativeEquals( numpy.array([ numpy.mean(abs(x_positions[-n_particles_halo:])), numpy.mean(abs(y_positions[-n_particles_halo:])), numpy.mean(abs(z_positions[-n_particles_halo:])) ]), numpy.array( [94.242819476127622, 88.41320479869843, 85.234394512176507]), 3) x_velocities, y_velocities, z_velocities, errors = instance.get_velocity( range(number_of_particles)) self.assertEquals(errors, numpy.zeros(number_of_particles)) 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[:n_particles_disk])), numpy.mean(abs(y_velocities[:n_particles_disk])), numpy.mean(abs(z_velocities[:n_particles_disk])) ]), numpy.array( [1.5026254250109197, 1.5649469271302223, 0.20230436498299242]), 5) self.assertAlmostRelativeEquals( numpy.array([ numpy.mean(abs(x_velocities[n_particles_disk:])), numpy.mean(abs(y_velocities[n_particles_disk:])), numpy.mean(abs(z_velocities[n_particles_disk:])) ]), numpy.array( [0.99470628838986164, 0.95913934175856408, 0.9359876788407564]), 5) self.assertEquals(instance.cleanup_code(), 0) instance.stop()
def slowtest3(self): print "Testing GalactICsInterface generate_particles" n_particles_halo = 100 n_particles_bulge = 100 n_particles_disk = 100 number_of_particles = n_particles_disk + n_particles_bulge + n_particles_halo 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(n_particles_halo), 0) self.assertEquals(instance.set_bulge_number_of_particles(n_particles_bulge), 0) self.assertEquals(instance.set_disk_number_of_particles(n_particles_disk), 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, 0]) mass_disk, mass_bulge, mass_halo = 26.578816771507263, 14.632800221443176, 1184.2350006103516 masses, errors = instance.get_mass(range(number_of_particles)) self.assertEquals(errors, numpy.zeros(number_of_particles)) self.assertAlmostRelativeEquals( masses, numpy.concatenate( ( numpy.ones(n_particles_disk) * mass_disk / n_particles_disk, numpy.ones(n_particles_bulge) * mass_bulge / n_particles_bulge, numpy.ones(n_particles_halo) * mass_halo / n_particles_halo, ) ), 3, ) x_positions, y_positions, z_positions, errors = instance.get_position(range(number_of_particles)) self.assertEquals(errors, numpy.zeros(number_of_particles)) 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[:n_particles_disk])), numpy.mean(abs(y_positions[:n_particles_disk])), numpy.mean(abs(z_positions[:n_particles_disk])), ] ), numpy.array([7.3994484072923656, 7.1570298135280606, 0.33854196755215527]), 3, ) self.assertAlmostRelativeEquals( numpy.array( [ numpy.mean(abs(x_positions[n_particles_disk : n_particles_disk + n_particles_bulge])), numpy.mean(abs(y_positions[n_particles_disk : n_particles_disk + n_particles_bulge])), numpy.mean(abs(z_positions[n_particles_disk : n_particles_disk + n_particles_bulge])), ] ), numpy.array([1.244429082274437, 1.1639373835548759, 0.8550614269822836]), 3, ) self.assertAlmostRelativeEquals( numpy.array( [ numpy.mean(abs(x_positions[-n_particles_halo:])), numpy.mean(abs(y_positions[-n_particles_halo:])), numpy.mean(abs(z_positions[-n_particles_halo:])), ] ), numpy.array([94.242819476127622, 88.41320479869843, 85.234394512176507]), 3, ) x_velocities, y_velocities, z_velocities, errors = instance.get_velocity(range(number_of_particles)) self.assertEquals(errors, numpy.zeros(number_of_particles)) 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[:n_particles_disk])), numpy.mean(abs(y_velocities[:n_particles_disk])), numpy.mean(abs(z_velocities[:n_particles_disk])), ] ), numpy.array([1.5026254250109197, 1.5649469271302223, 0.20230436498299242]), 5, ) self.assertAlmostRelativeEquals( numpy.array( [ numpy.mean(abs(x_velocities[n_particles_disk:])), numpy.mean(abs(y_velocities[n_particles_disk:])), numpy.mean(abs(z_velocities[n_particles_disk:])), ] ), numpy.array([0.99470628838986164, 0.95913934175856408, 0.9359876788407564]), 5, ) self.assertEquals(instance.cleanup_code(), 0) instance.stop()