Swarm-NG  1.1
ejection_tutorial.py
1 #!/usr/bin/env python2
2 
3 # @page TutorialPythonEjection Testing for ejection of planets
4 #
5 # In this tutorial, we write a test to examine if the stop_on_ejection monitor works
6 # as expected. It involves generating a test case that causes some planets to eject and
7 # examining the ensemble after the integration.
8 #
9 # Source code for this tutorial can be found at @ref py/ejection_tutorial.py
10 #
11 # The first step is to import the swarmng module. We also use make_test_case from the
12 # @ref TutorialPythonEnsemble "Ensemble generation tutorial" to generate our test case.
13 import swarmng
14 from ensemble_tutorial import make_test_case
15 # \subsection candi Configuration and initial conditions
16 # RMAX is the maximum radius of the planetary system. If the planets is farther than RMAX from
17 # the origin, we consider it ejected.
18 RMAX = 10
19 #
20 # Configuratino for the integration, we use CPU version of the PECĀ² Hermite integrator, it is
21 # by default checks for ejections when the planets get too far from the origin.
22 cfg = swarmng.config(
23  integrator = "hermite_cpu",
24  time_step = 1e-3,
25  nogpu = 1,
26  deactivate_on_ejection = 1,
27  rmax = RMAX
28  )
29 # We have to set the destination_time directly on the integrator object
30 # and it cannot be included in the Config object.
31 destination_time = 100
32 #
33 # We create an ensemble with very close orbits. This ensures that the planets
34 # will come close at some point and the result would be an ejection.
35 ens = make_test_case(nsys=20, nbod = 6, spacing_factor=1.01);
36 #
37 # \section int Integration
38 # Same procedure as in @ref TutorialPython. Set-up the integrator parameters and
39 # call the method @ref swarmng.Integrator.integrate "integrate".
40 swarmng.init(cfg)
41 integ = swarmng.Integrator.create( cfg )
42 integ.ensemble = ens
43 integ.destination_time = destination_time
44 integ.integrate()
45 #
46 # \section ex Examine
47 # After the integration finished, we can look into the ensemble to see if
48 # in fact the integrator has worked as expected.
49 #
50 #
51 for s in ens:
52  for b in s:
53  if( b.distance_to_origin() > RMAX ):
54  assert(sys.state == -1)
55 #
56 #
57 #
58