fealpy icon indicating copy to clipboard operation
fealpy copied to clipboard

TriangleMesh 中 coarsen() 对特定网格的 bug ?

Open yoczhang opened this issue 2 years ago • 1 comments

如果生成 字型网格, coarsen() 后出现 bug:

  1. 原始网格 image

  2. 只标记第 42 个单元, 进行 coarsen() 后的网格 image


下面是测试代码

from fealpy.mesh import MeshFactory as MF
import numpy as np
import matplotlib 
matplotlib.use("TkAgg")  
import matplotlib.pyplot as plt


def boxmesh2d_rice(box, nx=10, ny=10):
    qmesh = MF.boxmesh2d(box, nx=nx, ny=ny, meshtype='quad')
    node = qmesh.entity('node')
    cell = qmesh.entity('cell')

    isLeftCell = np.zeros((nx, ny), dtype=bool)
    isLeftCell[0, 0::2] = True
    isLeftCell[1, 1::2] = True
    if nx > 2:
        isLeftCell[2::2, :] = isLeftCell[0, :]
    if nx > 3:
        isLeftCell[3::2, :] = isLeftCell[1, :]
    isLeftCell = isLeftCell.reshape(-1)

    lcell = cell[isLeftCell]
    rcell = cell[~isLeftCell]
    newCell = np.r_['0',
                    lcell[:, [1, 2, 0]],
                    lcell[:, [3, 0, 2]],
                    rcell[:, [0, 1, 3]],
                    rcell[:, [2, 3, 1]]]
    return MF.TriangleMesh(node, newCell)


# |--- to test ---| #
if __name__ == '__main__':
    box = [-1.5, 1.5, 0, 1]
    mesh = boxmesh2d_rice(box, nx=4 * 3, ny=4)
    ax = mesh.add_plot(plt)
    mesh.find_cell(ax.axes, showindex=True)
    plt.show()
    # plt.savefig('mesh-0.png')
    plt.close()

    # |--- coarsen
    isMarkedCell = np.zeros(mesh.number_of_cells(), dtype=bool)
    isMarkedCell[42] = True
    mesh.coarsen(isMarkedCell=isMarkedCell)
    mesh.add_plot(plt)
    plt.show()
    # plt.savefig('mesh-1.png')
    plt.close()

yoczhang avatar Jun 11 '22 12:06 yoczhang

bug 已经修正了,你再测试一下

weihuayi avatar Jul 04 '22 07:07 weihuayi