Example #1
0
 def test_get_2d_circle(self):
     dx = 0.05
     radius = 3.0
     center = np.array([1.45, -0.43])
     x, y = G.get_2d_circle(dx, radius, center)
     xc, yc = x - center[0], y - center[1]
     assert not np.any(xc * xc + yc * yc) > radius * radius
Example #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
Example #3
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
Example #4
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
Example #5
0
    def create_particles(self):
        fluid_x, fluid_y = get_2d_block(dx=dx,
                                        length=Lx,
                                        height=Ly,
                                        center=np.array([0., 0.]))
        rho_fluid = np.ones_like(fluid_x) * rho2
        m_fluid = rho_fluid * volume
        h_fluid = np.ones_like(fluid_x) * h0
        cs_fluid = np.ones_like(fluid_x) * c0
        circle_x, circle_y = get_2d_circle(dx=dx,
                                           r=0.2,
                                           center=np.array([0.0, 0.0]))
        rho_circle = np.ones_like(circle_x) * rho1
        m_circle = rho_circle * volume
        h_circle = np.ones_like(circle_x) * h0
        cs_circle = np.ones_like(circle_x) * c0
        wall_x, wall_y = get_2d_block(dx=dx,
                                      length=Lx + 6 * dx,
                                      height=Ly + 6 * dx,
                                      center=np.array([0., 0.]))
        rho_wall = np.ones_like(wall_x) * rho2
        m_wall = rho_wall * volume
        h_wall = np.ones_like(wall_x) * h0
        cs_wall = np.ones_like(wall_x) * c0
        additional_props = [
            'V', 'color', 'scolor', 'cx', 'cy', 'cz', 'cx2', 'cy2', 'cz2',
            'nx', 'ny', 'nz', 'ddelta', 'uhat', 'vhat', 'what', 'auhat',
            'avhat', 'awhat', 'ax', 'ay', 'az', 'wij', 'vmag2', 'N', 'wij_sum',
            'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0', 'kappa', 'arho', 'nu',
            'wg', 'ug', 'vg', 'pi00', 'pi01', 'pi10', 'pi11'
        ]
        consts = {'max_ddelta': np.zeros(1, dtype=float)}
        gas = get_particle_array(name='gas',
                                 x=fluid_x,
                                 y=fluid_y,
                                 h=h_fluid,
                                 m=m_fluid,
                                 rho=rho_fluid,
                                 cs=cs_fluid,
                                 additional_props=additional_props,
                                 constants=consts)
        gas.nu[:] = nu2
        gas.color[:] = 0.0
        liquid = get_particle_array(name='liquid',
                                    x=circle_x,
                                    y=circle_y,
                                    h=h_circle,
                                    m=m_circle,
                                    rho=rho_circle,
                                    cs=cs_circle,
                                    additional_props=additional_props,
                                    constants=consts)
        liquid.nu[:] = nu1
        liquid.color[:] = 1.0
        wall = get_particle_array(name='wall',
                                  x=wall_x,
                                  y=wall_y,
                                  h=h_wall,
                                  m=m_wall,
                                  rho=rho_wall,
                                  cs=cs_wall,
                                  additional_props=additional_props)
        wall.color[:] = 0.0
        remove_overlap_particles(wall, liquid, dx_solid=dx, dim=2)
        remove_overlap_particles(wall, gas, dx_solid=dx, dim=2)
        remove_overlap_particles(gas, liquid, dx_solid=dx, dim=2)
        gas.add_output_arrays([
            'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'kappa', 'N',
            'scolor', 'p'
        ])
        liquid.add_output_arrays([
            'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'kappa', 'N',
            'scolor', 'p'
        ])
        wall.add_output_arrays([
            'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'kappa', 'N',
            'scolor', 'p'
        ])

        for i in range(len(gas.x)):
            R = sqrt(r(gas.x[i], gas.y[i]) + 0.0001 * gas.h[i] * gas.h[i])
            gas.u[i] = v0 * gas.x[i] * (1.0 - (gas.y[i] * gas.y[i]) /
                                        (r0 * R)) * np.exp(-R / r0) / r0
            gas.v[i] = -v0 * gas.y[i] * (1.0 - (gas.x[i] * gas.x[i]) /
                                         (r0 * R)) * np.exp(-R / r0) / r0
        for i in range(len(liquid.x)):
            R = sqrt(
                r(liquid.x[i], liquid.y[i]) +
                0.0001 * liquid.h[i] * liquid.h[i])
            liquid.u[i] = v0*liquid.x[i] * \
                (1.0 - (liquid.y[i]*liquid.y[i])/(r0*R))*np.exp(-R/r0)/r0
            liquid.v[i] = -v0*liquid.y[i] * \
                (1.0 - (liquid.x[i]*liquid.x[i])/(r0*R))*np.exp(-R/r0)/r0
        return [liquid, gas, wall]