You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FiPy中能否通过坐标查询点归属oxideMesh或siliconMesh网格

FiPy坐标归属网格判断实现方案

方案1:复用原始Gmsh网格标记(推荐,性能更高)

你所用的原始gmsh_mesh已经自带物理组标记,直接基于原始网格查询无需重复遍历两个子网格,效率提升明显:

  1. 先构建全局材料标记变量
import fipy as fp
# 初始化材料标记:1=Oxide,2=Silicon
material_var = fp.CellVariable(mesh=gmsh_mesh, value=0)
material_var[gmsh_mesh.physicalCells["Oxide"]] = 1
material_var[gmsh_mesh.physicalCells["Silicon"]] = 2
  1. 实现坐标判断方法
def get_material_type(x, y):
    # 2D网格仅需传入(x,y)坐标,无需补充z轴0值
    cell_id = gmsh_mesh.cellContaining((x, y))
    if cell_id == -1:
        return "out_of_mesh"
    mat_val = material_var[cell_id].value[0]
    if mat_val == 1:
        return "oxide"
    elif mat_val == 2:
        return "silicon"
    return "unknown_material"

方案2:直接判断子网格归属

如果确实需要单独查询两个拆分后的子网格,直接调用FiPy网格内置的cellContaining方法即可,返回值为-1时代表坐标不在当前网格范围内:

def judge_mesh_belong(x, y):
    if oxideMesh.cellContaining((x, y)) != -1:
        return "oxide"
    elif siliconMesh.cellContaining((x, y)) != -1:
        return "silicon"
    return "out_of_both_meshes"

注意事项

  • 两个子网格从同一原始网格的不同物理组提取,天然不存在重叠区域,先后判断顺序不影响结果
  • 若需批量判断多个坐标,可将坐标拼接为shape=(2, N)的数组传入cellContaining,一次性获取所有点的归属结果,避免循环调用大幅提升效率
  • 若使用旧版本FiPy调用cellContaining报错,可替换为内部方法_getCellContaining,功能完全一致

内容的提问来源于stack exchange,提问作者mindful_machina

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 10:24:04