def test_single_wall_mobility_zero_at_wall(self): ''' Test that single wall mobility from Swan Brady paper is zero for very small particles at the wall. ''' a = 0.0001 r_vectors = [np.array([0., 0., a]), np.array([1., 1., 8.])] mobility = mb.single_wall_fluid_mobility(r_vectors, 1., a) for j in range(3): for k in range(3): self.assertAlmostEqual(mobility[j, 3 + k], 0.0, places=6)
def test_single_wall_mobility_zero_at_wall(self): ''' Test that single wall mobility from Swan Brady paper is zero for very small particles at the wall. ''' a = 0.0001 r_vectors = [np.array([0., 0., a]), np.array([1., 1., 8.])] mobility = mb.single_wall_fluid_mobility(r_vectors, 1., a) for j in range(3): for k in range(3): self.assertAlmostEqual(mobility[j, 3 + k], 0.0, places=6)
def test_finite_size_limit(self): ''' Test that the finite size mobility goes to the oseen for small a.''' n_particles = 4 a = 0.000001 # Random configuration, all above wall. r_vectors = [np.random.normal(5., 1., 3) for _ in range(n_particles)] mobility_finite = mb.single_wall_fluid_mobility(r_vectors, 1., a) mobility_point = mb.image_singular_stokeslet(r_vectors, 1.0, a) for j in range(3*n_particles): for k in range(3*n_particles): # We multiply by a to get reasonable numbers for mobility. self.assertAlmostEqual(a*mobility_finite[j,k], a*mobility_point[j,k])
def test_finite_size_limit(self): ''' Test that the finite size mobility goes to the oseen for small a.''' n_particles = 4 a = 0.000001 # Random configuration, all above wall. r_vectors = [np.random.normal(5., 1., 3) for _ in range(n_particles)] mobility_finite = mb.single_wall_fluid_mobility(r_vectors, 1., a) mobility_point = mb.image_singular_stokeslet(r_vectors, 1.0, a) for j in range(3 * n_particles): for k in range(3 * n_particles): # We multiply by a to get reasonable numbers for mobility. self.assertAlmostEqual(a * mobility_finite[j, k], a * mobility_point[j, k])
def test_boosted_v_python_agreement(self): ''' Test that for random R vectors, the boosted and python versions of mobility agree.''' location = [np.random.normal(10., 3., 3) for _ in range(4)] eta = 1.0 a = 0.25 fluid_mobility = mb.single_wall_fluid_mobility(location, eta, a) fluid_mobility_boost = mb.boosted_single_wall_fluid_mobility( location, eta, a) for i in range(len(fluid_mobility)): for j in range(len(fluid_mobility[0])): self.assertAlmostEqual(fluid_mobility[i, j], fluid_mobility_boost[i, j])
def test_boosted_v_python_agreement(self): ''' Test that for random R vectors, the boosted and python versions of mobility agree.''' location = [np.random.normal(10., 3., 3) for _ in range(4)] eta = 1.0 a = 0.25 fluid_mobility = mb.single_wall_fluid_mobility(location, eta, a) fluid_mobility_boost = mb.boosted_single_wall_fluid_mobility( location, eta, a) for i in range(len(fluid_mobility)): for j in range(len(fluid_mobility[0])): self.assertAlmostEqual(fluid_mobility[i, j], fluid_mobility_boost[i, j])
def test_single_wall_mobility_spd(self): ''' Test that single wall mobility from Swan Brady paper is SPD. ''' # Number of particles n_particles = 5 height = 10. def is_pos_def(x): return np.all(np.linalg.eigvals(x) > 0) # Random configuration. r_vectors = [np.random.normal(height, 1., 3) for _ in range(n_particles)] mobility = mb.single_wall_fluid_mobility(r_vectors, 1., 1.) self.assertTrue(is_pos_def(mobility)) for j in range(3*n_particles): for k in range(j+1, 3*n_particles): self.assertAlmostEqual(mobility[j, k], mobility[k, j])
def test_single_wall_mobility_spd(self): ''' Test that single wall mobility from Swan Brady paper is SPD. ''' # Number of particles n_particles = 5 height = 10. def is_pos_def(x): return np.all(np.linalg.eigvals(x) > 0) # Random configuration. r_vectors = [ np.random.normal(height, 1., 3) for _ in range(n_particles) ] mobility = mb.single_wall_fluid_mobility(r_vectors, 1., 1.) self.assertTrue(is_pos_def(mobility)) for j in range(3 * n_particles): for k in range(j + 1, 3 * n_particles): self.assertAlmostEqual(mobility[j, k], mobility[k, j])
u_no_wall_pycuda = mob.no_wall_mobility_trans_times_force_pycuda(r_vectors, force, eta, a) timer('zz_no_wall_pycuda') u_no_wall_pycuda = mob.no_wall_mobility_trans_times_force_pycuda(r_vectors, force, eta, a) timer('zz_no_wall_pycuda') # ================================================================ # WALL TESTS # ================================================================ timer('python_loops') mobility_loops = mob.single_wall_fluid_mobility_loops(r_vectors, eta, a) u_loops = np.dot(mobility_loops, force.flatten()) timer('python_loops') timer('python') mobility = mob.single_wall_fluid_mobility(r_vectors, eta, a) u = np.dot(mobility, force.flatten()) timer('python') u_numba = mob.single_wall_mobility_trans_times_force_numba(r_vectors, force, eta, a) timer('numba') u_numba = mob.single_wall_mobility_trans_times_force_numba(r_vectors, force, eta, a, periodic_length = L) timer('numba') if found_pycuda: u_gpu = mob.single_wall_mobility_trans_times_force_pycuda(r_vectors, force, eta, a) timer('pycuda') u_gpu = mob.single_wall_mobility_trans_times_force_pycuda(r_vectors, force, eta, a, periodic_length = L) timer('pycuda') if found_cpp:
u_no_wall_pycuda = mob.no_wall_mobility_trans_times_force_pycuda(r_vectors, force, eta, a) timer('zz_no_wall_pycuda') u_no_wall_pycuda = mob.no_wall_mobility_trans_times_force_pycuda(r_vectors, force, eta, a) timer('zz_no_wall_pycuda') # ================================================================ # WALL TESTS # ================================================================ timer('python_loops') mobility_loops = mob.single_wall_fluid_mobility_loops(r_vectors, eta, a) u_loops = np.dot(mobility_loops, force.flatten()) timer('python_loops') timer('python') mobility = mob.single_wall_fluid_mobility(r_vectors, eta, a) u = np.dot(mobility, force.flatten()) timer('python') if found_boost: timer('boost_full_matrix') mobility_boost = mob.boosted_single_wall_fluid_mobility(r_vectors, eta, a) u_boost_full = np.dot(mobility_boost, force.flatten()) timer('boost_full_matrix') timer('boost') force_hstack=np.hstack(force) u_boost = mob.boosted_mobility_vector_product(r_vectors, force_hstack, eta, a, periodic_length = L) timer('boost')