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


Python Huayno.initialize_code方法代码示例

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


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

示例1: test5

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

        instance = Huayno(convert_nbody)
        instance.initialize_code()
        
        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)
        self.assertEquals(len(instance.particles), 2)
        
        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, actural 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(actural,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, actural 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(actural,expected)
开发者ID:mherkazandjian,项目名称:amuse,代码行数:35,代码来源:test_huayno.py

示例2: test3

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

        instance = Huayno(convert_nbody)
        instance.initialize_code()
        instance.parameters.epsilon_squared = 0.00001 | units.AU**2
        
        stars = datamodel.Stars(2)
        star1 = stars[0]
        star2 = stars[1]

        star1.mass = units.MSun(1.0)
        star1.position = units.AU(numpy.array((-1.0,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((1.0,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)
    
        for x in range(1,2000,10):
            instance.evolve_model(x | units.day)
            instance.particles.copy_values_of_all_attributes_to(stars)
            stars.savepoint()
开发者ID:mherkazandjian,项目名称:amuse,代码行数:29,代码来源:test_huayno.py

示例3: test1

# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import initialize_code [as 别名]
 def test1(self):
     convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
 
     huayno = Huayno(convert_nbody)
     huayno.initialize_code()
     huayno.parameters.epsilon_squared = 0.0 | units.AU**2
     
     stars = self.new_system_of_sun_and_earth()
     earth = stars[1]
     
     huayno.particles.add_particles(stars)
     
     huayno.evolve_model(365.0 | units.day)
     huayno.particles.copy_values_of_all_attributes_to(stars)
     
     position_at_start = earth.position.value_in(units.AU)[0]
     position_after_full_rotation = earth.position.value_in(units.AU)[0]
     self.assertAlmostEqual(position_at_start, position_after_full_rotation, 6)
     
     huayno.evolve_model(365.0 + (365.0 / 2) | units.day)
     
     huayno.particles.copy_values_of_all_attributes_to(stars)
     position_after_half_a_rotation = earth.position.value_in(units.AU)[0]
     self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 2)
             
     huayno.evolve_model(365.0 + (365.0 / 2) + (365.0 / 4)  | units.day)
     
     huayno.particles.copy_values_of_all_attributes_to(stars)
     position_after_half_a_rotation = earth.position.value_in(units.AU)[1]
     self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 3)
     
     huayno.cleanup_code()
     
     huayno.stop()
开发者ID:mherkazandjian,项目名称:amuse,代码行数:36,代码来源:test_huayno.py

示例4: test13

# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import initialize_code [as 别名]
 def test13(self):
     particles = plummer.new_plummer_model(31)
    
     instance = Huayno(number_of_workers=1)#, debugger="xterm")
     instance.initialize_code()
     instance.parameters.epsilon_squared = 0.01 | nbody_system.length ** 2
     instance.particles.add_particles(particles)
     
     instance.evolve_model(0.1 | nbody_system.time)
     instance.synchronize_model()
     expected_positions = instance.particles.position
     instance.stop()
开发者ID:mherkazandjian,项目名称:amuse,代码行数:14,代码来源:test_huayno.py

示例5: test2

# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import initialize_code [as 别名]
 def test2(self):
     convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
 
     instance = Huayno(convert_nbody)
     instance.initialize_code()
     instance.parameters.epsilon_squared = 0.0 | units.AU**2
     
     stars = self.new_system_of_sun_and_earth()
     earth = stars[1]
     instance.particles.add_particles(stars)
 
     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, "huayno-earth-sun2.svg")
         figure.savefig(output_file)
           
     instance.cleanup_code()
     del instance
开发者ID:mherkazandjian,项目名称:amuse,代码行数:40,代码来源:test_huayno.py

示例6: test15

# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import initialize_code [as 别名]
 def test15(self):
     particles = plummer.new_plummer_model(512)
     expected_positions = None
     for mode in ["cpu", "openmp", "opencl"]:
         try:
             instance = Huayno(mode=mode, number_of_workers=1)#, debugger="xterm")
         except:
             print "Running huayno with mode=", mode, " was unsuccessful."
             continue
         else:
             print "Running huayno with mode=", mode, "... "
             
         instance.initialize_code()
         instance.parameters.epsilon_squared = 0.01 | nbody_system.length ** 2
         instance.particles.add_particles(particles)
         
         instance.evolve_model(0.2 | nbody_system.time)
         instance.synchronize_model()
         if expected_positions is None:
             expected_positions = instance.particles.position
         else:
             self.assertAlmostRelativeEquals(expected_positions, instance.particles.position, 8)
         instance.stop()
开发者ID:mherkazandjian,项目名称:amuse,代码行数:25,代码来源:test_huayno.py

示例7: test4

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

        instance = Huayno(convert_nbody)
        instance.initialize_code()
        
        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)
        self.assertEquals(len(instance.particles), 2)
        
        instance.particles.mass =  [17.0, 33.0] | units.kg
        
        
        self.assertEquals(instance.get_mass(0), 17.0| units.kg) 
        self.assertEquals(instance.get_mass(1), 33.0| units.kg)  
开发者ID:mherkazandjian,项目名称:amuse,代码行数:25,代码来源:test_huayno.py

示例8: test7

# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import initialize_code [as 别名]
    def test7(self):
        print "Test7: Testing effect of Huayno parameter epsilon_squared"
        convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 1.0 | units.AU)
        
        particles = datamodel.Particles(2)
        sun = particles[0]
        sun.mass = 1.0 | units.MSun
        sun.position = [0.0, 0.0, 0.0] | units.AU
        sun.velocity = [0.0, 0.0, 0.0] | units.AU / units.yr
        sun.radius = 1.0 | units.RSun

        earth = particles[1]
        earth.mass = 5.9736e24 | units.kg
        earth.radius = 6371.0 | units.km
        earth.position = [0.0, 1.0, 0.0] | units.AU
        earth.velocity = [2.0*numpy.pi, -0.0001, 0.0] | units.AU / units.yr
        
        initial_direction = math.atan((earth.velocity[0]/earth.velocity[1]))
        final_direction = []
        for log_eps2 in range(-9,10,2):
            instance = Huayno(convert_nbody)
            instance.initialize_code()
            instance.parameters.epsilon_squared = 10.0**log_eps2 | units.AU ** 2
            instance.particles.add_particles(particles)
            instance.commit_particles()
            instance.evolve_model(0.25 | units.yr)
            final_direction.append(math.atan((instance.particles[1].velocity[0]/
                instance.particles[1].velocity[1])))
            instance.stop()
        # Small values of epsilon_squared should result in normal earth-sun dynamics: rotation of 90 degrees
        self.assertAlmostEquals(abs(final_direction[0]), abs(initial_direction+math.pi/2.0), 2)
        # Large values of epsilon_squared should result in ~ no interaction
        self.assertAlmostEquals(final_direction[-1], initial_direction, 2)
        # Outcome is most sensitive to epsilon_squared when epsilon_squared = d(earth, sun)^2
        delta = [abs(final_direction[i+1]-final_direction[i]) for i in range(len(final_direction)-1)]
        self.assertEquals(delta[len(final_direction)/2 -1], max(delta))
开发者ID:mherkazandjian,项目名称:amuse,代码行数:38,代码来源:test_huayno.py


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