[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. Mesh module

Gmsh's mesh module regroups several 1D, 2D and 3D meshing algorithms, all producing grids conforming in the sense of finite elements (see section 1.2 Mesh: finite element mesh generation):

All meshes can be subdivided to generate fully quadrangular or fully hexahedral meshes with the Mesh.SubdivisionAlgorihm option (see section B.3 Mesh options list). However, beware that the quality of subdivided elements initially generated with an unstructured algorithm can be quite poor.

6.1 Elementary vs. physical entities  
6.2 Mesh commands  
6.3 Mesh options  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 Elementary vs. physical entities

If only elementary geometrical entities are defined (or if the Mesh.SaveAll option is set; see B.3 Mesh options list), the grid produced by the mesh module will be saved "as is". That is, all the elements in the grid will be saved using the identification number of the elementary entities they discretize as their elementary region number (and 0 as their physical region number(8); 9. File formats). This can sometimes be inconvenient:

To remedy these problems, the geometry module (see section 5. Geometry module) introduces the notion of "physical" entities (also called "physical groups"). The purpose of physical entities is to assemble elementary entities into larger, possibly overlapping groups, and to control the orientation of the elements in these groups. The introduction of physical entities in large models usually greatly facilitates the manipulation of the model (e.g., using `Tools->Visibility' in the GUI) and the interfacing with external solvers.

In the MSH file format (see section 9. File formats), if physical entities are defined, the output mesh only contains those elements that belong to physical entities. Other file formats each treat physical entities in slightly different ways, depending on their capability to define groups.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2 Mesh commands

The mesh module commands mostly permit to modify the characteristic lengths and specify structured grid parameters. The actual mesh "actions" (i.e., "mesh the lines", "mesh the surfaces" and "mesh the volumes") cannot be specified in the script files. They have to be given either in the GUI or on the command line (see 3. Running Gmsh on your system, and 3.3 Command-line options).

6.2.1 Characteristic lengths  
6.2.2 Structured grids  
6.2.3 Miscellaneous  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2.1 Characteristic lengths

There are three ways to specify the size of the mesh elements for a given geometry:

  1. First, if Mesh.CharacteristicLengthFromPoints is set (it is by default), you can simply specify characteristic lengths at the geometrical points of the model (with the Point command: see 5.1.1 Points). The size of the mesh elements will then be computed by linearly interpolating these characteristic lengths on the initial mesh (see 1.2 Mesh: finite element mesh generation). This might sometimes lead to over-refinement in some areas, so that you may have to add "dummy" geometrical entities in the model in order to get the desired element sizes.

    This method works with all the algorithms implemented in the mesh module. The final element sizes are of course constrained by the structured algorithms for which the element sizes are explicitly specified (e.g., transfinite and extruded grids: see 6.2.2 Structured grids).

  2. Second, if Mesh.CharacteristicLengthFromCurvature is set (it is not by default), the mesh will be adapted with respect to the curvature of the geometrical entities.
  3. Finally, you can specify general characteristic lengths using mesh size "fields". Various fields exist:

    Fields are supported by all the algorithms except those based on Netgen. The list of available fields with their options is given below.

The three aforementioned methods can be used simultaneously, in which case the smallest element size is selected at any given point.

All element sizes are further constrained by the Mesh.CharacteristicLengthMin, Mesh.CharacteristicLengthMax and Mesh.CharacteristicLengthFactor options (see section B.3 Mesh options list)

Here are the mesh commands that are related to the specification of characteristic lengths:

Characteristic Length { expression-list } = expression;
Modify the characteristic length of the points whose identification numbers are listed in expression-list. The new value is given by expression.
Field[expression] = string;
Create a new field (with id number expression), of type string.
Field[expression].string = char-expression | expression | expression-list;
Set the option string of the expression-th field.
Background Field = expression;
Select the expression-th field as the one used to compute element sizes. Only one background field can be given; if you want to combine several field, use the Min or Max field (see below).

Here is the list of all available fields with their associated options:

Attractor
Compute the distance from the nearest node in a list. It can also
be used to compute the distance from curves, in which case each curve
is replaced by NNodesByEdge equidistant nodes and the distance from those
nodes is computed.
Options:
EdgesList
Indices of curves in the geometric model
type: list
default value: {}
FacesList
Indices of surfaces in the geometric model (Warning: might give strange results for complex surfaces)
type: list
default value: {}
NNodesByEdge
Number of nodes used to discetized each curve
type: integer
default value: 20
NodesList
Indices of nodes in the geomtric model
type: list
default value: {}

Box
The value of this field is VIn inside the box, VOut outside the box.
The box is given by

Xmin <= x <= XMax &&
YMin <= y <= YMax &&
ZMin <= z <= ZMax
Options:
VIn
Value inside the box
type: float
default value: 0
VOut
Value outside the box
type: float
default value: 0
XMax
Maximum X coordinate of the box
type: float
default value: 0
XMin
Minimum X coordinate of the box
type: float
default value: 0
YMax
Maximum Y coordinate of the box
type: float
default value: 0
YMin
Minimum Y coordinate of the box
type: float
default value: 0
ZMax
Maximum Z coordinate of the box
type: float
default value: 0
ZMin
Minimum Z coordinate of the box
type: float
default value: 0

Curvature
Compute the curvature of Field[IField]:

F = div(norm(grad(Field[IField])))
Options:
Delta
Step of the finite differences
type: float
default value: 0
IField
Field index
type: integer
default value: 1

Gradient
Compute the finite difference gradient of Field[IField]:

F = (Field[IField](X + Delta/2) -
Field[IField](X - Delta/2)) / Delta
Options:
Delta
Finite difference step
type: float
default value: 0
IField
Field index
type: integer
default value: 1
Kind
Component of the gradient to evaluate: 0 for X, 1 for Y, 2 for Z, 3 for the norm
type: integer
default value: 0

Laplacian
Compute finite difference the Laplacian of Field[IField]:

F = G(x+d,y,z) + G(x-d,y,z) +
G(x,y+d,z) + G(x,y-d,z) +
G(x,y,z+d) + G(x,y,z-d) - 6 * G(x,y,z),

where G=Field[IField] and d=Delta
Options:
Delta
Finite difference step
type: float
default value: 0.1
IField
Field index
type: integer
default value: 1

LonLat
Evaluate Field[IField] in geographic coordinates (longitude, latitude):

F = Field[IField](atan(y/x), asin(z/sqrt(x^2+y^2+z^2))
Options:
IField
Index of the field to evaluate.
type: integer
default value: 1

MathEval
Evaluate a mathematical expression. The expression can contain
x, y, z for spatial coordinates, F0, F1, ... for field values, and
and mathematical functions.
Options:
F
Mathematical function to evaluate.
type: string
default value: "F2 + Sin(z)"

Max
Take the maximum value of a list of fields.
Options:
FieldsList
Field indices
type: list
default value: {}

MaxEigenHessian
Compute the maximum eigenvalue of the Hessian matrix of
Field[IField], with the gradients evaluated by finite differences:

F = max(eig(grad(grad(Field[IField]))))
Options:
Delta
Step used for the finite differences
type: float
default value: 0
IField
Field index
type: integer
default value: 1

Mean
Simple smoother:

F = (G(x+delta,y,z) + G(x-delta,y,z) +
G(x,y+delta,z) + G(x,y-delta,z) +
G(x,y,z+delta) + G(x,y,z-delta) +
G(x,y,z)) / 7,

where G=Field[IField]
Options:
Delta
Distance used to compute the mean value
type: float
default value: 0.0001
IField
Field index
type: integer
default value: 0

Min
Take the minimum value of a list of fields.
Options:
FieldsList
Field indices
type: list
default value: {}

Param
Evaluate Field IField in parametric coordinates:

F = Field[IField](FX,FY,FZ)

See the MathEval Field help to get a description of valid FX, FY
and FZ expressions.
Options:
FX
X component of parametric function
type: string
default value: ""
FY
Y component of parametric function
type: string
default value: ""
FZ
Z component of parametric function
type: string
default value: ""
IField
Field index
type: integer
default value: 1

PostView
Evaluate the post processing view IView.
Options:
CropNegativeValues
return LC_MAX instead of a negative value (this option is needed for backward compatibility with the BackgroundMesh option
type: boolean
default value: 1
IView
Post-processing view index
type: integer
default value: 0

Restrict
Restrict the application of a field to a given list of geometrical
curves, surfaces or volumes.
Options:
EdgesList
Curve indices
type: list
default value: {}
FacesList
Surface indices
type: list
default value: {}
IField
Field index
type: integer
default value: 1
RegionsList
Volume indices
type: list
default value: {}

Structured
Linearly interpolate between data provided on a 3D rectangular
structured grid.

The format of the input file is:

Ox Oy Oz
Dx Dy Dz
nx ny nz
v(0,0,0) v(0,0,1) v(0,0,2) ...
v(0,1,0) v(0,1,1) v(0,1,2) ...
v(0,2,0) v(0,2,1) v(0,2,2) ...
... ... ...
v(1,0,0) ... ...

where O are the coordinates of the first node, D are the distances
between nodes in each direction, n are the numbers of nodes in each
direction, and v are the values on each node.
Options:
FileName
Name of the input file
type: path
default value: ""
TextFormat
True for ASCII input files, false for binary files (4 bite signed integers for n, double precision floating points for v, D and O)
type: boolean
default value: 0

Threshold
F = LCMin if Field[IField] <= DistMin,
F = LCMax if Field[IField] >= DistMax,
F = interpolation between LcMin and LcMax if DistMin < Field[IField] < DistMax
Options:
DistMax
Distance from entity after which element size will be LcMax
type: float
default value: 10
DistMin
Distance from entity up to which element size will be LcMin
type: float
default value: 1
IField
Index of the field to evaluate
type: integer
default value: 0
LcMax
Element size outside DistMax
type: float
default value: 1
LcMin
Element size inside DistMin
type: float
default value: 0.1
Sigmoid
True to interpolate between LcMin and LcMax using a sigmoid, false to interpolate linearly
type: boolean
default value: 0
StopAtDistMax
True to not impose element size outside DistMax (i.e., F = a very big value if Field[IField] > DistMax)
type: boolean
default value: 0

UTM
Evaluate Field[IField] in Universal Transverse Mercator coordinates.
The formulas for the coordinates transformation are taken from:

http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM
Options:
IField
Index of the field to evaluate
type: integer
default value: 1
Zone
Zone of the UTM projection
type: integer
default value: 0


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2.2 Structured grids

Extrude { expression-list } { extrude-list layers }
Extrudes both the geometry and the mesh using a translation (see section 5.1.5 Extrusions). The layers option determines how the mesh is extruded and has the following syntax:

 
layers:
  Layers { expression } | 
  Layers { { expression-list }, { expression-list } } | 
  Recombine; ...

In the first Layers form, expression gives the number of elements to be created in the (single) layer. In the second form, the first expression-list defines how many elements should be created in each extruded layer, and the second expression-list gives the normalized height of each layer (the list should contain a sequence of n numbers 0 < h1 < h2 < ... < hn <= 1). See A.3 `t3.geo', for an example.

For line extrusions, the Recombine option will recombine triangles into quadrangles when possible. For surface extrusions, the Recombine option will recombine tetrahedra into prisms, hexahedra or pyramids.

Please note that, starting with Gmsh 2.0, region numbers cannot be specified explicitly anymore in Layers commands. Instead, as with all other geometry commands, you must use the automatically created entity identifier created by the extrusion command. For example, the following extrusion command will return the id of the new "top" surface in num[0] and the id of the new volume in num[1]:
 
num[] = Extrude {0,0,1} { Surface{1}; Layers{10}; };

Extrude { { expression-list }, { expression-list }, expression } { extrude-list layers }
Extrudes both the geometry and the mesh using a rotation (see section 5.1.5 Extrusions). The layers option is defined as above.

Extrude { { expression-list }, { expression-list }, { expression-list }, expression } { extrude-list layers }
Extrudes both the geometry and the mesh using a combined translation and rotation (see section 5.1.5 Extrusions). The layers option is defined as above.

Extrude { Surface { expression-list }; layers }
Extrudes a boundary layer along the normals of the specified surfaces.

Transfinite Line { expression-list } | "*" = expression < Using Progression | Bump expression >;
Selects the lines in expression-list to be meshed with the 1D transfinite algorithm. The expression on the right hand side gives the number of nodes that will be created on the line (this overrides any characteristic length prescription--see 6.2.1 Characteristic lengths). The optional argument `Using Progression expression' instructs the transfinite algorithm to distribute the nodes following a geometric progression (Progression 2 meaning for example that each line element in the series will be twice as long as the preceding one). The optional argument `Using Bump expression' instructs the transfinite algorithm to distribute the nodes with a refinement at both ends of the line.

Transfinite Surface { expression-list } | "*" < = { expression-list } > < Left | Right | Alternate > ;
Selects surfaces to be meshed with the 2D transfinite algorithm. The expression-list on the right-hand-side should contain the identification numbers of three or four points on the boundary of the surface that define the corners of the transfinite interpolation. If no identfication numbers are given, the transfinite algorithm will try to find the corners automatically. The optional argument specifies the way the triangles are oriented when the mesh is not recombined.

Transfinite Volume { expression-list } | "*" < = { expression-list } > ;
Selects five- or six-face volumes to be meshed with the 3D transfinite algorithm. The expression-list on the right-hand-side should contain the identification numbers of the six or eight points on the boundary of the volume that define the corners of the transfinite interpolation. If no identfication numbers are given, the transfinite algorithm will try to find the corners automatically.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2.3 Miscellaneous

Here is a list of all other mesh commands currently available:

Coherence Mesh;
Removes all duplicate mesh vertices.

Color color-expression { Point | Line | Surface | Volume { expression-list }; ... }
Sets the mesh color of the entities in expression-list to color-expression.

Hide { Point | Line | Surface | Volume { expression-list }; ... }
Hides the mesh of the entities in expression-list, if General.VisibilityMode is set to 0 or 2.

Hide char-expression;
Hides the mesh of the entity char-expression, if General.VisibilityMode is set to 0 or 2 (char-expression can for example be "*").

Recombine Surface { expression-list } | "*" < = expression >;
Recombines the triangular meshes of the surfaces listed in expression-list into mixed triangular/quadrangular meshes. The optional expression on the right hand side specifies the maximum difference (in degrees) allowed between the largest angle of a quadrangle and a right angle (a value of 0 would only accept quadrangles with right angles; a value of 90 would allow degenerate quadrangles; default value is 45).

Save char-expression;
Saves the mesh in a file named char-expression, using the current Mesh.Format (see section B.3 Mesh options list). If the path in char-expression is not absolute, char-expression is appended to the path of the current file.

Show { Point | Line | Surface | Volume { expression-list }; ... }
Shows the mesh of the entities in expression-list, if General.VisibilityMode is set to 0 or 2.

Show char-expression;
Shows the mesh of the entity char-expression, if General.VisibilityMode is set to 0 or 2 (char-expression can for example be "*").

Smoother Surface { expression-list } = expression;
Sets number of elliptic smoothing steps for the surfaces listed in expression-list (smothing only applies to transfinite meshes at the moment).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3 Mesh options

The list of all the options that control the behavior of mesh commands, as well as the way meshes are displayed in the GUI, is given in B.3 Mesh options list.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

Back to geuz.org/gmsh