def test9(self): print "Test HermiteInterface evolve_model" instance = Hacs64Interface() self.assertEquals(0, instance.initialize_code()) #self.assertEquals(0, instance.set_eta_irr(0.14)) #self.assertEquals(0, instance.set_eta_reg(0.001)) self.assertEquals(0, instance.commit_parameters()) # Set up an equal-mass binary on a circular orbit: self.assertEquals([0, 0], instance.new_particle(0.5, 0.5, 0, 0, 0, 0.5, 0, 0.01).values()) self.assertEquals([1, 0], instance.new_particle(0.5, -0.5, 0, 0, 0, -0.5, 0, 0.01).values()) self.assertEquals(0, instance.commit_particles()) self.assertEquals(0, instance.evolve_model(math.pi)) for result, expected in zip( instance.get_position(0).values(), [-0.5, -0.007, 0.0, 0]): self.assertAlmostEquals(result, expected, 3) for result, expected in zip( instance.get_position(1).values(), [0.5, 0.007, 0.0, 0]): self.assertAlmostEquals(result, expected, 3) self.assertEquals(0, instance.evolve_model(2 * math.pi)) for result, expected in zip( instance.get_position(0).values(), [0.5, 0.0147, 0.0, 0]): self.assertAlmostEquals(result, expected, 3) for result, expected in zip( instance.get_position(1).values(), [-0.5, -0.0147, 0.0, 0]): self.assertAlmostEquals(result, expected, 3) self.assertEquals(0, instance.cleanup_code()) instance.stop()
def test8(self): instance = Hacs64Interface() instance.initialize_code() instance.set_eps2(0) 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=1.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, -1.0 / numpy.sqrt(2.0**2), 8) total_potential, errorcode = instance.get_potential_energy() potentials, errorcode = instance.get_potential([id1, id2]) instance.stop() self.assertAlmostRelativeEquals( total_potential, numpy.sum(potentials * [10.0, 1.0]) / 2.0)
def test6(self): instance = Hacs64Interface() instance.initialize_code() instance.commit_parameters() instance.new_particle([10, 10], [-1, 1], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1]) instance.commit_particles() self.assertFalse(hasattr(instance, "get_potential_at_point")) #retr, error = instance.get_potential_at_point(0.01, 0,0,0) #@print retr #self.assertEqual(error, -1) # TODO: Not IMPLEMENTED yet #self.assertEqual(retr['phi'], -20.0) instance.cleanup_code() instance.stop()
def test4(self): instance = Hacs64Interface() instance.initialize_code() self.assertEquals(0, instance.set_h2max(0.1)) self.assertEquals((0.1, 0), tuple(instance.get_h2max())) self.assertEquals((0.14, 0), tuple(instance.get_eta_reg())) self.assertEquals(0, instance.set_eta_reg(0.4)) self.assertEquals((0.4, 0), tuple(instance.get_eta_reg())) self.assertEquals((0.8, 0), tuple(instance.get_eta_irr())) self.assertEquals(0, instance.set_eta_irr(0.6)) self.assertEquals((0.6, 0), tuple(instance.get_eta_irr())) self.assertEquals(0, instance.commit_parameters()) instance.cleanup_code() instance.stop()
def test5(self): instance = Hacs64Interface() instance.initialize_code() instance.commit_parameters() instance.new_particle([10, 20], [0, 1], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [1, 1]) instance.commit_particles() retrieved_state = instance.get_state(0) self.assertEquals(10.0, retrieved_state['mass']) self.assertEquals(1, retrieved_state['radius']) retrieved_state = instance.get_state([0, 1]) self.assertEquals(20.0, retrieved_state['mass'][1]) self.assertEquals( instance.get_number_of_particles()['number_of_particles'], 2) instance.cleanup_code() instance.stop()
def test3(self): instance = Hacs64Interface() instance.initialize_code() self.assertEquals(0, instance.set_nmax(10)) self.assertEquals((10, 0), tuple(instance.get_nmax())) self.assertEquals(0, instance.set_dtmax(4)) self.assertEquals((4, 0), tuple(instance.get_dtmax())) self.assertEquals(0, instance.set_eps2(2)) self.assertEquals((2, 0), tuple(instance.get_eps2())) self.assertEquals(0, instance.commit_parameters()) self.assertEquals(-1, instance.set_nmax(11)) self.assertEquals((10, 0), tuple(instance.get_nmax())) self.assertEquals(-1, instance.set_dtmax(6)) self.assertEquals((4, 0), tuple(instance.get_dtmax())) instance.cleanup_code() instance.stop()
def test2(self): instance = Hacs64Interface() instance.initialize_code() instance.commit_parameters() for i in [1, 2, 3]: temp_particle = instance.new_particle(mass=i, radius=1.0, x=i * 1.0, y=0.0, z=0.0, vx=0.0, vy=0.0, vz=0.0) self.assertEquals(i - 1, temp_particle['index_of_the_particle']) error = instance.commit_particles() self.assertEquals(0, error) error = instance.delete_particle(1) self.assertEquals(0, error) error = instance.recommit_particles() self.assertEquals(0, error) self.assertEquals( 2, instance.get_number_of_particles()['number_of_particles']) self.assertEquals( 0, instance.get_index_of_first_particle()['index_of_the_particle']) self.assertEquals( 2, instance.get_index_of_next_particle(0) ['index_of_the_next_particle']) self.assertEquals(0, instance.get_index_of_next_particle(0)['__result']) self.assertEquals(-1, instance.get_index_of_next_particle(1)['__result']) self.assertEquals(1, instance.get_index_of_next_particle(2)['__result']) instance.stop()
def test1(self): instance = Hacs64Interface() 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) self.assertEquals(0, res1['index_of_the_particle']) self.assertEquals(1, res2['index_of_the_particle']) error = instance.commit_particles() self.assertEquals(0, error) retrieved_state1 = instance.get_state(0) retrieved_state2 = instance.get_state(1) self.assertEquals(0, retrieved_state1['__result']) self.assertEquals(0, retrieved_state2['__result']) 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(5.0, retrieved_state2['radius']) instance.cleanup_code() instance.stop()
def test0(self): instance = Hacs64Interface() instance.stop()