本文整理汇总了Python中amuse.community.huayno.interface.Huayno.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Huayno.stop方法的具体用法?Python Huayno.stop怎么用?Python Huayno.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amuse.community.huayno.interface.Huayno
的用法示例。
在下文中一共展示了Huayno.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test1
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test1(self):
convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 149.5e6 | units.km)
huayno = Huayno(convert_nbody)
huayno.initialize_code()
huayno.parameters.epsilon_squared = 0.0 | units.AU**2
stars = self.new_system_of_sun_and_earth()
earth = stars[1]
huayno.particles.add_particles(stars)
huayno.evolve_model(365.0 | units.day)
huayno.particles.copy_values_of_all_attributes_to(stars)
position_at_start = earth.position.value_in(units.AU)[0]
position_after_full_rotation = earth.position.value_in(units.AU)[0]
self.assertAlmostEqual(position_at_start, position_after_full_rotation, 6)
huayno.evolve_model(365.0 + (365.0 / 2) | units.day)
huayno.particles.copy_values_of_all_attributes_to(stars)
position_after_half_a_rotation = earth.position.value_in(units.AU)[0]
self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 2)
huayno.evolve_model(365.0 + (365.0 / 2) + (365.0 / 4) | units.day)
huayno.particles.copy_values_of_all_attributes_to(stars)
position_after_half_a_rotation = earth.position.value_in(units.AU)[1]
self.assertAlmostEqual(-position_at_start, position_after_half_a_rotation, 3)
huayno.cleanup_code()
huayno.stop()
示例2: test16
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test16(self):
instance = Huayno()
instance.parameters.epsilon_squared = 0.0 | nbody_system.length**2
particles = datamodel.Particles(2)
particles.mass = [1.] | nbody_system.mass
particles.radius = [0.0] | nbody_system.length
particles.position = [[0.0,0.0,0.0],[1.0,0.0,0.0]] | nbody_system.length
particles.velocity = [[0.0, 0.0, 0.0]] | nbody_system.speed
instance.particles.add_particles(particles)
zero = 0.0 | nbody_system.length
for x in (0.25, 0.5, 0.75):
x0 = x | nbody_system.length
potential0 = instance.get_potential_at_point(zero, x0, zero, zero)
fx0, fy0, fz0 = instance.get_gravity_at_point(zero, x0, zero, zero)
self.assertAlmostEqual(fy0, 0.0 | nbody_system.acceleration,14)
self.assertAlmostEqual(fz0, 0.0 | nbody_system.acceleration,14)
fx = (-1.0 / (x0**2)+1.0 / (((1.0|nbody_system.length)-x0)**2)) * (1.0 | nbody_system.length ** 3 / nbody_system.time ** 2)
self.assertAlmostEqual(fx, fx0,14)
self.assertAlmostEqual(potential0, -nbody_system.G*(1.|nbody_system.mass)*(1./x0+1./((1.|nbody_system.length)-x0)),14)
instance.stop()
示例3: test13
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test13(self):
particles = plummer.new_plummer_model(31)
instance = Huayno(number_of_workers=1)#, debugger="xterm")
instance.initialize_code()
instance.parameters.epsilon_squared = 0.01 | nbody_system.length ** 2
instance.particles.add_particles(particles)
instance.evolve_model(0.1 | nbody_system.time)
instance.synchronize_model()
expected_positions = instance.particles.position
instance.stop()
示例4: binary_with_planet_run
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def binary_with_planet_run(m1=1.|units.MSun, m2=1.| units.MSun, m_planet=1|units.MJupiter,
r1=None, r2=None, r_planet=None, ecc_binary=0, P_binary=20 | units.day,
ecc_planet=0., P_planet=1.| units.yr, pangle_planet=0., a_planet=None,
tend=100. | units.yr,hostname=''):
dEcrit=1.e-6
three=binary_with_planet(m1=m1,m2=m2,m_planet=m_planet,r1=r1,r2=r2,r_planet=r_planet,
ecc_binary=ecc_binary,P_binary=P_binary,
ecc_planet=ecc_planet,a_planet=a_planet,pangle_planet=pangle_planet)
convert=nbody_system.nbody_to_si(1|units.MSun,1|units.AU)
code=Huayno(convert,hostname=hostname)
code.parameters.inttype_parameter=code.inttypes.SHARED10
code.parameters.timestep_parameter=.2
code.parameters.timestep=100. | units.day
dt=10000. | units.day
code.particles.add_particles(three)
E0=code.potential_energy+code.kinetic_energy
a0,eps0,pangle0=elements( three.total_mass(),
code.particles.x[2],
code.particles.y[2],
code.particles.z[2],
code.particles.vx[2],
code.particles.vy[2],
code.particles.vz[2] )
t=0. | units.day
result="stable"
while(t < tend-dt/2):
t=t+dt
code.evolve_model(t)
E=code.potential_energy+code.kinetic_energy
dE=abs(((E-E0)/E0))
a,eps,pangle=elements( three.total_mass(),
code.particles.x[2],
code.particles.y[2],
code.particles.z[2],
code.particles.vx[2],
code.particles.vy[2],
code.particles.vz[2] )
if dE > dEcrit or a<0.5*a0 or a>2.*a0:
result="unstable"
if dE > dEcrit:
result="failed"
break
code.stop()
return result,t,dE,a.in_(units.AU),eps,pangle
示例5: test14
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test14(self):
import hashlib
numpy.random.seed(123456)
particles = plummer.new_plummer_model(64)
sha=hashlib.sha1()
class inttypes(object):
SHARED2=1
EXTRAPOLATE=5
PASS_KDK=2
PASS_DKD=7
HOLD_KDK=3
HOLD_DKD=8
PPASS_DKD=9
BRIDGE_KDK=4
BRIDGE_DKD=10
CC=11
CC_KEPLER=12
OK=13
KEPLER=14
SHARED4=15
SHARED6=18
SHARED8=19
SHARED10=20
SHAREDBS=21
@classmethod
def _list(cls):
return set([x for x in cls.__dict__.keys() if not x.startswith('_')])
for itype in sorted(inttypes._list()):
if itype in ("KEPLER"): continue
instance = Huayno()
instance.parameters.inttype_parameter=getattr(Huayno.inttypes,itype)
instance.particles.add_particles(particles)
instance.evolve_model(0.125 | nbody_system.time)
part_out= instance.particles.copy()
position = part_out.position.number
if hasattr(position,'tobytes'):
as_bytes = position.tobytes()
else:
as_bytes = numpy.copy(position.data, order='C')
sha.update(as_bytes)
instance.stop()
# this result is probably dependent on system architecture hence no good for assert
print
print sha.hexdigest()
print "8e71f9441578a43af4af927943577ad2c4130e4c"
示例6: _run_collision_with_integrator
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def _run_collision_with_integrator(self, inttype_parameter):
particles = datamodel.Particles(7)
particles.mass = 0.001 | nbody_system.mass
particles.radius = 0.01 | nbody_system.length
particles.x = [-101.0, -100.0, -0.5, 0.5, 100.0, 101.0, 104.0] | nbody_system.length
particles.y = 0 | nbody_system.length
particles.z = 0 | nbody_system.length
particles.velocity = [[2, 0, 0], [-2, 0, 0]]*3 + [[-4, 0, 0]] | nbody_system.speed
instance = Huayno()
instance.parameters.inttype_parameter = inttype_parameter
instance.particles.add_particles(particles)
collisions = instance.stopping_conditions.collision_detection
collisions.enable()
instance.evolve_model(1.0 | nbody_system.time)
self.assertTrue(collisions.is_set())
self.assertTrue(instance.model_time < 0.5 | nbody_system.time)
self.assertEquals(len(collisions.particles(0)), 3)
self.assertEquals(len(collisions.particles(1)), 3)
self.assertEquals(len(particles - collisions.particles(0) - collisions.particles(1)), 1)
self.assertEquals(abs(collisions.particles(0).x - collisions.particles(1).x) <=
(collisions.particles(0).radius + collisions.particles(1).radius),
[True, True, True])
sticky_merged = datamodel.Particles(len(collisions.particles(0)))
sticky_merged.mass = collisions.particles(0).mass + collisions.particles(1).mass
sticky_merged.radius = collisions.particles(0).radius
for p1, p2, merged in zip(collisions.particles(0), collisions.particles(1), sticky_merged):
merged.position = (p1 + p2).center_of_mass()
merged.velocity = (p1 + p2).center_of_mass_velocity()
print instance.model_time
print instance.particles
instance.particles.remove_particles(collisions.particles(0) + collisions.particles(1))
instance.particles.add_particles(sticky_merged)
instance.evolve_model(1.0 | nbody_system.time)
print
print instance.model_time
print instance.particles
self.assertTrue(collisions.is_set())
self.assertTrue(instance.model_time < 1.0 | nbody_system.time)
self.assertEquals(len(collisions.particles(0)), 1)
self.assertEquals(len(collisions.particles(1)), 1)
self.assertEquals(len(instance.particles - collisions.particles(0) - collisions.particles(1)), 2)
self.assertEquals(abs(collisions.particles(0).x - collisions.particles(1).x) <=
(collisions.particles(0).radius + collisions.particles(1).radius),
[True])
instance.stop()
示例7: _compare_integrator_with_collision_integrator
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def _compare_integrator_with_collision_integrator(self, inttype_parameter1, inttype_parameter2):
numpy.random.seed(12345)
particles = plummer.new_plummer_model(101)
instance = Huayno()
instance.parameters.inttype_parameter = inttype_parameter1
instance.particles.add_particles(particles)
instance.evolve_model(0.2 | nbody_system.time)
expected_position = instance.particles.position
expected_velocity = instance.particles.velocity
instance.reset()
instance.parameters.inttype_parameter = inttype_parameter2
instance.particles.add_particles(particles)
instance.evolve_model(0.2 | nbody_system.time)
self.assertAlmostRelativeEquals(expected_position, instance.particles.position, 8)
self.assertAlmostRelativeEquals(expected_velocity, instance.particles.velocity, 8)
instance.stop()
示例8: orbit_evolve
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def orbit_evolve(bodies, time_peri, eta, n_steps=100):
converter=nbody_system.nbody_to_si(1|units.MSun,1|units.AU)
gravity = Huayno(converter,channel_type="sockets")
gravity.particles.add_particles(bodies)
gravity.commit_particles()
gravity.parameters.timestep_parameter = eta
channel_from_gravity_to_framework = gravity.particles.new_channel_to(bodies)
Etot_init = gravity.kinetic_energy + gravity.potential_energy
Etot = Etot_init
file_snap = "orbit_ini.hdf5"
t_end = 2.0*abs(time_peri.value_in(units.yr)) | units.yr
dt = t_end / float(n_steps)
time = 0.0 | units.yr
while time <= t_end:
gravity.evolve_model(time)
channel_from_gravity_to_framework.copy()
bodies.age = time
# checking energy conservation
Ekin = gravity.kinetic_energy
Epot = gravity.potential_energy
Etot = Ekin + Epot
dE = Etot_init-Etot
# output centerd on the bodies[0] star
bodies.position -= bodies[0].position
bodies.velocity -= bodies[0].velocity
write_set_to_file(bodies, file_snap, "hdf5")
rel_r = (bodies[1].position - bodies[0].position).lengths()
print " \t\t", time, "\t", dE/Etot_init, rel_r.in_(units.AU)
time += dt
gravity.stop()
bodies.position -= bodies[0].position
bodies.velocity -= bodies[0].velocity
print bodies
return
示例9: test29
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test29(self):
instance = Huayno()
instance.parameters.epsilon_squared = 0.0 | nbody_system.length**2
particles = datamodel.Particles(2)
particles.position = ([0,0,0], [1,0,0] )| nbody_system.length
particles.velocity = ([-1,0,0], [2,0,0] )| nbody_system.speed
particles.radius = 0| nbody_system.length
particles.mass = 0.1| nbody_system.mass
instance.particles.add_particles(particles)
instance.stopping_conditions.out_of_box_detection.enable()
instance.parameters.stopping_conditions_out_of_box_size = 2 | nbody_system.length
instance.parameters.stopping_conditions_out_of_box_use_center_of_mass = False
instance.evolve_model(1 | nbody_system.time)
self.assertTrue(instance.stopping_conditions.out_of_box_detection.is_set())
self.assertEquals(len(instance.stopping_conditions.out_of_box_detection.particles(0)), 1)
self.assertEquals(instance.stopping_conditions.out_of_box_detection.particles(0)[0].key, particles[1].key)
instance.stop()
示例10: test22
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test22(self):
print "Testing zero-mass test particles in Huayno, can be used for removing particles when inside recursive evolve loop"
sun_and_earth = self.new_system_of_sun_and_earth()
period = (4.0 * math.pi**2 * (1.0 | units.AU)**3 / (constants.G * sun_and_earth.total_mass())).sqrt()
convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 1.0 | units.AU)
huayno = Huayno(convert_nbody)
huayno.parameters.epsilon_squared = 0.0 | units.AU**2
huayno.parameters.inttype_parameter = huayno.inttypes.SHARED8
test_particle = datamodel.Particle(mass=0|units.MSun, position=[4,0,0]|units.AU, velocity=[0,0,0]|units.kms)
test_particle.vy = (constants.G * sun_and_earth.total_mass() / (4.0 | units.AU)).sqrt()
sun_and_earth.add_particle(test_particle)
huayno.particles.add_particles(sun_and_earth)
huayno.evolve_model(period)
self.assertAlmostRelativeEqual(huayno.particles[:2].x, sun_and_earth[:2].x, 13)
huayno.evolve_model(1.25 * period)
self.assertAlmostRelativeEqual(huayno.particles[1].y, sun_and_earth[1].x, 13)
huayno.evolve_model(8.0 * period)
self.assertAlmostRelativeEqual(huayno.particles.x, sun_and_earth.x, 8)
huayno.stop()
示例11: test6
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test6(self):
print "Test6: Testing Huayno parameters"
convert_nbody = nbody_system.nbody_to_si(1.0 | units.yr, 1.0 | units.AU)
instance = Huayno(convert_nbody)
(value, error) = instance.legacy_interface.get_eps2()
self.assertEquals(0, error)
self.assertEquals(0.0, value)
self.assertAlmostEquals(0.0 | units.AU**2, instance.parameters.epsilon_squared, in_units=units.AU**2)
for x in [0.01, 0.1, 0.2]:
instance.parameters.epsilon_squared = x | units.AU**2
self.assertAlmostEquals(x | units.AU**2, instance.parameters.epsilon_squared, in_units=units.AU**2)
(value, error) = instance.legacy_interface.get_time()
self.assertEquals(0, error)
self.assertEquals(0.0, value)
self.assertAlmostEquals(0.0 | units.yr, instance.parameters.begin_time, in_units=units.yr)
for x in [1.0, 10.0, 100.0]:
instance.parameters.begin_time = x | units.yr
self.assertAlmostEquals(x | units.yr, instance.parameters.begin_time, in_units=units.yr)
instance.stop()
示例12: test27
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test27(self):
particles = plummer.new_plummer_model(31)
tend=0.25| nbody_system.time
instance = Huayno()
instance.particles.add_particles(particles)
instance.evolve_model(tend)
expected_positions = instance.particles.position
self.assertEqual(instance.model_time, tend)
instance.stop()
particles2=particles.copy()
particles2.velocity*=-1
instance = Huayno()
instance.particles.add_particles(particles2)
instance.evolve_model(-tend)
positions = instance.particles.position
self.assertEqual(instance.model_time, -tend)
instance.stop()
self.assertAlmostEqual(positions,expected_positions)
示例13: test15
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test15(self):
particles = plummer.new_plummer_model(512)
expected_positions = None
for mode in ["cpu", "openmp", "opencl"]:
try:
instance = Huayno(mode=mode, number_of_workers=1)#, debugger="xterm")
except:
print "Running huayno with mode=", mode, " was unsuccessful."
continue
else:
print "Running huayno with mode=", mode, "... "
instance.initialize_code()
instance.parameters.epsilon_squared = 0.01 | nbody_system.length ** 2
instance.particles.add_particles(particles)
instance.evolve_model(0.2 | nbody_system.time)
instance.synchronize_model()
if expected_positions is None:
expected_positions = instance.particles.position
else:
self.assertAlmostRelativeEquals(expected_positions, instance.particles.position, 8)
instance.stop()
示例14: test7
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test7(self):
print "Test7: Testing effect of Huayno parameter epsilon_squared"
convert_nbody = nbody_system.nbody_to_si(1.0 | units.MSun, 1.0 | units.AU)
particles = datamodel.Particles(2)
sun = particles[0]
sun.mass = 1.0 | units.MSun
sun.position = [0.0, 0.0, 0.0] | units.AU
sun.velocity = [0.0, 0.0, 0.0] | units.AU / units.yr
sun.radius = 1.0 | units.RSun
earth = particles[1]
earth.mass = 5.9736e24 | units.kg
earth.radius = 6371.0 | units.km
earth.position = [0.0, 1.0, 0.0] | units.AU
earth.velocity = [2.0*numpy.pi, -0.0001, 0.0] | units.AU / units.yr
initial_direction = math.atan((earth.velocity[0]/earth.velocity[1]))
final_direction = []
for log_eps2 in range(-9,10,2):
instance = Huayno(convert_nbody)
instance.initialize_code()
instance.parameters.epsilon_squared = 10.0**log_eps2 | units.AU ** 2
instance.particles.add_particles(particles)
instance.commit_particles()
instance.evolve_model(0.25 | units.yr)
final_direction.append(math.atan((instance.particles[1].velocity[0]/
instance.particles[1].velocity[1])))
instance.stop()
# Small values of epsilon_squared should result in normal earth-sun dynamics: rotation of 90 degrees
self.assertAlmostEquals(abs(final_direction[0]), abs(initial_direction+math.pi/2.0), 2)
# Large values of epsilon_squared should result in ~ no interaction
self.assertAlmostEquals(final_direction[-1], initial_direction, 2)
# Outcome is most sensitive to epsilon_squared when epsilon_squared = d(earth, sun)^2
delta = [abs(final_direction[i+1]-final_direction[i]) for i in range(len(final_direction)-1)]
self.assertEquals(delta[len(final_direction)/2 -1], max(delta))
示例15: test_run
# 需要导入模块: from amuse.community.huayno.interface import Huayno [as 别名]
# 或者: from amuse.community.huayno.interface.Huayno import stop [as 别名]
def test_run():
three=binary_with_planet(
m1=0.6897 | units.MSun,m2=0.20255 | units.MSun,m_planet=0.333 | units.MJupiter,
r1=0.6489 | units.RSun,r2=0.22623 | units.RSun,r_planet=0.754 | units.RJupiter,
ecc_binary=0.15944,P_binary=41.08| units.day,ecc_planet=0.00685,a_planet=.7048 | units.AU,
pangle_planet=0.)
convert=nbody_system.nbody_to_si(1|units.MSun,1|units.AU)
code=Huayno(convert)
code.parameters.inttype_parameter=code.inttypes.SHARED4
code.parameters.timestep_parameter=0.1
# tend=100. | units.yr
tend=100. | units.day
snapfreq=1
dt=10. | units.day
# dt=convert.to_si( 1. | nbody_system.time).in_(units.day)
code.particles.add_particles(three)
x = AdaptingVectorQuantity()
y = AdaptingVectorQuantity()
z = AdaptingVectorQuantity()
vx = AdaptingVectorQuantity()
vy = AdaptingVectorQuantity()
vz = AdaptingVectorQuantity()
x.append(code.particles.x)
y.append(code.particles.y)
z.append(code.particles.z)
vx.append(code.particles.vx)
vy.append(code.particles.vy)
vz.append(code.particles.vz)
ts=[0.]
E0=code.potential_energy+code.kinetic_energy
dE=[1.e-14]
t=0. | units.day
i=0
while(t < tend-dt/2):
i+=1
t=t+dt
if i%snapfreq==0:
print t
ts.append(t.value_in(units.day))
code.evolve_model(t)
x.append(code.particles.x)
y.append(code.particles.y)
z.append(code.particles.z)
vx.append(code.particles.vx)
vy.append(code.particles.vy)
vz.append(code.particles.vz)
E=code.potential_energy+code.kinetic_energy
dE.append(abs(((E-E0)/E0)))
code.stop()
a,eps,pangle=elements(three.total_mass(),
x[:,2],
y[:,2],
z[:,2],
vx[:,2],
vy[:,2],
vz[:,2])
x=x.value_in(units.AU)
y=y.value_in(units.AU)
a=a.value_in(units.AU)
eps=eps
print a[-1],eps[-1],pangle[-1]
f=pyplot.figure(figsize=(8,8))
pyplot.plot(x[:,0],y[:,0],'r.')
pyplot.plot(x[:,1],y[:,1],'g.')
pyplot.plot(x[:,2],y[:,2],'b.')
pyplot.xlim(-3,3)
pyplot.ylim(-3,3)
pyplot.xlabel('AU')
pyplot.savefig('three_16b.eps')
f=pyplot.figure(figsize=(8,8))
pyplot.semilogy(ts,dE,'g.')
pyplot.xlabel('time (day)')
pyplot.ylabel('dE/E0')
pyplot.savefig('three_16b_eerr.eps')
f=pyplot.figure(figsize=(8,8))
pyplot.plot(ts,a,'g.')
pyplot.xlabel('time (day)')
pyplot.ylabel('a (AU)')
pyplot.savefig('three_16b_a.eps')
f=pyplot.figure(figsize=(8,8))
pyplot.plot(ts,eps,'g.')
pyplot.xlabel('time (day)')
pyplot.ylabel('eccentricity')
pyplot.savefig('three_16b_ecc.eps')
f=pyplot.figure(figsize=(8,8))
#.........这里部分代码省略.........