Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
pull_request:
branches:
- main
- updates/examples/textbook

jobs:
run-linters:
Expand Down
39 changes: 22 additions & 17 deletions examples/textbook/1987ApJ...323..614B.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from amuse.lab import *
from amuse.io import store
import numpy
from amuse.io import read_set_from_file, write_set_to_file
from amuse.units import nbody_system, units, constants
from amuse.datamodel import Particles
from amuse.community.fi import Fi
from amuse.ext.orbital_elements import new_binary_from_orbital_elements

def collide_two_stars(t_end, distance, offset, v_vesc, nsteps):
Expand All @@ -8,9 +11,9 @@ def collide_two_stars(t_end, distance, offset, v_vesc, nsteps):
pstar = read_set_from_file(filename, format='hdf5')
except:
from star_to_sph import evolve_star_and_convert_to_sph, evolve_star
mass = 0.6|units.MSun
mass = 0.6 | units.MSun
age = 8 | units.Gyr
omega = 0|units.s**-1
omega = 0 | units.s**-1
Nsph = 1000
stellar = evolve_star(mass, age)
pstar, pcore = evolve_star_and_convert_to_sph(stellar, omega, Nsph)
Expand All @@ -24,17 +27,16 @@ def collide_two_stars(t_end, distance, offset, v_vesc, nsteps):
sstar = read_set_from_file(filename, format='hdf5')
except:
from star_to_sph import evolve_star_and_convert_to_sph, evolve_star
mass = 0.6|units.MSun
mass = 0.6 | units.MSun
age = 8 | units.Gyr
omega = 0|units.s**-1
omega = 0 | units.s**-1
Nsph = 1000
stellar = evolve_star(mass, age)
sstar, score = evolve_star_and_convert_to_sph(stellar, omega, Nsph)
print(sstar)
smass = sstar.mass.sum()
print(smass.in_(units.MSun))

import numpy
v_esc = numpy.sqrt(2*constants.G*pmass/distance)
velocity = v_vesc*v_esc

Expand All @@ -46,7 +48,7 @@ def collide_two_stars(t_end, distance, offset, v_vesc, nsteps):
sph_particles.add_particles(pstar)
sph_particles.add_particles(sstar)
sph_particles.move_to_center()
converter=nbody_system.nbody_to_si(pmass, distance)
converter = nbody_system.nbody_to_si(pmass, distance)

hydro = Fi(converter)

Expand All @@ -58,7 +60,10 @@ def collide_two_stars(t_end, distance, offset, v_vesc, nsteps):
to_framework = hydro.gas_particles.new_channel_to(sph_particles)

output_file = "1987ApJ...323..614B.h5"
write_set_to_file(sph_particles.savepoint(0.0 | t_end.unit), output_file, "hdf5", append_to_file=False)
write_set_to_file(
sph_particles.savepoint(0.0 | t_end.unit),
output_file, "hdf5", append_to_file=False,
)

time = 0.0 | t_end.unit
while time < t_end:
Expand Down Expand Up @@ -92,28 +97,28 @@ def collide_two_stars(t_end, distance, offset, v_vesc, nsteps):

hydro.stop()


def new_option_parser():
from amuse.units.optparse import OptionParser
result = OptionParser()
result.add_option("-t", unit=units.hour,
dest="t_end", type="float", default = 10|units.hour,
dest="t_end", type="float", default=10 | units.hour,
help="end time of the simulation [%default]")
result.add_option("-r", unit=units.MSun,
dest="distance", type="float", default = 1.4|units.RSun,
dest="distance", type="float", default=1.4 | units.RSun,
help="initial sepration [%default]")
result.add_option("-o", unit=units.RSun,
dest="offset", type="float", default = 0|units.RSun,
dest="offset", type="float", default=0 | units.RSun,
help="offset sepration [%default]")
result.add_option("-v",
dest="v_vesc", type="float", default = 1.7,
dest="v_vesc", type="float", default=1.7,
help="impact velocity wrt escape speed [%default]")
result.add_option("-n",
dest="nsteps", type="int", default = 10,
dest="nsteps", type="int", default=10,
help="number of steps [%default]")
return result


if __name__ in ('__main__', '__plot__'):
o, arguments = new_option_parser().parse_args()
o, arguments = new_option_parser().parse_args()
collide_two_stars(o.t_end, o.distance, o.offset, o.v_vesc, o.nsteps)

8 changes: 4 additions & 4 deletions examples/textbook/three_body_bridge_hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ def new_system_of_sun_and_earth():
return stars

def main():
filename = "SunAndEarthAndMoon.hdf"
filename = "SunAndEarthAndMoon.amuse"
ss = new_system_of_sun_and_earth()
star = ss[0]
planet = ss[1]
moon = ss[2]
converter=nbody_system.nbody_to_si(star.mass,planet.position.length())
star_gravity = ph4(converter)
star_gravity = Ph4(converter)
star_gravity.particles.add_particle(star)

planet_gravity = ph4(converter)
planet_gravity = Ph4(converter)
planet_gravity.particles.add_particle(planet)

moon_gravity = ph4(converter)
moon_gravity = Ph4(converter)
moon_gravity.particles.add_particle(moon)

channel_from_star_to_framework = star_gravity.particles.new_channel_to(ss)
Expand Down
16 changes: 10 additions & 6 deletions examples/textbook/three_body_bridge_order4m4.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,30 @@ def new_system_of_sun_and_earth():
return stars

def main():
filename = "SunAndEarthAndMoon_TBB.h5"
filename = "SunAndEarthAndMoon_TBB.amuse"
ss = new_system_of_sun_and_earth()
star = ss[0]
planet = ss[1]
moon = ss[2]

print(moon)
converter=nbody_system.nbody_to_si(star.mass, 1|units.AU)
star_gravity = ph4(converter)
star_gravity = Ph4(converter)
star_gravity.particles.add_particle(star)

planet_gravity = ph4(converter)
planet_gravity = Ph4(converter)
planet_gravity.particles.add_particle(planet)

moon_gravity = ph4(converter)
moon_gravity = Ph4(converter)
moon_gravity.particles.add_particle(moon)

channel_from_star_to_framework = star_gravity.particles.new_channel_to(ss)
channel_from_planet_to_framework = planet_gravity.particles.new_channel_to(ss)
channel_from_moon_to_framework = moon_gravity.particles.new_channel_to(ss)

write_set_to_file(ss.savepoint(0.0|units.Myr), filename, 'hdf5', append_to_file=False, version='2')
write_set_to_file(
ss.savepoint(0.0|units.Myr), filename, 'hdf5', overwrite_file=True,
)

gravity = bridge.Bridge(use_threading=False, method=SPLIT_4TH_S_M4)
####gravity = bridge.Bridge(use_threading=False, method=SPLIT_6TH_SS_M13)
Expand All @@ -73,7 +75,9 @@ def main():
channel_from_star_to_framework.copy()
channel_from_planet_to_framework.copy()
channel_from_moon_to_framework.copy()
write_set_to_file(ss.savepoint(time), filename, 'hdf5', version='2')
write_set_to_file(
ss.savepoint(time), filename, 'hdf5', append_to_file=True,
)

Ekin = gravity.kinetic_energy
Epot = gravity.potential_energy
Expand Down