示例#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
    def __init__(self,
                 grid=None,
                 iterations=1000,
                 eps=None,
                 check_convergence=False,
                 solid_cells=None,
                 relaxation_time=None,
                 density=None,
                 ext_force=None,
                 boundary=None,
                 reynolds=None,
                 plot_velocity=True,
                 plot_streamlines=True,
                 path=None):

        global Q, D, e, w, c, c_s2, dt
        w = self.initialize_weights()
        e = self.initialize_normal_velocities()
        self.iterations = iterations
        self.grid = (grid, gd.Grid(10, 10))[grid is None]
        self.solid = (solid_cells, np.zeros(
            (self.grid.height, self.grid.width)))[solid_cells is None]
        self.bc = (boundary, gd.default_poiseuille_boundaries(
            self.grid))[boundary is None]
        self.tau = (relaxation_time,
                    1)[relaxation_time is None]  # short 'if-else' statement
        self.initial_density = (density, 1)[density is None]
        self.applied_force = (ext_force,
                              gd.LatticeVelocity(0., 0.))[ext_force is None]
        self.viscosity = (1. / 3.) * (self.tau - 0.5)
        self.reynolds = (reynolds, 0)[reynolds is None]
        self.f, self.u, self.rho = self.initialize(self.grid.width,
                                                   self.grid.height)
        self.stream = np.zeros((self.grid.height, self.grid.width))
        self.vorticity = np.zeros((self.grid.height, self.grid.width))
        if path is None:
            path = os.path.dirname(
                os.path.abspath(inspect.getfile(inspect.currentframe())))
        title = ''
        # elapsed_time=0
        start = timer()
        if check_convergence:
            self.iterations = 0
            eps = (eps, 1e-8)[eps is None]
            while True:
                ux_temp = np.copy(self.u.x)
                uy_temp = np.copy(self.u.y)
                rho_temp = np.copy(self.rho)
                mv.compute_macroscopic(self, e)
                if (self.applied_force.x != 0) | (self.applied_force.y != 0):
                    self.external_force()
                if self.converge(ux=ux_temp, uy=uy_temp, rho=rho_temp,
                                 eps=eps):
                    if self.iterations > 100:
                        break
                self.collision_step()
                self.streaming_step()
                self.boundary_conditions()
                if (self.iterations % 50 == 0) & (self.iterations > 0):
                    print(self.iterations)
                    title = "Re_" + str(self.reynolds) + "_vis_" + str(self.viscosity) + \
                            "_grid_" + str(self.grid.width) + 'x' + str(self.grid.height) + '_t_' + str(self.iterations)
                    if plot_streamlines:
                        if self.iterations % 500 == 0:
                            ps.plot_streamlines(self,
                                                title=title,
                                                path=path,
                                                save=True)
                    if plot_velocity:
                        ps.plot_ux(self, title=title, path=path)
                        ps.plot_uy(self, title=title, path=path)
                self.iterations += 1
                print self.iterations
        else:
            for i in range(0, self.iterations + 1):
                mv.compute_macroscopic(self, e)
                if (self.applied_force.x != 0) | (self.applied_force.y != 0):
                    self.external_force()
                self.collision_step()
                self.streaming_step()
                self.boundary_conditions()

                if (i % 50 == 0) & (i > 0):
                    print(i)
                    title = "Re_" + str(self.reynolds) + "_vis_" + str(self.viscosity) + \
                            "_grid_" + str(self.grid.width) + 'x' + str(self.grid.height) + '_t_' + str(i)
                    if plot_streamlines:
                        if i % 500 == 0:
                            ps.plot_streamlines(self,
                                                title=title,
                                                path=path,
                                                save=True)
                    if plot_velocity:
                        ps.plot_ux(self, title=title, path=path)
                        ps.plot_uy(self, title=title, path=path)

        elapsed_time = timer() - start
        print(str(elapsed_time) + " sec.")
示例#9
0
        return False

    def velocity_stream_and_vorticity(self):
        # todo return vorticity and stream, save them
        u = np.array(self.u.x)
        v = np.array(self.u.y)
        int_u_x = it.simps(u, axis=1)
        int_u_y = it.simps(u, axis=0)
        int_v_x = it.simps(v, axis=1)
        int_v_y = it.simps(v, axis=0)
        self.stream = int_u_y[
            np.newaxis, :] - int_v_x[:, np.newaxis]  # stream function (psi)
        self.vorticity = int_u_x[:, np.newaxis] + int_v_y[
            np.newaxis, :]  # vorticity


if __name__ == "__main__":
    n = 30  # width  - lx
    m = 60  # height - ly
    t = 500  # final time
    gravity = gd.LatticeVelocity(0, 1e-8)  # acceleration by gravity
    solid = np.zeros((Q, n, m))

    userGrid = gd.Grid(n, m)
    lat_bol = D2Q9(grid=userGrid,
                   iterations=t,
                   ext_force=gravity,
                   plot_velocity=False,
                   plot_streamlines=False)
    ps.plot_poiseuille_solution_0x(lat_bol)
示例#10
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)