From a8c1f2e1bd5f5831cb6c1b895d8b37be3adfd791 Mon Sep 17 00:00:00 2001 From: Hanno Rein Date: Wed, 1 Jan 2025 17:30:09 -0500 Subject: [PATCH] Improved boundary.c test coverage --- rebound/tests/test_boundary.py | 71 +++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/rebound/tests/test_boundary.py b/rebound/tests/test_boundary.py index 2e56f1fbd..7c653fe65 100644 --- a/rebound/tests/test_boundary.py +++ b/rebound/tests/test_boundary.py @@ -4,29 +4,72 @@ class TestBoundary(unittest.TestCase): def test_open(self): - sim = rebound.Simulation() - sim.boundary = "open" - sim.configure_box(10.) - sim.add(m=0.1,x=1., vx=5.0) - sim.add(m=0.1,x=-1., vx=-5.0) - sim.add(m=0.1,y=1., vx=6.0) - sim.add(m=0.1,x=-1., y=-1., vx=-3., vy=-3.) - self.assertEqual(sim.N,4) - sim.integrate(1.) - self.assertEqual(sim.N,1) - with self.assertRaises(rebound.NoParticles): - sim.integrate(2.) + for gravity in ["basic", "tree"]: + sim = rebound.Simulation() + sim.boundary = "open" + sim.gravity = gravity + sim.configure_box(10.) + sim.add(m=0.1,x=1., vx=5.0) + sim.add(m=0.1,x=-1., vx=-5.0) + sim.add(m=0.1,y=1., vx=6.0) + sim.add(m=0.1,x=-1., y=-1., vx=-3., vy=-3.) + sim.add(m=0.1,z=1., vz=5.0) + sim.add(m=0.1,z=-1., vz=-5.0) + self.assertEqual(sim.N,6) + sim.integrate(1.) + self.assertEqual(sim.N,1) + with self.assertRaises(rebound.NoParticles): + sim.integrate(2.) def test_periodic(self): sim = rebound.Simulation() sim.boundary = "periodic" sim.configure_box(10.) - sim.add(m=0.1,x=1., vx=5.0, vy=15.1, vz=26.) + sim.add(m=0.0,x=1., vx=5.0, vy=15.1, vz=26.) + sim.add(m=0.0,x=-1., vx=-5.0, vy=-15.1, vz=-26.) sim.integrate(1.) self.assertAlmostEqual(sim.particles[0].x,-4,delta=1e-16) + self.assertAlmostEqual(sim.particles[0].y,-4.9,delta=1e-14) + self.assertAlmostEqual(sim.particles[0].z,-4.0,delta=1e-16) + self.assertAlmostEqual(sim.particles[1].x,4,delta=1e-16) sim.integrate(2.) self.assertAlmostEqual(sim.particles[0].x,1,delta=1e-16) - self.assertEqual(sim.N,1) + self.assertAlmostEqual(sim.particles[0].y,0.2,delta=1e-14) + self.assertAlmostEqual(sim.particles[0].z,2.0,delta=1e-16) + self.assertAlmostEqual(sim.particles[1].x,-1,delta=1e-16) + self.assertEqual(sim.N,2) + + def test_shear_vertical(self): + # Note: not physical + sim = rebound.Simulation() + sim.ri_sei.OMEGA = 1 + sim.configure_box(1) + sim.N_ghost_x = 2 + sim.N_ghost_y = 2 + sim.integrator = "sei" + sim.boundary = "shear" + sim.add(z=0.45,vz=100.0) + sim.add(z=-0.45,vz=-100.0) + sim.integrate(1) + self.assertEqual(2,sim.N) + + def test_add_outside(self): + for boundary in ["open", "shear", "periodic"]: + sim = rebound.Simulation() + sim.boundary = boundary + sim.configure_box(10.) + with self.assertRaises(RuntimeError): + sim.add(x=6.) + with self.assertRaises(RuntimeError): + sim.add(x=-6.) + with self.assertRaises(RuntimeError): + sim.add(y=6.) + with self.assertRaises(RuntimeError): + sim.add(y=-6.) + with self.assertRaises(RuntimeError): + sim.add(z=6.) + with self.assertRaises(RuntimeError): + sim.add(z=-6.) if __name__ == "__main__":