Swarm-NG  1.1
Testing for ejection of planets

In this tutorial, we write a test to examine if the stop_on_ejection monitor works as expected.

It involves generating a test case that causes some planets to eject and examining the ensemble after the integration.

Source code for this tutorial can be found at py/ejection_tutorial.py

The first step is to import the swarmng module. We also use make_test_case from the Ensemble generation tutorial to generate our test case.

1 import swarmng
2 from ensemble_tutorial import make_test_case

RMAX is the maximum radius of the planetary system. If the planets is farther than RMAX from the origin, we consider it ejected.

1 RMAX = 10

Configuratino for the integration, we use CPU version of the PECĀ² Hermite integrator, it is by default checks for ejections when the planets get too far from the origin.

1 cfg = swarmng.config(
2  integrator = "hermite_cpu",
3  time_step = 1e-3,
4  nogpu = 1,
5  deactivate_on_ejection = 1,
6  rmax = RMAX
7  )

We have to set the destination_time directly on the integrator object and it cannot be included in the Config object.

1 destination_time = 100

We create an ensemble with very close orbits. This ensures that the planets will come close at some point and the result would be an ejection.

1 ens = make_test_case(nsys=20, nbod = 6, spacing_factor=1.01);

Integration

Same procedure as in Beginner Python Tutorial. Set-up the integrator parameters and call the method integrate.

1 swarmng.init(cfg)
2 integ = swarmng.Integrator.create( cfg )
3 integ.ensemble = ens
4 integ.destination_time = destination_time
5 integ.integrate()

Examine

After the integration finished, we can look into the ensemble to see if in fact the integrator has worked as expected.

1 for s in ens:
2  for b in s:
3  if( b.distance_to_origin() > RMAX ):
4  assert(sys.state == -1)