Ejemplo n.º 1
0
    eps = 1e-6
    for k in xrange(n_nodes):
        x, y = pts[k]
        if (np.fabs(x - 1) < eps or  #np.fabs(x - (-1)) < eps or
                np.fabs(y - 1) < eps):  # or np.fabs(y - (-1)) < eps):
            bc_nodes[k] = 1

    return bc_nodes


if __name__ == "__main__":
    # Try the quad mesh with Q1 elements:
    if True:
        import poisson_optimized as poisson
        # import poisson
        pts, quads, tri = create_mesh.quad_rectangle(0, 1, 0, 1, 21, 21)
        bc_nodes = set_bc_nodes_square(pts)

        # forcing term at mesh nodes
        f_pts = f(pts)
        # Dirichlet boundary conditions at *all* mesh nodes (most of these values are not used)
        u_bc_pts = u_bc(pts)

        # Set up the system and solve:
        tic = time.clock()
        A, b = poisson.poisson(pts, quads, bc_nodes, f_pts, u_bc_pts,
                               FEM.Q1Aligned, FEM.GaussQuad2x2())
        toc = time.clock()
        print "Matrix assembly took %f s" % (toc - tic)

        if pts.shape[0] < 50:
Ejemplo n.º 2
0
        x = pts[:, 0]
        y = pts[:, 1]
    except:
        x = pts[0]
        y = pts[1]

    return 2.0 * (1 + y) / ((3 + x)**2 + (1 + y)**2)


errors = []
Ns = np.array([5, 11, 21, 41, 81])
for n in Ns:
    print "Running with N = %d" % n

    tic = time.clock()
    pts, quads, tri = create_mesh.quad_rectangle(-1, 1, -1, 1, n, n)
    bc_nodes = set_bc_nodes_square(pts)
    toc = time.clock()
    print "Mesh generation took %f s" % (toc - tic)

    f_pts = f(pts)
    u_bc_pts = u_exact(pts)

    # Set up the system and solve:
    tic = time.clock()
    A, b = poisson.poisson(pts, quads, bc_nodes, f_pts, u_bc_pts, FEM.Q1,
                           FEM.GaussQuad2x2())
    toc = time.clock()
    print "Matrix assembly took %f s" % (toc - tic)

    tic = time.clock()
Ejemplo n.º 3
0
    eps = 1e-6
    for k in xrange(n_nodes):
        x, y = pts[k]
        if np.fabs(x - 1) < eps or np.fabs(y - 1) < eps:  # np.fabs(x - (-1)) < eps or  # or np.fabs(y - (-1)) < eps):
            bc_nodes[k] = 1

    return bc_nodes


if __name__ == "__main__":
    # Try the quad mesh with Q1 elements:
    if True:
        import poisson_optimized as poisson

        # import poisson
        pts, quads, tri = create_mesh.quad_rectangle(0, 1, 0, 1, 21, 21)
        bc_nodes = set_bc_nodes_square(pts)

        # forcing term at mesh nodes
        f_pts = f(pts)
        # Dirichlet boundary conditions at *all* mesh nodes (most of these values are not used)
        u_bc_pts = u_bc(pts)

        # Set up the system and solve:
        tic = time.clock()
        A, b = poisson.poisson(pts, quads, bc_nodes, f_pts, u_bc_pts, FEM.Q1Aligned, FEM.GaussQuad2x2())
        toc = time.clock()
        print "Matrix assembly took %f s" % (toc - tic)

        if pts.shape[0] < 50:
            print "cond(A) = %3.3f" % np.linalg.cond(A.todense())
Ejemplo n.º 4
0
        x = pts[:,0]
        y = pts[:,1]
    except:
        x = pts[0]
        y = pts[1]

    return 2.0*(1+y) / ((3+x)**2 + (1+y)**2)


errors = []
Ns = np.array([5, 11, 21, 41, 81])
for n in Ns:
    print "Running with N = %d" % n

    tic = time.clock()
    pts,quads,tri = create_mesh.quad_rectangle(-1, 1, -1, 1, n, n)
    bc_nodes = set_bc_nodes_square(pts)
    toc = time.clock()
    print "Mesh generation took %f s" % (toc - tic)

    f_pts = f(pts)
    u_bc_pts = u_exact(pts)

    # Set up the system and solve:
    tic = time.clock()
    A,b = poisson.poisson(pts, quads, bc_nodes, f_pts, u_bc_pts, FEM.Q1, FEM.GaussQuad2x2())
    toc = time.clock()
    print "Matrix assembly took %f s" % (toc - tic)

    tic = time.clock()
    x = spsolve(A.tocsr(), b)