def solve_poisson_3d(self, n=2): from fealpy.pde.poisson_3d import CosCosCosData as PDE from fealpy.mesh import MeshFactory from fealpy.functionspace import LagrangeFiniteElementSpace from fealpy.boundarycondition import DirichletBC pde = PDE() mf = MeshFactory() m = 2**n box = [0, 1, 0, 1, 0, 1] mesh = mf.boxmesh3d(box, nx=m, ny=m, nz=m, meshtype='tet') space = LagrangeFiniteElementSpace(mesh, p=1) gdof = space.number_of_global_dofs() NC = mesh.number_of_cells() print('gdof:', gdof, 'NC:', NC) bc = DirichletBC(space, pde.dirichlet) uh = space.function() A = space.stiff_matrix() A = space.parallel_stiff_matrix(q=1) M = space.parallel_mass_matrix(q=2) M = space.mass_matrix() F = space.source_vector(pde.source) A, F = bc.apply(A, F, uh) solver = PETScSolver() solver.solve(A, F, uh) error = space.integralalg.L2_error(pde.solution, uh) print(error)
] errorMatrix = np.zeros((2, maxit), dtype=np.float) NDof = np.zeros(maxit, dtype=np.float) for i in range(maxit): print("The {}-th computation:".format(i)) space = LagrangeFiniteElementSpace(mesh, p=p) NDof[i] = space.number_of_global_dofs() bc = DirichletBC(space, pde.dirichlet) uh = space.function() if d == 2: A = space.stiff_matrix() elif d == 3: A = space.parallel_stiff_matrix(q=p) F = space.source_vector(pde.source) A, F = bc.apply(A, F, uh) #ml = pyamg.ruge_stuben_solver(A) #uh[:] = ml.solve(F, tol=1e-12, accel='cg').reshape(-1) if d == 2: uh[:] = spsolve(A, F).reshape(-1) # elif d==3: # solver = PETScSolver() # solver.solve(A, F, uh) errorMatrix[0, i] = space.integralalg.L2_error(pde.solution, uh)