Exemple #1
0
    def test9(self):
        print("Test HermiteInterface evolve_model")
        instance = HermiteInterface()
        self.assertEqual(0, instance.initialize_code())
        self.assertEqual(0, instance.set_dt_param(0.001))
        self.assertEqual(0, instance.set_end_time_accuracy_factor(0.0))
        self.assertEqual(0, instance.commit_parameters())

        # Set up an equal-mass binary on a circular orbit:
        self.assertEqual([0, 0], list(instance.new_particle(0.5,  0.5, 0, 0,  0, 0.5, 0, 0.01).values()))
        self.assertEqual([1, 0], list(instance.new_particle(0.5,  -0.5, 0, 0,  0,-0.5, 0, 0.01).values()))
        self.assertEqual(0, instance.commit_particles())

        self.assertEqual(0, instance.evolve_model(math.pi))
        for result, expected in zip(list(instance.get_position(0).values()), [-0.5, 0.0, 0.0, 0]):
            self.assertAlmostEqual(result, expected, 3)
        for result, expected in zip(list(instance.get_position(1).values()), [0.5, 0.0, 0.0, 0]):
            self.assertAlmostEqual(result, expected, 3)

        self.assertEqual(0, instance.evolve_model(2 * math.pi))
        for result, expected in zip(list(instance.get_position(0).values()), [0.5, 0.0, 0.0, 0]):
            self.assertAlmostEqual(result, expected, 3)
        for result, expected in zip(list(instance.get_position(1).values()), [-0.5, 0.0, 0.0, 0]):
            self.assertAlmostEqual(result, expected, 3)

        self.assertEqual(0, instance.cleanup_code())
        instance.cleanup_code()
        instance.stop()
Exemple #2
0
    def test8(self):
        instance = HermiteInterface()
        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.assertEqual(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.cleanup_code()
        instance.stop()

        self.assertAlmostRelativeEquals(
            total_potential,
            numpy.sum(potentials * [10.0, 1.0]) / 2.0)
Exemple #3
0
    def test6(self):
        hermite = HermiteInterface()
        hermite.initialize_code()

        hermite.new_particle([10,10],[-1,1],[0,0], [0,0], [0,0], [0,0], [0,0], [1,1])
        retrieved_state = hermite.get_state(0)

        retr = hermite.get_potential_at_point(0.01, 0,0,0)
        self.assertEqual(retr['phi'], -20.0)
        hermite.cleanup_code()
        hermite.stop()
Exemple #4
0
    def test2(self):
        instance = HermiteInterface()
        instance.initialize_code()

        for i in [0, 1, 2]:
            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.assertEqual(i, temp_particle['index_of_the_particle'])

        instance.delete_particle(1)

        self.assertEqual(
            2,
            instance.get_number_of_particles()['number_of_particles'])

        self.assertEqual(
            0,
            instance.get_index_of_first_particle()['index_of_the_particle'])

        self.assertEqual(
            2,
            instance.get_index_of_next_particle(0)
            ['index_of_the_next_particle'])
        self.assertEqual(0, instance.get_index_of_next_particle(0)['__result'])
        self.assertEqual(-1,
                         instance.get_index_of_next_particle(1)['__result'])
        self.assertEqual(1, instance.get_index_of_next_particle(2)['__result'])
        instance.cleanup_code()
        instance.stop()
Exemple #5
0
    def test5(self):
        hermite = HermiteInterface()
        hermite.initialize_code()

        hermite.new_particle([10, 20], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                             [0, 0], [1, 1])
        retrieved_state = hermite.get_state(0)

        self.assertEqual(10.0, retrieved_state['mass'])
        self.assertEqual(1, retrieved_state['radius'])

        retrieved_state = hermite.get_state([0, 1])
        self.assertEqual(20.0, retrieved_state['mass'][1])
        self.assertEqual(
            hermite.get_number_of_particles()['number_of_particles'], 2)
        hermite.cleanup_code()
        hermite.stop()
Exemple #6
0
    def test1(self):
        instance = HermiteInterface()
        instance.initialize_code()

        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.assertEqual(0, res1['index_of_the_particle'])
        self.assertEqual(1, res2['index_of_the_particle'])

        retrieved_state1 = instance.get_state(0)
        retrieved_state2 = instance.get_state(1)

        self.assertEqual(11.0, retrieved_state1['mass'])
        self.assertEqual(21.0, retrieved_state2['mass'])
        self.assertEqual(0.0, retrieved_state1['x'])
        self.assertEqual(10.0, retrieved_state2['x'])
        self.assertEqual(2.0, retrieved_state1['radius'])
        self.assertEqual(5.0, retrieved_state2['radius'])

        instance.cleanup_code()
        instance.stop()