Gmsh 网格和后处理文件格式

$Id: GmshFormats.html,v 1.1 2004/09/15 02:54:11 rli Exp $

这个文件是 Gmsh 1.2 版的网格和后处理文件的文件格式的描述。 (本文件中只描述了 Gmsh 的输入输出接口。关于 Gmsh 怎么 样进行几何体、选项、脚本等的行为和表现请参考 一步一步学习 Gmsh 中的详细内容。)

  1. Gmsh 的网格文件格式
  2. Gmsh ASCII 后处理文件格式
  3. Gmsh 二进制后处理文件格式
  4. Gmsh Parsed 后处理文件格式
  5. 几何体的节点排序

Gmsh 的网格文件格式

'msh' 文件格式是 Gmsh 的内部输出文件格式。这个文件格式被分成了 两个部分,分别用一对 $KEY$ENDKEY 引用 起来,其中 $NOD/$ENDNOD 段中描述的是结点,$ELM/$ENDELM 段中描述的是元素。

    $NOD
    number-of-nodes
    node-number coord1 coord2 coord3 
    ...
    $ENDNOD

    $ELM
    number-of-elements
    elm-number elm-type elm-region unused nb-nodes node-numbers
    ...
    $ENDELM
上面的语法中所有的变量,除了 coord1coord2, 和 coord3 是符点数以外,其他的都是整型数。其中 node-numbers 是一串整数,表示该元素的各个节点。 ele-type 是几何体的类型,取值和意义如下:
1Line(2 nodes, 1 edge).
2Triangle(3 nodes, 3 edges).
3Quadrangle(4 nodes, 4 edges).
4Tetrahedron(4 nodes, 6 edges, 4 facets).
5Hexahedron(8 nodes, 12 edges, 6 facets).
6Prism(6 nodes, 9 edges, 5 facets).
7Pyramid(5 nodes, 8 edges, 5 facets).
15Point(1 node).
elm-region 是元素的区域指标。

Gmsh ASCII 后处理文件格式

后处理文件分为几个部分:其中一个部分用 $PostFormat/$EndPostFormat 括起来,其它的部分是使用 $View/$EndView 括起来的,每个 部分对应着一个视图。语法描述如下:

    $PostFormat
    1.2 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-tetrahedra nb-vector-tetrahedra nb-tensor-tetrahedra
    nb-text2d nb-text2d-chars nb-test3d 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 ...
    text2d ... text2d-chars ...
    text3d ... text3d-chars ...
    $endView
其中:

Gmsh 二进制后处理文件格式

二进制文件的后处理文件的格式和 ASCII 文件格式基本一样。我们仅列出 不同的部分:

  1. file-type 是 1;
  2. 所有的浮点数和字符串都是二进制形式的;
  3. time-step-values 之前,多一个整数,取值为 1。 这个整数是用来检测文件被写入的时候的格式和读取时候的格式 是否是相同的(高位在前还是在后);

下面是一段存储一个二进制后处理文件的 C 语言伪代码:

    int one = 1;
    
    fprintf(file, "$PostFormat\n");
    fprintf(file, "%g %d %d\n", 1.2, 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\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-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");
在这段伪代码中, all-scalar-point-values 是双精度浮点数组, 其中存储的是所有的 scalar-point-value 列表,它们被一个接 一个的放在一起,形成一个很长的数组。其它变量的处理方式也是这样的。

Gmsh Parsed 后处理文件格式

如果数据量非常小,或者是为了测试的目的,Gmsh 还提供了一种使用几何体 的语法进行解释的后处理文件格式。您能够将这样的后处理视图放在几何 造型的描述文件中,这个格式的语法如下:

   View "name" {
     type-of-element (list-of-coordinates) {list-of-values} ;
     ...
   };
这个格式支持 26 种对象的显示,如下表:
object nametype-of-elementlist-of-coordinateslist-of-values
scalar pointSP31 * nb-time-steps
vector pointVP33 * nb-time-steps
tensor pointTP39 * nb-time-steps
scalar lineSL62 * nb-time-steps
vector lineVL66 * nb-time-steps
tensor lineTL618 * nb-time-steps
scalar triangleST93 * nb-time-steps
vector triangleVT99 * nb-time-steps
tensor triangleTT927 * nb-time-steps
scalar quadrangleSQ124 * nb-time-steps
vector quadrangleVQ1212 * nb-time-steps
tensor quadrangleTQ1236 * nb-time-steps
scalar tetrahedronSS124 * nb-time-steps
vector tetrahedronVS1212 * nb-time-steps
tensor tetrahedronTS1236 * nb-time-steps
scalar hexahedronSH248 * nb-time-steps
vector hexahedronVH2424 * nb-time-steps
tensor hexahedronTH2472 * nb-time-steps
scalar prismSI186 * nb-time-steps
vector prismVI1818 * nb-time-steps
tensor prismTI1854 * nb-time-steps
scalar pyramidSY155 * nb-time-steps
vector pyramidVY1515 * nb-time-steps
tensor pyramidTY1545 * nb-time-steps
text 2dT24arbitrary
text 3dT35arbitrary
和 ASCII 格式不同的是,这里的坐标是按节点给的,即 (coord1, coord2, coord3) 表示一个点,(coord1-node1, coord2-node1, coord3-node1, coord1-node2, coord2-node2, coord3-node2) 表示一条线,(coord1-node1, coord2-node1, coord3-node1, coord1-node2, coord2-node2, coord3-node2, coord1-node3, coord2-node3, coord3-node3) 表示一个三角形,以此类推。变量的排列顺序和 ASCII 格式是一样的。

几何体的节点排序