Gmsh Example 2

Gmsh第二个例子. 在包含[0.2, 0.8]*[0.3, 0.7]的二维区域[0,1]*[0,1]上生成结构或非结构网格. 这样的网格在试验一些处理椭圆界面问题的有限元算法时是很有用的. 我们将内部矩形的四个边称为界面, 该界面将方形区域分成两个子区域: 内部和外部.
squre_with_rect
网格生成的过程很简单: 首先将区域分割成4个小正方形, 每个小正方形又包含两个三角形, 在Gmsh脚本里依次定义这些图形就可以了. 有同学可能会有疑问: 为什么要定义内部8个三角形这么麻烦, 直接定义一个内部矩形不是简单吗? 答案是, 定义8个三角形可以确保两件事:第一, 不会有三角形横跨两个区域; 第二, 矩形的四个角至少有两个内部单元共享. 这样的好处是, 最大限度的适应界面条件, 尽量降低网格对算法的影响. 下面给出脚本语言和生成的两个网格示例(结构网格lc2=lc和非结构网格lc2=0.1*lc).
squre_with_rect1squre_with_rect2

//////////////////////////////////////////////////////////////////////////////
lc = 0.2/1.0;
lc2 = 0.1*lc; //lc,lc2 - Control size of elements around points
Point(1) = {0.0, 0.0, 0.0, lc}; Point(2) = { 1.0, 0.0, 0.0, lc};
Point(3) = { 1.0, 1.0, 0.0, lc};Point(4) = {0.0, 1.0, 0.0, lc};

Point(5) = {0.2, 0.3, 0.0, lc2}; Point(6) = { 0.8, 0.3, 0.0, lc2};
Point(7) = { 0.8, 0.7, 0.0, lc2}; Point(8) = { 0.2, 0.7, 0.0, lc2};

Point(9) = {0.5, 0.5, 0.0, lc};
Point(10) = { 0.5, 0.3, 0.0, lc2}; Point(11) = { 0.8, 0.5, 0.0, lc2};
Point(12) = { 0.5, 0.7, 0.0, lc2}; Point(13) = { 0.2, 0.5, 0.0, lc2};

Point(14) = { 0.5, 0.0, 0.0, lc}; Point(15) = { 1.0, 0.5, 0.0, lc};
Point(16) = { 0.5, 1.0, 0.0, lc}; Point(17) = { 0.0, 0.5, 0.0, lc};

Line(1) = {5, 10}; Line(2) = {10, 6}; Line(3) = {5, 13}; Line(4) = {10, 9};
Line(5) = {6, 11}; Line(6) = {13, 9}; Line(7) = {9, 11}; Line(8) = {13, 8};
Line(9) = {9, 12}; Line(10) = {11, 7}; Line(11) = {8, 12}; Line(12) = {12, 7};
Line(13) = {5, 9}; Line(14) = {6, 9}; Line(15) = {8, 9}; Line(16) = {7, 9};
Line(17) = {14, 10}; Line(18) = {15, 11}; Line(19) = {16, 12}; Line(20) = {17, 13};
Line Loop(201) = {1,4,-13}; Line Loop(202) = {2,14,-4};
Line Loop(203) = {5,-7,-14}; Line Loop(204) = {7,10,16};
Line Loop(205) = {-9,-16,-12}; Line Loop(206) = {9,-11,15};
Line Loop(207) = {-8,6,-15}; Line Loop(208) = {-3,13,-6};

Plane Surface(201) = {201}; Plane Surface(202) = {202};
Plane Surface(203) = {203}; Plane Surface(204) = {204};
Plane Surface(205) = {205}; Plane Surface(206) = {206};
Plane Surface(207) = {207}; Plane Surface(208) = {208};

Line(61) = {1,14};Line(62) = {14,2};Line(63) = {2,15}; Line(64) = {15,3};
Line(65) = {3,16};Line(66) = {16,4};Line(67) = {4,17}; Line(68) = {17,1};
Line Loop(21) = {61,17,-1,3,-20,68};Line Loop(22) = {62,63,18,-5,-2,-17};
Line Loop(23) = {64,65,19,12,-10,-18};Line Loop(24) = {66,67,20,8,11,-19};
Plane Surface(21) = {21}; Plane Surface(22) = {22};
Plane Surface(23) = {23}; Plane Surface(24) = {24};

Physical Surface(1) = {201,208} ;Physical Surface(2) = {202,203} ;
Physical Surface(3) = {204,205} ;Physical Surface(4) = {206,207} ;
Physical Surface(5) = {21,22,23,24} ;

////////////////////////////////////////////////////////////////////////////////