Skip to content

Instantly share code, notes, and snippets.

@rieder
Created June 24, 2022 11:43
Show Gist options
  • Save rieder/cd00f45409bab3402b95211bd4f33048 to your computer and use it in GitHub Desktop.
Save rieder/cd00f45409bab3402b95211bd4f33048 to your computer and use it in GitHub Desktop.
Setup AMUSE Bridge with external kicker codes
"""
Example of combining gas and stars via Bridge with a dedicated kicker code.
"""
from amuse.units import nbody_system, units
from amuse.couple.bridge import Bridge, CalculateFieldForCodes
from amuse.community.bhtree import Bhtree
from amuse.community.fastkick import Fastkick
from amuse.community.ph4 import Ph4
from amuse.community.gadget2 import Gadget2
TIME_STEP = 0.01 | units.Myr
CONVERTER = nbody_system.nbody_to_si(TIME_STEP, 0.1 | units.pc)
EPSILON = 0.01 | units.pc
FIELD_CODE_TYPE = "tree"
def new_field_tree_gravity_code(
code=Bhtree,
):
"Create a new field tree code"
result = code(
CONVERTER,
# redirection="none",
)
result.parameters.epsilon_squared = EPSILON**2
return result
def new_field_direct_gravity_code(
code=Fastkick,
):
"Create a new field direct code"
print("Creating field direct code")
result = code(
CONVERTER,
# redirection="none",
number_of_workers=8,
)
result.parameters.epsilon_squared = EPSILON**2
return result
def new_field_code(
code,
mode="direct",
):
" something"
if mode == "tree":
new_field_gravity_code = new_field_tree_gravity_code
elif mode == "direct":
new_field_gravity_code = new_field_direct_gravity_code
else:
new_field_gravity_code = new_field_direct_gravity_code
result = CalculateFieldForCodes(
new_field_gravity_code,
[code],
)
return result
INTEGRATOR_STARS = Ph4(CONVERTER)
INTEGRATOR_GAS = Gadget2(CONVERTER)
to_gas_kickers = []
to_stars_kickers = []
to_gas_kickers.append(
new_field_code(
INTEGRATOR_STARS,
mode=FIELD_CODE_TYPE,
)
)
to_stars_kickers.append(
new_field_code(
INTEGRATOR_GAS,
mode=FIELD_CODE_TYPE,
)
)
system = Bridge(
timestep=TIME_STEP,
use_threading=False,
)
system.add_system(
INTEGRATOR_STARS,
partners=to_stars_kickers,
do_sync=True,
)
system.add_system(
INTEGRATOR_GAS,
partners=to_gas_kickers,
do_sync=True,
h_smooth_is_eps=True,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment