def test2(self): instance = BHTreeInterface() instance.initialize_code() instance.commit_parameters() for i in [1, 2, 3]: temp_particle = instance.new_particle(mass = i, radius = 1.0, x = 0.0, y = 0.0, z = 0.0, vx = 0.0, vy = 0.0, vz = 0.0) self.assertEquals(i, temp_particle['index_of_the_particle']) instance.commit_particles() self.assertEquals(1, instance.get_index_of_first_particle()['index_of_the_particle']) self.assertEquals(2, instance.get_index_of_next_particle(1)['index_of_the_next_particle']) self.assertEquals(3, instance.get_index_of_next_particle(2)['index_of_the_next_particle']) instance.delete_particle(1) self.assertEquals(2, instance.get_number_of_particles()['number_of_particles']) #the deletion does a swap, so 3 is copied to 1, (overwriting old 1 and treesize -> treesize-1 self.assertEquals(3, instance.get_index_of_first_particle()['index_of_the_particle']) self.assertEquals(1, instance.get_index_of_next_particle(2)['__result']) instance.cleanup_code() instance.stop()
def test8(self): instance = BHTreeInterface() instance.initialize_code() instance.set_epsilon_squared(0.1 * 0.1) instance.commit_parameters() id1, errorcode = instance.new_particle(mass=10.0, radius=1.0, x=0.0, y=0.0, z=0.0, vx=0.0, vy=0.0, vz=0.0) id2, errorcode = instance.new_particle(mass=10.0, radius=1.0, x=2.0, y=0.0, z=0.0, vx=10.0, vy=0.0, vz=0.0) instance.commit_particles() potential, errorcode = instance.get_potential(id1) self.assertEquals(errorcode, 0) self.assertAlmostRelativeEquals(potential, -10.0 / numpy.sqrt(2.0**2 + 0.1**2), 8) instance.cleanup_code() instance.stop()
def test6(self): instance = BHTreeInterface() instance.initialize_code() instance.commit_parameters() ids = [] for i in [1, 2, 3]: id, error = instance.new_particle(mass=i, radius=1.0, x=0.0, y=0.0, z=0.0, vx=0.0, vy=0.0, vz=0.0) ids.append(id) print ids instance.commit_particles() instance.delete_particle(ids[0]) id, error = instance.new_particle(mass=4, radius=1.0, x=0.0, y=0.0, z=0.0, vx=0.0, vy=0.0, vz=0.0) self.failIfEqual(id, ids[-1]) instance.cleanup_code() instance.stop()
def test8(self): instance = BHTreeInterface() instance.initialize_code() instance.set_epsilon_squared(0.1 * 0.1) instance.commit_parameters() id1,errorcode = instance.new_particle(mass = 10.0, radius = 1.0, x = 0.0, y = 0.0, z = 0.0, vx = 0.0, vy = 0.0, vz = 0.0) id2,errorcode = instance.new_particle(mass = 10.0, radius = 1.0, x = 2.0, y = 0.0, z = 0.0, vx = 10.0, vy = 0.0, vz = 0.0) instance.commit_particles() potential, errorcode = instance.get_potential(id1) self.assertEquals(errorcode, 0) self.assertAlmostRelativeEquals(potential, -10.0 / numpy.sqrt(2.0**2 + 0.1**2), 8) instance.cleanup_code() instance.stop()
def test5(self): interface = BHTreeInterface() interface.initialize_code() interface.commit_parameters() interface.new_particle([10,20],[0,0],[0,0], [0,0], [0,0], [0,0], [0,0],[1,1]) interface.commit_particles() retrieved_state = interface.get_state(1) self.assertEquals(10.0, retrieved_state['mass']) self.assertEquals(1, retrieved_state['radius']) retrieved_state = interface.get_state([1,2]) self.assertEquals(20.0, retrieved_state['mass'][1]) self.assertEquals(interface.get_number_of_particles()['number_of_particles'], 2) interface.cleanup_code() interface.stop()
def test2(self): instance = BHTreeInterface() instance.initialize_code() instance.commit_parameters() for i in [1, 2, 3]: temp_particle = instance.new_particle(mass=i, radius=1.0, x=0.0, y=0.0, z=0.0, vx=0.0, vy=0.0, vz=0.0) self.assertEquals(i, temp_particle['index_of_the_particle']) instance.commit_particles() self.assertEquals( 1, instance.get_index_of_first_particle()['index_of_the_particle']) self.assertEquals( 2, instance.get_index_of_next_particle(1) ['index_of_the_next_particle']) self.assertEquals( 3, instance.get_index_of_next_particle(2) ['index_of_the_next_particle']) instance.delete_particle(1) self.assertEquals( 2, instance.get_number_of_particles()['number_of_particles']) #the deletion does a swap, so 3 is copied to 1, (overwriting old 1 and treesize -> treesize-1 self.assertEquals( 3, instance.get_index_of_first_particle()['index_of_the_particle']) self.assertEquals(1, instance.get_index_of_next_particle(2)['__result']) instance.cleanup_code() instance.stop()
def test1(self): instance = BHTreeInterface() instance.initialize_code() instance.commit_parameters() res1 = instance.new_particle(mass=11.0, radius=2.0, x=0.0, y=0.0, z=0.0, vx=0.0, vy=0.0, vz=0.0) res2 = instance.new_particle(mass=21.0, radius=5.0, x=10.0, y=0.0, z=0.0, vx=10.0, vy=0.0, vz=0.0) instance.commit_particles() self.assertEquals(1, res1['index_of_the_particle']) self.assertEquals(2, res2['index_of_the_particle']) retrieved_state1 = instance.get_state(1) retrieved_state2 = instance.get_state(2) self.assertEquals(11.0, retrieved_state1['mass']) self.assertEquals(21.0, retrieved_state2['mass']) self.assertEquals(0.0, retrieved_state1['x']) self.assertEquals(10.0, retrieved_state2['x']) self.assertEquals( 1, instance.get_index_of_first_particle()['index_of_the_particle']) self.assertEquals( 2, instance.get_index_of_next_particle(1) ['index_of_the_next_particle']) instance.cleanup_code() instance.stop()
def test5(self): interface = BHTreeInterface() interface.initialize_code() interface.commit_parameters() interface.new_particle([10, 20], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1]) interface.commit_particles() retrieved_state = interface.get_state(1) self.assertEquals(10.0, retrieved_state['mass']) self.assertEquals(1, retrieved_state['radius']) retrieved_state = interface.get_state([1, 2]) self.assertEquals(20.0, retrieved_state['mass'][1]) self.assertEquals( interface.get_number_of_particles()['number_of_particles'], 2) interface.cleanup_code() interface.stop()
def test7(self): interface = BHTreeInterface( ) #channel_type="remote") #, debugger="xterm") interface.initialize_code() interface.commit_parameters() interface.new_particle([10, 20], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1]) interface.commit_particles() retrieved_state = interface.get_state(1) self.assertEqual(10.0, retrieved_state['mass']) self.assertEqual(1, retrieved_state['radius']) retrieved_state = interface.get_state([1, 2]) self.assertEqual(20.0, retrieved_state['mass'][1]) self.assertEqual( interface.get_number_of_particles()['number_of_particles'], 2) interface.cleanup_code() interface.stop()
def test6(self): instance = BHTreeInterface() instance.initialize_code() instance.commit_parameters() ids = [] for i in [1, 2, 3]: id, error = instance.new_particle(mass = i, radius = 1.0, x = 0.0, y = 0.0, z = 0.0, vx = 0.0, vy = 0.0, vz = 0.0) ids.append(id) print ids instance.commit_particles() instance.delete_particle(ids[0]) id, error = instance.new_particle(mass = 4, radius = 1.0, x = 0.0, y = 0.0, z = 0.0, vx = 0.0, vy = 0.0, vz = 0.0) self.failIfEqual(id, ids[-1]) instance.cleanup_code() instance.stop()
def test1(self): instance = BHTreeInterface() instance.initialize_code() instance.commit_parameters() res1 = instance.new_particle(mass = 11.0, radius = 2.0, x = 0.0, y = 0.0, z = 0.0, vx = 0.0, vy = 0.0, vz = 0.0) res2 = instance.new_particle(mass = 21.0, radius = 5.0, x = 10.0, y = 0.0, z = 0.0, vx = 10.0, vy = 0.0, vz = 0.0) instance.commit_particles() self.assertEquals(1, res1['index_of_the_particle']) self.assertEquals(2, res2['index_of_the_particle']) retrieved_state1 = instance.get_state(1) retrieved_state2 = instance.get_state(2) self.assertEquals(11.0, retrieved_state1['mass']) self.assertEquals(21.0, retrieved_state2['mass']) self.assertEquals(0.0, retrieved_state1['x']) self.assertEquals(10.0, retrieved_state2['x']) self.assertEquals(1, instance.get_index_of_first_particle()['index_of_the_particle']) self.assertEquals(2, instance.get_index_of_next_particle(1)['index_of_the_next_particle']) instance.cleanup_code() instance.stop()