FEALPy 创建各种各样的网格

FEALPy 创建各种各样的网格

利用 Mesh Factory 生成网格

三角形网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

domain = [0, 1, 0, 1]
mesh = MF.boxmesh2d(domain, nx=10, ny=10, meshtype='tri')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x121f92970>

png

矩形网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1]
mesh = MF.boxmesh2d(domain, nx=10, ny=10, meshtype='quad')
# mesh.uniform_refine(n=2)  # 网格加密次数
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x12208cf40>

png

多项式网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1]
mesh = MF.boxmesh2d(domain, nx=10, ny=10, meshtype='poly')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PatchCollection at 0x1220f9b20>

png

鱼骨网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1]
mesh = MF.special_boxmesh2d(domain, n=10, meshtype='fishbone')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x12215d850>

png

米字型网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1]
mesh = MF.special_boxmesh2d(domain, n=10, meshtype='rice')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x1221c47c0>

png

交叉型网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1]
mesh = MF.special_boxmesh2d(domain, n=10, meshtype='cross')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x12222c2b0>

png

非一致网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1]
mesh = MF.special_boxmesh2d(domain, n=10, meshtype='nonuniform')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x12229a940>

png

圆上的网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
mesh = MF.unitcirclemesh(h=0.1, meshtype='tri')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x12232b610>

png

L-shape 网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
mesh = MF.lshape_mesh(n=2)
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x1223bb880>

png

Polygon 网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
mesh = MF.polygon_mesh()
mesh.uniform_refine(n=3)  # 网格加密次数
NC = mesh.number_of_cells()
print('Number of cells:', NC)
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
Number of cells: 288





<matplotlib.collections.PatchCollection at 0x122428b50>

png

四面体网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1, 0, 1]
mesh = MF.boxmesh3d(domain, nx=4, ny=4, nz=4, meshtype='tet')
fig = plt.figure()
axes = fig.gca(projection='3d')
mesh.add_plot(axes)
memory size of node array (GB):  2.7939677238464355e-06
memory size of cell array (GB):  1.1444091796875e-05
memory size of face array (GB):  1.9311904907226562e-05
memory size of edge array (GB):  9.000301361083984e-06
memory size of face2cell array (GB):  2.574920654296875e-05
memory size of cell2edge array (GB):  1.71661376953125e-05
Total memory size (GB):  8.546561002731323e-05


/var/folders/z_/_4v3r8650yv8dpcq7bz94d3m0000gn/T/ipykernel_9683/2032695478.py:5: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
  axes = fig.gca(projection='3d')





<mpl_toolkits.mplot3d.art3d.Poly3DCollection at 0x1222f55e0>

png

六面体网格

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1, 0, 1]
mesh = MF.boxmesh3d(domain, nx=4, ny=4, nz=4, meshtype='hex')
fig = plt.figure()
axes = fig.gca(projection='3d')
mesh.add_plot(axes)
/var/folders/z_/_4v3r8650yv8dpcq7bz94d3m0000gn/T/ipykernel_9683/691261962.py:5: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
  axes = fig.gca(projection='3d')





<mpl_toolkits.mplot3d.art3d.Poly3DCollection at 0x122485970>

png

利用Threshold构造你想要的网格

我们之前给出过 L-shape 的网格,但是有些时候想要变换 L-shape 的方向,这时候便要借助 Threshold 函数来完成。

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1]
mesh = MF.boxmesh2d(domain, nx=10, ny=10, meshtype='tri', threshold=lambda p: (p[..., 0]<0.5) & (p[..., 1]<0.5))
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x1225d2bb0>

png

挖掉一部分的网络

from fealpy.mesh import MeshFactory as MF # 导入网格工厂模块
domain = [0, 1, 0, 1]
mesh = MF.boxmesh2d(domain, nx=50, ny=50, meshtype='tri', threshold=lambda p: (p[..., 0]-0.5) ** 2 + (p[..., 1]-0.5) ** 2 < 0.2)
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
<matplotlib.collections.PolyCollection at 0x122626f40>

png

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

图灵猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值