Commits

remosu committed 3b572fb

loading initials coords from the command line

Comments (0)

Files changed (2)

 
 
 class CollisionRules(object):
-    def __init__(self, box, eps=0.0):
+    def __init__(self, box, eps=1.0):
         self.tolerance = 10.0e-10
         self.eps = eps
         self.radius = 1.0
 
 
 if __name__ == '__main__':
-    coords_filename = "./tests/data/coords_ini_test_events.txt"
-    vels_filename = "./tests/data/v_ini_test_events.txt"
+    import sys
+    coords_filename = "./tests/data/coords_ini_test_update.txt"
+    if len(sys.argv) > 1:
+        coords_filename = sys.argv[1]
+    vels_filename = "./tests/data/v_ini_test_update.txt"
+    if len(sys.argv) > 2:
+        vels_filename = sys.argv[2]
     sim = create_simulation_from_files(coords_filename, vels_filename, box_size=10)
-    print "koko"
     sim.run(100)

tests/test_edmd.py

     assert(particle_j.v[0] == 1 and particle_j.v[1] == 1)
 
 
+def test_inelastic_collide():
+    collision_rules = CollisionRules(Box(), 0.0)
+    particle_i = Particle(np.random.random(2) * 10, np.random.random(2) * 10)
+    particle_j = Particle(np.random.random(2) * 10, np.random.random(2) * 10)
+
+    collision_rules.collide(particle_i, particle_j)
+
+    vi_norm = np.dot(particle_i.x - particle_j.x, particle_i.v)
+    vj_norm = np.dot(particle_i.x - particle_j.x, particle_j.v)
+
+    assert(abs(vi_norm - vj_norm) < 1e-10)
+
+
+def test_elastic_collide():
+    collision_rules = CollisionRules(Box(), 1.0)
+    particle_i = Particle(np.random.random(2) * 10, np.random.random(2) * 10)
+    particle_j = Particle(np.random.random(2) * 10, np.random.random(2) * 10)
+    vi_norm_before = np.dot(particle_i.x - particle_j.x, particle_i.v)
+    vj_norm_before = np.dot(particle_i.x - particle_j.x, particle_j.v)
+
+    collision_rules.collide(particle_i, particle_j)
+
+    vi_norm_after = np.dot(particle_i.x - particle_j.x, particle_i.v)
+    vj_norm_after = np.dot(particle_i.x - particle_j.x, particle_j.v)
+
+    assert(abs(vi_norm_before - vj_norm_after) < 1e-10)
+    assert(abs(vj_norm_before - vi_norm_after) < 1e-10)
+
+
 def test_move_1():
     particle_i = Particle(array([0, 0]), array([1, 0]), 0)