当前位置: 首页>>代码示例>>Python>>正文


Python BHTree.get_gravity_at_point方法代码示例

本文整理汇总了Python中amuse.community.bhtree.interface.BHTree.get_gravity_at_point方法的典型用法代码示例。如果您正苦于以下问题:Python BHTree.get_gravity_at_point方法的具体用法?Python BHTree.get_gravity_at_point怎么用?Python BHTree.get_gravity_at_point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在amuse.community.bhtree.interface.BHTree的用法示例。


在下文中一共展示了BHTree.get_gravity_at_point方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test10

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import get_gravity_at_point [as 别名]
 def test10(self):
     instance = BHTree()
     instance.initialize_code()
     instance.parameters.epsilon_squared = 0.00001 | nbody_system.length**2
     instance.commit_parameters()
     
     
     particles = datamodel.Particles(6)
     particles.mass = 1.0 | nbody_system.mass
     particles.radius =   0.00001 | nbody_system.length
     particles.position = [[-1.0,0.0,0.0],[1.0,0.0,0.0],[0.0,-1.0,0.0],[0.0,1.0,0.0],[0.0,0.0,-1.0],[0.0,0.0,1.0]] | nbody_system.length
     particles.velocity = [[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0]] | nbody_system.speed
     instance.particles.add_particles(particles)
     instance.commit_particles()
     
     zero = 0.0 | nbody_system.length
     fx, fy, fz = instance.get_gravity_at_point(zero, zero, zero, zero)
     self.assertAlmostEqual(fx, 0.0 | nbody_system.acceleration, 3)
     self.assertAlmostEqual(fy, 0.0 | nbody_system.acceleration, 3)
     self.assertAlmostEqual(fz, 0.0 | nbody_system.acceleration, 3)
     
     
     for position in (0.25, 0.5, 0.75):
         p0 = position | nbody_system.length
         p1 = -position | nbody_system.length
         for i in range(3):
             args0 = [zero] * 4
             args1 = [zero] * 4
             args0[1 + i] = p0
             args1[1 + i] = p1
             f0 = instance.get_gravity_at_point(*args0)
             f1 = instance.get_gravity_at_point(*args1)
             
             for j in range(3):
                 if j != i:
                     self.assertAlmostEqual(f0[j], 0.0 | nbody_system.acceleration, 3)
                     self.assertAlmostEqual(f1[j], 0.0 | nbody_system.acceleration, 3)
                 else:
                     self.assertAlmostEqual(f0[j], -1.0 * f1[j], 5)
     
     instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:43,代码来源:test_bhtree.py

示例2: test9

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import get_gravity_at_point [as 别名]
    def test9(self):
        instance = BHTree()
        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, 3)
        self.assertAlmostEqual(fy, 0.0 | nbody_system.acceleration, 3)
        self.assertAlmostEqual(fz, 0.0 | nbody_system.acceleration, 3)

        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, 3)
            self.assertAlmostEqual(fz0, 0.0 | nbody_system.acceleration, 3)
            self.assertAlmostEqual(fy1, 0.0 | nbody_system.acceleration, 3)
            self.assertAlmostEqual(fz1, 0.0 | nbody_system.acceleration, 3)
            
            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.cleanup_code()
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:39,代码来源:test_bhtree.py


注:本文中的amuse.community.bhtree.interface.BHTree.get_gravity_at_point方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。