def test10(self): instance = BHTree() instance.initialize_code() instance.parameters.epsilon_squared = 0.00001 | nbody_system.length**2 instance.commit_parameters() particles = datamodel.Particles(6) particles.mass = 1.0 | nbody_system.mass particles.radius = 0.00001 | nbody_system.length particles.position = [[-1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, -1.0], [0.0, 0.0, 1.0] ] | nbody_system.length particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [ 0.0, 0.0, 0.0 ], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0] ] | nbody_system.speed instance.particles.add_particles(particles) instance.commit_particles() zero = 0.0 | nbody_system.length fx, fy, fz = instance.get_gravity_at_point(zero, zero, zero, zero) self.assertAlmostEqual(fx, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fy, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fz, 0.0 | nbody_system.acceleration, 3) for position in (0.25, 0.5, 0.75): p0 = position | nbody_system.length p1 = -position | nbody_system.length for i in range(3): args0 = [zero] * 4 args1 = [zero] * 4 args0[1 + i] = p0 args1[1 + i] = p1 f0 = instance.get_gravity_at_point(*args0) f1 = instance.get_gravity_at_point(*args1) for j in range(3): if j != i: self.assertAlmostEqual(f0[j], 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(f1[j], 0.0 | nbody_system.acceleration, 3) else: self.assertAlmostEqual(f0[j], -1.0 * f1[j], 5) instance.stop()
def test9(self): instance = BHTree() instance.initialize_code() instance.parameters.epsilon_squared = 0.00001 | nbody_system.length**2 particles = datamodel.Particles(2) particles.mass = [1.0, 1.0] | nbody_system.mass particles.radius = [0.0001, 0.0001] | nbody_system.length particles.position = [[0.0, 0.0, 0.0], [2.0, 0.0, 0.0] ] | nbody_system.length particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0] ] | nbody_system.speed instance.particles.add_particles(particles) zero = 0.0 | nbody_system.length fx, fy, fz = instance.get_gravity_at_point(zero, 1.0 | nbody_system.length, zero, zero) self.assertAlmostEqual(fx, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fy, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fz, 0.0 | nbody_system.acceleration, 3) for x in (0.25, 0.5, 0.75): x0 = x | nbody_system.length x1 = (2.0 - x) | nbody_system.length potential0 = instance.get_potential_at_point(zero, x0, zero, zero) potential1 = instance.get_potential_at_point(zero, x1, zero, zero) fx0, fy0, fz0 = instance.get_gravity_at_point(zero, x0, zero, zero) fx1, fy1, fz1 = instance.get_gravity_at_point(zero, x1, zero, zero) self.assertAlmostEqual(fy0, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fz0, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fy1, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fz1, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fx0, -1.0 * fx1, 5) fx = (-1.0 / (x0**2) + 1.0 / (x1**2)) * (1.0 | nbody_system.length**3 / nbody_system.time**2) self.assertAlmostEqual(fx, fx0, 2) self.assertAlmostEqual(potential0, potential1, 5) instance.cleanup_code() instance.stop()
def test10(self): instance = BHTree() instance.initialize_code() instance.parameters.epsilon_squared = 0.00001 | nbody_system.length**2 instance.commit_parameters() particles = datamodel.Particles(6) particles.mass = 1.0 | nbody_system.mass particles.radius = 0.00001 | nbody_system.length particles.position = [[-1.0,0.0,0.0],[1.0,0.0,0.0],[0.0,-1.0,0.0],[0.0,1.0,0.0],[0.0,0.0,-1.0],[0.0,0.0,1.0]] | nbody_system.length particles.velocity = [[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0]] | nbody_system.speed instance.particles.add_particles(particles) instance.commit_particles() zero = 0.0 | nbody_system.length fx, fy, fz = instance.get_gravity_at_point(zero, zero, zero, zero) self.assertAlmostEqual(fx, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fy, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fz, 0.0 | nbody_system.acceleration, 3) for position in (0.25, 0.5, 0.75): p0 = position | nbody_system.length p1 = -position | nbody_system.length for i in range(3): args0 = [zero] * 4 args1 = [zero] * 4 args0[1 + i] = p0 args1[1 + i] = p1 f0 = instance.get_gravity_at_point(*args0) f1 = instance.get_gravity_at_point(*args1) for j in range(3): if j != i: self.assertAlmostEqual(f0[j], 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(f1[j], 0.0 | nbody_system.acceleration, 3) else: self.assertAlmostEqual(f0[j], -1.0 * f1[j], 5) instance.stop()
def test9(self): instance = BHTree() instance.initialize_code() instance.parameters.epsilon_squared = 0.00001 | nbody_system.length**2 particles = datamodel.Particles(2) particles.mass = [1.0, 1.0] | nbody_system.mass particles.radius = [0.0001, 0.0001] | nbody_system.length particles.position = [[0.0,0.0,0.0], [2.0,0.0,0.0]] | nbody_system.length particles.velocity = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]] | nbody_system.speed instance.particles.add_particles(particles) zero = 0.0 | nbody_system.length fx, fy, fz = instance.get_gravity_at_point(zero, 1.0 | nbody_system.length, zero, zero) self.assertAlmostEqual(fx, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fy, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fz, 0.0 | nbody_system.acceleration, 3) for x in (0.25, 0.5, 0.75): x0 = x | nbody_system.length x1 = (2.0 - x) | nbody_system.length potential0 = instance.get_potential_at_point(zero, x0, zero, zero) potential1 = instance.get_potential_at_point(zero, x1, zero, zero) fx0, fy0, fz0 = instance.get_gravity_at_point(zero, x0, zero, zero) fx1, fy1, fz1 = instance.get_gravity_at_point(zero, x1, zero, zero) self.assertAlmostEqual(fy0, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fz0, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fy1, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fz1, 0.0 | nbody_system.acceleration, 3) self.assertAlmostEqual(fx0, -1.0 * fx1, 5) fx = (-1.0 / (x0**2) + 1.0 / (x1**2)) * (1.0 | nbody_system.length ** 3 / nbody_system.time ** 2) self.assertAlmostEqual(fx, fx0, 2) self.assertAlmostEqual(potential0, potential1, 5) instance.cleanup_code() instance.stop()