def test_collision_routine_sphere(): # Initialize the Ellipsoids el1 = Ellipsoid(1, 5, 5, 5, 2.0, 2.0, 2.0, np.array([0.52532199, 0., -0., 0.85090352])) el2 = Ellipsoid(2, 5.5, 5.5, 5.5, 2.0, 2.0, 2.0, np.array([0.52532199, 0., -0., 0.85090352])) el1.speedx, el1.speedy, el1.speedz = 0.1, 0.075, -0.05 el2.speedx, el2.speedy, el2.speedz = -0.1, -0.025, -0.36 # Test if the 'collision_react' function is called twice with mock.patch( 'kanapy.collision_detect_react.collision_react') as mocked_method: collision_routine(el1, el2) assert mocked_method.call_count == 2
def test_particle_grow(rot_surf): ell1 = Ellipsoid(1, 1, 0.5, 0.75, 2.0, 1.5, 1.5, rot_surf[0]) ell2 = Ellipsoid(2, 1.9, 1.68, 2.6, 2.0, 1.5, 1.5, rot_surf[0]) ell1.speedx, ell1.speedy, ell1.speedz = -0.02, 0.075, -0.05 ell2.speedx, ell2.speedy, ell2.speedz = 0.5, -0.025, -0.36 ells = [ell1, ell2] sb = Simulation_Box(10, 10, 10) particle_grow(sb, ells, True, 10) assert round(ell1.x, 6) == 0.78 assert round(ell1.y, 6) == 1.325 assert round(ell1.z, 6) == 0.2 assert round(ell2.x, 6) == 7.4 assert round(ell2.y, 6) == 1.405 assert round(ell2.z, 6) == 8.64
def particle_generator(particle_data, sim_box): """ Initializes ellipsoids by assigning them random positions and speeds within the simulation box. :param particle_data: Ellipsoid information such as such as Major, Minor, Equivalent diameters and its tilt angle. :type particle_data: Python dictionary :param sim_box: Simulation box representing RVE. :type sim_box: :class:`entities.Simulation_Box` :returns: Ellipsoids for the packing routine :rtype: list """ num_particles = particle_data['Number'] # Total number of ellipsoids Ellipsoids = [] for n in range(num_particles): iden = n+1 # ellipsoid 'id' a = particle_data['Major_diameter'][n] / 2. # Semi-major length b = particle_data['Minor_diameter1'][n] / 2. # Semi-minor length 1 c = particle_data['Minor_diameter2'][n] / 2. # Semi-minor length 2 # Random placement for ellipsoids x = random.uniform(c, sim_box.w - c) y = random.uniform(c, sim_box.h - c) z = random.uniform(c, sim_box.d - c) # Angle represents inclination of Major axis w.r.t positive x-axis angle = np.radians(particle_data['Orientation'][n]) # Extract the angle vec_a = np.array([a*np.cos(angle), a*np.sin(angle), 0.0]) # Tilt vector wrt (+ve) x axis cross_a = np.cross(np.array([1, 0, 0]), vec_a) # Do the cross product to find the quaternion axis norm_cross_a = np.linalg.norm(cross_a, 2) # norm of the vector (Magnitude) quat_axis = cross_a/norm_cross_a # normalize the quaternion axis # Find the quaternion components qx, qy, qz = quat_axis * np.sin(angle/2) qw = np.cos(angle/2) quat = np.array([qw, qx, qy, qz]) # instance of Ellipsoid class ellipsoid = Ellipsoid(iden, x, y, z, a, b, c, quat) ellipsoid.color = (random.randint(0, 255), random.randint( 0, 255), random.randint(0, 255)) # Define random speed values along the 3 axes x, y & z ellipsoid.speedx = np.random.uniform(low=-c/20., high=c/20.) ellipsoid.speedy = np.random.uniform(low=-c/20., high=c/20.) ellipsoid.speedz = np.random.uniform(low=-c/20., high=c/20.) Ellipsoids.append(ellipsoid) # adds ellipsoid to list return Ellipsoids
def test_collision_react(): # Initialize the Ellipsoids el1 = Ellipsoid(1, 5, 5, 5, 2.0, 2.0, 2.0, np.array([0.52532199, 0., -0., 0.85090352])) el2 = Ellipsoid(2, 5.5, 5.5, 5.5, 2.0, 2.0, 2.0, np.array([0.52532199, 0., -0., 0.85090352])) el1.speedx, el1.speedy, el1.speedz = 0.1, 0.075, -0.05 el2.speedx, el2.speedy, el2.speedz = -0.1, -0.025, -0.36 # Test different conditions # Condition: xdiff > 0 && zdiff > 0 collision_react(el1, el2) collision_react(el2, el1) assert round(el1.speedx, 6) == -0.077728 assert round(el1.speedy, 6) == -0.077728 assert round(el1.speedz, 6) == -0.077728 assert round(el2.speedx, 6) == 0.216198 assert round(el2.speedy, 6) == 0.216198 assert round(el2.speedz, 6) == 0.216198 # Condition: xdiff > 0 && zdiff < 0 el2.z = 4.5 collision_react(el1, el2) collision_react(el2, el1) assert round(el1.speedx, 6) == -0.077728 assert round(el1.speedy, 6) == -0.077728 assert round(el1.speedz, 6) == 0.077728 assert round(el2.speedx, 6) == 0.216198 assert round(el2.speedy, 6) == 0.216198 assert round(el2.speedz, 6) == -0.216198 # Condition: xdiff < 0 && zdiff > 0 el2.x = 4.5 el2.z = 5.5 collision_react(el1, el2) collision_react(el2, el1) assert round(el1.speedx, 6) == 0.077728 assert round(el1.speedy, 6) == -0.077728 assert round(el1.speedz, 6) == -0.077728 assert round(el2.speedx, 6) == -0.216198 assert round(el2.speedy, 6) == 0.216198 assert round(el2.speedz, 6) == 0.216198 # Condition: xdiff < 0 && zdiff < 0 el2.x = 4.5 el2.z = 4.5 collision_react(el1, el2) collision_react(el2, el1) assert round(el1.speedx, 6) == 0.077728 assert round(el1.speedy, 6) == -0.077728 assert round(el1.speedz, 6) == 0.077728 assert round(el2.speedx, 6) == -0.216198 assert round(el2.speedy, 6) == 0.216198 assert round(el2.speedz, 6) == -0.216198 # Condition: xdiff = 0 && zdiff = 0 el2.x = 5.0 el2.z = 5.0 collision_react(el1, el2) collision_react(el2, el1) assert round(el1.speedx, 6) == 0.000038 assert round(el1.speedy, 6) == 0.134629 assert round(el1.speedz, 6) == 0.0 assert round(el2.speedx, 6) == 0.000106 assert round(el2.speedy, 6) == -0.374466 assert round(el2.speedz, 6) == 0.0 # Condition: xdiff = 0 && zdiff > 0 el2.x = 5.0 el2.z = 5.5 collision_react(el1, el2) collision_react(el2, el1) assert round(el1.speedx, 6) == 0.0 assert round(el1.speedy, 6) == 0.095197 assert round(el1.speedz, 6) == -0.095197 assert round(el2.speedx, 6) == 0.0 assert round(el2.speedy, 6) == -0.264788 assert round(el2.speedz, 6) == 0.264788 # Condition: xdiff = 0 && zdiff < 0 el2.x = 5.0 el2.z = 4.5 collision_react(el1, el2) collision_react(el2, el1) assert round(el1.speedx, 6) == 0.0 assert round(el1.speedy, 6) == 0.095197 assert round(el1.speedz, 6) == 0.095197 assert round(el2.speedx, 6) == 0.0 assert round(el2.speedy, 6) == -0.264788 assert round(el2.speedz, 6) == -0.264788 # Condition: xdiff < 0 && zdiff = 0 el2.x = 4.5 el2.z = 5.0 collision_react(el1, el2) collision_react(el2, el1) assert round(el1.speedx, 6) == 0.095197 assert round(el1.speedy, 6) == 0.095197 assert round(el1.speedz, 6) == 0.0 assert round(el2.speedx, 6) == -0.264788 assert round(el2.speedy, 6) == -0.264788 assert round(el2.speedz, 6) == 0.0 # Condition: xdiff > 0 && zdiff = 0 el2.x = 5.5 el2.z = 5.0 collision_react(el1, el2) collision_react(el2, el1) assert round(el1.speedx, 6) == -0.095197 assert round(el1.speedy, 6) == 0.095197 assert round(el1.speedz, 6) == 0.0 assert round(el2.speedx, 6) == 0.264788 assert round(el2.speedy, 6) == -0.264788 assert round(el2.speedz, 6) == 0.0