Introduction
Version 2 was Gmsh’s native mesh format before version 4, and many solvers and converters still exchange it. Its last revision is 2.2. Nodes and elements are flat lists; each element carries a list of integer tags that say which physical group, geometrical entity and partition it belongs to. A file is text, or text section lines around binary numbers. This page follows the version 2 section of the Gmsh 4.15.2 manual and the version 2 reader and writer in the source of that release.
Sections
Each section starts with a $Name line and ends with $EndName.
| Section | Holds |
|---|---|
$MeshFormat | Version, text or binary, number size |
$PhysicalNames | Names of physical groups |
$Nodes | Node numbers and coordinates |
$ParametricNodes | Nodes with their position on a model entity, in place of $Nodes |
$Elements | Elements, their type, tags and nodes |
$Periodic | Matching nodes of periodic entities |
$NodeData | A field of values on nodes |
$ElementData | A field of values on elements |
$ElementNodeData | A field of values on the nodes of each element |
$InterpolationScheme | Interpolation matrices for the fields |
Example
Two quadrangles in physical group 99 on entity 2, with a scalar field on the six nodes.
$MeshFormat
2.2 0 8
$EndMeshFormat
$Nodes
6
1 0.0 0.0 0.0
2 1.0 0.0 0.0
3 1.0 1.0 0.0
4 0.0 1.0 0.0
5 2.0 0.0 0.0
6 2.0 1.0 0.0
$EndNodes
$Elements
2
1 3 2 99 2 1 2 3 4
2 3 2 99 2 2 5 6 3
$EndElements
$NodeData
1
"My view"
1
0.0
3
0
1
6
1 0.0
2 0.1
3 0.2
4 0.0
5 0.2
6 0.4
$EndNodeData
$MeshFormat
$MeshFormat
version file-type data-size
$EndMeshFormat
version– a decimal number, 2.2 for the current revision.file-type– 0 for text, 1 for binary.data-size– size in bytes of the floating point numbers; only 8, the size of a double, is supported.
$PhysicalNames
$PhysicalNames
number-of-names
dimension physical-tag "name"
…
$EndPhysicalNames
The dimension is that of the group’s entities: 0 point, 1 curve, 2 surface, 3 volume. The section is text even in a binary file. Gmsh’s reader expects the dimension only when the file’s version is above 2.0, and its writer cuts names to 128 characters.
$Nodes
$Nodes
number-of-nodes
node-number x y z
…
$EndNodes
Node numbers are positive; they need not be continuous or in order.
$ParametricNodes
Gmsh can write this section instead, to keep each node’s place on the model. The manual does not describe it; the layout below is that of Gmsh’s reader and writer.
node-number x y z entity-dimension entity-tag [u [v]]
u is present for dimension 1, u v for dimension 2, and nothing follows for
dimensions 0 and 3. In a binary file the integers are 4 bytes and the parameters doubles.
$Elements
$Elements
number-of-elements
elm-number elm-type number-of-tags tag … node-number …
…
$EndElements
elm-type fixes how many node numbers follow. The tags mean, in order:
| Position | Tag |
|---|---|
| 1 | Physical group |
| 2 | Elementary model entity |
| 3 | Number of mesh partitions the element belongs to |
| 4 onwards | The partition numbers; a negative number marks a ghost cell in that partition |
A tag of 0 means the same as no tag. Gmsh and most programs expect at least the first two.
$Periodic
$Periodic
number-of-periodic-entities
dimension entity-tag master-entity-tag
Affine value …
number-of-nodes
node-number master-node-number
…
$EndPeriodic
The block from dimension to the last node pair repeats for each periodic entity. The
Affine line is optional; Gmsh reads and writes 16 values after the word, the transform
from the master entity. Its reader looks entities up for dimensions 0 to 2.
Result data
$NodeData, $ElementData and $ElementNodeData share one header:
three lists of tags, each preceded by its length.
number-of-string-tags
"string-tag"
…
number-of-real-tags
real-tag
…
number-of-integer-tags
integer-tag
…
| Tag | Meaning |
|---|---|
| String 1 | Name of the view |
| String 2 | Name of the interpolation scheme |
| Real 1 | Time value |
| Integer 1 | Time step, counted from 0 |
| Integer 2 | Components per value: 1, 3 or 9 |
| Integer 3 | Number of nodes or elements listed |
| Integer 4 | Partition of the data, 0 for none |
The rows follow, with n the number of components:
| Section | Row |
|---|---|
$NodeData | node number, n values |
$ElementData | element number, n values |
$ElementNodeData | element number, number of nodes m, n × m values |
$InterpolationScheme
"name"
number-of-element-topologies
elm-topology
number-of-interpolation-matrices
num-rows num-columns value …
…
Topology numbers are 1 point, 2 line, 3 triangle, 4 quadrangle, 5 tetrahedron, 6 pyramid, 7 prism, 8 hexahedron, 9 polygon and 10 polyhedron. The manual asks for two matrices per topology, each given as its row and column counts followed by its values.
Binary form
With file-type 1, the format line is followed by the integer 1 written as four bytes,
which shows the byte order of the writer; Gmsh swaps bytes when it does not read back as 1. Integers
are 4 bytes and coordinates are doubles.
Nodes
The count stays a text line. Each node is then 28 bytes: the number (integer) and three doubles.
Elements
The count stays a text line. Elements come in runs, each opened by a header of three integers:
| Integer | Meaning |
|---|---|
| 1 | Element type of the run |
| 2 | Number of elements in the run |
| 3 | Number of tags on each |
Each element of the run is its number, its tags and its node numbers, all integers. Runs follow until the section’s element count is reached. Gmsh’s writer makes every run one element long.
Other sections
The remaining sections look as in text files, except that in the data sections the node or element
number, the number of nodes per element and the values are binary. Every $End line must
begin on a new line.
How Gmsh reads it
These points come from the version 2 reader and writer in Gmsh 4.15.2’s source.
- The reader is used for any version below 3.
- In files below version 2.2, the third element tag is taken as a single partition number instead of a count.
- Where an element has exactly one tag more than its partition list needs, that last tag is the number of a parent element, used by cut meshes.
- In text files, an element of type 34 (polygon) gives its node count after the tags.
- Elements with a negative elementary tag are skipped in text files.
- In binary files ghost partitions in the tag list are not applied.
- The writer cannot write polygons or polyhedra to binary files. It writes version 2.2 elements that have no partition, parent or domain with two tags.
- When asked to save the model’s topology, the writer adds a
$Entitiessection that this reader passes over. - The
Mesh.IgnorePeriodicityMsh2option makes it skip periodic data.
In this reference
- Element types – every type code with its node count, and the order of nodes within an element
Variants
- MSH version 4 – nodes and elements in blocks by entity
- MSH version 3 – entities, and an entity on every node and element
- MSH version 2 – flat node and element lists with integer tags
- MSH version 1 –
$NODand$ELM, text only
Links
Software
- Gmsh – mesh generator that reads and writes version 2.2 (Windows, macOS, Linux)
Developers
- Gmsh source – the version 2 reader and writer (C++)
- meshio – library and converter that handles Gmsh 2.2 files (Python)
Reference
- Gmsh reference manual: MSH file format version 2 – the text and binary layouts
- GModelIO_MSH2.cpp, Gmsh 4.15.2 – the reader and writer