예제 #1
0
파일: test_sakura.py 프로젝트: vdhelm/amuse
    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()
예제 #2
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()
예제 #3
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()
예제 #4
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()
예제 #5
0
파일: test_sakura.py 프로젝트: vdhelm/amuse
    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()
예제 #6
0
파일: test_sakura.py 프로젝트: vdhelm/amuse
    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()