NDof[i] = space.number_of_global_dofs() bc = DirichletBC(space, pde.dirichlet) uh = space.function() A, F = bc.apply(A, F, uh) uh[:] = spsolve(A, F) errorMatrix[0, i] = space.integralalg.error(pde.solution, uh.value, power=2) errorMatrix[1, i] = space.integralalg.error(pde.gradient, uh.grad_value, power=2) errorMatrix[2, i] = space.integralalg.error(pde.gradient, rguh.value, power=2) eta = space.recovery_estimate(uh) errorMatrix[3, i] = np.sqrt(np.sum(eta**2)) if i < maxit - 1: isMarkedCell = mark(eta, theta=theta) mesh.bisect(isMarkedCell) mesh.add_plot(plt) plt.savefig('./test-' + str(i + 1) + '.png') plt.close() mesh.add_plot(plt) showmultirate(plt, maxit - 5, NDof, errorMatrix, errorType) plt.show()
F = space.source_vector(source) F *= dt F += M @ uh0 # t1 时间层的 Dirichlet 边界条件处理 @cartesian def dirichlet(p): return pde.dirichlet(p, t1) bc = DirichletBC(space, dirichlet) GD, F = bc.apply(G, F, uh1) # 代数系统求解 uh1[:] = spsolve(GD, F) eta = space.recovery_estimate(uh1, method='area_harmonic') err = np.sqrt(np.sum(eta**2)) print('errrefine', err) if err < tol: break else: # 加密并插值 NN0 = smesh.number_of_nodes() edge = smesh.entity('edge') isMarkedCell = smesh.refine_marker(eta, rtheta, method='L2') smesh.refine_triangle_rg(isMarkedCell) i += 1 smesh.add_plot(plt) plt.savefig('./test-' + str(i + 1) + '.png') plt.close() space = LagrangeFiniteElementSpace(smesh, p=1)