Swarm-NG  1.1
parabolic_collision.py
Go to the documentation of this file.
1 ## @file parabolic_collision.py Testing collision detection module by putting planets on a parabolic orbit.
2 from common import *
3 from math import sqrt
4 def norm(*args):
5  return sqrt(sum(x * x for x in args))
6 
7 class ParabolicTest(abstract.IntegrationTest):
8  """
9  collision happens at exactly t= 1.885638833885 for nbod=3
10  """
11  cfg = swarmng.config(
12  integrator = "hermite_cpu",
13  time_step = 1e-3,
14  nogpu = 1,
15  )
16  destination_time = 1.885638833885
17 
18  def createEnsemble(self):
19  nsys = 16
20  nbod = 3
21  R = 1
22  mu = 1
23  mass_planet = 0.0001
24 
25 
26  ens = swarmng.DefaultEnsemble.create(nbod,nsys)
27  for s in ens:
28  s.time = 0
29  s.id = 0
30  s.state = 0
31  s[0].pos = [ 0, 0, 0 ]
32  s[0].vel = [ 0, 0, 0 ]
33  s[0].mass = 1
34  for j in range(1,ens.nbod):
35  x = ((j % 2)*2-1)*2*((j+1)/2)
36  y = x * x / 4 / R - R
37  vmag = sqrt(2*mu/norm(x,y))
38  vdirx = (x/abs(x))/norm(1,x/2/R)
39  vdiry = abs(x)/2/R / norm(1,x/2/R)
40  s[j].pos = [ x, y, 0 ]
41  s[j].vel = [ -vmag*vdirx, -vmag*vdiry, 0 ]
42  s[j].mass = mass_planet
43  return ens
44 
45 
46  def examine(self):
47  rs = self.ref[0]
48  s = self.ens[0]
49  print rs[1].pos, rs[2].pos, rs[1].vel, rs[2].vel
50  print s[1].pos, s[2].pos
51 
52  x1,y1,z1 = s[1].pos
53  x2,y2,z2 = s[2].pos
54  self.assertAlmostEqual(norm(x2-x1,y2-y1,z2-z1),0)
55 
56