[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter describes Gmsh's native mesh and post-processing file formats. (These formats have version numbers that are independent of Gmsh's main version number.)
All non-parsed file formats have sections enclosed between $Key
and
$EndKey
tags.
9.1 Gmsh mesh file formats 9.2 Gmsh post-processing file formats 9.3 Gmsh node ordering
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Please note that the list of nodes and elements in Gmsh's mesh files do not have to be dense or ordered (i.e., the node and element numbers do not have to be given in a consecutive or even an ordered way).
9.1.1 Version 1.0 9.1.2 Version 2.0 ASCII 9.1.3 Version 2.0 Binary
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The `.msh' file format, version 1.0, is Gmsh's old native mesh file format, now superseded by the format described in 9.1.2 Version 2.0 ASCII.
In the `.msh' file format, version 1.0, the file is divided in two
sections, defining the nodes ($NOD
-$ENDNOD
) and the elements
($ELM
-$ENDELM
) in the mesh:
$NOD number-of-nodes node-number x-coord y-coord z-coord ... $ENDNOD $ELM number-of-elements elm-number elm-type reg-phys reg-elem number-of-nodes node-number-list ... $ENDELM |
where
number-of-nodes
node-number
x-coord y-coord z-coord
number-of-elements
elm-number
elm-type
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
reg-phys
reg-elem
number-of-nodes
node-number-list
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The version 2.0 of the `.msh' file format is Gmsh's new native mesh file format. It is very similar to the old one (see section 9.1.1 Version 1.0), but is more general: it contains information about itself and allows to associate an arbitrary number of integer tags with each element. Ialso exists in both ASCII and binary form.
The `.msh' file format, version 2.0, is divided in three main
sections, defining the file format
($MeshFormat
-$EndMeshFormat
), the nodes
($Nodes
-$EndNodes
) and the elements
($Elements
-$EndElements
) in the mesh:
$MeshFormat 2.0 file-type data-size $EndMeshFormat $Nodes number-of-nodes node-number x-coord y-coord z-coord ... $EndNodes $Elements number-of-elements elm-number elm-type number-of-tags < tag > ... node-number-list ... $EndElements |
where
file-type
data-size
number-of-nodes
node-number
x-coord y-coord z-coord
number-of-elements
elm-number
elm-type
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
number-of-tags
tag
node-number-list
Additional sections can be present in the file, which an external parser
can simply ignore. One such additional section
($PhysicalNames
-$EndPhysicalNames
) associates names with
physical entity identification numbers:
$PhysicalNames number-of-names phyical-number "physical-name" $EndPhysicalNames |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The binary file format is similar to the ASCII format described in 9.1.2 Version 2.0 ASCII:
$MeshFormat 2.0 file-type data-size one-binary $EndMeshFormat $Nodes number-of-nodes nodes-binary $EndNodes $Elements number-of-elements element-header-binary elements-binary element-header-binary elements-binary ... $EndElements |
where
file-type
data-size
one-binary
Here is a pseudo C code to write one-binary:
int one = 1; fwrite(&one, sizeof(int), 1, file); |
number-of-nodes
nodes-binary
Here is a pseudo C code to write nodes-binary:
for(i = 0; i < number_of_nodes; i++){ fwrite(&num_i, sizeof(int), 1, file); double xyz[3] = {node_i_x, node_i_y, node_i_z}; fwrite(&xyz, sizeof(double), 3, file); } |
number-of-elements
element-header-binary
Here is a pseudo C code to write element-header-binary:
int header[3] = {elm_type, num_elm_follow, num_tags}; fwrite(&header, sizeof(int), 3, file); |
elements-binary
Here is a pseudo C code to write elements-binary for triangles with the 3 standard tags (the physical and elementary regions, and the mesh partition):
for(i = 0; i < number_of_triangles; i++){ int data[7] = {num_i, physical, elementary, partition, node_i_1, node_i_2, node_i_3}; fwrite(data, sizeof(int), 7, file); } |
The same additional sections as in the ASCII format can be present in the file.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Gmsh can read and write data sets in three different file formats: the "parsed", "ASCII" and "binary" file formats. The parsed format is the oldest and most flexible, but also the slowest to read/write. The ASCII and binary formats are less flexible but allow for faster read/write operations, which is useful for (very) large data sets.
Gmsh can convert any format to any other, either in a script (cf. Save
View
and PostProcessing.Format
in 6.1 Post-processing commands,
and 6.3 Post-processing options, respectively) or in the graphical user
interface (using the `View->Save As' menu).
9.2.1 Parsed post-processing file format 9.2.2 ASCII post-processing file format 9.2.3 Binary post-processing file format
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Gmsh's oldest post-processing format ("parsed") is read by Gmsh's script parser (see also 6.1 Post-processing commands). You can thus, for example, embed parsed post-processing views directly into your geometrical descriptions (see, e.g., 7.4 `t4.geo').
The parsed format is very powerful, since all the values are expressions, and it can be easily generated "on-the-fly", as there is no header containing a priori information on the size of the data set. Its syntax is also very permissive, which makes it ideal for testing purposes. Its main disadvantage resides in the overhead introduced by the parser, which makes loading a view in parsed format slower than loading a view in ASCII or binary format. This is only a disadvantage for very large data sets, though.
A post-processing view in parsed format is defined as follows (there can be one or more views in the same file):
View "string" { < TIME { expression-list }; > type ( list-of-coords ) { list-of-values }; ... }; |
where the 47 object types that can be displayed are:
type #list-of-coords #list-of-values -------------------------------------------------------------------- Scalar point SP 3 1 * nb-time-steps Vector point VP 3 3 * nb-time-steps Tensor point TP 3 9 * nb-time-steps Scalar line SL 6 2 * nb-time-steps Vector line VL 6 6 * nb-time-steps Tensor line TL 6 18 * nb-time-steps Scalar triangle ST 9 3 * nb-time-steps Vector triangle VT 9 9 * nb-time-steps Tensor triangle TT 9 27 * nb-time-steps Scalar quadrangle SQ 12 4 * nb-time-steps Vector quadrangle VQ 12 12 * nb-time-steps Tensor quadrangle TQ 12 36 * nb-time-steps Scalar tetrahedron SS 12 4 * nb-time-steps Vector tetrahedron VS 12 12 * nb-time-steps Tensor tetrahedron TS 12 36 * nb-time-steps Scalar hexahedron SH 24 8 * nb-time-steps Vector hexahedron VH 24 24 * nb-time-steps Tensor hexahedron TH 24 72 * nb-time-steps Scalar prism SI 18 6 * nb-time-steps Vector prism VI 18 18 * nb-time-steps Tensor prism TI 18 54 * nb-time-steps Scalar pyramid SY 15 5 * nb-time-steps Vector pyramid VY 15 15 * nb-time-steps Tensor pyramid TY 15 45 * nb-time-steps Second order scalar line SL2 9 3 * nb-time-steps Second order vector line VL2 9 9 * nb-time-steps Second order tensor line TL2 9 27 * nb-time-steps Second order scalar triangle ST2 18 6 * nb-time-steps Second order vector triangle VT2 18 18 * nb-time-steps Second order tensor triangle TT2 18 54 * nb-time-steps Second order scalar quadrangle SQ2 27 9 * nb-time-steps Second order vector quadrangle VQ2 27 27 * nb-time-steps Second order tensor quadrangle TQ2 27 81 * nb-time-steps Second order scalar tetrahedron SS2 30 10 * nb-time-steps Second order vector tetrahedron VS2 30 30 * nb-time-steps Second order tensor tetrahedron TS2 30 90 * nb-time-steps Second order scalar hexahedron SH2 81 27 * nb-time-steps Second order vector hexahedron VH2 81 81 * nb-time-steps Second order tensor hexahedron TH2 81 243* nb-time-steps Second order scalar prism SI2 54 18 * nb-time-steps Second order vector prism VI2 54 54 * nb-time-steps Second order tensor prism TI2 54 162* nb-time-steps Second order scalar pyramid SY2 42 14 * nb-time-steps Second order vector pyramid VY2 42 42 * nb-time-steps Second order tensor pyramid TY2 42 126* nb-time-steps 2D text T2 3 arbitrary 3D text T3 4 arbitrary |
The coordinates are given `by node'(9), i.e.,
(coord1, coord2, coord3)
for a point,
(coord1-node1, coord2-node1, coord3-node1,
coord1-node2, coord2-node2, coord3-node2)
for a line,
(coord1-node1, coord2-node1, coord3-node1,
coord1-node2, coord2-node2, coord3-node2,
coord1-node3, coord2-node3, coord3-node3)
for a triangle,
The ordering of the nodes is given in 9.3 Gmsh node ordering. For second order elements, the first order nodes are given first, followed by the nodes associated with the edges, followed by the nodes associated with the quadrangular faces (if any), followed by the nodes associated with the volume (if any). The ordering of these additional nodes follows the ordering of the edges and quadrangular faces given in 9.3 Gmsh node ordering.
The values are given by time step, by node and by component, i.e.:
comp1-node1-time1, comp2-node1-time1, comp3-node1-time1, comp1-node2-time1, comp2-node2-time1, comp3-node2-time1, comp1-node3-time1, comp2-node3-time1, comp3-node3-time1, comp1-node1-time2, comp2-node1-time2, comp3-node1-time2, comp1-node2-time2, comp2-node2-time2, comp3-node2-time2, comp1-node3-time2, comp2-node3-time2, comp3-node3-time2, ... |
For the 2D text objects, the two first expressions in list-of-coords give the X-Y position of the string in screen coordinates, measured from the top-left corner of the window. If the first (respectively second) expression is negative, the position is measured from the right (respectively bottom) edge of the window. If the value of the first (respectively second) expression is larger than 99999, the string is centered horizontally (respectively vertically). If the third expression is equal to zero, the text is aligned bottom-left and displayed using the default font and size. Otherwise, the third expression is converted into an integer whose eight lower bits give the font size, whose eight next bits select the font (the index corresponds to the position in the font menu in the GUI), and whose eight next bits define the text alignment (0=bottom-left, 1=bottom-center, 2=bottom-right, 3=top-left, 4=top-center, 5=top-right, 6=center-left, 7=center-center, 8=center-right).
For the 3D text objects, the three first expressions in list-of-coords give the XYZ position of the string in model (real world) coordinates. The fourth expression has the same meaning as the third expression in 2D text objects.
For both 2D and 3D text objects, the list-of-values can contain an arbitrary number of char-expressions.
The optional TIME
list can contain a list of expressions giving the
value of the time (or any other variable) for which an evolution was saved.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The ASCII post-processing file is divided in several sections: one format
section, enclosed between $PostFormat
-$EndPostFormat
tags, and
one or more post-processing views, enclosed between
$View
-$EndView
tags:
$PostFormat 1.4 file-type data-size $EndPostFormat $View view-name nb-time-steps nb-scalar-points nb-vector-points nb-tensor-points nb-scalar-lines nb-vector-lines nb-tensor-lines nb-scalar-triangles nb-vector-triangles nb-tensor-triangles nb-scalar-quadrangles nb-vector-quadrangles nb-tensor-quadrangles nb-scalar-tetrahedra nb-vector-tetrahedra nb-tensor-tetrahedra nb-scalar-hexahedra nb-vector-hexahedra nb-tensor-hexahedra nb-scalar-prisms nb-vector-prisms nb-tensor-prisms nb-scalar-pyramids nb-vector-pyramids nb-tensor-pyramids nb-scalar-lines2 nb-vector-lines2 nb-tensor-lines2 nb-scalar-triangles2 nb-vector-triangles2 nb-tensor-triangles2 nb-scalar-quadrangles2 nb-vector-quadrangles2 nb-tensor-quadrangles2 nb-scalar-tetrahedra2 nb-vector-tetrahedra2 nb-tensor-tetrahedra2 nb-scalar-hexahedra2 nb-vector-hexahedra2 nb-tensor-hexahedra2 nb-scalar-prisms2 nb-vector-prisms2 nb-tensor-prisms2 nb-scalar-pyramids2 nb-vector-pyramids2 nb-tensor-pyramids2 nb-text2d nb-text2d-chars nb-text3d nb-text3d-chars time-step-values < scalar-point-value > ... < vector-point-value > ... < tensor-point-value > ... < scalar-line-value > ... < vector-line-value > ... < tensor-line-value > ... < scalar-triangle-value > ... < vector-triangle-value > ... < tensor-triangle-value > ... < scalar-quadrangle-value > ... < vector-quadrangle-value > ... < tensor-quadrangle-value > ... < scalar-tetrahedron-value > ... < vector-tetrahedron-value > ... < tensor-tetrahedron-value > ... < scalar-hexahedron-value > ... < vector-hexahedron-value > ... < tensor-hexahedron-value > ... < scalar-prism-value > ... < vector-prism-value > ... < tensor-prism-value > ... < scalar-pyramid-value > ... < vector-pyramid-value > ... < tensor-pyramid-value > ... < scalar-line2-value > ... < vector-line2-value > ... < tensor-line2-value > ... < scalar-triangle2-value > ... < vector-triangle2-value > ... < tensor-triangle2-value > ... < scalar-quadrangle2-value > ... < vector-quadrangle2-value > ... < tensor-quadrangle2-value > ... < scalar-tetrahedron2-value > ... < vector-tetrahedron2-value > ... < tensor-tetrahedron2-value > ... < scalar-hexahedron2-value > ... < vector-hexahedron2-value > ... < tensor-hexahedron2-value > ... < scalar-prism2-value > ... < vector-prism2-value > ... < tensor-prism2-value > ... < scalar-pyramid2-value > ... < vector-pyramid2-value > ... < tensor-pyramid2-value > ... < text2d > ... < text2d-chars > ... < text3d > ... < text3d-chars > ... $EndView |
where
file-type
data-size
view-name
nb-time-steps
nb-scalar-points
nb-vector-points
...
nb-text2d
nb-text3d
nb-text2d-chars
nb-text3d-chars
time-step-values
scalar-point-value
vector-point-value
...
For example, vector-triangle-value is defined as:
coord1-node1 coord1-node2 coord1-node3 coord2-node1 coord2-node2 coord2-node3 coord3-node1 coord3-node2 coord3-node3 comp1-node1-time1 comp2-node1-time1 comp3-node1-time1 comp1-node2-time1 comp2-node2-time1 comp3-node2-time1 comp1-node3-time1 comp2-node3-time1 comp3-node3-time1 comp1-node1-time2 comp2-node1-time2 comp3-node1-time2 comp1-node2-time2 comp2-node2-time2 comp3-node2-time2 comp1-node3-time2 comp2-node3-time2 comp3-node3-time2 ... |
The ordering of the nodes is given in 9.3 Gmsh node ordering. For second order elements, the first order nodes are given first, followed by the nodes associated with the edges, followed by the nodes associated with the quadrangular faces (if any), followed by the nodes associated with the volume (if any). The ordering of these additional nodes follows the ordering of the edges and quadrangular faces given in 9.3 Gmsh node ordering.
text2d
coord1 coord2 style index |
text2d-chars
\0
' character.
text3d
coord1 coord2 coord3 style index |
text3d-chars
\0
' character.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The binary post-processing file format is the same as the ASCII file format described in 9.2.2 ASCII post-processing file format, except that:
Here is a pseudo C code to write a post-processing file in binary format:
int one = 1; fprintf(file, "$PostFormat\n"); fprintf(file, "%g %d %d\n", 1.4, 1, sizeof(double)); fprintf(file, "$EndPostFormat\n"); fprintf(file, "$View\n"); fprintf(file, "%s %d " "%d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d " "%d %d %d %d\n", view-name, nb-time-steps, nb-scalar-points, nb-vector-points, nb-tensor-points, nb-scalar-lines, nb-vector-lines, nb-tensor-lines, nb-scalar-triangles, nb-vector-triangles, nb-tensor-triangles, nb-scalar-quadrangles, nb-vector-quadrangles, nb-tensor-quadrangles, nb-scalar-tetrahedra, nb-vector-tetrahedra, nb-tensor-tetrahedra, nb-scalar-hexahedra, nb-vector-hexahedra, nb-tensor-hexahedra, nb-scalar-prisms, nb-vector-prisms, nb-tensor-prisms, nb-scalar-pyramids, nb-vector-pyramids, nb-tensor-pyramids, nb-scalar-lines2, nb-vector-lines2, nb-tensor-lines2, nb-scalar-triangles2, nb-vector-triangles2, nb-tensor-triangles2, nb-scalar-quadrangles2, nb-vector-quadrangles2, nb-tensor-quadrangles2, nb-scalar-tetrahedra2, nb-vector-tetrahedra2, nb-tensor-tetrahedra2, nb-scalar-hexahedra2, nb-vector-hexahedra2, nb-tensor-hexahedra2, nb-scalar-prisms2, nb-vector-prisms2, nb-tensor-prisms2, nb-scalar-pyramids2, nb-vector-pyramids2, nb-tensor-pyramids2, nb-text2d, nb-text2d-chars, nb-text3d, nb-text3d-chars); fwrite(&one, sizeof(int), 1, file); fwrite(time-step-values, sizeof(double), nb-time-steps, file); fwrite(all-scalar-point-values, sizeof(double), ..., file); ... fprintf(file, "\n$EndView\n"); |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For all mesh and post-processing file formats, the reference elements are defined as follows:
Point: v | | -----1-----u | | |
Line: edge 1: nodes 1 2 v | | --1-----2--u | | |
Triangle: edge 1: nodes 1 2 v 2: 2 3 | 3: 3 1 | 3 |\ | \ |__\___u 1 2 |
Quadrangle: edge 1: nodes 1 2 quad. face 1: nodes 1 2 3 4 v 2: 2 3 | 3: 3 4 4--|--3 4: 4 1 | | | -----------u | | | 1--|--2 | |
Tetrahedron: edge 1: nodes 1 2 v 2: 2 3 | 3: 3 1 | 4: 4 1 | 5: 4 3 3 6: 4 2 |\ | \ |__\2_____u 1\ / \4 \ w |
Hexahedron: edge 1: nodes 1 2 quad. face 1: nodes 1 2 3 4 v 2: 1 4 2: 1 2 5 6 | 3: 1 5 3: 1 4 5 8 | 4: 2 3 4: 2 3 6 7 4----|--3 5: 2 6 5: 3 4 7 8 |\ | |\ 6: 3 4 6: 5 6 7 8 | 8-------7 7: 3 7 | | ----|---u 8: 4 8 1-|---\-2 | 9: 5 6 \| \ \| 10: 5 8 5-----\-6 11: 6 7 \ 12: 7 8 w |
Prism: edge 1: nodes 1 2 quad. face 1: nodes 1 2 4 5 v 2: 1 3 2: 1 3 4 6 3 | 3: 1 4 3: 2 3 5 6 |\| 4: 2 3 | | 5: 2 5 1_|2 6: 3 6 \| 6 7: 4 5 |_|_\___u 8: 4 6 \| \ 9: 5 6 4 __5 \ \ w |
Pyramid: edge 1: nodes 1 2 quad. face 1: nodes 1 2 3 4 v 2 1 4 | 3 1 5 | 4 2 3 4---|---3 5 2 5 | \ | /| 6 3 4 | \ -/-|---u 7 3 5 | / 5\ | 8 4 5 1/----\-2 \ \ w |
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |