10 def fill(list_like,initial_value):
11 for i
in range(0,len(list_like)):
12 list_like[i] = initial_value
15 def make_test_case(nsys = 16, nbod = 3 , spacing_factor = 1.4, planet_mass = 0.001, ejection_factor = 1, seed = None):
18 for i
in range(0,d.nsys):
23 s[0].pos = [ 0, 0, 0 ]
24 s[0].vel = [ 0, 0, 0 ]
27 for j
in range(0,d.nbod):
28 fill(s[j].attributes, 0)
30 for j
in range(1,d.nbod):
31 r = spacing_factor ** (j-1)
32 v = sqrt(1/r) * ejection_factor
33 phi = random.uniform(0,2*pi)
34 s[j].pos = [ r*cos(phi), r*sin(phi), 0 ]
35 s[j].vel = [ -v*sin(phi), v*cos(phi), 0 ]
36 s[j].mass = planet_mass
41 return sqrt(sum(x**2
for x
in l))
44 class BasicIntegration(abstract.IntegrationTest):
46 integrator =
'hermite_cpu',
50 def createEnsemble(self):
51 return make_test_case(nsys = 16, nbod = 3, spacing_factor=1.4)
54 self.assertLess(max_deltaE, 1e-13)
57 class InitialConditions(unittest.TestCase):
59 ref = make_test_case(nsys = 16, nbod = 3, spacing_factor=1.4, seed = 14321)
60 ref.save_to_text(
"sample.txt")
61 r =
system(
"diff sample.txt '{0}'".format(path.join(TESTDIR,
"ref.txt")) )
62 self.assertEqual(r, 0)
65 class EjectionTest(abstract.IntegrationTest):
68 integrator =
"hermite_cpu",
71 deactivate_on_ejection = 1,
74 destination_time = 100
76 def createEnsemble(self):
77 return make_test_case(nsys=20, nbod = 6, spacing_factor=1.01);
82 if( b.distance_to_origin() > self.RMAX ):
83 self.assertEqual(sys.state, -1,
"a system with an ejected body should be disabled")