fealpy
fealpy copied to clipboard
TriangleMesh 中 coarsen() 对特定网格的 bug ?
如果生成 米
字型网格, coarsen()
后出现 bug:
-
原始网格
-
只标记第
42
个单元, 进行coarsen()
后的网格
下面是测试代码
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()
bug 已经修正了,你再测试一下