當前位置: 首頁>>代碼示例>>Python>>正文


Python SSE.initialize_code方法代碼示例

本文整理匯總了Python中amuse.community.sse.interface.SSE.initialize_code方法的典型用法代碼示例。如果您正苦於以下問題:Python SSE.initialize_code方法的具體用法?Python SSE.initialize_code怎麽用?Python SSE.initialize_code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在amuse.community.sse.interface.SSE的用法示例。


在下文中一共展示了SSE.initialize_code方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test13

# 需要導入模塊: from amuse.community.sse.interface import SSE [as 別名]
# 或者: from amuse.community.sse.interface.SSE import initialize_code [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: test12

# 需要導入模塊: from amuse.community.sse.interface import SSE [as 別名]
# 或者: from amuse.community.sse.interface.SSE import initialize_code [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


注:本文中的amuse.community.sse.interface.SSE.initialize_code方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。