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


Python BHTree.stop方法代码示例

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


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

示例1: test7

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

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import stop [as 别名]
    def test20(self):
        particles = datamodel.Particles(2)
        particles.x = [0.0,10.0] | nbody_system.length
        particles.y = 0.0 | nbody_system.length
        particles.z = 0.0 | nbody_system.length
        particles.radius = 0.005 | nbody_system.length
        particles.vx =  0.0 | nbody_system.speed
        particles.vy =  0.0 | nbody_system.speed
        particles.vz =  0.0 | nbody_system.speed
        particles.mass = 1.0 | nbody_system.mass

        very_short_time_to_evolve = 1 | units.s
        very_long_time_to_evolve = 1e9 | nbody_system.time
       
        instance = BHTree()
        instance.initialize_code()
        instance.parameters.stopping_conditions_timeout = very_short_time_to_evolve 
        self.assertEquals(instance.parameters.stopping_conditions_timeout, very_short_time_to_evolve)
        instance.parameters.epsilon_squared = (0.01 | nbody_system.length)**2
        instance.particles.add_particles(particles) 
        codeparticles1 = instance.particles
        instance.particles.add_particle(datamodel.Particle(
            position = [0,1,2] |  nbody_system.length, 
            velocity = [0,0,0] |  nbody_system.speed,
            radius = 0.005 | nbody_system.length,
            mass = 1 | nbody_system.mass
        ))
        codeparticles2 = instance.particles
        self.assertTrue(codeparticles1 is codeparticles2)
        instance.cleanup_code()
        codeparticles3 = instance.particles
        self.assertFalse(codeparticles1 is codeparticles3)
    
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:36,代码来源:test_bhtree.py

示例3: test19

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import stop [as 别名]
    def test19(self):
        particles = datamodel.Particles(2)
        particles.x = [0.0,10.0] | nbody_system.length
        particles.y = 0.0 | nbody_system.length
        particles.z = 0.0 | nbody_system.length
        particles.radius = 0.005 | nbody_system.length
        particles.vx =  0.0 | nbody_system.speed
        particles.vy =  0.0 | nbody_system.speed
        particles.vz =  0.0 | nbody_system.speed
        particles.mass = 1.0 | nbody_system.mass

        very_short_time_to_evolve = 1 | units.s
        very_long_time_to_evolve = 1e9 | nbody_system.time
       
        instance = BHTree()
        instance.initialize_code()
        instance.parameters.stopping_conditions_timeout = very_short_time_to_evolve 
        self.assertEquals(instance.parameters.stopping_conditions_timeout, very_short_time_to_evolve)
        instance.parameters.epsilon_squared = (0.01 | nbody_system.length)**2
        instance.particles.add_particles(particles) 
        instance.stopping_conditions.timeout_detection.enable()
        start = time.time()
        instance.evolve_model(very_long_time_to_evolve)
        end = time.time()
        self.assertTrue(instance.stopping_conditions.timeout_detection.is_set())
        self.assertTrue((end-start) < very_short_time_to_evolve.value_in(units.s) + 2)#2 = some overhead compensation
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:29,代码来源:test_bhtree.py

示例4: test22

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import stop [as 别名]
    def test22(self):
        particles = datamodel.Particles(2)
        particles.x = [0.0,10.0] | nbody_system.length
        particles.y = 0.0 | nbody_system.length
        particles.z = 0.0 | nbody_system.length
        particles.vx =  0.0 | nbody_system.speed
        particles.vy =  0.0 | nbody_system.speed
        particles.vz =  0.0 | nbody_system.speed
        particles.mass = 1.0 | nbody_system.mass

        instance = BHTree()
        instance.particles.add_particles(particles) 
        instance.commit_particles()
        self.assertEquals(instance.particles[0].radius, 0.0 | nbody_system.length)
        p = datamodel.Particle(
            x = 1.0  | nbody_system.length,
            y = 2.0 | nbody_system.length,
            z = 3.0 | nbody_system.length,
            vx = 1.0  | nbody_system.speed,
            vy = 2.0 | nbody_system.speed,
            vz = 3.0 | nbody_system.speed,
            mass = 1.0 | nbody_system.mass,
            radius = 4.0 | nbody_system.length,
        )
        instance.particles.add_particle(p) 
        self.assertEquals(instance.particles[0].radius, 0.0 | nbody_system.length)
        self.assertEquals(instance.particles[1].radius, 0.0 | nbody_system.length)
        self.assertEquals(instance.particles[2].radius, 4.0 | nbody_system.length)
        
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:32,代码来源:test_bhtree.py

示例5: test1

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import stop [as 别名]
 def test1(self):
     print "Test collect_required_attributes"
     in_memory = self.new_colliders()
     gravity = BHTree(nbody_system.nbody_to_si(1|units.MSun, 1.0|units.RSun))
     gravity.particles.add_particles(in_memory)
     stellar = SeBa()
     stellar.particles.add_particles(in_memory)
     
     collision = StellarEncounterInHydrodynamics(None, None, verbose=True)
     
     self.assertFalse(hasattr(in_memory, "radius"))
     collision.collect_required_attributes(in_memory, gravity, stellar)
     self.assertTrue(hasattr(in_memory, "radius"))
     self.assertAlmostRelativeEqual(in_memory.radius.sum(), 4.2458 | units.RSun, 3)
     
     from_stellar = stellar.particles.copy()
     for attribute in ["x", "y", "z", "vx", "vy", "vz"]:
         self.assertFalse(hasattr(from_stellar, attribute))
     collision.collect_required_attributes(from_stellar, gravity, stellar)
     
     gravity.stop()
     stellar.stop()
     
     for attribute in ["x", "y", "z", "vx", "vy", "vz"]:
         self.assertTrue(hasattr(from_stellar, attribute))
     self.assertAlmostEqual(from_stellar.position, in_memory.position)
     self.assertAlmostEqual(from_stellar.velocity, in_memory.velocity)
开发者ID:Ingwar,项目名称:amuse,代码行数:29,代码来源:test_hydro_collision.py

示例6: test11

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

        instance = BHTree(convert_nbody)
        
        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)
        
        copyof =  instance.particles.copy()
        
        self.assertAlmostEqual(30 | units.kg, copyof[1].mass, 6)
        
        copyof[1].mass = 35 | units.kg
        
        copyof.copy_values_of_all_attributes_to(instance.particles)
        
        self.assertAlmostEqual(35 | units.kg, instance.particles[1].mass, 6)
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:29,代码来源:test_bhtree.py

示例7: test17

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import stop [as 别名]
    def test17(self):
        print "Testing BHTree collision_detection"
        particles = datamodel.Particles(7)
        particles.mass = 0.001 | nbody_system.mass
        particles.radius = 0.01 | nbody_system.length
        particles.x = [-101.0, -100.0, -0.5, 0.5, 100.0, 101.0, 104.0] | nbody_system.length
        particles.y = 0 | nbody_system.length
        particles.z = 0 | nbody_system.length
        particles.velocity = [[2, 0, 0], [-2, 0, 0]]*3 + [[-4, 0, 0]] | nbody_system.speed
        
        instance = BHTree(redirection='none')
        instance.initialize_code()
        instance.parameters.set_defaults()
        
        # Uncommenting any of the following two lines will suppress collision detection
#~        instance.parameters.use_self_gravity = 0
#~        instance.parameters.epsilon_squared = 0.0 | nbody_system.length**2
        
        instance.parameters.opening_angle = 0.1
        instance.particles.add_particles(particles)
        collisions = instance.stopping_conditions.collision_detection
        collisions.enable()
        instance.evolve_model(1.0 | nbody_system.time)
        
        self.assertTrue(collisions.is_set())
        self.assertTrue(instance.model_time < 0.5 | nbody_system.time)
        self.assertEquals(len(collisions.particles(0)), 3)
        self.assertEquals(len(collisions.particles(1)), 3)
        self.assertEquals(len(particles - collisions.particles(0) - collisions.particles(1)), 1)
        self.assertEquals(abs(collisions.particles(0).x - collisions.particles(1).x) < 
                (collisions.particles(0).radius + collisions.particles(1).radius),
                [True, True, True])
        
        sticky_merged = datamodel.Particles(len(collisions.particles(0)))
        sticky_merged.mass = collisions.particles(0).mass + collisions.particles(1).mass
        sticky_merged.radius = collisions.particles(0).radius
        for p1, p2, merged in zip(collisions.particles(0), collisions.particles(1), sticky_merged):
            merged.position = (p1 + p2).center_of_mass()
            merged.velocity = (p1 + p2).center_of_mass_velocity()
        
        print instance.model_time
        print instance.particles
        instance.particles.remove_particles(collisions.particles(0) + collisions.particles(1))
        instance.particles.add_particles(sticky_merged)
        
        instance.evolve_model(1.0 | nbody_system.time)
        print
        print instance.model_time
        print instance.particles
        self.assertTrue(collisions.is_set())
        self.assertTrue(instance.model_time < 1.0 | nbody_system.time)
        self.assertEquals(len(collisions.particles(0)), 1)
        self.assertEquals(len(collisions.particles(1)), 1)
        self.assertEquals(len(instance.particles - collisions.particles(0) - collisions.particles(1)), 2)
        self.assertEquals(abs(collisions.particles(0).x - collisions.particles(1).x) < 
                (collisions.particles(0).radius + collisions.particles(1).radius),
                [True])
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:60,代码来源:test_bhtree.py

示例8: test2

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

示例9: test14

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import stop [as 别名]
 def test14(self):
     print "Test14: Testing BHTree parameters (I)"
     convert_nbody = nbody_system.nbody_to_si(1.0 | units.yr, 1.0 | units.AU)
     instance = BHTree(convert_nbody)
     
     value,error = instance.legacy_interface.get_epsilon_squared()
     self.assertEquals(0, error)
     self.assertEquals(0.125, value)
     self.assertAlmostEquals(0.125 | units.AU**2, instance.parameters.epsilon_squared, in_units=units.AU**2)
     for x in [0.01, 0.1, 0.2]:
         instance.parameters.epsilon_squared = x | units.AU**2
         self.assertAlmostEquals(x | units.AU**2, instance.parameters.epsilon_squared, in_units=units.AU**2)
     
     (value, error) = instance.legacy_interface.get_time_step()
     self.assertEquals(0, error)
     self.assertEquals(0.015625, value)
     self.assertAlmostEquals(0.015625 | units.yr, instance.parameters.timestep, in_units=units.yr)
     for x in [0.001, 0.01, 0.1]:
         instance.parameters.timestep = x | units.yr
         self.assertAlmostEquals(x | units.yr, instance.parameters.timestep, in_units=units.yr)
     
     (value, error) = instance.legacy_interface.get_theta_for_tree()
     self.assertEquals(0, error)
     self.assertEquals(0.75, value)
     self.assertEquals(0.75, instance.parameters.opening_angle)
     for x in [0.2, 0.5, 0.7]:
         instance.parameters.opening_angle = x
         self.assertEquals(x, instance.parameters.opening_angle)
     
     (value, error) = instance.legacy_interface.get_use_self_gravity()
     self.assertEquals(0, error)
     self.assertEquals(1, value)
     self.assertEquals(1, instance.parameters.use_self_gravity)
     for x in [0, 1]:
         instance.parameters.use_self_gravity = x
         self.assertEquals(x, instance.parameters.use_self_gravity)
     
     (value, error) = instance.legacy_interface.get_ncrit_for_tree()
     self.assertEquals(0, error)
     self.assertEquals(12, value)
     self.assertEquals(12, instance.parameters.ncrit_for_tree)
     for x in [512, 2048, 4096]:
         instance.parameters.ncrit_for_tree = x
         self.assertEquals(x, instance.parameters.ncrit_for_tree)
     
     (value, error) = instance.legacy_interface.get_dt_dia()
     self.assertEquals(0, error)
     self.assertEquals(1.0, value)
     self.assertAlmostEquals(1.0 | units.yr, instance.parameters.dt_dia, in_units=units.yr)
     for x in [0.1, 10.0, 100.0]:
         instance.parameters.dt_dia = x | units.yr
         self.assertAlmostEquals(x | units.yr, instance.parameters.dt_dia, in_units=units.yr)
     instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:55,代码来源:test_bhtree.py

示例10: evolve_cluster_in_galaxy

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import stop [as 别名]
def evolve_cluster_in_galaxy(N, W0, Rinit, tend, timestep, M, R):

    R_galaxy=0.1 | units.kpc
    M_galaxy=1.6e10 | units.MSun
    converter=nbody_system.nbody_to_si(M_galaxy, R_galaxy)
    galaxy=new_plummer_model(10000,convert_nbody=converter)

    print "com:", galaxy.center_of_mass().in_(units.kpc)
    print "comv:", galaxy.center_of_mass_velocity().in_(units.kms)
   
    print len(galaxy)
    galaxy_code = BHTree(converter, number_of_workers=2)
    galaxy_code.parameters.epsilon_squared = (0.01 | units.kpc)**2
    channe_to_galaxy = galaxy_code.particles.new_channel_to(galaxy)
    channe_to_galaxy.copy()
    galaxy_code.particles.add_particles(galaxy)
    inner_stars = galaxy.select(lambda r: r.length()<Rinit,["position"])
    Minner = inner_stars.mass.sum()
    print "Minner=", Minner.in_(units.MSun)
    print "Ninner=", len(inner_stars)
    vc_inner = (constants.G*Minner/Rinit).sqrt()

    converter=nbody_system.nbody_to_si(Mcluster,Rcluster)
    stars=new_king_model(N,W0,convert_nbody=converter)
    masses = new_powerlaw_mass_distribution(N, 0.1|units.MSun, 100|units.MSun, -2.35)
    stars.mass = masses
    stars.scale_to_standard(converter)
    
    stars.x += Rinit
    stars.vy += 0.8*vc_inner
    cluster_code=ph4(converter, number_of_workers=2)
    cluster_code.particles.add_particles(stars)
    channel_to_stars=cluster_code.particles.new_channel_to(stars)

    system=bridge(verbose=False)
    system.add_system(cluster_code, (galaxy_code,))
    system.add_system(galaxy_code, (cluster_code,))
    system.timestep = 0.1*timestep

    times = quantities.arange(0|units.Myr, tend, timestep)
    for i,t in enumerate(times):
        print "Time=", t.in_(units.Myr)
        channe_to_galaxy.copy()
        channel_to_stars.copy()

        inner_stars =  galaxy.select(lambda r: r.length()<Rinit,["position"])
        print "Minner=", inner_stars.mass.sum().in_(units.MSun)

        system.evolve_model(t,timestep=timestep)
    plot_galaxy_and_stars(galaxy, stars)
    galaxy_code.stop()
    cluster_code.stop()
开发者ID:amusecode,项目名称:amuse,代码行数:54,代码来源:gravity_gravity.py

示例11: test1

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

        instance = BHTree(convert_nbody)
        instance.parameters.epsilon_squared = 0.001 | units.AU**2
        
        stars = datamodel.Stars(2)
        
        sun = stars[0]
        sun.mass = units.MSun(1.0)
        sun.position = [0.0,0.0,0.0] | units.m
        sun.velocity = [0.0,0.0,0.0] | units.ms
        sun.radius = units.RSun(1.0)

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

        #instance.particles.add_particles(stars)
        instance.particles.add_particles(stars)
        
        postion_at_start = earth.position.value_in(units.AU)[0]
        
        instance.evolve_model(365.0 | units.day)
        instance.particles.copy_values_of_all_attributes_to(stars)
        
        postion_after_full_rotation = earth.position.value_in(units.AU)[0]
       
        self.assertAlmostEqual(postion_at_start, postion_after_full_rotation, 3)
        
        instance.evolve_model(365.0 + (365.0 / 2) | units.day)
        
        instance.particles.copy_values_of_all_attributes_to(stars)
        
        postion_after_half_a_rotation = earth.position.value_in(units.AU)[0]
        self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 2)
        
        
        instance.evolve_model(365.0 + (365.0 / 2) + (365.0 / 4)  | units.day)
         
        instance.particles.copy_values_of_all_attributes_to(stars)
        
        postion_after_half_a_rotation = earth.position.value_in(units.AU)[1]
        
        self.assertAlmostEqual(-postion_at_start, postion_after_half_a_rotation, 1)
        instance.cleanup_code()
        instance.stop()
开发者ID:Ingwar,项目名称:amuse,代码行数:51,代码来源:test_bhtree.py

示例12: test5

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

示例13: test4

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

示例14: nbody_integrator

# 需要导入模块: from amuse.community.bhtree.interface import BHTree [as 别名]
# 或者: from amuse.community.bhtree.interface.BHTree import stop [as 别名]
def nbody_integrator(Ncl, mcl, rcl, t_end, n_steps, escape_velocity_fraction, R):
    converter = nbody_system.nbody_to_si(mcl, rcl)
    bodies = new_plummer_model(Ncl, convert_nbody=converter)

    #estimate of milky way mass by "Mass models of the Milky Way", McMillan
    blackhole_mass = 1.26e12 | units.MSun
    blackhole = Particle(mass=blackhole_mass)
    blackhole.position = [0,0,0] | units.m

    cluster_velocity = [0,0,0] | units.m / units.s
    cluster_position = [0,0,0] | units.parsec
    cluster_position[0] = R
    G_si = converter.to_si(nbody_system.G)
    escape_v = (2*G_si*blackhole_mass/R).sqrt().as_quantity_in(units.m/units.s)
    V = escape_v * escape_velocity_fraction
    cluster_velocity[1] = V
    bodies.move_to_center()
    bodies.velocity += cluster_velocity
    bodies.position += cluster_position
    bodies.add_particle(blackhole)
        

    gravity = BHTree(converter)
    gravity.particles.add_particles(bodies)
    channel_from_gravity_to_framework = gravity.particles.\
        new_channel_to(bodies)

    time = zero
    dt = t_end / float(n_steps)
    x = 0
    base_path = "encounter_plots/"+str(R.value_in(units.parsec))+"_"+\
        str(escape_velocity_fraction)+"_"
    while time < t_end:
        plot_cluster(bodies, base_path+str(x),time, rcl, V)
        time += dt
        gravity.evolve_model(time)
        channel_from_gravity_to_framework.copy()
        x+=1
    plot_cluster(bodies, base_path+str(x),time, rcl, V)

    gravity.stop()
    return V, bodies
开发者ID:tlrh314,项目名称:ComputationalAstrophysics,代码行数:44,代码来源:bound_unbound_encounter.py

示例15: test10

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


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