本文整理汇总了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"
示例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()