Пример #1
0
    def test9(self):
        instance = PhiGRAPEInterface(**default_test_options)
        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)
Пример #2
0
    def xtest8(self):
        instance = PhiGRAPEInterface(**default_test_options)
        instance.initialize_code()
        instance.set_eps2(0.0**2)
        instance.set_eta(0.01, 0.02)
        instance.new_particle([0.01, 0.01], [10., -10.], [0.0, 0.0],
                              [0.0, 0.0], [-5.0, 5.0], [0.0, 0.0], [0.0, 0.0],
                              [0.1, 0.1])
        instance.commit_particles()
        #HAS NO RESULT...
        result = instance.evolve_model(3.14159)

        tnow = instance.get_time()['time']
        print("after evolve(pi), tnow = %f" % (tnow))
        #self.assertEqual( id1, 1)
        """
        instance.evolve(instance.get_time(),1)
        id2=instance.find_colliding_secondary(id1)
        self.assertEqual( id2, 2)
        self.assertAlmostEqual( tnow, 2.,2)
        state1 = instance.get_state(id1)
        state2 = instance.get_state(id2)
        self.assertTrue( abs(state1['x'] - state2['x'])<0.2)
        """
        instance.cleanup_code()
        instance.stop()
Пример #3
0
    def test7(self):
        instance = PhiGRAPEInterface(**
                                     default_test_options)  #(debugger="xterm")
        instance.initialize_code()

        instance.set_eps2(0.0**2)
        instance.set_eta(0.01, 0.02)
        instance.commit_parameters()

        instance.new_particle([1.0, 1.0, 1.0], [1.0, 0.0, -1.0],
                              [0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
                              [0.0, 1.0, 0.0], [0.0, 0.0, 0.0],
                              [0.0, 0.0, 0.0])
        instance.recommit_particles()
        Ep = instance.get_potential_energy()['potential_energy']
        Ek = instance.get_kinetic_energy()['kinetic_energy']
        self.assertEqual(Ek, 0.5)
        self.assertEqual(Ep, -2.5)
        instance.delete_particle(2)
        instance.recommit_particles()
        n = instance.get_number_of_particles()['number_of_particles']
        Ep = instance.get_potential_energy()['potential_energy']
        Ek = instance.get_kinetic_energy()['kinetic_energy']

        self.assertEqual(n, 2)
        self.assertEqual(Ek, 0.)
        self.assertEqual(Ep, -0.5)

        instance.cleanup_code()
        instance.stop()
Пример #4
0
 def test2(self):
     instance = PhiGRAPEInterface(**default_test_options)
     for x in [0.101, 4.0]:
         error = instance.set_eps2(x)
         self.assertEqual(error, 0)
         value, error = instance.get_eps2()
         self.assertEqual(error, 0)
         self.assertEqual(x, value)
     instance.cleanup_code()
     instance.stop()
 def test1(self):
     instance = PhiGRAPEInterface(**default_test_options)
     instance.initialize_code()
     instance.new_particle(11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0)
     retrieved_state = instance.get_state(1)
     self.assertEquals(11.0,  retrieved_state['mass'])
     self.assertEquals(2.0, retrieved_state['radius'])
     self.assertEquals(instance.get_number_of_particles()['number_of_particles'], 1)
     instance.cleanup_code()
     instance.stop()
Пример #6
0
 def test5(self):
     instance = PhiGRAPEInterface(**default_test_options)
     instance.initialize_code()
     n = 4000
     ids = [i for i in range(1, n)]
     values = [1.0 * i for i in range(1, n)]
     instance.new_particle(values, values, values, values, values, values,
                           values)
     retrieved_state = instance.get_state(3999)
     self.assertEqual(3999.0, retrieved_state['mass'])
     instance.cleanup_code()
     instance.stop()
Пример #7
0
    def test3(self):
        instance = PhiGRAPEInterface(**default_test_options)
        instance.initialize_code()

        instance.new_particle([11.0, 12.0, 13.0, 14.0], [2.1, 3.1, 4.1, 5.1],
                              [2.2, 3.2, 4.2, 5.2], [2.3, 3.3, 4.3, 5.3],
                              [2.4, 3.4, 4.4, 5.4], [2.5, 3.5, 4.5, 5.5],
                              [2.6, 3.6, 4.6, 5.6], [2.0, 3.0, 4.0, 5.0])
        retrieved_state = instance.get_state(1)
        self.assertEqual(11.0, retrieved_state['mass'])
        retrieved_state = instance.get_state([2, 3, 4])
        self.assertEqual(12.0, retrieved_state['mass'][0])
        self.assertEqual(
            instance.get_number_of_particles()['number_of_particles'], 4)
        instance.cleanup_code()
        instance.stop()