Beispiel #1
0
 def test_distance_2d(self):
     point_1 = np.array([np.pi, np.exp(2.5)])
     point_2 = np.array([np.sqrt(2.4), np.pi])
     d1 = G.distance_2d(point_1, point_2)
     d2 = np.linalg.norm(point_1 - point_2)
     d3 = np.linalg.norm(point_1)
     assert d1 == pytest.approx(d2)
     assert G.distance_2d(point_1) == pytest.approx(d3)
Beispiel #2
0
 def test_get_2d_circle(self):
     dx = (10.0)**(np.random.uniform(-2, -1))
     center = np.random.random_sample(2)
     radius = np.random.randint(50, 100) * dx
     x, y = get_2d_circle(dx, radius, center)
     count = 0
     for i in range(len(x)):
         point = np.array([x[i], y[i]])
         dist = distance_2d(point, center)
         if dist >= radius * (1.0 + dx * 1.0e-03):
             count += 1
     assert count == 0
Beispiel #3
0
 def test_get_3d_hollow_cylinder(self):
     dx = 0.17
     radius = np.random.randint(20, 40) * dx
     length = np.random.randint(20, 40) * dx
     center = np.random.random_sample(3)
     num_layers = np.random.randint(1, 5)
     x, y, z = get_3d_hollow_cylinder(dx, radius, length, center,
                                      num_layers)
     x = x - center[0]
     y = y - center[1]
     z = z - center[2]
     count = 0
     for i in range(len(x)):
         point = np.array([x[i], y[i]])
         dist = distance_2d(point)
         condition_1 = dist >= radius * (1.0 + dx * 1.0e-03)
         condition_2 = abs(z[i]) >= (length / 2.0) * (1.0 + dx * 1.0e-03)
         if condition_1 or condition_2:
             count += 1
     assert count == 0
Beispiel #4
0
 def test_remove_overlap_particles(self):
     dx_1 = 0.1
     dx_2 = 0.15
     length = 4.5
     height = 3.0
     radius = 2.0
     x1, y1 = G.get_2d_block(dx_1, length, height)
     x2, y2 = G.get_2d_circle(dx_2, radius)
     r1 = np.ones_like(x1) * 100.0
     m1 = r1 * dx_1 * dx_1
     h1 = np.ones_like(x1) * dx_1 * 1.5
     fluid = get_particle_array(name='fluid',
                                x=x1,
                                y=y1,
                                h=h1,
                                rho=r1,
                                m=m1)
     r2 = np.ones_like(x2) * 100.0
     m2 = r2 * dx_2 * dx_2
     h2 = np.ones_like(x2) * dx_2 * 1.5
     solid = get_particle_array(name='solid',
                                x=x2,
                                y=y2,
                                h=h2,
                                rho=r2,
                                m=m2)
     G.remove_overlap_particles(fluid, solid, dx_2, 2)
     x1 = fluid.x
     y1 = fluid.y
     count = 0
     for i in range(len(x1)):
         point = np.array([x1[i], y1[i]])
         dist = G.distance_2d(point)
         if dist <= radius:
             count += 1
     assert count == 0
Beispiel #5
0
 def test_remove_overlap_particles(self):
     dx_1 = (10)**(np.random.randint(-2, -1))
     dx_2 = (10)**(np.random.randint(-2, -1))
     length = np.random.randint(20, 40) * dx_1
     height = np.random.randint(20, 40) * dx_1
     radius = np.random.randint(20, 40) * dx_2
     x1, y1 = get_2d_block(dx_1, length, height)
     x2, y2 = get_2d_circle(dx_2, radius)
     r1 = np.ones_like(x1) * 100.0
     m1 = r1 * dx_1 * dx_1
     h1 = np.ones_like(x1) * dx_1 * 1.5
     fluid = get_particle_array(name='fluid',
                                x=x1,
                                y=y1,
                                h=h1,
                                rho=r1,
                                m=m1)
     r2 = np.ones_like(x2) * 100.0
     m2 = r2 * dx_2 * dx_2
     h2 = np.ones_like(x2) * dx_2 * 1.5
     solid = get_particle_array(name='solid',
                                x=x2,
                                y=y2,
                                h=h2,
                                rho=r2,
                                m=m2)
     remove_overlap_particles(fluid, solid, dx_2, 2)
     x1 = fluid.x
     y1 = fluid.y
     count = 0
     for i in range(len(x1)):
         point = np.array([x1[i], y1[i]])
         dist = distance_2d(point)
         if dist <= radius:
             count += 1
     assert count == 0
Beispiel #6
0
 def test_distance_2d(self):
     point_1 = np.random.random_sample(2)
     point_2 = np.random.random_sample(2)
     self.assertAlmostEqual(distance_2d(point_1, point_2),
                            np.linalg.norm(point_1 - point_2))