Beispiel #1
0
    # 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())

        tic = time.clock()
        x = spsolve(A.tocsr(), b)
        toc = time.clock()
        print "Sparse solve took %f s" % (toc - tic)

        # Plot:
        plt.figure()
        plot_mesh.plot_mesh(pts, quads)
        plt.figure()
Beispiel #2
0
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)
    toc = time.clock()
    print "Sparse solve took %f s\n" % (toc - tic)

    x_exact = u_exact(pts)

    errors.append(np.max(np.fabs(x - x_exact)))

dxs = 2.0 / np.array(Ns - 1)

p = np.polyfit(np.log10(dxs), np.log10(errors), 1)