Gmsh 导出到 .su2 网格

Gmsh export to .su2 mesh

我目前正在使用 python 脚本在机翼周围构建网格。然而,一旦 msh 完成并且是时候从 Gmsh 导出到 .su2 网格格式,就会发生错误。为 SU2 生成的网格文件 .su2 文件包含在构建几何体过程中使用的点。我曾尝试创建物理组,然后在不点击全部保存的情况下导出,但这没有用。当前的 .geo 文件如下:

Point(1)={0.99655,0.00159,0,1};
Point(2)={0.98706,0.0065,0,1};
Point(3)={0.97304,0.01434,0,1};
Point(4)={0.9553,0.02381,0,1};
Point(5)={0.93358,0.03376,0,1};
Point(6)={0.90734,0.044,0,1};
Point(7)={0.87671,0.05481,0,1};
Point(8)={0.84221,0.0662,0,1};
Point(9)={0.80436,0.07803,0,1};
Point(10)={0.76373,0.0901,0,1};
Point(11)={0.7209,0.10215,0,1};
Point(12)={0.67644,0.11391,0,1};
Point(13)={0.63092,0.12506,0,1};
Point(14)={0.58491,0.13524,0,1};
Point(15)={0.53893,0.1441,0,1};
Point(16)={0.49347,0.15116,0,1};
Point(17)={0.4487,0.15593,0,1};
Point(18)={0.40464,0.15828,0,1};
Point(19)={0.36149,0.15824,0,1};
Point(20)={0.31947,0.1559,0,1};
Point(21)={0.27885,0.15138,0,1};
Point(22)={0.23987,0.14485,0,1};
Point(23)={0.20286,0.13657,0,1};
Point(24)={0.16816,0.12676,0,1};
Point(25)={0.13611,0.11562,0,1};
Point(26)={0.107,0.10337,0,1};
Point(27)={0.08106,0.09023,0,1};
Point(28)={0.05852,0.07646,0,1};
Point(29)={0.03953,0.06232,0,1};
Point(30)={0.02421,0.04812,0,1};
Point(31)={0.01262,0.03419,0,1};
Point(32)={0.00481,0.02093,0,1};
Point(33)={0.00071,0.00879,0,1};
Point(34)={2e-05,0.00088,0,1};
Point(35)={0.00033,-0.00192,0,1};
Point(36)={0.00071,-0.00362,0,1};
Point(37)={0.00125,-0.00518,0,1};
Point(38)={0.00157,-0.0059,0,1};
Point(39)={0.00194,-0.00656,0,1};
Point(40)={0.00237,-0.00717,0,1};
Point(41)={0.00288,-0.00771,0,1};
Point(42)={0.00348,-0.00823,0,1};
Point(43)={0.00415,-0.00874,0,1};
Point(44)={0.00571,-0.00969,0,1};
Point(45)={0.00751,-0.01057,0,1};
Point(46)={0.01065,-0.01177,0,1};
Point(47)={0.01365,-0.01266,0,1};
Point(48)={0.02892,-0.01485,0,1};
Point(49)={0.04947,-0.01482,0,1};
Point(50)={0.07533,-0.01236,0,1};
Point(51)={0.1067,-0.0074,0,1};
Point(52)={0.14385,-2e-05,0,1};
Point(53)={0.18727,0.00922,0,1};
Point(54)={0.23688,0.01913,0,1};
Point(55)={0.29196,0.02865,0,1};
Point(56)={0.35163,0.03687,0,1};
Point(57)={0.41449,0.04283,0,1};
Point(58)={0.47867,0.04626,0,1};
Point(59)={0.54275,0.0476,0,1};
Point(60)={0.60579,0.04715,0,1};
Point(61)={0.6669,0.04501,0,1};
Point(62)={0.72503,0.04126,0,1};
Point(63)={0.77912,0.03625,0,1};
Point(64)={0.82836,0.0305,0,1};
Point(65)={0.87219,0.02444,0,1};
Point(66)={0.91012,0.01844,0,1};
Point(67)={0.94179,0.01286,0,1};
Point(68)={0.96692,0.00794,0,1};
Point(69)={0.98519,0.0039,0,1};
Point(70)={0.99629,0.00106,0,1};
Point(71)={0.99655,0.25159,0,1};
Point(72)={0.67644,0.36391,0,1};
Point(73)={0.20286,0.38656999999999997,0,1};
Point(74)={-0.75,0,0,1};
Point(75)={0.23688,-0.23087,0,1};
Point(76)={0.72503,-0.20874,0,1};
Point(77)={0.99629,-0.24894,0,1};
Point(78)={0.99655,10.13657,0,1};
Point(79)={0.20286,10.13657,0,1};
Point(80)={-30,0,0,1};
Point(81)={0.23688,-9.98087,0,1};
Point(82)={0.99629,-9.98087,0,1};
BSpline(1)={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
Transfinite Curve {1}=20 Using Progression 1;
BSpline(2)={23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54};
Transfinite Curve {2}=50 Using Progression 1;
BSpline(3)={54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70};
Transfinite Curve {3}=20 Using Progression 1;
BSpline(4)={71, 72, 73};
Transfinite Curve {4}=20 Using Progression 1;
BSpline(5)={73, 74, 75};
Transfinite Curve {5}=50 Using Progression 1;
BSpline(6)={75, 76, 77};
Transfinite Curve {6}=20 Using Progression 1;
BSpline(7)={79, 80, 81};
Transfinite Curve {7}=50 Using Progression 1;
Line(8)={70,1};
Transfinite Curve {8}=5 Using Progression 1;
Line(9)={1,71};
Transfinite Curve {9}=10 Using Progression 1.2;
Line(10)={71,78};
Transfinite Curve {10}=10 Using Progression 1;
Line(11)={78,79};
Transfinite Curve {11}=20 Using Progression 1;
Line(12)={79,73};
Transfinite Curve {12}=10 Using Progression 1;
Line(13)={23,73};
Transfinite Curve {13}=10 Using Progression 1.2;
Line(14)={54,75};
Transfinite Curve {14}=10 Using Progression 1.2;
Line(15)={75,81};
Transfinite Curve {15}=10 Using Progression 1;
Line(16)={81,82};
Transfinite Curve {16}=20 Using Progression 1;
Line(17)={82,77};
Transfinite Curve {17}=10 Using Progression 1;
Line(18)={70,77};
Transfinite Curve {18}=10 Using Progression 1.2;
Point(83)={20.99655,10.13657,0,1};
Point(84)={20.99655,0.25159,0,1};
Point(85)={20.99655,0.00159,0,1};
Point(86)={20.99655,0.00106,0,1};
Point(87)={20.99655,-0.24894,0,1};
Point(88)={20.99655,-9.98087,0,1};
Line(19)={78,83};
Transfinite Curve {19}=20 Using Progression 1;
Line(20)={71,84};
Transfinite Curve {20}=20 Using Progression 1;
Line(21)={1,85};
Transfinite Curve {21}=20 Using Progression 1;
Line(22)={70,86};
Transfinite Curve {22}=20 Using Progression 1;
Line(23)={77,87};
Transfinite Curve {23}=20 Using Progression 1;
Line(24)={82,88};
Transfinite Curve {24}=20 Using Progression 1;
Line(25)={86,85};
Transfinite Curve {25}=5 Using Progression 1;
Line(26)={85,84};
Transfinite Curve {26}=10 Using Progression 1.2;
Line(27)={84,83};
Transfinite Curve {27}=10 Using Progression 1;
Line(28)={86,87};
Transfinite Curve {28}=10 Using Progression 1.2;
Line(29)={87,88};
Transfinite Curve {29}=10 Using Progression 1;
Curve Loop(1) = {12, 5, 15, -7};Curve Loop(2) = {14, -5, -13, 2};Curve Loop(3) = {10, 11, 12, -4};Curve Loop(4) = {9, 4, -13, -1};Curve Loop(5) = {3, 18, -6, -14};Curve Loop(6) = {6, -17, -16, -15};Curve Loop(7) = {19, -27, -20, 10};Curve Loop(8) = {20, -26, -21, 9};Curve Loop(9) = {25, -21, -8, 22};Curve Loop(10) = {22, 28, -23, -18};Curve Loop(11) = {23, 29, -24, 17};Plane Surface(1) = {1};
 Transfinite Surface {1};
 Recombine Surface {1};
 Plane Surface(2) = {2};
 Transfinite Surface {2};
 Recombine Surface {2};
 Plane Surface(3) = {3};
 Transfinite Surface {3};
 Recombine Surface {3};
 Plane Surface(4) = {4};
 Transfinite Surface {4};
 Recombine Surface {4};
 Plane Surface(5) = {5};
 Transfinite Surface {5};
 Recombine Surface {5};
 Plane Surface(6) = {6};
 Transfinite Surface {6};
 Recombine Surface {6};
 Plane Surface(7) = {7};
 Transfinite Surface {7};
 Recombine Surface {7};
 Plane Surface(8) = {8};
 Transfinite Surface {8};
 Recombine Surface {8};
 Plane Surface(9) = {9};
 Transfinite Surface {9};
 Recombine Surface {9};
 Plane Surface(10) = {10};
 Transfinite Surface {10};
 Recombine Surface {10};
 Plane Surface(11) = {11};
 Transfinite Surface {11};
 Recombine Surface {11};
Physical Curve("airfoil") = {1, 2, 3,8};
Physical Curve("farfield") = {25, 26, 27, 19, 11, 7, 16, 24, 29, 28};
Physical Surface("domain") = {1, 3, 7, 11, 8, 10, 6, 5, 2, 4,9};

这有点奇怪,我不知道如何以标准方式解决这个问题,因为那些实体(比如 Point 80 at (-30,0,0))甚至出现在原生 GMSH 中网格格式。 "building points" 出现在最近引入的 msh v4 format 中。虽然我确信有一种方法可以将它们从导出中关闭,但我不知道具体怎么做。

不过,我找到了解决方法。除了标准工作流程,您还可以使用 msh v2 legacy format。在这种情况下,我看到一个没有额外点的干净网格:

然后,您可以使用此 mshv2 文件将其转换为您选择的任何其他网格格式。

要获取 mshv2,我使用命令行:

/Applications/Gmsh.app/Contents/MacOS/gmsh -2 -format msh2 test.geo 

如果您正在使用 Windows 或以任何其他方式安装的 GMSH 二进制文件,请调整 GMSH 可执行文件的路径。

虽然这个答案不能让我 100% 满意,但它至少应该提供一个临时的解决方法。

使用 Windows 下的 gmsh 4.8.4 不会出现此问题,您的脚本工作正常。您已经提到了 2 个重要步骤:

  1. 为边界和 2D 表面(或 3D 体积)创建物理标签。尽管 Physical Surface(/Volume) 的名称不会出现在 .su2 格式的网格中,但创建它很重要。据我所知,gmsh 仅写入物理标签中包含的内容 IF...

  2. ...您在导出网格时没有 select Save all elements

您可以通过以下方式扩展上述 gmsh 脚本:

Mesh 1; Mesh 2; // do 1D and 2D meshing
Mesh.Format = 42; // specifies the .su2 format
Mesh.SaveAll= 0; // 0= No (default), 1= Yes
Save "mesh_name.su2";

只需调用脚本即可创建网格并正确保存(例如,不保存所有元素)。

使用 Mesh.SaveAll= 0; 我将正确数量的 2454 个节点写入网格。在 .su2 格式中,点部分以 NPOIN= 2454 开头,在本例中为

NPOIN= 2454
0.99655 0.00159 0
0.20286 0.13657 1
0.23688 0.01913 2
0.99629 0.00106 3
0.99655 0.25159 4
0.20286 0.38657 5
0.23688 -0.23087 6
0.99629 -0.24894 7
0.99655 10.13657 8
0.20286 10.13657 9
0.23688 -9.980869999999999 10
0.99629 -9.980869999999999 11
20.99655 10.13657 12
20.99655 0.25159 13
20.99655 0.00159 14
20.99655 0.00106 15
20.99655 -0.24894 16
20.99655 -9.980869999999999 17
0.9585217395211783 0.0219493557141525 18
... more mesh points

特别注意:如果您的 gmsh-Points 之一最终成为实际的网格节点。它将首先写在该列表中。您会认出这些,因为您通常会在 gmsh 自行确定的节点上使用低于默认精度的精度。

现在有了 Mesh.SaveAll= 1;,我得到了 70 个“帮助”点,这些点被额外写入我们不想要的点列表中:

NPOIN= 2524
0.99655 0.00159 0
0.98706 0.0065 1
0.97304 0.01434 2
... more points
0.20286 10.13657 78
-30 0 79 // <-- this is exactly Point(80) in gmsh
0.23688 -9.980869999999999 80
... more points

如果看一下网格中点列表的开头就很容易发现,因为第一个写入的点都是 .geo 文件中的所有 Point

我使用这种方法将 .su2 网格与 SU2 求解器一起成功编写了几年,所以这不是最近可能已解决的问题。 总结一下:为你想要在最终网格中拥有的所有东西创建物理实体,而不是 Save all elements.