如何在Gmsh中为中间细化层生成结构化交替3D网格?
Gmsh中间结构化细化层箱体网格实现方案
我尝试在Gmsh中创建带有中间结构化细化层的箱体网格,当前2D网格符合预期,但生成3D网格时中间层元素变为对角元,需要实现中间层的结构化交替3D网格。以下是初始.geo代码:
lc = 100.; Mesh.CharacteristicLengthFromPoints = 1.; Mesh.CharacteristicLengthExtendFromBoundary = 1.; Mesh.CharacteristicLengthFromCurvature = 1.; Mesh.CharacteristicLengthMin = 10.; Mesh.CharacteristicLengthMax = lc; Lbox = 100; Hbox = 100; Wbox = 100; Wref = 12; Point(1) = {0, 0, (Wbox - Wref)/2, 1.0}; Point(2) = {Lbox, 0, (Wbox - Wref)/2, 1.0}; Point(3) = {Lbox, Hbox, (Wbox - Wref)/2, 1.0}; Point(4) = {0, Hbox, (Wbox - Wref)/2, 1.0}; Line(1) = {2, 1}; Line(2) = {1, 4}; Line(3) = {4, 3}; Line(4) = {3, 2}; Curve Loop(1) = {4, 1, 2, 3}; Plane Surface(1) = {1}; size_el = 1.5; n_el_big = Lbox/size_el + 1.; n_el_small = Wref/size_el + 1.; Extrude {0, 0, Wref} { Surface{1}; //Layers{n_el_small}; } Transfinite Curve {2, 3, 4, 1, 8, 9, 6, 7} = n_el_big Using Progression 1; Transfinite Curve {20, 11, 12, 16} = n_el_small Using Progression 1; Transfinite Surface {1} Alternate; Transfinite Surface {21} Alternate; Transfinite Surface {26} Alternate; Transfinite Surface {13} Alternate; Transfinite Surface {25} Alternate; Transfinite Surface {17} Alternate; /*//Recombine Surface {1, 21, 26, 13, 25, 17}; Used to have hexahedron elements*/ Transfinite Volume{1} = {14, 10, 6, 5, 4, 1, 2, 3}; Point(15) = {0, 0, 0, 1.0}; Point(16) = {Lbox, 0, 0, 1.0}; Point(17) = {Lbox, Hbox, 0, 1.0}; Point(18) = {0, Hbox, 0, 1.0}; Point(19) = {0, 0, Wbox, 1.0}; Point(20) = {Lbox, 0, Wbox, 1.0}; Point(21) = {Lbox, Hbox, Wbox, 1.0}; Point(22) = {0, Hbox, Wbox, 1.0}; Line(21) = {14, 22}; Line(22) = {22, 21}; Line(23) = {21, 5}; Line(24) = {22, 19}; Line(25) = {19, 10}; Line(26) = {19, 20}; Line(27) = {20, 6}; Line(28) = {20, 21}; Line(29) = {2, 16}; Line(30) = {16, 17}; Line(31) = {17, 3}; Line(32) = {17, 18}; Line(33) = {18, 4}; Line(34) = {18, 15}; Line(35) = {15, 1}; Line(36) = {15, 16}; /*//+*/ Curve Loop(2) = {31, -3, -33, -32}; Plane Surface(27) = {2}; Curve Loop(3) = {33, -2, -35, -34}; Plane Surface(28) = {3}; Curve Loop(4) = {35, -1, 29, -36}; Plane Surface(29) = {4}; Curve Loop(5) = {30, 31, 4, 29}; Plane Surface(30) = {5}; Curve Loop(6) = {32, 34, 36, 30}; Plane Surface(31) = {6}; Curve Loop(7) = {23, 6, -27, 28}; Plane Surface(32) = {7}; Curve Loop(8) = {23, -9, 21, 22}; Plane Surface(33) = {8}; Curve Loop(9) = {27, 7, -25, 26}; Plane Surface(34) = {9}; Curve Loop(10) = {25, 8, 21, 24}; Plane Surface(35) = {10}; Curve Loop(11) = {26, 28, -22, 24}; Plane Surface(36) = {11}; Surface Loop(1) = {35, 34, 32, 33, 36, 26}; Volume(2) = {1}; Surface Loop(2) = {28, 27, 30, 31, 29, 1}; Volume(3) = {2}; Transfinite Curve {33, 35, 25, 31, 27, 23} = 6 Using Progression 0.6; Transfinite Curve {29, 21} = 6 Using Progression 1.4;
问题原因及解决步骤
- Extrude未指定Layers:拉伸中间层时未明确层数,导致网格节点数不匹配,需启用
Layers{n_el_small}参数 - 未重组曲面:注释掉了曲面重组命令,结构化四边形曲面是生成六面体网格的前提,必须启用
Recombine Surface - Transfinite Volume缺失Alternate关键字:未指定体的交替结构,导致生成对角元
- 未重组体:需对中间层Volume执行重组,强制生成六面体元素
修改后的核心代码片段
// 修正Extrude,指定拉伸层数 Extrude {0, 0, Wref} { Surface{1}; Layers{n_el_small}; } // 启用曲面重组,生成结构化四边形 Recombine Surface {1, 21, 26, 13, 25, 17}; // 修正Transfinite Volume,添加Alternate关键字 Transfinite Volume{1} = {14, 10, 6, 5, 4, 1, 2, 3} Alternate; // 重组中间层Volume,生成六面体元素 Recombine Volume {1};
完整修改后代码
lc = 100.; Mesh.CharacteristicLengthFromPoints = 1.; Mesh.CharacteristicLengthExtendFromBoundary = 1.; Mesh.CharacteristicLengthFromCurvature = 1.; Mesh.CharacteristicLengthMin = 10.; Mesh.CharacteristicLengthMax = lc; Lbox = 100; Hbox = 100; Wbox = 100; Wref = 12; Point(1) = {0, 0, (Wbox - Wref)/2, 1.0}; Point(2) = {Lbox, 0, (Wbox - Wref)/2, 1.0}; Point(3) = {Lbox, Hbox, (Wbox - Wref)/2, 1.0}; Point(4) = {0, Hbox, (Wbox - Wref)/2, 1.0}; Line(1) = {2, 1}; Line(2) = {1, 4}; Line(3) = {4, 3}; Line(4) = {3, 2}; Curve Loop(1) = {4, 1, 2, 3}; Plane Surface(1) = {1}; size_el = 1.5; n_el_big = Lbox/size_el + 1.; n_el_small = Wref/size_el + 1.; // 启用Layers参数,明确拉伸层数 Extrude {0, 0, Wref} { Surface{1}; Layers{n_el_small}; } Transfinite Curve {2, 3, 4, 1, 8, 9, 6, 7} = n_el_big Using Progression 1; Transfinite Curve {20, 11, 12, 16} = n_el_small Using Progression 1; Transfinite Surface {1} Alternate; Transfinite Surface {21} Alternate; Transfinite Surface {26} Alternate; Transfinite Surface {13} Alternate; Transfinite Surface {25} Alternate; Transfinite Surface {17} Alternate; // 重组曲面,生成结构化四边形网格 Recombine Surface {1, 21, 26, 13, 25, 17}; // 添加Alternate关键字,指定体的交替结构 Transfinite Volume{1} = {14, 10, 6, 5, 4, 1, 2, 3} Alternate; // 重组体,强制生成六面体元素 Recombine Volume {1}; Point(15) = {0, 0, 0, 1.0}; Point(16) = {Lbox, 0, 0, 1.0}; Point(17) = {Lbox, Hbox, 0, 1.0}; Point(18) = {0, Hbox, 0, 1.0}; Point(19) = {0, 0, Wbox, 1.0}; Point(20) = {Lbox, 0, Wbox, 1.0}; Point(21) = {Lbox, Hbox, Wbox, 1.0}; Point(22) = {0, Hbox, Wbox, 1.0}; Line(21) = {14, 22}; Line(22) = {22, 21}; Line(23) = {21, 5}; Line(24) = {22, 19}; Line(25) = {19, 10}; Line(26) = {19, 20}; Line(27) = {20, 6}; Line(28) = {20, 21}; Line(29) = {2, 16}; Line(30) = {16, 17}; Line(31) = {17, 3}; Line(32) = {17, 18}; Line(33) = {18, 4}; Line(34) = {18, 15}; Line(35) = {15, 1}; Line(36) = {15, 16}; /*//+*/ Curve Loop(2) = {31, -3, -33, -32}; Plane Surface(27) = {2}; Curve Loop(3) = {33, -2, -35, -34}; Plane Surface(28) = {3}; Curve Loop(4) = {35, -1, 29, -36}; Plane Surface(29) = {4}; Curve Loop(5) = {30, 31, 4, 29}; Plane Surface(30) = {5}; Curve Loop(6) = {32, 34, 36, 30}; Plane Surface(31) = {6}; Curve Loop(7) = {23, 6, -27, 28}; Plane Surface(32) = {7}; Curve Loop(8) = {23, -9, 21, 22}; Plane Surface(33) = {8}; Curve Loop(9) = {27, 7, -25, 26}; Plane Surface(34) = {9}; Curve Loop(10) = {25, 8, 21, 24}; Plane Surface(35) = {10}; Curve Loop(11) = {26, 28, -22, 24}; Plane Surface(36) = {11}; Surface Loop(1) = {35, 34, 32, 33, 36, 26}; Volume(2) = {1}; Surface Loop(2) = {28, 27, 30, 31, 29, 1}; Volume(3) = {2}; Transfinite Curve {33, 35, 25, 31, 27, 23} = 6 Using Progression 0.6; Transfinite Curve {29, 21} = 6 Using Progression 1.4;
验证说明
修改后生成的中间层3D网格会是结构化交替的六面体元素,而非对角元。关键在于确保曲面重组为四边形,体的Transfinite设置包含Alternate关键字,同时重组体元素。
内容的提问来源于stack exchange,提问作者Gabriel Dante
相关产品推荐
相关产品推荐

