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


Python SSE.initialize_module_with_default_parameters方法代码示例

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


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

示例1: simulate_small_cluster

# 需要导入模块: from amuse.community.sse.interface import SSE [as 别名]
# 或者: from amuse.community.sse.interface.SSE import initialize_module_with_default_parameters [as 别名]
def simulate_small_cluster(number_of_stars, end_time=40 | units.Myr,
                           name_of_the_figure="test-2.svg"):
    # numpy.random.seed(1)

    salpeter_masses = new_salpeter_mass_distribution(number_of_stars)
    total_mass = salpeter_masses.sum()

    convert_nbody = nbody_system.nbody_to_si(total_mass, 1.0 | units.parsec)

    particles = new_plummer_model(number_of_stars, convert_nbody)

    gravity = BHTree(convert_nbody)
    gravity.initialize_code()
    # gravity.parameters.set_defaults()
    # print gravity.parameters.timestep.as_quantity_in(units.Myr)
    gravity.parameters.timestep = 0.0001 | units.Myr  # tiny!
    gravity.parameters.epsilon_squared \
        = (float(number_of_stars)**(-0.333333) | units.parsec) ** 2

    stellar_evolution = SSE()
    stellar_evolution.initialize_module_with_default_parameters()

    print "setting masses of the stars"
    particles.radius = 0.0 | units.RSun
    particles.mass = salpeter_masses

    print "initializing the particles"
    stellar_evolution.particles.add_particles(particles)
    from_stellar_evolution_to_model \
        = stellar_evolution.particles.new_channel_to(particles)
    from_stellar_evolution_to_model.copy_attributes(["mass"])

    print "centering the particles"
    particles.move_to_center()
    print "scaling particles to viridial equilibrium"
    particles.scale_to_standard(convert_nbody)

    gravity.particles.add_particles(particles)
    from_model_to_gravity = particles.new_channel_to(gravity.particles)
    from_gravity_to_model = gravity.particles.new_channel_to(particles)

    gravity.commit_particles()

    time = 0.0 | units.Myr
    particles.savepoint(time)

    total_energy_at_t0 = gravity.kinetic_energy + gravity.potential_energy

    print "evolving the model until t = " + str(end_time)
    while time < end_time:
        time += 0.25 | units.Myr

        print "Gravity evolve step starting"
        gravity_evolve = gravity.evolve_model.async(time)

        print "Stellar evolution step starting"
        stellar_evolution_evolve = stellar_evolution.evolve_model(time)

        print "Stellar evolution step done."

        gravity_evolve.result()
        print "Gravity evolve step done."

        from_gravity_to_model.copy()
        from_stellar_evolution_to_model.copy_attributes(["mass", "radius"])

        particles.savepoint(time)

        from_model_to_gravity.copy_attributes(["mass"])

        total_energy_at_this_time \
            = gravity.kinetic_energy + gravity.potential_energy
        print_log(time, gravity, particles,
                  total_energy_at_t0, total_energy_at_this_time)

    test_results_path = get_path_to_results()
    output_file = os.path.join(test_results_path, "small.hdf5")
    if os.path.exists(output_file):
        os.remove(output_file)
    storage = store.StoreHDF(output_file)
    storage.store(particles)

    gravity.stop()
    stellar_evolution.stop()

    plot_particles(particles, name_of_the_figure)
开发者ID:amusecode,项目名称:amuse,代码行数:88,代码来源:test_smallcluster_async.py


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