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


Python BHTree.commit_parameters方法代码示例

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


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

示例1: test7

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [as 别名]
 def test7(self):
     convert_nbody = nbody_system.nbody_to_si(5.0 | units.kg, 10.0 | units.m)
 
     instance = BHTree(convert_nbody)
     instance.commit_parameters()
     
     particles = datamodel.Particles(2)
     self.assertEquals(len(instance.particles), 0)
     
     particles.mass = [15.0, 30.0] | units.kg
     particles.radius =  [10.0, 20.0] | units.m
     particles.position = [[10.0, 20.0, 30.0], [20.0, 40.0, 60.0]] | units.m
     particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] | units.m / units.s
 
     
     instance.particles.add_particles(particles)
     instance.commit_particles()
     
     self.assertEquals(instance.get_mass(1), 15.0| units.kg)
     self.assertAlmostRelativeEquals(instance.get_position(1)[2], 30.0| units.m)
     
     self.assertEquals(len(instance.particles), 2)
     
     
     self.assertAlmostRelativeEquals(instance.particles.mass[1], 30.0 | units.kg)
     self.assertAlmostRelativeEquals(instance.particles.position[1][2], 60.0 | units.m)   
     instance.cleanup_code()
     instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:30,代码来源:test_bhtree.py

示例2: test2

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [as 别名]
    def test2(self):
        #not completed 
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)

        instance = BHTree(convert_nbody)
        #instance.dt_dia = 1
        instance.parameters.epsilon_squared = 0.001 | units.AU**2
        #instance.timestep = 0.0001
        #instance.use_self_gravity = 0
        instance.commit_parameters()
        
        stars = datamodel.Stars(2)
        sun = stars[0]
        sun.mass = units.MSun(1.0)
        sun.position = units.m(numpy.array((0.0,0.0,0.0)))
        sun.velocity = units.ms(numpy.array((0.0,0.0,0.0)))
        sun.radius = units.RSun(1.0)

        earth = stars[1]
        earth.mass = units.kg(5.9736e24)
        earth.radius = units.km(6371) 
        earth.position = units.km(numpy.array((149.5e6,0.0,0.0)))
        earth.velocity = units.ms(numpy.array((0.0,29800,0.0)))

        instance.particles.add_particles(stars)
        instance.commit_particles()
        self.assertAlmostRelativeEquals(sun.radius, instance.particles[0].radius)
    
        for x in range(1,2000,10):
            instance.evolve_model(x | units.day)
            instance.particles.copy_values_of_all_attributes_to(stars)
            stars.savepoint()
            
        if HAS_MATPLOTLIB:
            figure = pyplot.figure()
            plot = figure.add_subplot(1,1,1)
            
            x_points = earth.get_timeline_of_attribute("x")
            y_points = earth.get_timeline_of_attribute("y")
            
            x_points_in_AU = map(lambda (t,x) : x.value_in(units.AU), x_points)
            y_points_in_AU = map(lambda (t,x) : x.value_in(units.AU), y_points)
            
            plot.scatter(x_points_in_AU,y_points_in_AU, color = "b", marker = 'o')
            
            plot.set_xlim(-1.5, 1.5)
            plot.set_ylim(-1.5, 1.5)
               
            
            test_results_path = self.get_path_to_results()
            output_file = os.path.join(test_results_path, "bhtree-earth-sun.svg")
            figure.savefig(output_file)    
        
        instance.cleanup_code()
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:57,代码来源:test_bhtree.py

示例3: test5

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [as 别名]
    def test5(self):

        instance = BHTree()
        instance.commit_parameters()
        
        index = instance.new_particle(
            15.0 | nbody_system.mass,
            10.0 | nbody_system.length, 20.0 | nbody_system.length, 30.0 | nbody_system.length,
            1.0 | nbody_system.speed, 1.0 | nbody_system.speed, 3.0 | nbody_system.speed,
            10.0 | nbody_system.length
        )
        instance.commit_particles()
        self.assertEquals(instance.get_mass(index), 15.0| nbody_system.mass)
        self.assertEquals(instance.get_radius(index), 10.0| nbody_system.length)
        
        instance.cleanup_code()
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:19,代码来源:test_bhtree.py

示例4: test4

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [as 别名]
    def test4(self):
        convert_nbody = nbody_system.nbody_to_si(5.0 | units.kg, 10.0 | units.m)

        instance = BHTree(convert_nbody)
        instance.commit_parameters()
        
        index = instance.new_particle(
            15.0 | units.kg,
            10.0 | units.m, 20.0 | units.m, 30.0 | units.m,
            #1.0 | units.m/units.s, 1.0 | units.m/units.s, 3.0 | units.m/units.s
            0.0 | units.m/units.s, 0.0 | units.m/units.s, 0.0 | units.m/units.s,
            10.0 | units.m
        )
        instance.commit_particles()
        self.assertEquals(instance.get_mass(index), 15.0| units.kg)
        self.assertEquals(instance.get_radius(index), 10.0| units.m)
        instance.cleanup_code()
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:20,代码来源:test_bhtree.py

示例5: test10

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [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

示例6: test6

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [as 别名]
 def test6(self):
     convert_nbody = nbody_system.nbody_to_si(5.0 | units.kg, 10.0 | units.m)
     instance = BHTree(convert_nbody)
     instance.commit_parameters()
     
     indices = instance.new_particle(
         [15.0, 30.0] | units.kg,
         [10.0, 20.0] | units.m, [20.0, 40.0] | units.m, [30.0, 50.0] | units.m,
         #1.0 | units.m/units.s, 1.0 | units.m/units.s, 3.0 | units.m/units.s
         [0.0, 0.01] | units.m/units.s, [0.0, 0.01] | units.m/units.s, [0.0, 0.01] | units.m/units.s,
         [10.0, 20.0] | units.m
     )
     instance.commit_particles()
     
     self.assertEquals(instance.get_mass(indices[0]), 15.0| units.kg)
     self.assertEquals(instance.get_mass(indices)[0], 15.0| units.kg)
     
     self.assertRaises(AmuseException, instance.get_mass, [4,5], 
         expected_message = "Error when calling 'get_mass' of a 'BHTree', errorcode is -1")
     
     instance.cleanup_code()
     instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:24,代码来源:test_bhtree.py

示例7: test12

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [as 别名]
    def test12(self):
       
        convert_nbody = nbody_system.nbody_to_si(5.0 | units.kg, 10.0 | units.m)

        instance = BHTree(convert_nbody)
        instance.commit_parameters()
        
        particles = datamodel.Particles(2)
        self.assertEquals(len(instance.particles), 0)
        
        particles.mass = [15.0, 30.0] | units.kg
        particles.radius =  [10.0, 20.0] | units.m
        particles.position = [[10.0, 20.0, 30.0], [20.0, 40.0, 60.0]] | units.m
        particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] | units.m / units.s

        
        instance.particles.add_particles(particles)
        instance.commit_particles()
        
        copyof =  instance.particles.copy()
        
        instance.set_state(1, 16|units.kg, 20.0|units.m, 40.0|units.m, 60.0|units.m, 
                                 1.0|units.ms, 1.0|units.ms, 1.0|units.ms)
        
        curr_state =  instance.get_state(1)
        for expected, actual in zip((16|units.kg, 20.0|units.m, 40.0|units.m, 60.0|units.m, 
                                 1.0|units.ms, 1.0|units.ms, 1.0|units.ms, 0 | units.m), curr_state):
            self.assertAlmostRelativeEquals(actual,expected)
        
        instance.set_state(1, 16|units.kg, 20.0|units.m, 40.0|units.m, 60.0|units.m, 
                                 1.0|units.ms, 1.0|units.ms, 1.0|units.ms , 20.0|units.m)
        
        curr_state =  instance.get_state(1)
        for expected, actual in zip((16|units.kg, 20.0|units.m, 40.0|units.m, 60.0|units.m, 
                                 1.0|units.ms, 1.0|units.ms, 1.0|units.ms, 20 | units.m), curr_state):
            self.assertAlmostRelativeEquals(actual,expected)
        
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:40,代码来源:test_bhtree.py

示例8: test13

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [as 别名]
 def test13(self):
    
     convert_nbody = nbody_system.nbody_to_si(1.0 | units.kg, 1.0 | units.m)
     
     instance = BHTree(convert_nbody)
     instance.commit_parameters()
     
     particles = datamodel.Particles(2)
     self.assertEquals(len(instance.particles), 0)
     
     particles.mass = [30.0, 30.0] | units.kg
     particles.radius =  [1.0, 1.0] | units.m
     particles.position = [[-10.0, 0.0, 0.0], [10.0, 0.0, 0.0]] | units.m
     particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] | units.m / units.s
     
     instance.particles.add_particles(particles)
     instance.commit_particles()
     
     copyof =  instance.particles.copy()
     
     com = instance.center_of_mass_position
     self.assertAlmostEqual(com[0], quantities.new_quantity(0.0, units.m), constants.precision)
     instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:25,代码来源:test_bhtree.py

示例9: test3

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [as 别名]
    def test3(self):
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)

        instance = BHTree(convert_nbody)
        #instance.dt_dia = 1
        instance.parameters.epsilon_squared = 0.001 | units.AU**2
        #instance.timestep = 0.0001
        #instance.use_self_gravity = 0
        instance.commit_parameters()
        
        
        stars = datamodel.Stars(2)
        star1 = stars[0]
        star2 = stars[1]

        star1.mass = units.MSun(1.0)
        star1.position = units.AU(numpy.array((-.10,0.0,0.0)))
        star1.velocity = units.AUd(numpy.array((0.0,0.0,0.0)))
        star1.radius = units.RSun(1.0)

        star2.mass = units.MSun(1.0)
        star2.position = units.AU(numpy.array((.10,0.0,0.0)))
        star2.velocity = units.AUd(numpy.array((0.0,0.0,0.0)))
        star2.radius = units.RSun(100.0)
        
        instance.particles.add_particles(stars)
        instance.commit_particles()
    
        for x in range(1,200,1):
            instance.evolve_model(x | units.day)
            instance.particles.copy_values_of_all_attributes_to(stars)
            #instance.get_indices_of_colliding_particles()
            #print stars[0].position-stars[1].position
            stars.savepoint()
            
        instance.cleanup_code()
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:39,代码来源:test_bhtree.py

示例10: test16

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import commit_parameters [as 别名]
 def test16(self):
     numpy.random.seed(0)
     number_of_stars = 2
     stars = plummer.new_plummer_model(number_of_stars)
     stars.radius = 0.00001 | nbody_system.length
     stars.scale_to_standard()
     
     instance = BHTree()
     instance.initialize_code()
     instance.parameters.epsilon_squared = (1.0 / 20.0 / (number_of_stars**0.33333) | nbody_system.length)**2
     instance.parameters.timestep = 0.004 | nbody_system.time
     instance.parameters.timestep = 0.00001 | nbody_system.time
     instance.commit_parameters()
     print instance.parameters.timestep
     instance.particles.add_particles(stars)
     instance.commit_particles()
     energy_total_t0 = instance.potential_energy + instance.kinetic_energy
     request = instance.evolve_model.async(1.0 | nbody_system.time)
     request.result()
     energy_total_t1 = instance.potential_energy + instance.kinetic_energy
     
     self.assertAlmostRelativeEqual(energy_total_t0, energy_total_t1, 3)
     instance.stop()
     numpy.random.seed()
开发者ID:Ingwar,项目名称:amuse,代码行数:26,代码来源:test_bhtree.py


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