Gmsh(1) 简介

Gmsh(1) 简介_第1张图片
Gmsh: 三维网格生成软件(开源-免费)

我在德国留学期间,在课题组做了一个关于gmsh的讲座同时在我们课题组的gitlab上写了相应的教程。因为那个gitlab只能我们内部访问,因此直接将这几个教程搬过来,先凑合着看,等我有空了再改成中文版!

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
Gmsh(1) 简介_第2张图片
step-1-box

代码

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};

你可能感兴趣的:(Gmsh(1) 简介)