Beispiel #1
0
    def test8(self):
        print "Test MI6Interface evolve_model, binary (+SMBH) --> accretion!?"
        instance = MI6Interface(**default_options)
        self.assertEquals(0, instance.initialize_code())
        self.assertEquals(0, instance.set_include_smbh_flag(1))
        self.assertEquals(0, instance.set_calculate_postnewtonian(0))
        self.assertEquals(0, instance.commit_parameters())
        # Set up a light binary on circular orbits around the SMBH:
        mass = 1.0e-6
        self.assertEquals([1, 0],
                          instance.new_particle(mass, 1.0, 0, 0, 0, 1.0, 0,
                                                0.001).values())
        self.assertEquals([2, 0],
                          instance.new_particle(mass, -1.0, 0, 0, 0, -1.0, 0,
                                                0.001).values())
        self.assertEquals(0, instance.commit_particles())

        self.assertEquals(0, instance.evolve_model(0.00001))
        result1 = instance.get_position(1).values()
        result2 = instance.get_position(2).values()
        print result1
        print result2

        self.assertEquals(0, instance.cleanup_code())
        instance.stop()
Beispiel #2
0
    def test6(self):
        print "Test MI6Interface evolve_model, single particle (+SMBH)"
        instance = MI6Interface(**default_options)
        self.assertEquals(0, instance.initialize_code())
        self.assertEquals(0, instance.set_include_smbh_flag(1))
        self.assertEquals(0, instance.set_calculate_postnewtonian(0))
        self.assertEquals(0, instance.commit_parameters())

        # Set up a light particle on a circular orbit around the SMBH:
        self.assertEquals([1, 0],
                          instance.new_particle(1.0e-4, 1.0, 0, 0, 0, 1.0, 0,
                                                0.001).values())
        self.assertEquals(0, instance.commit_particles())

        self.assertEquals(0, instance.evolve_model(math.pi))  # half an orbit
        for result, expected in zip(
                instance.get_position(1).values(), [-1.0, 0.0, 0.0, 0]):
            self.assertAlmostEquals(result, expected, 4)

        self.assertEquals(0, instance.evolve_model(2 * math.pi))  # full orbit
        for result, expected in zip(
                instance.get_position(1).values(), [1.0, 0.0, 0.0, 0]):
            self.assertAlmostEquals(result, expected, 4)

        self.assertEquals(0, instance.cleanup_code())
        instance.stop()
Beispiel #3
0
    def test7(self):
        print "Test MI6Interface evolve_model, 2 particles orbiting the SMBH"
        instance = MI6Interface(**default_options)
        self.assertEquals(0, instance.initialize_code())
        self.assertEquals(0, instance.set_include_smbh_flag(1))
        self.assertEquals(0, instance.set_calculate_postnewtonian(0))
        self.assertEquals(0, instance.commit_parameters())
        # Set up a light binary on circular orbits around the SMBH:
        mass = 1.0e-4
        dv = 0.5 * (math.sqrt(1.0 + 0.5 * mass) - 1.0)
        self.assertEquals([1, 0],
                          instance.new_particle(mass, 1.0, 0, 0, 0, 1.0 + dv,
                                                0, 0.001).values())
        self.assertEquals([2, 0],
                          instance.new_particle(mass, -1.0, 0, 0, 0, -1.0 - dv,
                                                0, 0.001).values())
        self.assertEquals(0, instance.commit_particles())

        P = 2 * math.pi / (1 + dv)
        self.assertEquals(0, instance.evolve_model(P / 2))  # half an orbit
        for result, expected in zip(
                instance.get_position(1).values(), [-1.0, 0.0, 0.0, 0]):
            self.assertAlmostEquals(result, expected, 4)

        self.assertEquals(0, instance.evolve_model(P))  # full orbit
        for result, expected in zip(
                instance.get_position(1).values(), [1.0, 0.0, 0.0, 0]):
            self.assertAlmostEquals(result, expected, 4)

        self.assertEquals(0, instance.cleanup_code())
        instance.stop()
Beispiel #4
0
 def test1(self):
     print "Test MI6Interface initialization"
     instance = MI6Interface(**default_options)
     self.assertEquals(0, instance.initialize_code())
     self.assertEquals(0, instance.commit_parameters())
     self.assertEquals(0, instance.cleanup_code())
     instance.stop()
Beispiel #5
0
    def test5(self):
        print "Test MI6Interface parameters"
        instance = MI6Interface(**default_options)
        self.assertEquals(0, instance.initialize_code())

        # MI6 has separate epsilon_squared parameters for different interactions!
        self.assertEquals([0, 0], instance.get_eps2_fs_fs().values())
        self.assertEquals([0, 0], instance.get_eps2_fs_bh().values())
        self.assertEquals([0, 0], instance.get_eps2_bh_bh().values())
        self.assertEquals(-2,
                          instance.get_eps2()
                          ['__result'])  # Not implemented (would be ambiguous)

        self.assertEquals(0, instance.set_eps2_fs_fs(0.2))
        self.assertEquals([0.2, 0], instance.get_eps2_fs_fs().values())
        self.assertEquals(0, instance.set_eps2_fs_bh(0.3))
        self.assertEquals([0.3, 0], instance.get_eps2_fs_bh().values())
        self.assertEquals(0, instance.set_eps2_bh_bh(0.4))
        self.assertEquals([0.4, 0], instance.get_eps2_bh_bh().values())
        self.assertEquals(
            -2, instance.set_eps2(0.1))  # Not implemented (would be ambiguous)

        self.assertEquals([1.0e-4, 0], instance.get_eta_s().values())
        self.assertEquals([0.1, 0], instance.get_eta_fs().values())
        self.assertEquals([0.4, 0], instance.get_eta_smbh().values())
        self.assertEquals([0.4, 0], instance.get_eta_imbh().values())

        self.assertEquals(0, instance.set_eta_s(0.01))
        self.assertEquals([0.01, 0], instance.get_eta_s().values())
        self.assertEquals(0, instance.set_eta_fs(0.02))
        self.assertEquals([0.02, 0], instance.get_eta_fs().values())
        self.assertEquals(0, instance.set_eta_smbh(0.03))
        self.assertEquals([0.03, 0], instance.get_eta_smbh().values())
        self.assertEquals(0, instance.set_eta_imbh(0.04))
        self.assertEquals([0.04, 0], instance.get_eta_imbh().values())

        self.assertEquals(0, instance.set_max_relative_energy_error(1.0e-6))
        self.assertEquals([1.0e-6, 0],
                          instance.get_max_relative_energy_error().values())
        self.assertEquals(0, instance.set_maximum_timestep(1.0e-6))
        self.assertEquals([1.0e-6, 0],
                          instance.get_maximum_timestep().values())

        self.assertEquals(0, instance.set_smbh_mass(0.1))
        self.assertEquals([0.1, 0], instance.get_smbh_mass().values())

        self.assertEquals([0, 0], instance.get_include_smbh_flag().values())
        self.assertEquals(0, instance.set_include_smbh_flag(1))
        self.assertEquals([1, 0], instance.get_include_smbh_flag().values())
        self.assertEquals([1, 0],
                          instance.get_calculate_postnewtonian().values())
        self.assertEquals(0, instance.set_calculate_postnewtonian(0))
        self.assertEquals([0, 0],
                          instance.get_calculate_postnewtonian().values())

        self.assertEquals(0, instance.commit_parameters())
        self.assertEquals(0, instance.cleanup_code())
        instance.stop()
Beispiel #6
0
    def test4(self):
        print("Test MI6Interface particle property getters/setters")
        instance = MI6Interface(**default_options)
        self.assertEqual(0, instance.initialize_code())
        self.assertEqual(0, instance.commit_parameters())
        self.assertEqual([1, 0],
                         list(
                             instance.new_particle(0.01, 1, 0, 0, 0, 1, 0,
                                                   0.1).values()))
        self.assertEqual([2, 0],
                         list(
                             instance.new_particle(0.02, -1, 0, 0, 0, -1, 0,
                                                   0.1).values()))
        self.assertEqual(
            -3,
            instance.get_mass(1)['__result'])  # Have to commit first
        self.assertEqual(0, instance.commit_particles())

        # getters
        mass, result = instance.get_mass(1)
        self.assertAlmostEqual(0.01, mass)
        self.assertEqual(0, result)
        radius, result = instance.get_radius(2)
        self.assertAlmostEqual(0.1, radius)
        self.assertEqual(0, result)
        self.assertEqual(
            -3,
            instance.get_mass(3)['__result'])  # Particle not found
        self.assertEqual([1, 0, 0, 0], list(instance.get_position(1).values()))
        self.assertEqual([-1, 0, 0, 0],
                         list(instance.get_position(2).values()))
        self.assertEqual([0, 1, 0, 0], list(instance.get_velocity(1).values()))
        self.assertEqual([0, -1, 0, 0],
                         list(instance.get_velocity(2).values()))

        # setters
        self.assertEqual(0, instance.set_state(1, 0.01, 1, 2, 3, 4, 5, 6, 0.1))
        self.assertEqual([0.01, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.1, 0],
                         list(instance.get_state(1).values()))
        self.assertEqual(0, instance.set_mass(1, 0.02))
        self.assertEqual([0.02, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.1, 0],
                         list(instance.get_state(1).values()))
        self.assertEqual(0, instance.set_radius(1, 0.2))
        self.assertEqual([0.02, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.2, 0],
                         list(instance.get_state(1).values()))
        self.assertEqual(0, instance.set_position(1, 10, 20, 30))
        self.assertEqual([0.02, 10.0, 20.0, 30.0, 4.0, 5.0, 6.0, 0.2, 0],
                         list(instance.get_state(1).values()))
        self.assertEqual(0, instance.set_velocity(1, 40, 50, 60))
        self.assertEqual([0.02, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 0.2, 0],
                         list(instance.get_state(1).values()))

        self.assertEqual(0, instance.cleanup_code())
        instance.stop()
Beispiel #7
0
    def xtest3(self):
        print(
            "Test MI6Interface get_index_of_first_particle, get_index_of_next_particle"
        )
        instance = MI6Interface(**default_options)
        instance.initialize_code()
        instance.commit_parameters()
        for i in [1, 2, 3]:
            result = 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.assertEqual(i, result['index_of_the_particle'])

        instance.commit_particles()
        self.assertEqual(
            1,
            instance.get_index_of_first_particle()['index_of_the_particle'])
        self.assertEqual(
            2,
            instance.get_index_of_next_particle(1)
            ['index_of_the_next_particle'])
        self.assertEqual(
            3,
            instance.get_index_of_next_particle(2)
            ['index_of_the_next_particle'])

        instance.delete_particle(1)

        self.assertEqual(
            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.assertEqual(
            3,
            instance.get_index_of_first_particle()['index_of_the_particle'])

        self.assertEqual(1, instance.get_index_of_next_particle(2)['__result'])

        instance.cleanup_code()
        instance.stop()
Beispiel #8
0
    def test2(self):
        print "Test MI6Interface new_particle / get_state"
        instance = MI6Interface(**default_options)
        self.assertEquals(0, instance.initialize_code())
        self.assertEquals(0, instance.commit_parameters())

        id, error = 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)
        self.assertEquals(0, error)
        self.assertEquals(1, id)
        id, error = 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, error)
        self.assertEquals(2, id)
        self.assertEquals(0, instance.commit_particles())

        retrieved_state1 = instance.get_state(1)
        retrieved_state2 = instance.get_state(2)
        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(0, instance.cleanup_code())
        instance.stop()