如何在将网格导入Fipy后从Python中访问gmsh代码?

huangapple go评论117阅读模式
英文:

How to access gmsh code from python after importing mesh into Fipy?

问题

我已经生成了一个通过Gmsh2D导入到FiPy中的gmsh网格。我想要处理表面面以设置边界条件,但我不知道如何做。

在FiPy的文档中,我找到了一些示例,建议在导入网格后命名某些线条以后续引用。在我将网格导入到FiPy之后,我该如何做这个?

// 注意如果您不使用任何标签所有单元格都将包括在内

Physical Surface("Outer") = {1};
Physical Surface("Middle") = {2};
Physical Surface("Inner") = {3};

// 对外部边界的西北部分进行标记

// 注意您只需要为您感兴趣的边界标记Face元素
//在2D中为Physical Line在3D中为Physical Surface)。
// FiPy不需要它们来构建网格

Physical Line("NW") = {5};

编辑

对于简单的表面面,这将起作用:
我忽略了mesh.exteriorFaces
对于一个简单的圆,这会导致简单的解决方案:

xfc, yfc = mesh.faceCenters()   # 返回x面中心坐标,...
xcc, ycc = mesh.cellCenters()

plot(xfc[where(mesh.exteriorFaces == False)],yfc[where(mesh.exteriorFaces == False)],'ro', label='inside')    
plot(xfc[where(mesh.exteriorFaces == True)],yfc[where(mesh.exteriorFaces == True)],'ko', label='surface')    
legend() 

IdentifiedSurfaceCells

尽管如此,我仍在寻找如何从外部访问gmsh代码的答案,但也许这会对其他人有所帮助:)

英文:

I have generated a gmsh mesh that I imported into FiPy via Gmsh2D. I would like to adress the surface Faces to set boundary conditions but I did not know how to.

In FiPy examples I found in the documentation it is suggested to name certain lines to address them later. How do I do this after I imported the mesh into fipy?

// note: if you do not use any labels, all Cells will be included.

Physical Surface("Outer") = {1};
Physical Surface("Middle") = {2};
Physical Surface("Inner") = {3};

// label the "north-west" part of the exterior boundary

// note: you only need to label the Face elements
// (Physical Line in 2D and Physical Surface in 3D) that correspond
// to boundaries you are interested in. FiPy does not need them to
// construct the Mesh.

Physical Line("NW") = {5};

-----------------

Edit:

For simple surface faces this will work:
I overlooked mesh.exteriorFaces.
For a simple circle this leads to the simple solution:

xfc, yfc = mesh.faceCenters()   # returns x faceCenters coordinate, ...
xcc, ycc = mesh.cellCenters()

plot(xfc[where(mesh.exteriorFaces == False)],yfc[where(mesh.exteriorFaces == False)],'ro', label='inside')    
plot(xfc[where(mesh.exteriorFaces == True)],yfc[where(mesh.exteriorFaces == True)],'ko', label='surface')    
legend() 

IdentifiedSurfaceCells

Nevertheless i am still searching for an answer on how to access the gmsh code from outside, but maybe this helps others:)

答案1

得分: 1

"Outer" 不是一个物理面,它是一组物理单元。要访问 "Outer" 的边界面,您可以将以下内容添加到您的 Gmsh 脚本中:

Physical Line("Outer Boundary") = {1, 2, 3, 4, 5, 6, 7, 8};

然后应用一个约束条件:

var.constrain(value, where=squaredCircle.physicalFaces["Outer Boundary"])

正如您发现的,您始终可以访问 mesh.exteriorFaces 以获取定义整个网格边界的面(即只有一侧有单元的面)。使用 Physical Surface 定义的 Gmsh 域不一定由 mesh.exteriorFaces 限定。

英文:

"Outer" is not a physical face, it is a set of physical cells. To access the bounding faces of "Outer", you can add

Physical Line("Outer Boundary") = {1, 2, 3, 4, 5, 6, 7, 8};

to your Gmsh script, and then apply a constraint with

var.constrain(value, where=squaredCircle.physicalFaces["Outer Boundary"])

As you found, you can always access mesh.exteriorFaces to get the faces that define the boundaries of the entire mesh (i.e., faces which only have a cell on one side). The Gmsh domains defined with Physical Surface are not necessarily bounded by mesh.exteriorFaces.

huangapple
  • 本文由 发表于 2020年1月6日 20:56:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612531.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定