Skip to content

Commit 0014feb

Browse files
committed
make changes
1 parent ff7a667 commit 0014feb

28 files changed

+2642
-151
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1987apj_323_614b.py
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
from amuse.lab import *
2+
from amuse.io import store
3+
from amuse.ext.orbital_elements import new_binary_from_orbital_elements
4+
5+
def collide_two_stars(t_end, distance, offset, v_vesc, nsteps):
6+
filename = "Hydro_AM06MSun.h5"
7+
try:
8+
pstar = read_set_from_file(filename, format='hdf5')
9+
except:
10+
from amuse.examples.star_to_sph import evolve_star_and_convert_to_sph, evolve_star
11+
mass = 0.6|units.MSun
12+
age = 8 | units.Gyr
13+
omega = 0|units.s**-1
14+
Nsph = 1000
15+
stellar = evolve_star(mass, age)
16+
pstar, pcore, _ = evolve_star_and_convert_to_sph(stellar, omega, Nsph)
17+
18+
print(pstar)
19+
pmass = pstar.mass.sum()
20+
print(pmass.in_(units.MSun))
21+
22+
filename = "Hydro_BM06MSun.h5"
23+
try:
24+
sstar = read_set_from_file(filename, format='hdf5')
25+
except:
26+
from amuse.examples.star_to_sph import evolve_star_and_convert_to_sph, evolve_star
27+
mass = 0.6|units.MSun
28+
age = 8 | units.Gyr
29+
omega = 0|units.s**-1
30+
Nsph = 1000
31+
stellar = evolve_star(mass, age)
32+
sstar, score, _ = evolve_star_and_convert_to_sph(stellar, omega, Nsph)
33+
print(sstar)
34+
smass = sstar.mass.sum()
35+
print(smass.in_(units.MSun))
36+
37+
import numpy
38+
v_esc = numpy.sqrt(2*constants.G*pmass/distance)
39+
velocity = v_vesc*v_esc
40+
41+
sstar.x += distance
42+
sstar.y += offset
43+
sstar.vx -= velocity
44+
45+
sph_particles = Particles(0)
46+
sph_particles.add_particles(pstar)
47+
sph_particles.add_particles(sstar)
48+
sph_particles.move_to_center()
49+
converter=nbody_system.nbody_to_si(pmass, distance)
50+
51+
hydro = Fi(converter)
52+
53+
dt = t_end/float(nsteps)
54+
55+
hydro.gas_particles.add_particles(pstar)
56+
hydro.gas_particles.add_particles(sstar)
57+
Etot_init = hydro.kinetic_energy + hydro.potential_energy + hydro.thermal_energy
58+
to_framework = hydro.gas_particles.new_channel_to(sph_particles)
59+
60+
output_file = "1987ApJ...323..614B.h5"
61+
write_set_to_file(sph_particles.savepoint(0.0 | t_end.unit), output_file, "hdf5", append_to_file=False)
62+
63+
time = 0.0 | t_end.unit
64+
while time < t_end:
65+
time += dt
66+
print(time)
67+
hydro.evolve_model(time)
68+
to_framework.copy()
69+
70+
"""
71+
from amuse.plot import sph_particles_plot
72+
sph_particles_plot(hydro.particles)
73+
from matplotlib import pyplot
74+
pyplot.show()
75+
"""
76+
77+
write_set_to_file(sph_particles.savepoint(time), output_file, "hdf5")
78+
79+
"""
80+
Ekin = hydro.kinetic_energy
81+
Epot = hydro.potential_energy
82+
Eth = hydro.thermal_energy
83+
Etot = Ekin + Epot + Eth
84+
print "T=", hydro.get_time(), "M=", hydro.gas_particles.mass.sum(),
85+
print "E= ", Etot, "Q= ", (Ekin+Eth)/Epot, "dE=", (Etot_init-Etot)/Etot
86+
"""
87+
88+
from amuse.plot import sph_particles_plot
89+
sph_particles_plot(hydro.particles)
90+
from matplotlib import pyplot
91+
pyplot.show()
92+
93+
hydro.stop()
94+
95+
96+
def new_option_parser():
97+
from amuse.units.optparse import OptionParser
98+
result = OptionParser()
99+
result.add_option("-t", unit=units.hour,
100+
dest="t_end", type="float", default = 10|units.hour,
101+
help="end time of the simulation [%default]")
102+
result.add_option("-r", unit=units.MSun,
103+
dest="distance", type="float", default = 1.4|units.RSun,
104+
help="initial sepration [%default]")
105+
result.add_option("-o", unit=units.RSun,
106+
dest="offset", type="float", default = 0|units.RSun,
107+
help="offset sepration [%default]")
108+
result.add_option("-v",
109+
dest="v_vesc", type="float", default = 1.7,
110+
help="impact velocity wrt escape speed [%default]")
111+
result.add_option("-n",
112+
dest="nsteps", type="int", default = 10,
113+
help="number of steps [%default]")
114+
return result
115+
116+
if __name__ in ('__main__', '__plot__'):
117+
o, arguments = new_option_parser().parse_args()
118+
collide_two_stars(o.t_end, o.distance, o.offset, o.v_vesc, o.nsteps)
119+
6.74 KB
Binary file not shown.
13.3 MB
Binary file not shown.

0 commit comments

Comments
 (0)