fealpy
fealpy copied to clipboard
Issue in mesh_tools.py
我在运行如下代码时遇到一些问题:
import numpy as np
import matplotlib.pyplot as plt
from fealpy.mesh import MeshFactory as MF
box = [0, 1, 0, 1]
mesh = MF.boxmesh2d(box, nx=2, ny=2, meshtype='quad', p=1)
node = mesh.entity('node')
cell = mesh.entity('cell')
edge = mesh.entity('edge')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
mesh.find_node(axes, showindex=True, fontsize=15)
mesh.find_edge(axes, showindex=True, fontsize=17)
mesh.find_cell(axes, showindex=True, fontsize=13)
plt.show()
报错如下:
Traceback (most recent call last):
File "/tmp/ipykernel_23862/3436525850.py", line 1, in <module>
get_ipython().kernel._show_mpl_backend_errors()
AttributeError: 'SpyderKernel' object has no attribute '_show_mpl_backend_errors'
runfile('/home/idc/.config/spyder-py3/temp.py', wdir='/home/idc/.config/spyder-py3')
run boxmesh2d with time: 0.0005260530015220866
Traceback (most recent call last):
File "/home/idc/.config/spyder-py3/temp.py", line 14, in <module>
mesh.add_plot(axes)
File "/home/idc/fealpy/fealpy/mesh/Mesh2d.py", line 170, in add_plot
return show_mesh_2d(axes, self,
File "/home/idc/fealpy/fealpy/mesh/mesh_tools.py", line 341, in show_mesh_2d
poly = PolyCollection(node[cell[:, mesh.ds.ccw], :])
AttributeError: 'LagrangeQuadrangleMeshDataStructure' object has no attribute 'ccw'
在使用下列矩形网格图像展示,图像是能正常表示,
import argparse
import numpy as np
import matplotlib.pyplot as plt#显示数学公式
# from mpl_toolkits.mplot3d import Axes3D
from fealpy.mesh import MeshFactory as MF
## 参数解析
parser = argparse.ArgumentParser(description=
"""
It's a mesh display's python code
""")
parser.add_argument('-nx',
default=2, type=int,
help='在x方向上的剖分段数')
parser.add_argument('-ny',
default=2, type=int,
help='在x方向上的剖分段数')
parser.add_argument('-n',
default=0, type=int,
help='加密次数')
parser.add_argument('-nodeshow',
default=1, type=int,
help='节点编号')
parser.add_argument('-edgeshow',
default=1, type=int,
help='边编号')
parser.add_argument('-cellshow',
default=1, type=int,
help='单元编号')
parser.add_argument('-mt',
default='quad', type=str,
help='meshtype')
parser.print_help()
args = parser.parse_args()
print(args)
box = [0,1,0,1]
#mesh=mf.boxmesh2d(box,nx=4,ny=4,meshtype='tri')
mesh = MF.boxmesh2d(box,args.nx,args.ny,args.mt)
#mesh=mf.boxmesh2d(box,nx=4,ny=4,meshtype='poly')
mesh.uniform_refine(args.n)
node = mesh.entity('node')
cell = mesh.entity('cell')
# print('node:\n',node)
# print('cell:\n',cell)
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)#显示绿色底部
if args.nodeshow == 1:
mesh.find_node(axes, showindex=True, fontsize=15)
if args.edgeshow == 1:
mesh.find_edge(axes, showindex=True, fontsize=17)
if args.cellshow == 1:
mesh.find_cell(axes, showindex=True, fontsize=13)
plt.show()
我发现在 MF.boxmesh2d() 中传不传参数 p,所得到的网格编号虽然一致,但对于单个单元的顺序不一致,如不传参数p,单元内会按照逆时针顺序输出四个顶点编号,而传参数p,会使得单元输出按照沿y方向,再沿x方向输出,这样的不同是因为什么原因呢?
不传 p 的时候,返回的是 QuadrangleMesh 对象。传 p 进去的时候是 LagrangeQuadrangleMesh 对象,这是四边形的高阶网格对象,其单个单元顶点的编号规则和 QuadrangleMesh 是不一样的。
四边形的高阶网格对象是为参数有限元服务的,因为其边可能是曲边的,其画图需要特别的处理方法。我会在首先加入对 p = 1 四边形网格的支持,p > 1 的情形需要再想一下。
老师,传参数p的网格画图fealpy中有例子吗?
四边形的高阶网格对象是为参数有限元服务的,因为其边可能是曲边的,其画图需要特别的处理方法。我会在首先加入对 p = 1 四边形网格的支持,p > 1 的情形需要再想一下。
import numpy as np
import matplotlib.pyplot as plt
from fealpy.mesh import MeshFactory as MF
box = [0, 1, 0, 1]
#mesh = MF.boxmesh2d(box, nx=2, ny=2, meshtype='tri', p=3)
mesh = MF.boxmesh2d(box, nx=2, ny=2, meshtype='quad', p=3)
node = mesh.entity('node')
cell = mesh.entity('cell')
edge = mesh.entity('edge')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
mesh.find_node(axes, showindex=True, fontsize=15)
mesh.find_edge(axes, showindex=True, fontsize=17)
mesh.find_cell(axes, showindex=True, fontsize=13)
plt.show()
你更新一下 fealpy, 我已经的把画图的支持加进去了。
好的,谢谢老师
你更新一下 fealpy, 我已经的把画图的支持加进去了。