Ejemplo n.º 1
0
    def test05(self):
        if MODULES_MISSING:
            self.skip("Failed to import a module required for Sakura")
        print "Test SakuraInterface evolve_model, binary"
        instance = SakuraInterface(redirection='none')  #,debugger="gdb")
        self.assertEquals(0, instance.initialize_code())
        self.assertEquals(0, instance.commit_parameters())

        self.assertEquals([0, 0],
                          instance.new_particle(0.5, 0.5, 0, 0, 0, 0.5, 0,
                                                0.001).values())
        self.assertEquals([1, 0],
                          instance.new_particle(0.5, -0.5, 0, 0, 0, -0.5, 0,
                                                0.001).values())
        self.assertEquals(0, instance.commit_particles())

        P = 2 * math.pi
        self.assertEquals(0, instance.evolve_model(P / 2))  # half an orbit
        for result, expected in zip(
                instance.get_position(0).values(), [-0.5, 0.0, 0.0, 0]):
            self.assertAlmostEquals(result, expected, 2)
        self.assertEquals(0, instance.evolve_model(P))  # full orbit
        for result, expected in zip(
                instance.get_position(0).values(), [0.5, 0.0, 0.0, 0]):
            self.assertAlmostEquals(result, expected, 2)
        self.assertEquals(0, instance.cleanup_code())
        instance.stop()
Ejemplo n.º 2
0
    def test02(self):
        if MODULES_MISSING:
            self.skip("Failed to import a module required for Sakura")
        print "Test SakuraInterface new_particle / get_state"
        instance = SakuraInterface()
        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(0, 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(1, id)
        self.assertEquals(0, instance.commit_particles())

        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(0, instance.cleanup_code())
        instance.stop()
Ejemplo n.º 3
0
    def xtest04(self):
        if MODULES_MISSING:
            self.skip("Failed to import a module required for Sakura")
        print "Test SakuraInterface parameters"
        instance = SakuraInterface()
        self.assertEquals(0, instance.initialize_code())

        self.assertEquals([0.03125, 0], instance.get_eta().values())
        self.assertEquals(0, instance.set_eta(0.001))
        self.assertEquals([0.001, 0], instance.get_eta().values())

        self.assertEquals([0.0, 0], instance.get_begin_time().values())
        self.assertEquals(0, instance.set_begin_time(1.0))
        self.assertEquals([1.0, 0], instance.get_begin_time().values())

        self.assertEquals(["sakura", 0], instance.get_integrator_method().values())
        self.assertEquals(0, instance.set_integrator_method("bogus"))
        self.assertEquals(["bogus", 0], instance.get_integrator_method().values())
        self.assertEquals(-1, instance.commit_parameters())
        self.assertEquals(0, instance.set_integrator_method("asakura"))
        self.assertEquals(["asakura", 0], instance.get_integrator_method().values())

        self.assertEquals(0, instance.commit_parameters())

        self.assertEquals(0, instance.set_pn_order(7))
        self.assertEquals([7, 0], instance.get_pn_order().values())
        self.assertEquals(-1, instance.commit_parameters())
        self.assertEquals(0, instance.set_clight(1024))
        self.assertEquals([1024, 0], instance.get_clight().values())

        self.assertEquals(0, instance.commit_parameters())
        self.assertEquals(0, instance.cleanup_code())
        instance.stop()
Ejemplo n.º 4
0
 def test01(self):
     if MODULES_MISSING:
         self.skip("Failed to import a module required for Sakura")
     print "Test SakuraInterface initialization"
     instance = SakuraInterface()
     self.assertEquals(0, instance.initialize_code())
     self.assertEquals(0, instance.commit_parameters())
     self.assertEquals(0, instance.cleanup_code())
     instance.stop()
Ejemplo n.º 5
0
 def test01(self):
     if MODULES_MISSING:
         self.skip("Failed to import a module required for Sakura")
     print "Test SakuraInterface initialization"
     instance = SakuraInterface()
     self.assertEquals(0, instance.initialize_code())
     self.assertEquals(0, instance.commit_parameters())
     self.assertEquals(0, instance.cleanup_code())
     instance.stop()
Ejemplo n.º 6
0
    def test03(self):
        if MODULES_MISSING:
            self.skip("Failed to import a module required for Sakura")
        print("Test SakuraInterface particle property getters/setters")
        instance = SakuraInterface()
        self.assertEqual(0, instance.initialize_code())
        self.assertEqual(0, instance.commit_parameters())
        self.assertEqual([0, 0],
                         list(
                             instance.new_particle(0.01, 1, 0, 0, 0, 1, 0,
                                                   0.1).values()))
        self.assertEqual([1, 0],
                         list(
                             instance.new_particle(0.02, -1, 0, 0, 0, -1, 0,
                                                   0.1).values()))
        ####        self.assertEquals(-1, instance.get_mass(1)['__result']) # Have to commit first
        self.assertEqual(0, instance.commit_particles())

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

        # setters
        self.assertEqual(0, instance.set_state(0, 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(0).values()))
        self.assertEqual(0, instance.set_mass(0, 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(0).values()))
        self.assertEqual(0, instance.set_radius(0, 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(0).values()))
        self.assertEqual(0, instance.set_position(0, 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(0).values()))
        self.assertEqual(0, instance.set_velocity(0, 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(0).values()))

        self.assertEqual(0, instance.cleanup_code())
        instance.stop()
Ejemplo n.º 7
0
    def test02(self):
        if MODULES_MISSING:
            self.skip("Failed to import a module required for Sakura")
        print "Test SakuraInterface new_particle / get_state"
        instance = SakuraInterface()
        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(0, 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(1, id)
        self.assertEquals(0, instance.commit_particles())

        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(0, instance.cleanup_code())
        instance.stop()
Ejemplo n.º 8
0
    def test05(self):
        if MODULES_MISSING:
            self.skip("Failed to import a module required for Sakura")
        print "Test SakuraInterface evolve_model, binary"
        instance = SakuraInterface(redirection="none")  # ,debugger="gdb")
        self.assertEquals(0, instance.initialize_code())
        self.assertEquals(0, instance.commit_parameters())

        self.assertEquals([0, 0], instance.new_particle(0.5, 0.5, 0, 0, 0, 0.5, 0, 0.001).values())
        self.assertEquals([1, 0], instance.new_particle(0.5, -0.5, 0, 0, 0, -0.5, 0, 0.001).values())
        self.assertEquals(0, instance.commit_particles())

        P = 2 * math.pi
        self.assertEquals(0, instance.evolve_model(P / 2))  # half an orbit
        for result, expected in zip(instance.get_position(0).values(), [-0.5, 0.0, 0.0, 0]):
            self.assertAlmostEquals(result, expected, 2)
        self.assertEquals(0, instance.evolve_model(P))  # full orbit
        for result, expected in zip(instance.get_position(0).values(), [0.5, 0.0, 0.0, 0]):
            self.assertAlmostEquals(result, expected, 2)
        self.assertEquals(0, instance.cleanup_code())
        instance.stop()
Ejemplo n.º 9
0
    def test03(self):
        if MODULES_MISSING:
            self.skip("Failed to import a module required for Sakura")
        print "Test SakuraInterface particle property getters/setters"
        instance = SakuraInterface()
        self.assertEquals(0, instance.initialize_code())
        self.assertEquals(0, instance.commit_parameters())
        self.assertEquals([0, 0], instance.new_particle(0.01, 1, 0, 0, 0, 1, 0, 0.1).values())
        self.assertEquals([1, 0], instance.new_particle(0.02, -1, 0, 0, 0, -1, 0, 0.1).values())
        ####        self.assertEquals(-1, instance.get_mass(1)['__result']) # Have to commit first
        self.assertEquals(0, instance.commit_particles())

        # getters
        mass, result = instance.get_mass(0)
        self.assertAlmostEquals(0.01, mass)
        self.assertEquals(0, result)
        radius, result = instance.get_radius(1)
        self.assertAlmostEquals(0.1, radius)
        self.assertEquals(0, result)
        self.assertEquals(-1, instance.get_mass(2)["__result"])  # Particle not found
        self.assertEquals([1, 0, 0, 0], instance.get_position(0).values())
        self.assertEquals([-1, 0, 0, 0], instance.get_position(1).values())
        self.assertEquals([0, 1, 0, 0], instance.get_velocity(0).values())
        self.assertEquals([0, -1, 0, 0], instance.get_velocity(1).values())

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

        self.assertEquals(0, instance.cleanup_code())
        instance.stop()
Ejemplo n.º 10
0
    def test04(self):
        if MODULES_MISSING:
            self.skip("Failed to import a module required for Sakura")
        print "Test SakuraInterface parameters"
        instance = SakuraInterface()
        self.assertEquals(0, instance.initialize_code())

        self.assertEquals([0.001, 0], instance.get_dt().values())
        self.assertEquals(0, instance.set_dt(0.01))
        self.assertEquals([0.01, 0], instance.get_dt().values())

        self.assertEquals([0.0, 0], instance.get_t_begin().values())
        self.assertEquals(0, instance.set_t_begin(1.0))
        self.assertEquals([1.0, 0], instance.get_t_begin().values())

        self.assertEquals([0.0, 0], instance.get_t().values())
        self.assertEquals(0, instance.set_t(1.0))
        self.assertEquals([1.0, 0], instance.get_t().values())

        #self.assertEquals(["sakura", 0], instance.get_integrator_method().values())
        #self.assertEquals(0, instance.set_integrator_method("bogus"))
        #self.assertEquals(["bogus", 0], instance.get_integrator_method().values())
        #self.assertEquals(-1, instance.commit_parameters())
        #self.assertEquals(0, instance.set_integrator_method("asakura"))
        #self.assertEquals(["asakura", 0], instance.get_integrator_method().values())

        self.assertEquals(0, instance.commit_parameters())

        #self.assertEquals(0, instance.set_pn_order(7))
        #self.assertEquals([7, 0], instance.get_pn_order().values())
        #self.assertEquals(-1, instance.commit_parameters())
        #self.assertEquals(0, instance.set_clight(1024))
        #self.assertEquals([1024, 0], instance.get_clight().values())

        self.assertEquals(0, instance.commit_parameters())
        self.assertEquals(0, instance.cleanup_code())
        instance.stop()