Gmsh example: uniform mesh

摘要:利用Gmsh的Transfinite功能生成二维或三维下的一致网格。

测试一个新的有限元方法有效性的最佳网格往往是二维或三维下的一致网格。生成一致网格的方法大概有两种,一种是利用一致网格中单元的排列规律手动剖分,另外一种是利用成熟的Mesh Generator,如Gmsh来生成。
二维一致网格的手动生成可以参考如下文章http://numanal.com/?p=242,这里只考虑如何用Gmsh生成一致网格。

Gmsh脚本二维一致网格

//利用Transfinite生成标准三角形网格.
//                    --Numanal 2016-06-06

len = 0.2;    //定义结点附近网格单元大小

Point(1) = {0,0,0,len}; Point(2) = {1,0,0,len};
Point(3) = {1,1,0,len}; Point(4) = {0,1,0,len};
Line(1) = {1,2}; Line(2) = {2,3};
Line(3) = {3,4}; Line(4) = {4,1};

Line Loop(5) = {1,2,3,4}; Plane Surface(1) = {5};

// 生成标准三角元,最后的参数可以是Left, Right, 或者Alternate
Transfinite Surface{1}={1,2,3,4} Alternate;

// 通过合并三角元生成标准矩形元
// Recombine Surface{1};

Physical Surface(2) = {1};

语法说明

Transfinite Surface { expression-list };
Transfinite Surface { expression-list } = { expression-lest };
Transfinite Surface { expression-list } = { expression-lest } Left | Right | Alternate;

第一个expression-list为Surface的标志符;
第二个expression-list为构成Surface边界的三个或四个角点的标志符,如果没有定义,Gmsh会尝试自动寻找;
最后的参数Left, Right, 或Alternate用来规定三角形在网格中的不同偏向;

以下三个图形分别对应Left, Right, Alternate生成的标准三角形网格:

square_std1 square_std2 square_std3

三维标准网格的生成与二维情况类似,笔者在这里只给出一个脚本示例,有兴趣的读者可以自行探索。

h = 0.2;

Point(1) = {-1, -1, -1, h}; Point(2) = {1, -1, -1, h};
Point(3) = {1, 1, -1, h}; Point(4) = {-1, 1, -1, h};
Point(5) = {-1, -1, 1, h}; Point(6) = {1, -1, 1, h};
Point(7) = {1, 1, 1, h}; Point(8) = {-1, 1, 1, h};

Line(1) = {1,2}; Line(2) = {2,3}; Line(3) = {3,4}; Line(4) = {4,1};
Line(5) = {1,5}; Line(6) = {2,6}; Line(7) = {3,7}; Line(8) = {4,8};
Line(9) = {5,6}; Line(10) = {6,7}; Line(11) = {7,8}; Line(12) = {8,5};

Line Loop(13) = {1,2,3,4}; Plane Surface(14) = {13};
Line Loop(15) = {1,6,-9,-5}; Plane Surface(16) = {15};
Line Loop(17) = {2,7,-10,-6}; Plane Surface(18) = {17};
Line Loop(19) = {3,8,-11,-7}; Plane Surface(20) = {19};
Line Loop(21) = {4,5,-12,-8}; Plane Surface(22) = {21};
Line Loop(23) = {9,10,11,12}; Plane Surface(24) = {23};

Surface Loop(224) = {14,16,18,20,22,24};
Volume(225) = {224};

// 根据Surface上的三角元或矩形元生成相应的四面体或6面体
Transfinite Volume{225};

Physical Volume(226) = {225};