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


Python SSE.commit_parameters方法代码示例

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


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

示例1: test13

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
    def test13(self):
        print "Testing SSE states"
        stars = Particles(1)
        stars.mass = 1.0 | units.MSun
        
        print "First do everything manually:",
        instance = SSE()
        self.assertEquals(instance.get_name_of_current_state(), 'UNINITIALIZED')
        instance.initialize_code()
        self.assertEquals(instance.get_name_of_current_state(), 'INITIALIZED')
        instance.commit_parameters()
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.cleanup_code()
        self.assertEquals(instance.get_name_of_current_state(), 'END')
        instance.stop()
        print "ok"

        print "initialize_code(), commit_parameters(), " \
            "and cleanup_code() should be called automatically:",
        instance = SSE()
        self.assertEquals(instance.get_name_of_current_state(), 'UNINITIALIZED')
        instance.parameters.reimers_mass_loss_coefficient = 0.5
        self.assertEquals(instance.get_name_of_current_state(), 'INITIALIZED')
        instance.particles.add_particles(stars)
        self.assertEquals(instance.get_name_of_current_state(), 'RUN')
        instance.stop()
        self.assertEquals(instance.get_name_of_current_state(), 'STOPPED')
        print "ok"
开发者ID:vdhelm,项目名称:amuse,代码行数:30,代码来源:test_sse.py

示例2: test11

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
 def test11(self):
     print "Test evolve_model optional arguments: end_time and keep_synchronous"
     stars = Particles(3)
     stars.mass = [1.0, 2.0, 3.0] | units.MSun
     instance = SSE()
     instance.commit_parameters()
     instance.particles.add_particles(stars)
     
     self.assertEqual(instance.particles.age, [0.0, 0.0, 0.0] | units.yr)
     self.assertAlmostEqual(instance.particles.time_step, [550.1565, 58.2081, 18.8768] | units.Myr, 3)
     self.assertAlmostEqual(instance.particles.radius, [0.8882494502, 1.610210385, 1.979134445] | units.RSun)
     
     print "evolve_model without arguments: use shared timestep = min(particles.time_step)"
     instance.evolve_model()
     self.assertAlmostEqual(instance.particles.age, [18.8768, 18.8768, 18.8768] | units.Myr, 3)
     self.assertAlmostEqual(instance.particles.time_step, [550.1565, 58.2081, 18.8768] | units.Myr, 3)
     self.assertAlmostEqual(instance.model_time, 18.8768 | units.Myr, 3)
     
     print "evolve_model with end_time: take timesteps, until end_time is reached exactly"
     instance.evolve_model(100 | units.Myr)
     self.assertAlmostEqual(instance.particles.age, [100.0, 100.0, 100.0] | units.Myr, 3)
     self.assertAlmostEqual(instance.particles.time_step, [550.1565, 58.2081, 18.8768] | units.Myr, 3)
     self.assertAlmostEqual(instance.model_time, 100.0 | units.Myr, 3)
     
     print "evolve_model with keep_synchronous: use non-shared timestep, particle ages will typically diverge"
     instance.evolve_model(keep_synchronous = False)
     self.assertAlmostEqual(instance.particles.age, (100 | units.Myr) + ([550.1565, 58.2081, 18.8768] | units.Myr), 3)
     self.assertAlmostEqual(instance.particles.time_step, [550.1565, 58.2081, 18.8768] | units.Myr, 3)
     self.assertAlmostEqual(instance.model_time, 100.0 | units.Myr, 3) # Unchanged!
     instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:32,代码来源:test_sse.py

示例3: test12

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
 def test12(self):
     print "Testing adding and removing particles from stellar evolution code..."
     
     particles = Particles(3)
     particles.mass = 1.0 | units.MSun
     
     instance = SSE()
     instance.initialize_code()
     instance.commit_parameters()
     self.assertEquals(len(instance.particles), 0) # before creation
     instance.particles.add_particles(particles[:-1])
     instance.commit_particles()
     instance.evolve_model(1.0 | units.Myr)
     self.assertEquals(len(instance.particles), 2) # before remove
     self.assertAlmostEqual(instance.particles.age, 1.0 | units.Myr)
     
     instance.particles.remove_particle(particles[0])
     self.assertEquals(len(instance.particles), 1)
     instance.evolve_model(2.0 | units.Myr)
     self.assertAlmostEqual(instance.particles[0].age, 2.0 | units.Myr)
     
     instance.particles.add_particles(particles[::2])
     self.assertEquals(len(instance.particles), 3) # it's back...
     self.assertAlmostEqual(instance.particles[0].age, 2.0 | units.Myr)
     self.assertAlmostEqual(instance.particles[1].age, 0.0 | units.Myr)
     self.assertAlmostEqual(instance.particles[2].age, 0.0 | units.Myr) # ... and rejuvenated.
     
     instance.evolve_model(3.0 | units.Myr) # The young stars keep their age offset from the old star
     self.assertAlmostEqual(instance.particles.age, [3.0, 1.0, 1.0] | units.Myr)
     instance.evolve_model(4.0 | units.Myr)
     self.assertAlmostEqual(instance.particles.age, [4.0, 2.0, 2.0] | units.Myr)
     instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:34,代码来源:test_sse.py

示例4: test5

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
 def test5(self):
     sse = SSE()
     sse.commit_parameters() 
     stars = Particles(1)
     
     star = stars[0]
     star.mass = 35 | units.MSun
     star.radius = 0.0 | units.RSun
     
     stars.synchronize_to(sse.particles)
     
     channel = sse.particles.new_channel_to(stars)
     channel.copy_attributes(sse.particles.get_attribute_names_defined_in_store())   
     
     previous_type = star.stellar_type
     results = []
     
     dt = 1 | units.Myr
     t = 0 | units.Myr
     while t < 30 | units.Myr:
         t += dt
         sse.evolve_model(t)
             
     self.assertTrue(sse.particles[0].mass.value_in(units.MSun) < 10.6)
      
     sse.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:28,代码来源:test_sse.py

示例5: test6

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
    def test6(self):
        print "Test whether a set of stars evolves synchronously..."
#       Create an array of stars with a range in stellar mass
        masses = [.5, 1., 2., 5., 10., 30.] | units.MSun
        number_of_stars = len(masses)
        stars = Particles(number_of_stars)
        stars.mass = masses

#       Initialize stellar evolution code
        instance = SSE()
        instance.commit_parameters() 
        instance.particles.add_particles(stars)
        instance.commit_particles()
        
        from_code_to_model = instance.particles.new_channel_to(stars)
        from_code_to_model.copy()
        
        instance.evolve_model(end_time = 125 | units.Myr)
        from_code_to_model.copy()
                
        end_types = (
            "deeply or fully convective low mass MS star",
            "Main Sequence star",
            "Main Sequence star",
            "Carbon/Oxygen White Dwarf",
            "Neutron Star",
            "Black Hole",
        )
        for i in range(number_of_stars):
            self.assertAlmostEquals(stars[i].age, 125.0 | units.Myr)
            self.assertTrue(stars[i].mass <= masses[i])
            self.assertEquals(str(stars[i].stellar_type), end_types[i])
        instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:35,代码来源:test_sse.py

示例6: test9

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
 def test9(self):
     print "Test: large number of particles"
     stellar_evolution = SSE(max_message_length=500)
     stellar_evolution.commit_parameters()
     number_of_particles = 10000
     print "Has been tested with up to a million particles!"
     print "Now using ", number_of_particles, "particles only, for speed."
     stars = Particles(number_of_particles)
     stars.mass = 1.0 | units.MSun
     stellar_evolution.particles.add_particles(stars)
     self.assertEqual(len(stellar_evolution.particles), number_of_particles)
     stellar_evolution.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:14,代码来源:test_sse.py

示例7: planetplot

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
def planetplot():
    sun, planets = new_solar_system_for_mercury()

    initial = 12.2138 | units.Gyr
    final = 12.3300 | units.Gyr
    step = 10000.0 | units.yr

    timerange = VectorQuantity.arange(initial, final, step)
    gd = MercuryWayWard()
    gd.initialize_code()
    # gd.stopping_conditions.timeout_detection.disable()
    gd.central_particle.add_particles(sun)
    gd.orbiters.add_particles(planets)
    gd.commit_particles()

    se = SSE()
    # se.initialize_code()
    se.commit_parameters()
    se.particles.add_particles(sun)
    se.commit_particles()
    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    for time in timerange:
        err = gd.evolve_model(time-initial)
        channelp.copy()
        # planets.savepoint(time)
        err = se.evolve_model(time)
        channels.copy()
        gd.central_particle.mass = sun.mass
        print(
                sun[0].mass.value_in(units.MSun),
                time.value_in(units.Myr),
                planets[4].x.value_in(units.AU),
                planets[4].y.value_in(units.AU),
                planets[4].z.value_in(units.AU)
                )

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        plot(x, y, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
开发者ID:amusecode,项目名称:amuse,代码行数:50,代码来源:mercury_solarsystem3.py

示例8: test2

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
 def test2(self):
     sse = SSE()
     sse.commit_parameters() 
     stars = Particles(1)
     
     star = stars[0]
     star.mass = 5 | units.MSun
     star.radius = 0.0 | units.RSun
     
     sse.particles.add_particles(stars)
     sse.evolve_model(120.1 | units.Myr)
             
     self.assertAlmostEqual(sse.particles[0].mass.value_in(units.MSun), 4.932, 3)
     self.assertAlmostEqual(sse.particles[0].temperature.value_in(units.K), 4221., 0)
      
     sse.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:18,代码来源:test_sse.py

示例9: test10

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
 def test10(self):
     stellar_evolution = SSE()
     stellar_evolution.commit_parameters()
     stars = Particles(10)
     stars.mass = 1.0 | units.MSun
     stellar_evolution.particles.add_particles(stars)
     self.assertEquals(stellar_evolution.particles._factory_for_new_collection(), Particles)
     
     filename = os.path.join(get_path_to_results(), "test.h5")
     if os.path.exists(filename):
         os.remove(filename)
         
     io.write_set_to_file(stellar_evolution.particles, filename, 'hdf5')
     stored_stars = io.read_set_from_file(filename, 'hdf5')
     self.assertEquals(len(stars), len(stored_stars))
 
     self.assertAlmostRelativeEquals(stars.mass, stored_stars.mass)
开发者ID:vdhelm,项目名称:amuse,代码行数:19,代码来源:test_sse.py

示例10: test8

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
 def test8(self):
     instance = SSE()
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, 0.5)
     myvalue = 0.7
     instance.parameters.reimers_mass_loss_coefficient = myvalue
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, myvalue)
     instance.commit_parameters()
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, myvalue)
     instance.stop()
     
     instance = SSE()
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, 0.5)
     myvalue = 0.7
     instance.parameters.reimers_mass_loss_coefficient = myvalue
     instance.parameters.set_defaults()
     instance.commit_parameters()
     self.assertEqual(instance.parameters.reimers_mass_loss_coefficient, 0.5)
     instance.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:20,代码来源:test_sse.py

示例11: test7

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
 def test7(self):
     print "Test: evolve particles one at a time."
     print "Used to be problematic, since initial_mass of idle particle is set to zero."
     stars = Particles(2)
     stars.mass = 1.0 | units.MSun
     for star in stars:
         print star
         stellar_evolution = SSE()
         stellar_evolution.commit_parameters()
         stellar_evolution.particles.add_particles(star.as_set())
         stellar_evolution.commit_particles()
         from_stellar_evolution_to_model = stellar_evolution.particles.new_channel_to(star.as_set())
         stellar_evolution.evolve_model()
         from_stellar_evolution_to_model.copy()
         stellar_evolution.stop()
     self.assertEquals(stars[0].initial_mass, stars[1].initial_mass)
     self.assertEquals(stars[0].luminosity, stars[1].luminosity)
     self.assertEquals(stars[0].age, stars[1].age)
     print "Solved: SSE_muse_interface.f sets initial_mass to mass when necessary."
开发者ID:vdhelm,项目名称:amuse,代码行数:21,代码来源:test_sse.py

示例12: test3

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
 def test3(self):
     sse = SSE()
     sse.commit_parameters() 
     stars = Particles(1)
     
     star = stars[0]
     star.mass = 5 | units.MSun
     star.radius = 0.0 | units.RSun
     
     stars.synchronize_to(sse.particles)
     
     channel = sse.particles.new_channel_to(stars)
     channel.copy_attributes(sse.particles.get_attribute_names_defined_in_store())   
     
     previous_type = sse.particles.stellar_type
     results = []
     
     sse.evolve_model(121.5 | units.Myr)
     
     channel.copy_attributes(sse.particles.get_attribute_names_defined_in_store())   
     
     self.assertAlmostEqual(star.mass.value_in(units.MSun), 0.997, 3)
      
     sse.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:26,代码来源:test_sse.py

示例13: test1

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
    def test1(self):
        sse = SSE()
        sse.commit_parameters() 
        stars = Particles(1)
        star = stars[0]
        star.mass = 5 | units.MSun
        star.radius = 0.0 | units.RSun
        
        sse.particles.add_particles(stars)
        from_sse_to_model = sse.particles.new_channel_to(stars)
        from_sse_to_model.copy()
        
        previous_type = star.stellar_type
        results = []
        t0 = 0 | units.Myr
        current_time = t0
        
        while current_time < (125 | units.Myr):
            sse.update_time_steps()
            
            current_time = current_time + sse.particles[0].time_step
            
            sse.evolve_model(current_time)

            from_sse_to_model.copy()
            
            if not star.stellar_type == previous_type:
                results.append((star.age, star.mass, star.stellar_type))
                previous_type = star.stellar_type
                
        self.assertEqual(len(results), 6)
        
        times = ( 
            104.0 | units.Myr, 
            104.4 | units.Myr, 
            104.7 | units.Myr, 
            120.1 | units.Myr,
            120.9 | units.Myr,
            121.5 | units.Myr
        )
        for result, expected in zip(results, times):
            self.assertAlmostEqual(result[0].value_in(units.Myr), expected.value_in(units.Myr), 1)
            
        masses = ( 
            5.000 | units.MSun, 
            5.000 | units.MSun, 
            4.998 | units.MSun, 
            4.932 | units.MSun,
            4.895 | units.MSun,
            0.997 | units.MSun
        )
        for result, expected in zip(results, masses):
            self.assertAlmostEqual(result[1].value_in(units.MSun), expected.value_in(units.MSun), 3)
         
        types = (
            "Hertzsprung Gap",
            "First Giant Branch",
            "Core Helium Burning",
            "First Asymptotic Giant Branch",
            "Second Asymptotic Giant Branch",
            "Carbon/Oxygen White Dwarf",
        )
        
        for result, expected in zip(results, types):
            self.assertEquals(str(result[2]), expected)
        
        sse.stop()
开发者ID:vdhelm,项目名称:amuse,代码行数:69,代码来源:test_sse.py

示例14: SSE

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_parameters [as 别名]
                      help="number of stars to calculate <m>. [10]")
    result.add_option("-m", dest="Mmin", type="float", default=0.15,
                      help="Minimal mass of the IMF in MSun. [0.15MSun]")
    result.add_option("-M", dest="Mmax", type="float", default=100,
                      help="Maximal mass of the IMF in MSun. [100MSun]")
    result.add_option("-x", dest="x_imf", type="float", default=-2.35,
                      help="Slope of the IMF. [-2.35]")
    result.add_option("-v", dest="verbose", action="store_true", default=False,
                      help="verbose output [True]")

    o, arguments = result.parse_args()
    t_end = o.t_end | units.Myr
    dt = o.dt | units.Myr

    stellar_evolution = SSE()
    stellar_evolution.commit_parameters()

    stars = Particles(o.N)
    Mmin = o.Mmin | units.MSun
    Mmax = o.Mmax | units.MSun
    if o.verbose:
        print("#Selected parameters: ")
        print("#\tN=", o.N)
        print("#\tIMF=", o.Mmin, "MSun", o.Mmax, "MSun", o.x_imf)
        print("#\t t [Myr] \t <m> [MSun] \t\t d<m>/dt [MSun/Myr]")

    stars.mass = new_salpeter_mass_distribution(
        o.N, mass_min=Mmin, mass_max=Mmax, alpha=o.x_imf)

    stars = stellar_evolution.particles.add_particles(stars)
    stellar_evolution.commit_particles()
开发者ID:amusecode,项目名称:amuse,代码行数:33,代码来源:stellar_mean_mass.py


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