我在德國留學期間儡蔓,在課題組做了一個關于gmsh的講座同時在我們課題組的gitlab上寫了相應的教程。因為那個gitlab只能我們內(nèi)部訪問疼邀,因此直接將這幾個教程搬過來喂江,先湊合著看,等我有空了再改成中文版檩小!
Introduction
Gmsh is a free 3D finite element mesh generator with a built-in CAD engine and post-processor. Its design goal is to provide a fast, light and user-friendly meshing tool with parametric input and advanced visualization capabilities. Gmsh is built around four modules: geometry, mesh, solver and post-processing. The specification of any input to these modules is done either interactively using the graphical user interface or in ASCII text files using Gmsh's own scripting language.
Install
It very easy to install Gmsh on your system. Just download and double click. It's not only a free but also a cross platform software.??
Windows (32 bit),
Linux,
MacOS.
Of course, it can be installed from source, but I don't recommend it so far.
simple structure of a .geo file
The .geo file, in fact, is a Gmsh's scripting file. I just call this language as Gs
=Gmsh's scripting
. Gs files support both C and C++ style comments.
lc = 1e-2;
//points
Point(1) = {0, 0, 0, lc};
Point(2) = {.1, 0, 0, lc} ;
Point(3) = {.1, .3, 0, lc} ;
Point(4) = {0, .3, 0, lc} ;
//lines
Line(1) = {1,2} ;
Line(2) = {3,2} ;
Line(3) = {3,4} ;
Line(4) = {4,1} ;
//line looped by points
Line Loop(1) = {4,1,-2,3} ;
//Plane surface is composed by line loop
Plane Surface(1) = {1} ;
//marke a specific point, line or surface
//format: Physical Point(number_label) = {point_index1,point_index_2};
Physical Point(1) = {1,2} ;
//label as a text
MY_LINE = 2;
Physical Line(MY_LINE) = {1,2} ;
Physical Line("My second line (automatic physical id)") = {3} ;
Physical Line("My third line (physical id 5)", 5) = {4} ;
Physical Surface("My surface") = {1} ;
How to display .geo
- double-click will automatically show the geometry in Gmsh GUI.
-
command line:
gmsh step-1.geo
- result
generate mesh from .geo file
using following to mesh a .geo file.
gmsh my.geo -2 -o my.msh
export to figure file
gmsh support several figure format, e.g. eps,pdf,svg...
- crop or cut the blank margins of a eps file:
epstool --copy --bbox my.eps my_new.eps
- convert eps to pdf:
epstopdf my_new.eps
- convert pdf to svg:
pdf2svg my_new.pdf my.svg
代碼
lc = 1e-2;
//points
Point(1) = {0, 0, 0, lc};
Point(2) = {.3, 0, 0, lc} ;
Point(3) = {.3, .3, 0, lc} ;
Point(4) = {0, .3, 0, lc} ;
//+
Line(1) = {4, 1};
//+
Line(2) = {1, 2};
//+
Line(3) = {3,2};
//+
Line(4) = {3, 4};
//+
//+
Line Loop(1) = {1, 2, -3, 4};
//+
Plane Surface(1) = {1};