Swarm-NG  1.1
collision_course.py
Go to the documentation of this file.
1 ## @file collision_course.py Testing collision detection module by putting planets on the same orbit in opposite directions
2 from common import *
3 from math import sqrt
4 from random import uniform
5 
6 def sphericalToCartesian(r,theta, phi = 0):
7  return [ r*cos(theta)*cos(phi), r*sin(theta)*cos(phi), r*sin(phi) ]
8 
9 
10 class CollisionCourseTest(abstract.IntegrationTest):
11 
12  cfg = swarmng.config(
13  integrator="hermite_cpu",
14  time_step_factor=0.017,
15  min_time_step=0.001,
16  time_step=0.0001,
17  destination_time=1,
18  deactivate_on_collision=1,
19  collision_radius=.05
20  )
21 
22  def createEnsemble(self):
23  nsys = 16
24  nbod = 4
25  orbit_radius = 1.0
26  orbit_velocity = sqrt(1/orbit_radius)
27 
28  ens = swarmng.DefaultEnsemble.create(nbod,nsys)
29 
30  for i,s in enumerate(ens):
31  # Trivial attributes of the system
32  s.id = i
33  s.time = 0
34  s.set_active()
35 
36  # select a random phase to put the first body
37  phi_base = uniform(0,2*pi)
38 
39  for j,b in enumerate(s):
40  if(j == 0):
41  # Set the central body as a large mass stationary object
42  b.pos = [0, 0, 0]
43  b.vel = [0, 0, 0]
44  b.mass = 1.0
45  else:
46  ## distribute the planets uniformly around the orbit by different phases
47  phi = phi_base + (j-1)*2*pi/(ens.nbod-1)
48  b.mass = 0.001
49  b.pos = sphericalToCartesian(orbit_radius, phi)
50  b.vel = sphericalToCartesian( -1**j * orbit_velocity, phi+ pi/2)
51 
52  return ens
53 
54  def examine(self):
55  for s in self.ens:
56  self.assertEqual(s.state, -1)
57 
58 
59