python - 将网格导入 Fipy 后如何从 python 访问 gmsh 代码?

标签 python import mesh surface fipy

我已经生成了一个 gmsh 网格,并通过 Gmsh2D 导入到 FiPy 中。我想解决表面问题以设置边界条件,但我不知道如何操作。

在我在文档中发现的 FiPy 示例中,建议命名某些行以便稍后处理它们。将网格导入 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};

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

编辑:

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

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

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

最佳答案

“外”不是一张物理面孔,而是一组物理细胞。要访问“Outer”的边界面,您可以添加

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

到您的 Gmsh 脚本,然后使用

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

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

关于python - 将网格导入 Fipy 后如何从 python 访问 gmsh 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59612531/

相关文章:

Python 与 Sage 的导入错误

基于法线和中心位置修复网格中翻转面的算法

python - 在 Pandas 中将 DataFrame 名称保存为 .csv 文件名

python - 将大括号更改为 str.format() 中的标识符

java - 是否有任何可以与 PHP/Python/其他集成的沙盒脚本引擎?

确定一个点是否在 3D 网格内的算法

c# - 三角网格的良好数据结构

python - 列表迭代 - 字典列表

java - 如何使用 Maven 中列为依赖项的包中的类?

java - 从 eclipse 中的 import 语句中查找引用的库