當前位置: 首頁>>代碼示例>>Python>>正文


Python Hermite.get_gravity_at_point方法代碼示例

本文整理匯總了Python中amuse.community.hermite0.interface.Hermite.get_gravity_at_point方法的典型用法代碼示例。如果您正苦於以下問題:Python Hermite.get_gravity_at_point方法的具體用法?Python Hermite.get_gravity_at_point怎麽用?Python Hermite.get_gravity_at_point使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在amuse.community.hermite0.interface.Hermite的用法示例。


在下文中一共展示了Hermite.get_gravity_at_point方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test14

# 需要導入模塊: from amuse.community.hermite0.interface import Hermite [as 別名]
# 或者: from amuse.community.hermite0.interface.Hermite import get_gravity_at_point [as 別名]
    def test14(self):
        instance = Hermite()
        instance.initialize_code()
        instance.parameters.epsilon_squared = 0.00001 | nbody_system.length**2
        
        particles = datamodel.Particles(2)
        particles.mass = [1.0, 1.0] | nbody_system.mass
        particles.radius =  [0.0001, 0.0001] | nbody_system.length
        particles.position = [[0.0,0.0,0.0], [2.0,0.0,0.0]] | nbody_system.length
        particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] | nbody_system.speed
        instance.particles.add_particles(particles)
        
        zero = 0.0 | nbody_system.length
        fx, fy, fz = instance.get_gravity_at_point(zero, 1.0 | nbody_system.length, zero, zero)
        self.assertAlmostEqual(fx, 0.0 | nbody_system.acceleration, 6)
        self.assertAlmostEqual(fy, 0.0 | nbody_system.acceleration, 6)
        self.assertAlmostEqual(fz, 0.0 | nbody_system.acceleration, 6)

        for x in (0.25, 0.5, 0.75):
            x0 = x | nbody_system.length
            x1 = (2.0 - x) | nbody_system.length
            potential0 = instance.get_potential_at_point(zero, x0, zero, zero)
            potential1 = instance.get_potential_at_point(zero, x1, zero, zero)
            fx0, fy0, fz0 = instance.get_gravity_at_point(zero, x0, zero, zero)
            fx1, fy1, fz1 = instance.get_gravity_at_point(zero, x1, zero, zero)
            
            self.assertAlmostEqual(fy0, 0.0 | nbody_system.acceleration, 6)
            self.assertAlmostEqual(fz0, 0.0 | nbody_system.acceleration, 6)
            self.assertAlmostEqual(fy1, 0.0 | nbody_system.acceleration, 6)
            self.assertAlmostEqual(fz1, 0.0 | nbody_system.acceleration, 6)
            
            self.assertAlmostEqual(fx0, -1.0 * fx1, 5)
            fx = (-1.0 / (x0**2) + 1.0 / (x1**2)) * (1.0 | nbody_system.length ** 3 / nbody_system.time ** 2)
            self.assertAlmostEqual(fx, fx0, 2)
            self.assertAlmostEqual(potential0, potential1, 5)
        instance.stop()
開發者ID:Ingwar,項目名稱:amuse,代碼行數:38,代碼來源:test_hermite.py


注:本文中的amuse.community.hermite0.interface.Hermite.get_gravity_at_point方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。