def setUp(self): self.l = l = 1.0 n = 20 dx = l / n hdx = 1.5 x, y, z = G.get_3d_block(dx, l, l, l) h = np.ones_like(x) * hdx * dx m = np.ones_like(x) * dx * dx * dx V = np.zeros_like(x) fluid = get_particle_array(name='fluid', x=x, y=y, z=z, h=h, m=m, V=V) x, y = G.get_2d_block(dx, l, l) z = np.ones_like(x) * (l + 5 * dx) / 2.0 z = np.concatenate([z, -z]) x = np.tile(x, 2) y = np.tile(y, 2) m = np.ones_like(x) * dx * dx * dx h = np.ones_like(x) * hdx * dx V = np.zeros_like(x) channel = get_particle_array(name='channel', x=x, y=y, z=z, h=h, m=m, V=V) self.particles = [fluid, channel] self.kernel = get_compiled_kernel(Gaussian(dim=3))
def create_an_unsymmetric_body(dx, l, b, h): # create a rigid body x, y, z = get_3d_block(dx, l, b, h, center=[l / 2., b / 2., h / 2.]) fltr = (x > l / 4.) & (y < b / 4.) & (z < h / 6.) x = x[~fltr] y = y[~fltr] z = z[~fltr] return x, y, z
def test_get_3d_block(self): dx = 0.23 length = 3.0 height = 2.0 depth = 1.5 center = np.array([0.4, np.pi, -1.6]) x, y, z = G.get_3d_block(dx, length, height, depth, center) len_x = max(x) - min(x) len_y = max(y) - min(y) len_z = max(z) - min(z) new_center = np.array([(max(x) + min(x)) / 2.0, (max(y) + min(y)) / 2.0, (max(z) + min(z)) / 2.0]) assert len_x == pytest.approx(length) assert len_y == pytest.approx(height) assert len_z == pytest.approx(depth) assert np.allclose(center, new_center)
def test_get_3d_block(self): dx = 0.23 center = np.random.random_sample(3) length = np.random.randint(50, 100) * dx height = np.random.randint(50, 100) * dx depth = np.random.randint(50, 100) * dx x, y, z = get_3d_block(dx, length, height, depth, center) len_x = max(x) - min(x) len_y = max(y) - min(y) len_z = max(z) - min(z) new_center = np.array([(max(x) + min(x)) / 2.0, (max(y) + min(y)) / 2.0, (max(z) + min(z)) / 2.0]) self.assertAlmostEqual(len_x, length) self.assertAlmostEqual(len_y, height) self.assertAlmostEqual(len_z, depth) assert np.allclose(center, new_center)