【问题标题】:FiPy: How to find node (vertex) at interface between two meshFiPy:如何在两个网格之间的界面处找到节点(顶点)
【发布时间】:2021-07-30 19:06:05
【问题描述】:

我已经通过 Gmsh 在 FiPy 中定义了两个网格,并希望在两个网格之间的接口处找到节点。有没有办法在 FiPy 中做到这一点?

siliconGeometry = '''
SetFactory("OpenCASCADE");
//set node spacing
ns = 1e-1;
ns2 = 1e-2;
x1 = 0;
y1 = 0;
x2 = 1;
y2 = 0.5;
Point(1) = {x1, y1, 0, ns};
Point(2) = {x2, y1, 0, ns};
Point(3) = {x2, y2, 0, ns2};
Point(4) = {x1, y2, 0, ns2};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Curve Loop(1) = {1, 2, 3, 4};
Plane Surface(1) = {1};
Physical Surface("Silicon") = {1};
'''

oxideGeometry = '''
SetFactory("OpenCASCADE");
//set node spacing
ns = 1e-1;
ns2 = 1e-2;
x1 = 0;
y1 = 0.5;
x2 = 1;
y2 = 1;
Point(5) = {x1, y1, 0, ns2};
Point(6) = {x2, y1, 0, ns2};
Point(7) = {x2, y2, 0, ns};
Point(8) = {x1, y2, 0, ns};
Line(5) = {5, 6};
Line(6) = {6, 7};
Line(7) = {7, 8};
Line(8) = {8, 5};
Curve Loop(2) = {5, 6, 7, 8};
Plane Surface(2) = {2};
Physical Surface("Oxide") = {2};

m0 = Gmsh2D(siliconGeometry)
m1 = Gmsh2D(oxideGeometry)

我想获取网格m0m1 之间接口处的所有节点(或线)。

【问题讨论】:

    标签: python process simulation fipy


    【解决方案1】:

    FiPy 有一个名为nearest 的函数 它得到两个向量的最接近的值。因此,要从 m0m1 获取重叠 ID,然后使用

    from fipy import Gmsh2D
    from fipy.tools.numerix import nearest
    import numpy as np
    
    siliconGeometry = '''
    ...
    '''
    
    oxideGeometry = '''
    ...
    '''
     
    m0 = Gmsh2D(siliconGeometry)
    m1 = Gmsh2D(oxideGeometry)
    
    near_ids = nearest(m0.vertexCoords, m1.vertexCoords)
    mask = np.all(np.isclose(m0.vertexCoords[:, near_ids], m1.vertexCoords), axis=0)
    m1_close_ids = np.arange(len(m1.vertexCoords[0]))[mask]
    m0_close_ids = near_ids[mask]
    
    for i in range(len(m0_close_ids)):
        m0_id = m0_close_ids[i]
        m1_id = m1_close_ids[i]
        print()
        print(f'm0: {m0_id}, {m0.vertexCoords[:, m0_id]}')
        print(f'm1: {m1_id}, {m1.vertexCoords[:, m1_id]}')
    

    我们使用nearest 来获取near_idsm0,然后使用np.isclose 检查节点是否关闭。使用mask,我们可以在两个网格之间构造对应的close ID。

    请注意,使用 Scipy 的 KDTree 查找最接近的值可能要快得多。然而,对于这个小问题,这并不重要,但对于一个非常大的网格,我想它会很重要。事实上,FiPy 应该确实在内部使用它(目前还没有)。

    另外,这里的另一个调整是你知道上面和下面是重叠的,所以你可以简单地要求 m0.facesTopm1.facesBottom 掩码将问题减少到重叠面,但这依赖于先验知识的网格。

    【讨论】:

      【解决方案2】:

      谢谢@wd15。这是我所做的:

      m0 = Gmsh2D(siliconGeometry) 
      m1 = Gmsh2D(oxideGeometry) 
      
      m0_faces = m0.exteriorFaces 
      m0_vertices = numerix.unique(m0.faceVertexIDs[..., m0_faces].flatten()) m0_vertexCoords = m0.vertexCoords[..., m0_vertices ] 
      
      m1_faces = m1.exteriorFaces 
      m1_vertices = numerix.unique(m1.faceVertexIDs[..., m1_faces].flatten()) m1_vertexCoords = m1.vertexCoords[..., m0_vertices ] 
      
      surfVertexID = numerix.nearest(m0_vertexCoords , m1_vertexCoords)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多