Introduction
Version 3 of Gmsh’s mesh format adds a section describing the model’s entities and gives every node and element its entity. Gmsh’s reference manual does not describe it. This page follows the version 3 reader and writer in the source of Gmsh 4.15.2, which accept version numbers from 3.0 up to, but not including, 4.
Sections
Each section starts with a $Name line and ends with $EndName. The writer
puts them in this order: $MeshFormat, $PhysicalNames (when there are names),
$Entities, $Nodes, $Elements and $Periodic (when
there are periodic entities). The reader also takes the result sections.
$MeshFormat
$MeshFormat
version file-type data-size
$EndMeshFormat
file-type is 0 for text and 1 for binary; data-size is the size of a double,
8. In a binary file the integer 1 follows as four bytes, then a line break; the reader swaps bytes when
it does not read back as 1.
$PhysicalNames
$PhysicalNames
number-of-names
dimension physical-tag "name"
…
$EndPhysicalNames
Always text. The writer cuts names to 254 characters.
$Entities
Always text, even in a binary file. The first line counts the points, curves, surfaces and volumes; one line per entity follows, in that order.
$Entities
num-points num-curves num-surfaces num-volumes
tag num-physicals physical-tag …
tag num-points point-tag … num-physicals physical-tag …
tag num-curves ±curve-tag … num-physicals physical-tag …
tag num-surfaces ±surface-tag … num-physicals physical-tag …
$EndEntities
The four lines after the counts show the shapes for a point, a curve, a surface and a volume. A curve lists its end points. A surface lists the curves round it and a volume the surfaces round it, each negated when used with reversed orientation.
$Nodes
$Nodes
number-of-nodes
node-number x y z entity-tag [entity-dimension [parameters]]
…
$EndNodes
An entity-tag of 0 ends the node. Otherwise the dimension follows, from 0 to 3, and then
the node’s parametric coordinates:
| Dimension | Parameters |
|---|---|
| 0 | None |
| 1 | u |
| 2 | u v |
| 3 | u v w |
In a binary file the node number, entity tag and dimension are 4-byte integers and the coordinates and parameters doubles.
$Elements
$Elements
number-of-elements
elm-number elm-type entity-tag number-of-data data …
…
$EndElements
The element count line is text; in a binary file every value of an element is a 4-byte integer, one
element after another with no run headers. elm-type is the Gmsh element type code, with the same node ordering as in version 2. The
data list holds, in order:
- the number of nodes, only for types without a fixed count (polygons and polyhedra);
- the node numbers;
- the number of the parent element, for sub-elements of cut meshes (types 133 to 136);
- optionally the number of partitions, then the element’s own partition and any ghost partitions.
For example 7 2 3 5 1 2 3 1 4 is element 7, a triangle on entity 3 with five data values:
nodes 1, 2 and 3, one partition, partition 4.
$Periodic
$Periodic
number-of-periodic-entities
dimension entity-tag master-entity-tag
Affine value …
number-of-nodes
node-number master-node-number
…
$EndPeriodic
The Affine line, with 16 values, is optional. The entry repeats for each periodic entity of
dimension 0, 1 or 2.
Result data
$NodeData, $ElementData and $ElementNodeData start with a list of
string tags, a list of real tags and a list of integer tags, each preceded by its length; the first
tags are the view name and interpolation scheme, the time, and the time step, component count (1, 3 or
9), row count and partition. Rows are then a node number and values, an element number and values, or
an element number, its node count and values for each node. In binary files the rows are binary.
$InterpolationScheme gives a quoted name, a count of element topologies and, for each, a
topology number (1 point to 8 hexahedron, 9 polygon, 10 polyhedron) with its interpolation matrices as
row count, column count and values.
Divergence in Gmsh’s writer
When parametric coordinates are saved in binary, the writer in 4.15.2 puts three 4-byte zeros after a volume node, while the reader expects three 8-byte doubles there. Text files are not affected.
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 3 files (Windows, macOS, Linux)
Developers
- Gmsh source – the version 3 reader and writer (C++)
Reference
- GModelIO_MSH3.cpp, Gmsh 4.15.2 – the reader and writer
- MVertex.cpp, Gmsh 4.15.2 – how nodes are written
- MElement.cpp, Gmsh 4.15.2 – how elements are written and read back