當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。