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


Python SSE.commit_particles方法代码示例

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


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

示例1: test12

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

示例2: test6

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

示例3: planetplot

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

示例4: test7

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

示例5: Particles

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import commit_particles [as 别名]
    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()
    t = 0 | units.Myr
    mm = stars.mass.sum()/len(stars)
    while t < t_end:
        mm_last = mm
        t += dt
        stellar_evolution.evolve_model(t)
        mm = stars.mass.sum()/len(stars)
        dmm_dt = (mm_last-mm)/dt
        if o.verbose:
            print("t = ", t, "<m>=", mm.as_quantity_in(units.MSun),
                  " d<m>/dt = ", dmm_dt.as_quantity_in(units.MSun/units.Myr))
        else:
            print("\t", t, "\t", mm.as_quantity_in(units.MSun),
                  " \t ", dmm_dt.as_quantity_in(units.MSun/units.Myr))
开发者ID:amusecode,项目名称:amuse,代码行数:32,代码来源:stellar_mean_mass.py


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