def vem_solve(model, quadtree): mesh = quadtree.to_polygonmesh() V = VirtualElementSpace2d(mesh, 1) uh = FiniteElementFunction(V) vem = PoissonVEMModel(model, V) BC = DirichletBC(V, model.dirichlet) A, b = solve(vem, uh, dirichlet=BC, solver='direct') uI = V.interpolation(model.solution) eta = vem.recover_estimate(uh) uIuh = np.sqrt((uh - uI) @ A @ (uh - uI)) return uh, V.number_of_global_dofs(), eta, uIuh
model = CosCosData() mesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='tri') maxit = 4 Ndof = np.zeros(maxit, dtype=np.int) error = np.zeros(maxit, dtype=np.float) ratio = np.zeros(maxit, dtype=np.float) for i in range(maxit): V = function_space(mesh, 'Lagrange', degree) uh = FiniteElementFunction(V) Ndof[i] = V.number_of_global_dofs() a = LaplaceSymetricForm(V, qt) L = SourceForm(V, model.source, qt) bc = DirichletBC(V, model.dirichlet, model.is_boundary) point = V.interpolation_points() solve(a, L, uh, dirichlet=bc, solver='direct') error[i] = L2_error(model.solution, uh, order=qt) # error[i] = np.sqrt(np.sum((uh - model.solution(point))**2)/Ndof[i]) if i < maxit-1: mesh.uniform_refine() # 输出结果 ratio[1:] = error[0:-1]/error[1:] print('Ndof:', Ndof) print('error:', error) print('ratio:', ratio) #fig = plt.figure() #axes = fig.gca() #axes.axis('tight') #axes.axis('off')
for i in range(maxit): if meshtype == 1: #fishbone mesh mesh = fishbone(box,n) integrator = mesh.integrator(3) mesh.add_plot(plt,cellcolor='w') V = LagrangeFiniteElementSpace(mesh,p=1) V2 = VectorLagrangeFiniteElementSpace(mesh,p=1) uh = FiniteElementFunction(V) rgh = FiniteElementFunction(V2) rlh = FiniteElementFunction(V) fem = BiharmonicRecoveryFEMModel(mesh, pde,integrator,rtype=rtype) bc = DirichletBC(V, pde.dirichlet) solve(fem, uh, dirichlet=bc, solver='direct') fem.recover_grad() #TODO fem.recover_laplace() eta1 = fem.grad_recover_estimate() eta2 = fem.laplace_recover_estimate() Ndof[i] = V.number_of_global_dofs() errorMatrix[0, i] = fem.error.L2_error(pde.solution, uh) errorMatrix[1, i] = fem.error.L2_error(pde.gradient, uh) errorMatrix[2, i] = np.sqrt(np.sum(eta1**2)) errorMatrix[3, i] = fem.error.L2_error(pde.gradient, rgh) errorMatrix[4, i] = fem.error.L2_error(pde.laplace, rgh) errorMatrix[5, i] = fem.error.L2_error(pde.laplace, rlh) errorMatrix[6, i] = np.sqrt(np.sum(eta2**2))
error = np.zeros((maxit, ), dtype=np.float) derror = np.zeros((maxit, ), dtype=np.float) gerror = np.zeros((maxit, ), dtype=np.float) Ndof = np.zeros((maxit, ), dtype=np.int) for i in range(maxit): V = function_space(mesh, 'Lagrange', degree) Ndof[i] = V.number_of_global_dofs() uh = FiniteElementFunction(V) a = BihamonicRecoveryForm(V, sigma=2) L = SourceForm(V, model.source, 4) BC = DirichletBC(V, model.dirichlet, isBoundaryDof) solve(a, L, uh, BC, 'direct') error[i] = L2_error(model.solution, uh, order=4) ruh = recover_grad(uh) derror[i] = div_error(model.laplace, ruh, order=4) gerror[i] = L2_error(model.gradient, ruh, order=4) if i < maxit - 1: mesh.uniform_refine() print(Ndof) print('L2 error:\n', error) order = np.log(error[0:-1] / error[1:]) / np.log(2) print('order:\n', order) print('div error:\n', derror) order = np.log(derror[0:-1] / derror[1:]) / np.log(2)
model = PolynomialData() model = ExpData() for i in range(maxit): # Mesh mesh0 = rectangledomainmesh(box, nx=n, ny=n, meshtype='tri') mesh1 = TriangleMeshWithInfinityPoint(mesh0) point, cell, cellLocation = mesh1.to_polygonmesh() mesh = PolygonMesh(point, cell, cellLocation) # VEM Space V = VirtualElementSpace2d(mesh, p) uh = FiniteElementFunction(V) Ndof[i] = V.number_of_global_dofs() vem = PoissonVEMModel(model, V) BC = DirichletBC(V, model.dirichlet) solve(vem, uh, dirichlet=BC, solver='direct') # error uI = V.interpolation(model.solution) error[i] = np.sqrt(np.sum((uh - uI)**2)/Ndof[i]) n = 2*n print(Ndof) print(error) print(error[:-1]/error[1:])
Ndof = np.zeros((maxit, ), dtype=np.int) for i in range(0, maxit): mesh = load_mat_mesh('../data/square' + str(i + 2) + '.mat') V = function_space(mesh, 'Lagrange', degree) Ndof[i] = V.number_of_global_dofs() uh = FiniteElementFunction(V) a = BihamonicRecoveryForm(V, sigma=sigma) L = SourceForm(V, model.source, 4) bc0 = DirichletBC(V, model.dirichlet, model.is_boundary_dof) bc1 = BihamonicRecoveryBC1(V, model.neuman, sigma=sigma) solve(a, L, uh, dirichlet=bc0, neuman=bc1, solver='direct') error[i] = L2_error(model.solution, uh, order=4) ruh = recover_grad(uh) derror[i] = div_error(model.laplace, ruh, order=4) gerror[i] = L2_error(model.gradient, ruh, order=5) # if i < maxit-1: # mesh.uniform_refine() print(Ndof) print('L2 error:\n', error) order = np.log(error[0:-1] / error[1:]) / np.log(2) print('order:\n', order) print('div error:\n', derror) order = np.log(derror[0:-1] / derror[1:]) / np.log(2)