Commits

trikitrok committed 4e5ca2c

added regression test for a short complete simulation

Comments (0)

Files changed (5)

 
 
 class CollisionRules(object):
-    def __init__(self, box=None, eps=1.0):
+    def __init__(self, box=None, eps=1.0, radius=1.0):
         self.tolerance = 0.0e-10
         self.eps = eps
-        self.radius = 1.0
+        self.radius = radius
         self.box = box if box else Box()
 
     def collide(self, particle_i, particle_j):
         self.time = 0
         self.update_particles()
         self.nprint = nprint
+        self.t_events = []
 
     def update_particles(self):
         for particle in self.particles:
 
             if i % self.nprint == 0:
                 print i,  self.time
+                
+            self.t_events.append(self.time)
 
             if next_event[1] is None:
                 delta_t = self.collision_rules.time_to_next_collision_with_wall(next_event[0])
             return True
     return False
 
-def create_simulation_from_files(coords_filename, vels_filename, **kwargs):
+def create_simulation_from_files(coords_filename, vels_filename, box_size, eps):
     particles = load_initial_particles(coords_filename, vels_filename)
-    rules = CollisionRules(box=Box(kwargs['box_size']), eps=0.0)
+    rules = CollisionRules(Box(box_size), eps)
+    return Simulation(particles, rules)
+
+def create_simulation(num_particles, seed, radius, box_size, eps, minimium_velocity, maximum_velocity):
+    box = Box(box_size)
+    particles = create_random_particles(seed, box, num_particles, radius, minimium_velocity, maximum_velocity)
+    rules = CollisionRules(box, eps, radius)
     return Simulation(particles, rules)
 
 

tests/data/coords_regression.txt

+5.192754108098075250e+00 -8.051253028126454936e+00
+-7.249248960007389497e-01 -4.351337136452056775e+00
+-5.527469948196050531e+00 -6.361679281784905271e+00
+-8.206180056441844783e+00 4.796107441215535783e-01
+4.576555112700224193e+00 -3.212899199377071913e+00
+-7.747363475125866872e-01 -1.157373701534148314e+00
+3.412797466898639609e+00 1.868747403211927782e+00
+6.803860143307101538e+00 -3.734235943580657580e+00
+-7.995815869128333198e+00 6.208228241974766526e+00
+1.605449768223229379e-01 6.572171273568396366e+00
+-2.997121858469443900e+00 5.321362424248744283e+00
+-3.389253104770272973e+00 -6.969596375212787187e+00
+5.497880364309415846e+00 -5.269703079388734501e+00
+8.468775181972086230e+00 -1.361318477218851353e+00
+-8.735175617350321886e+00 -3.020487269663816310e+00
+-3.686547681403062438e+00 1.400523336159249066e+00
+7.712598093680755440e+00 4.547619233008582285e+00
+-4.039617836476782742e+00 -8.860899025703268705e+00
+-8.214061752997835697e+00 8.607297509844672234e+00
+2.172892034845709475e+00 -6.135807328821433870e+00
+-5.971010259733249725e+00 5.110431446717159432e+00
+-1.358534693479419797e+00 1.038119410408218979e+00
+1.940371317065982648e+00 -8.400311612668300398e+00
+-3.941916129031243887e+00 -1.151206077801876448e+00
+7.029663098193872361e-01 3.593881509034603461e+00
+6.742314646458854810e+00 2.588653795853289363e+00
+-7.441898802414355529e+00 -5.769537989416074097e+00
+-8.725637031969705859e+00 -8.889157233561796545e+00
+-4.607739017975026385e+00 6.739476699140942273e+00
+4.478581628181805385e+00 -9.125820468111075501e-01

tests/data/t_events_regression.txt

+0.000000000000000000e+00
+1.111563317756657510e-01
+3.414993091893134824e-01
+7.209729180970664286e-01
+8.301441566947364015e-01
+8.409774347151965923e-01
+8.862995611930462037e-01
+9.436275525745366766e-01
+1.027356551490673731e+00
+1.114700637120318971e+00

tests/data/vels_regression.txt

+2.672964698525508442e-01 4.976077650772237071e-01
+-6.038742704807520401e-01 5.210614243979174720e-01
+3.707196367355944933e-01 9.067866923898730835e-01
+6.252419233042270097e-01 2.250521336587762988e-01
+-3.335257192327150122e-01 5.434878552284693187e-01
+2.355339569386343257e-01 2.627648510878177746e-02
+6.104463936654929146e-01 4.329430478726825626e-02
+6.918924640040990948e-01 -8.801297097763177701e-02
+-9.062073612215004736e-01 2.525742966227850772e-01
+-6.021049206423754185e-01 7.137006049154663856e-01
+2.741195659369326521e-01 6.178161653903169181e-02
+7.736070775334974448e-02 3.695448590251937393e-02
+-5.736709038192833177e-01 4.635982202945526098e-01
+-6.522456876854796359e-01 -4.972517315858813181e-01
+8.407738196880716330e-01 -3.890801633143634586e-01
+-3.073056998399339435e-01 -9.138052875900111172e-01
+7.561932854497166456e-01 -1.649817123214660786e-01
+-6.861770985581057136e-01 -3.341854875922735113e-01
+-3.205843127242726798e-01 -9.902738235091357311e-03
+-8.131505437205510667e-01 3.327059429336148844e-02
+-7.862408312128617016e-01 4.892064815511212306e-01
+-7.047596154294046844e-01 -6.319303558136974974e-01
+-5.886691003659147992e-01 -2.728217877079940901e-01
+8.444655738070925288e-01 8.507137457355535837e-01
+-7.029330972870828642e-01 -1.430985220642071454e-01
+5.654296364899422667e-01 6.970183637894291628e-01
+1.475524629024043133e-01 -4.123368895924639510e-01
+6.307463239714690140e-01 8.619333167654918970e-01
+-7.664971282287542653e-01 -3.348507845746939715e-02
+-9.511347100336717819e-01 7.136620852555051187e-01

tests/test_edmd.py

 def test_update():
     coords_filename = "./tests/data/coords_ini_test_events.txt"
     vels_filename = "./tests/data/v_ini_test_events.txt"
-    sim = edmd.create_simulation_from_files(coords_filename, vels_filename, box_size=10)
+    sim = edmd.create_simulation_from_files(coords_filename, vels_filename, 10, 0.0)
     expeted = array([float(line.split(';')[0]) for line in open('tests/data/events.txt')])
     result = array(sorted(sim.events.keys()))
     assert(all(np.abs(expeted - result) < 1e-4))
      part2 = Particle([0, 2], [0, 0])
      assert(not part1.overlaps_with(part2, 1))
      
+def test_complete_short_simulation():
+    radius = 1.0
+    maximum_velocity = 1.0
+    minimium_velocity = -1.0;
+    seed = 10
+    num_particles = 30
+    eps = 0.5
+    box_size = 10
+    sim = edmd.create_simulation(num_particles, seed, radius, box_size, eps, minimium_velocity, maximum_velocity)
+    sim.run(10)
+    assert(np.all(np.loadtxt("tests/data/coords_regression.txt") == [particle.x for particle in sim.particles]))
+    assert(np.all(np.loadtxt("tests/data/vels_regression.txt") == [particle.v for particle in sim.particles]))
+    assert(np.all(np.loadtxt("tests/data/t_events_regression.txt") == sim.t_events))