Exemple #1
0
theta = 0.2
k = maxit - 15
p = 1
q = 3
errorType = ['$|| u_I - u_h ||_{l_2}$',
             '$|| u - u_h||_{0}$',
             '$||\\nabla u - \\nabla u_h||_{0}$',
             '$||\\nabla u - G(\\nabla u_h)||_{0}$']

ralg = FEMFunctionRecoveryAlg()
Ndof = np.zeros((maxit,), dtype=np.int)
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)

for i in range(maxit):
    print('step:', i)
    fem = PoissonFEMModel(pde, mesh, 1, q=3)
    fem.solve()
    uh = fem.uh
    Ndof[i] = fem.mesh.number_of_nodes()
    errorMatrix[0, i] = fem.l2_error()
    errorMatrix[1, i] = fem.L2_error()
    errorMatrix[2, i] = fem.H1_semi_error()
    # rguh = ralg.harmonic_average(uh)
    # eta = fem.recover_estimate(rguh)
    eta = fem.residual_estimate()
    errorMatrix[3, i] = np.sqrt(np.sum(eta**2))
    markedCell = mark(eta, theta=theta)
    if i < maxit - 1:
        isMarkedCell = mark(eta, theta=theta)
        A = mesh.bisect(isMarkedCell, returnim=True)
errorType = ['$|| u_I - u_h ||_{l_2}$',
             '$|| u - u_h||_{0}$',
             '$||\\nabla u - \\nabla u_h||_{0}$', 
             '$||\\nabla u - G(\\nabla u_h)||_{0}sim$',]

maxit = 1
ralg = FEMFunctionRecoveryAlg()
Ndof = np.zeros((maxit,), dtype=np.int)
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)
integrator = mesh.integrator(3)


for i in range(maxit):
    print('step:', i)
    fem = PoissonFEMModel(pde, mesh, 1, integrator)
    fem.solve()
    uh = fem.uh
    Ndof[i] = fem.mesh.number_of_nodes()
    errorMatrix[0, i] = fem.get_l2_error()
    errorMatrix[1, i] = fem.get_L2_error()
    errorMatrix[2, i] = fem.get_H1_error()
    rguh = ralg.simple_average(uh)
    eta = fem.recover_estimate(rguh)
    errorMatrix[3, i] = fem.get_recover_error(rguh)

    estimator = Estimator(uh[:], mesh, 0.3, 0.5)
    tmesh.adaptive_refine(estimator)
    if i < maxit - 1:
        mesh = estimator.mesh
Ndof = np.zeros((maxit, ), dtype=np.int)
errorType = [
    '$|| u - u_h||_0$ with p=1',
    '$|| u - u_h||_0$ with p=2',
    '$|| u - u_h||_0$ with p=3',
    '$||\\nabla u - \\nabla u_h||_0$ with p=1',
    '$||\\nabla u - \\nabla u_h||_0$ with p=2',
    '$||\\nabla u - \\nabla u_h||_0$ with p=3',
]

ps = [1, 2, 3]
q = [4, 5, 6]

errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)

for i in range(maxit):
    Ndof[i] = mesh.number_of_nodes()
    for j, p in enumerate(ps):
        integrator = mesh.integrator(q[j])
        fem = PoissonFEMModel(pde, mesh, p, integrator)
        fem.solve()
        Ndof[i] = fem.femspace.number_of_global_dofs()
        errorMatrix[j, i] = fem.get_L2_error()
        errorMatrix[j + 3, i] = fem.get_H1_error()
    if i < maxit - 1:
        mesh.uniform_refine()

print(errorMatrix)
showmultirate(plt, 0, Ndof, errorMatrix, errorType)
plt.show()
Exemple #4
0
p = int(sys.argv[2])  # 有限元空间的次数
n = int(sys.argv[3])  # 初始网格的加密次数
maxit = int(sys.argv[4])  # 迭代加密的次数

pde = PDE()  # 创建 pde 模型

# 误差类型与误差存储数组
errorType = ['$|| u - u_h||_0$', '$||\\nabla u - \\nabla u_h||_0$']
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)

# 自由度数组
Ndof = np.zeros(maxit, dtype=np.int)

# 创建初始网格对象
mesh = pde.init_mesh(n)

for i in range(maxit):
    fem = PoissonFEMModel(pde, mesh, p, q=p + 2)  # 创建 Poisson 有限元模型
    ls = fem.solve()  # 求解
    Ndof[i] = fem.space.number_of_global_dofs()  # 获得空间自由度个数
    errorMatrix[0, i] = fem.L2_error()  # 计算 L2 误差
    errorMatrix[1, i] = fem.H1_semi_error()  # 计算 H1 误差
    if i < maxit - 1:
        mesh.uniform_refine()  # 一致加密网格

# 显示误差
show_error_table(Ndof, errorType, errorMatrix)
# 可视化误差收敛阶
showmultirate(plt, 0, Ndof, errorMatrix, errorType)
plt.show()
Exemple #5
0
        else:
            return False


pde = LShapeRSinData()
mesh = pde.init_mesh(n=4, meshtype='tri')
integrator = mesh.integrator(3)
node = mesh.entity('node')
cell = mesh.entity('cell')
tmesh = Tritree(node, cell)
pmesh = tmesh.to_conformmesh()

tol = 1.0e-4

for i in range(maxit):
    fem = PoissonFEMModel(pde, pmesh, p, integrator)
    fem.solve()
    res = fem.get_H1_error()
    #res = fem.get_L2_error()

    estimator = Estimator(fem.uh[:], mesh, 0.3, 0.5)

    fig = plt.figure()
    axes = fig.gca()
    mesh.add_plot(axes, cellcolor=estimator.eta, showcolorbar=True)

    if res < tol:
        break
    tmesh.adaptive_refine(estimator)
    pmesh = tmesh.to_conformmesh()
    print("Steps:", i)
Exemple #6
0
#tmesh.find_node(axes, showindex=True)
plt.show()
p = 1
maxit = 5

pde = PDE()
errorType = ['$|| u - u_h||_0$', '$||\\nabla u - \\nabla u_h||_0$']

errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)

Ndof = np.zeros(maxit, dtype=np.int)

integrator = tmesh.integrator(7)

for i in range(maxit):
    fem = PoissonFEMModel(pde, tmesh, p, integrator)
    ls = fem.solve()
    sio.savemat('test%d.mat' % (i), ls)
    Ndof[i] = fem.femspace.number_of_global_dofs()
    errorMatrix[0, i] = fem.get_L2_error()
    errorMatrix[1, i] = fem.get_H1_error()
    if i < maxit - 1:
        #tmesh.uniform_refine()
        h = h / 2
        pmesh = distmesh2d(fd, h, box, pfix, meshtype='polygon')
        node = pmesh.entity('node')
        t = Delaunay(node)
        tmesh = TriangleMesh(node, t.simplices.copy())
        area = tmesh.entity_measure('cell')
        tmesh.delete_cell(area < 1e-8)
        area = tmesh.entity_measure('cell')
Exemple #7
0
    from fealpy.pde.poisson_3d import LShapeRSinData as PDE

p = int(sys.argv[2])  # 有限元空间的次数
n = int(sys.argv[3])  # 初始网格的加密次数
maxit = int(sys.argv[3])
theta = int(sys.argv[4])
pde = PDE()  # 创建 pde 模型
mesh = pde.init_mesh(n)
errorType = ['$|| u - u_h||_{0}$', '$||\\nabla u - \\nabla u_h||_{0}$']

Ndof = np.zeros((maxit, ), dtype=np.int)
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)

for i in range(maxit):
    print('step:', i)
    fem = PoissonFEMModel(pde, mesh, p, q=p + 2)  # 创建 Poisson 有限元模型
    fem.solve()  # 求解
    uh = fem.uh
    space = uh.space
    Ndof[i] = space.mesh.number_of_nodes()
    errorMatrix[0, i] = fem.L2_error()  # 计算 L2 误差
    errorMatrix[1, i] = fem.H1_semi_error()  # 计算 H1 误差

    rguh = space.grad_recovery(uh)
    eta = fem.recover_estimate(rguh)
    markedCell = mark(eta, theta=theta, method='MAX')
    if i < maxit - 1:
        markedCell = mark(eta, theta=theta, method='MAX')
        mesh.bisect(markedCell)

# 可视化误差收敛阶
Exemple #8
0
p = int(sys.argv[2])  # 有限元空间的次数
n = int(sys.argv[3])  # 初始网格的加密次数
maxit = int(sys.argv[4])  # 迭代加密的次数

pde = PDE()  # 创建 pde 模型

# 误差类型与误差存储数组
errorType = ['$|| u - u_h||_0$', '$||\\nabla u - \\nabla u_h||_0$']
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)

# 自由度数组
Ndof = np.zeros(maxit, dtype=np.int)

# 创建初始网格对象
mesh = pde.init_mesh(n)

for i in range(maxit):
    fem = PoissonFEMModel(pde, mesh, p, p + 2)  # 创建 Poisson 有限元模型
    ls = fem.solve()  # 求解
    Ndof[i] = fem.space.number_of_global_dofs()  # 获得空间自由度个数
    errorMatrix[0, i] = fem.get_L2_error()  # 计算 L2 误差
    errorMatrix[1, i] = fem.get_H1_error()  # 计算 H1 误差
    if i < maxit - 1:
        mesh.uniform_refine()  # 一致加密网格

# 显示误差
show_error_table(Ndof, errorType, errorMatrix)
# 可视化误差收敛阶
showmultirate(plt, 0, Ndof, errorMatrix, errorType)
plt.show()