示例#1
0
 def testPastCylinder():
     n = 20  # width  - 0x
     m = 40  # length - 0y
     rho = 1.  # density
     v = 0.03
     tau = v * 3. + 0.5  # relaxation time
     t_f = 500  # final time
     u = 0.3
     reynolds = str(m * u / v)
     solid = np.zeros((m, n))
     # circle
     radius = 6
     x0 = 20
     y0 = m / 2
     for i in range(0, n):
         for j in range(0, m):
             if (j - y0)**2 + (i - x0)**2 <= radius**2:
                 solid[j, i] = 1
     userGrid = gd.Grid(n, m)
     bc = flow_past_cylinder(userGrid, u, rho)
     lat_bol = lb.D2Q9(grid=userGrid,
                       iterations=t_f,
                       relaxation_time=tau,
                       boundary=bc,
                       solid_cells=solid,
                       plot_velocity=False)
示例#2
0
 def testPressurePressurePipe():
     n = 50  # length  - 0x
     m = 300  # height - 0y
     v = 0.1  # viscosity
     p_left = 2. / 1.  # left pressure
     p_right = 1. / 1.  # right pressure
     t_f = 500  # final time
     tau = v * 3. + 0.5
     user_grid = gd.Grid(width=m, height=n)
     bc = pipe_pp_bc(grid=user_grid, p_right=p_right, p_left=p_left)
     lat_bol = lb.D2Q9(grid=user_grid,
                       iterations=t_f,
                       boundary=bc,
                       relaxation_time=tau,
                       plot_velocity=False)
示例#3
0
 def testVelocityVelocityPipe():
     n = 50  # length  - 0x
     m = 300  # height - 0y
     v = 0.1  # viscosity
     v_left = 1. / 10.  # left velocity
     v_right = 1. / 10.  # right pressure
     t_f = 500  # final time
     tau = v * 3. + 0.5
     user_grid = gd.Grid(width=m, height=n)
     # boundary conditions
     bc = pipe_vv_bc(grid=user_grid, v_right=v_right, v_left=v_left)
     lat_bol = lb.D2Q9(grid=user_grid,
                       iterations=t_f,
                       boundary=bc,
                       relaxation_time=tau,
                       plot_velocity=False)
示例#4
0
 def testDrivenCavity(self):
     n = 100  # width  - 0x
     m = 100  # length - 0y
     v = 0.1  # viscosity
     tau = v * 3. + 0.5  # relaxation time
     t_f = 500  # final time
     u_x = 0.1
     user_grid = gd.Grid(n, m)
     reynolds = n * u_x / v
     self.assertEqual(reynolds, n)
     bc = driven_cavity_boundaries(user_grid, u_x)
     lat_bol = lb.D2Q9(grid=user_grid,
                       iterations=t_f,
                       boundary=bc,
                       relaxation_time=tau,
                       plot_velocity=False)
示例#5
0
    def testPoiseuilleFlowPeriodicZeroVelocities():
        n = 100  # width  - 0x
        m = 30  # height - 0y
        v = 0.1  # viscosity
        tau = v * 3. + 0.5  # relaxation time
        t_f = 500  # final time
        g = 1e-5
        gravity = gd.LatticeVelocity(g, 0)  # acceleration by gravity

        userGrid = gd.Grid(n, m)
        bc = horizontal_poiseuille_boundaries_zero_v(grid=userGrid)
        lat_bol = lb.D2Q9(grid=userGrid,
                          iterations=t_f,
                          relaxation_time=tau,
                          ext_force=gravity,
                          boundary=bc,
                          plot_velocity=False)
    def start_driven_cavity(self, entries):
        print entries
        n = entries[2][1]  # width  - 0x
        m = entries[2][1]  # length - 0y
        v = entries[1][1]  # viscosity
        tau = self.calc_tau(v)
        t_f = 301  # final time
        u_x = entries[0][1]
        reynolds = n * u_x / v
        velocity = gd.LatticeVelocity(u_x, 0)
        user_grid = gd.Grid(n, m)
        # boundary conditions
        bc = self.driven_cavity_boundaries(user_grid, velocity)

        lat_bol = lb.D2Q9(grid=user_grid,
                          iterations=t_f,
                          boundary=bc,
                          relaxation_time=tau,
                          reynolds=reynolds)
    def start_pipe_flow(self, entries):
        print entries
        n = entries[4][1]  # width  - 0x
        m = entries[3][1]  # length - 0y
        v = entries[2][1]  # viscosity
        t_f = entries[5][1]  # final time
        tau = v * 3. + 0.5
        u_x = entries[0][1]
        p = entries[1][1]
        reynolds = n * u_x / v
        user_grid = gd.Grid(n, m)
        # print isinstance(velocity,lv.LatticeVelocity)
        # boundary conditions
        bc = self.pipe_vp_bc(grid=user_grid, v_left=u_x, p_right=p)
        lat_bol = lb.D2Q9(grid=user_grid,
                          iterations=t_f,
                          boundary=bc,
                          relaxation_time=tau,
                          reynolds=reynolds)

        path = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))
        ps.save_all(lat_bol, path=path)
        ps.plot_streamlines(lat_bol, path=path)
示例#8
0
    n = 60  # width  - 0x
    m = 30  # height - 0y
    rho = 1.  # density
    v = 0.1  # viscosity
    tau = v * 3. + 0.5  # relaxation time
    t = 3675  # final time
    gravity = gd.LatticeVelocity(1e-5, 0)  # acceleration by gravity
    path = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe())))
    userGrid = gd.Grid(n, m)
    bc = horizontal_poiseuille_boundaries2(userGrid)
    lat_bol = lb.D2Q9(
        grid=userGrid,
        # iterations=t,
        check_convergence=True,
        relaxation_time=tau,
        ext_force=gravity,
        boundary=bc,
        plot_velocity=True,
        path=path)

    path = get_path()
    #ps.save_all(lat_bol,path=path)
    ps.plot_poiseuille_solution_0y(lat_bol)
    ps.plot_poiseuille_solution_0x(lat_bol)

    # profile.run('print \
    #              lb.D2Q9(grid=userGrid, \
    #                      iterations=t, \
    #                      relaxation_time=tau, \
    #                      ext_force=gravity, \
    tau = viscosity * 3. + 0.15
    t = 70000  # final time
    u_x = 0.25
    re = (n - 1) * u_x / viscosity
    print(re)
    velocity = gd.LatticeVelocity(u_x, 0)
    userGrid = gd.Grid(n, m)
    bc = driven_cavity_boundaries(userGrid, velocity)
    path = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe())))
    lat_bol = lb.D2Q9(
        grid=userGrid,
        # iterations=t,
        check_convergence=True,
        eps=1e-6,
        boundary=bc,
        relaxation_time=tau,
        reynolds=re,
        plot_velocity=False,
        plot_streamlines=False,
        path=path)
    # print("Viscosity = " + str(lat_bol.viscosity))
    # print("Reynolds number = " + str(re))

    title = "Re_" + str(lat_bol.reynolds) + "_vis_" + str(lat_bol.viscosity) + \
            "_grid_" + str(lat_bol.grid.width) + 'x' + str(lat_bol.grid.height) + '_t_' + str(lat_bol.iterations)
    # print(path)
    ps.save_all(lat_bol, path=path, title=title)
    ps.plot_all(lat_bol)
    # ps.save_data(lat_bol, lat_bol.stream, 'stream',path=path)
    # ps.save_data(lat_bol, lat_bol.vorticity, 'vorticity',path=path)
示例#10
0
    print('Re = ' + str(m * u / v))
    solid = np.zeros((m, n))  # circle shape
    radius = m / 8  # radius of circle
    x0 = n / 7  # (x0,y0) - center of the circle
    y0 = m / 2
    for i in range(0, n):
        for j in range(0, m):
            if (j - y0)**2 + (i - x0)**2 <= radius**2:
                solid[j, i] = 1
    # solid[int(m/2)-20:int(m/2)+20, int(n/10)-20:int(n/10)+20] = 1  # square
    path = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe())))
    userGrid = gd.Grid(n, m)
    bc = flow_past_cylinder_bc(userGrid, u, rho)
    lat_bol = lb.D2Q9(grid=userGrid,
                      iterations=t,
                      relaxation_time=tau,
                      boundary=bc,
                      solid_cells=solid,
                      path=path)
    ps.save_all(lat_bol, path=path)
    ps.plot_streamlines(lat_bol, path=path)
    # print(isinstance(gravity, lv.LatticeVelocity))

    # profile.run('print \
    #              lb.D2Q9(grid=userGrid, \
    #              iterations=t, \
    #              relaxation_time=tau, \
    #              boundary=bc, \
    #              solid_cells=solid); print')
示例#11
0
    assert isinstance(p_right, float), "Incorrect type"
    assert isinstance(p_left, float), "Incorrect type"
    for i in range(0, grid.width):
        boundaries.append(gd.Boundary(grid.top_faces[i], 'zoe_he_velocity', value=u))
        boundaries.append(gd.Boundary(grid.bottom_faces[i], 'zoe_he_velocity', value=u))
    for i in range(0, grid.height):
        boundaries.append(gd.Boundary(grid.left_faces[i], 'zoe_he_pressure', value=p_left))
        boundaries.append(gd.Boundary(grid.right_faces[i], 'zoe_he_pressure', value=p_right))
    return boundaries

if __name__ == "__main__":
    n = 30  # length  - 0x
    m = 200  # height - 0y
    v = 0.1  # viscosity
    p_left = 2. / 1.  # left pressure
    p_right = 1. / 1.  # right pressure
    t_f = 500  # final time
    tau = v * 3. + 0.5
    user_grid = gd.Grid(width=m, height=n)
    # boundary conditions
    bc = pipe_pp_bc(grid=user_grid, p_right=p_right, p_left=p_left)
    lat_bol = lb.D2Q9(grid=user_grid,
                      iterations=t_f,
                      boundary=bc,
                      relaxation_time=tau)


    path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    print(path)
    ps.save_all(lat_bol,path=path)
    ps.plot_streamlines(lat_bol, path=path)