Gmsh划分网格|四点矩形

先看下面这段官方自带脚本

gmesh 复制代码
/*********************************************************************
 *
 *  Gmsh tutorial 1
 *
 *  Variables, elementary entities (points, curves, surfaces), physical
 *  entities (points, curves, surfaces)
 *
 *********************************************************************/

// The simplest construction in Gmsh's scripting language is the
// `affectation'. The following command defines a new variable `lc':

lc = 1e-2;

// This variable can then be used in the definition of Gmsh's simplest
// `elementary entity', a `Point'. A Point is defined by a list of four numbers:
// three coordinates (X, Y and Z), and a characteristic length (lc) that sets
// the target element size at the point:

Point(1) = {0, 0, 0, lc};

// The distribution of the mesh element sizes is then obtained by interpolation
// of these characteristic lengths throughout the geometry. Another method to
// specify characteristic lengths is to use general mesh size Fields (see
// `t10.geo'). A particular case is the use of a background mesh (see `t7.geo').

// We can then define some additional points as well as our first curve.  Curves
// are Gmsh's second type of elementery entities, and, amongst curves, straight
// lines are the simplest. A straight line is defined by a list of point
// numbers. In the commands below, for example, the line 1 starts at point 1 and
// ends at point 2:

Point(2) = {.1, 0,  0, lc} ;
Point(3) = {.1, .3, 0, lc} ;
Point(4) = {0,  .3, 0, lc} ;

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

// The third elementary entity is the surface. In order to define a simple
// rectangular surface from the four curves defined above, a curve loop has first
// to be defined. A curve loop is a list of connected curves, a sign being
// associated with each curve (depending on the orientation of the curve):

Curve Loop(1) = {4,1,-2,3} ;

// We can then define the surface as a list of curve loops (only one here, since
// there are no holes--see `t4.geo'):

Plane Surface(1) = {1} ;

// At this level, Gmsh knows everything to display the rectangular surface 6 and
// to mesh it. An optional step is needed if we want to group elementary
// geometrical entities into more meaningful groups, e.g. to define some
// mathematical ("domain", "boundary"), functional ("left wing", "fuselage") or
// material ("steel", "carbon") properties.
//
// Such groups are called "Physical Groups" in Gmsh. By default, if physical
// groups are defined, Gmsh will export in output files only those elements that
// belong to at least one physical group. (To force Gmsh to save all elements,
// whether they belong to physical groups or not, set "Mesh.SaveAll=1;", or
// specify "-save_all" on the command line.)
//
// Here we define a physical curve that groups the left, bottom and right lines
// in a single group (with prescribed tag 5); and a physical surface with name
// "My surface" (with an automatic tag) containg the geometrical surface 1:

Physical Curve(5) = {1, 2, 4} ;
Physical Surface("My surface") = {1} ;

// Note that starting with Gmsh 3.0, models can be built using different
// geometry kernels than the default "built-in" kernel. By specifying
//
//   SetFactory("OpenCASCADE");
//
// any subsequent command in the .geo file would be handled by the OpenCASCADE
// geometry kernel instead of the built-in kernel. A rectangular surface could
// then simply be created with
//
//   Rectangle(2) = {.2, 0, 0, 0.1, 0.3};
//
// See tutorial/t16.geo for a complete example, and demos/boolean for more.
//+
Field[1] = Box;
//+
Delete Field [1];

以下是该Gmsh脚本代码的逐段解释:


1. 定义特征长度

gmsh 复制代码
lc = 1e-2;
  • 作用 :设置网格的特征长度为0.01,该值将影响后续生成的网格密度。
    取0.01时,如下:

取0.1时,如下:

  • 说明lc 是局部网格尺寸的基准值,越小生成的网格越密。

2. 创建点(Points)

gmsh 复制代码
Point(1) = {0, 0, 0, lc};
Point(2) = {.1, 0,  0, lc};
Point(3) = {.1, .3, 0, lc};
Point(4) = {0,  .3, 0, lc};
  • 作用:在二维平面上定义四个点。
  • 参数Point(标签) = {X坐标, Y坐标, Z坐标, 特征长度}
  • 结果:四个点构成矩形的四个顶点(左下、右下、右上、左上)。

3. 创建线段(Lines)

gmsh 复制代码
Line(1) = {1, 2};  // 从点1到点2的线段
Line(2) = {3, 2};  // 从点3到点2的线段
Line(3) = {3, 4};  // 从点3到点4的线段
Line(4) = {4, 1};  // 从点4到点1的线段
  • 作用:通过连接点生成四条线段。
  • 注意 :线段方向影响后续曲线环的定义,负号表示反向(例如 -2 表示线段2的反方向)。

4. 定义曲线环(Curve Loop)

gmsh 复制代码
Curve Loop(1) = {4, 1, -2, 3};
  • 作用:将线段组合成闭合的环形,用于生成平面。
  • 顺序 :按闭合路径依次连接线段:
    1. 线段4(点4→点1)
    2. 线段1(点1→点2)
    3. 线段-2(点2→点3,反向线段2)
    4. 线段3(点3→点4)

5. 创建平面表面(Surface)

gmsh 复制代码
Plane Surface(1) = {1};
  • 作用:通过曲线环1生成平面表面。
  • 说明:此处定义了一个矩形区域,后续将在此区域内生成网格。

6. 定义物理实体(Physical Entities)

gmsh 复制代码
Physical Curve(5) = {1, 2, 4};
Physical Surface("My surface") = {1};
  • 作用 :将几何实体分组,用于后续仿真或导出。
    • 物理曲线5:包含线段1、2、4,代表模型的边界(例如左、下、右边)。
    • 物理表面"My surface":包含表面1,代表整个矩形区域。
  • 意义:物理实体用于在导出网格时标记不同区域(如边界条件、材料属性)。

7. 其他代码片段

gmsh 复制代码
Field[1] = Box;
Delete Field [1];
  • 作用 :尝试定义一个 Box 类型的场(用于控制网格尺寸),但随后被删除。
  • 说明:这段代码可能是测试或误操作,实际未生效。

关键概念总结

  1. 特征长度 lc:控制网格密度,值越小网格越密。
  2. 曲线环方向:线段的正负号决定方向,确保闭合路径正确。
  3. 物理实体
    • 定义仿真中需要关注的区域(如边界、体积)。
    • 默认仅导出属于物理实体的网格单元。

生成的几何结构

  • 一个矩形区域,左下角在原点 (0,0),右上角在 (0.1, 0.3)。
  • 物理曲线标记了左、下、右边界,物理表面标记了整个矩形区域。

通过此脚本,Gmsh将生成一个带有结构化网格的矩形,并仅导出标记的物理实体部分。

相关推荐
垂杨有暮鸦⊙_⊙3 个月前
阻尼与共振:从理论到工程实践的深度解析
有限元分析·anasys
垂杨有暮鸦⊙_⊙3 个月前
有限元分析学习——Anasys Workbanch第一阶段笔记梳理
笔记·学习·有限元分析
垂杨有暮鸦⊙_⊙4 个月前
有限元分析学习——Anasys Workbanch第一阶段笔记(14)静定与超静定问题、约束类型介绍、简支梁挠度求解和自定义材料库建立
笔记·学习·有限元分析
垂杨有暮鸦⊙_⊙4 个月前
有限元分析学习——Anasys Workbanch第一阶段笔记(9)带孔矩形板与L型支架案例的对称平面处理方案
笔记·学习·有限元分析
垂杨有暮鸦⊙_⊙4 个月前
有限元分析学习——Anasys Workbanch第一阶段笔记(10)桌子载荷案例分析_实际载荷与均布载荷的对比
笔记·学习·有限元分析
垂杨有暮鸦⊙_⊙4 个月前
有限元分析学习——Anasys Workbanch第一阶段笔记(8)水杯案例的对称与轴对称处理
笔记·学习·有限元分析
垂杨有暮鸦⊙_⊙4 个月前
有限元分析学习——Anasys Workbanch第一阶段笔记(6)圣维南原理和模型简化
笔记·学习·有限元分析
垂杨有暮鸦⊙_⊙4 个月前
有限元分析学习——Anasys Workbanch第一阶段笔记(2)应力奇异及位移结果对比、初步了解单元的基本知识
笔记·学习·有限元分析
垂杨有暮鸦⊙_⊙4 个月前
有限元分析学习——Anasys Workbanch第一阶段笔记(4)刚体平移和弱弹簧、接触设置和基础基础
笔记·学习·有限元分析