msh2vtu#

Section author: Dominik Kern (TU Bergakademie Freiberg)

msh2vtu is a command line application that converts a Gmsh mesh for use in OGS by extracting domain-, boundary- and physical group-submeshes and saves them in vtu-format.

Note that all mesh entities should belong to physical groups.

Supported element types:

  • lines (linear and quadratic) in 1D

  • triangles and quadrilaterals (linear and quadratic) in 2D

  • tetra- and hexahedrons (linear and quadratic) in 3D

Command line usage#

Convert a gmsh mesh (.msh) to an unstructured grid file (.vtu).

Prepares a Gmsh-mesh for use in OGS by extracting domain-,
boundary- and physical group-submeshes, and saves them in
vtu-format. Note that all mesh entities should belong to
physical groups.

usage: msh2vtu [-h] [-o OUTPUT_PATH] [-p PREFIX] [-d [DIM ...]] [-z] [-s] [-r]
               [-k] [-a] [-l LOG_LEVEL] [-v]
               filename

Positional Arguments#

filename

Gmsh mesh file (.msh) as input data

Named Arguments#

-o, --output_path

Path of output files, defaults to current working dir

Default: “”

-p, --prefix

Output files prefix, defaults to basename of inputfile

Default: “”

-d, --dim
Spatial dimension (1, 2 or 3), trying automatic detection,

if not given. If multiple dimensions are provided, all elements of these dimensions are embedded in the resulting domain mesh.

Default: 0

-z, --delz
Delete z-coordinate, for 2D-meshes with z=0.

Note that vtu-format requires 3D points.

Default: False

-s, --swapxy

Swap x and y coordinate

Default: False

-r, --reindex
Renumber physical group / region / Material IDs to be

renumbered beginning with zero.

Default: False

-k, --keep_ids
By default, rename ‘gmsh:physical’ to ‘MaterialIDs’

and change type of corresponding cell data to INT32. If True, this is skipped.

Default: False

-a, --ascii

Save output files (.vtu) in ascii format.

Default: False

-l, --log_level
Level of log output. Possible values:
returns:

A MeshSeries object

Default: “DEBUG”

-v, --version

show program’s version number and exit

API usage#

In addition, it may be used as Python module:

from ogstools.msh2vtu import msh2vtu

msh2vtu(
    input_filename="my_mesh.msh",
    output_path="",
    output_prefix="my_meshname",
    dim=0,
    delz=False,
    swapxy=False,
    rdcd=True,
    ogs=True,
    ascii=False,
    log_level="DEBUG",
)

Examples#

A geological model (2D) of a sediment basin by Christian Silbermann and a terrain model (3D) from the official Gmsh tutorials (x2).

msh2vtu example/geolayers_2d.msh generates the following output files:

  • geolayers_2d_boundary.vtu

  • geolayers_2d_domain.vtu

  • geolayers_2d_physical_group_RockBed.vtu

  • geolayers_2d_physical_group_SedimentLayer1.vtu

  • geolayers_2d_physical_group_SedimentLayer2.vtu

  • geolayers_2d_physical_group_SedimentLayer3.vtu

  • geolayers_2d_physical_group_Bottom.vtu

  • geolayers_2d_physical_group_Left.vtu

  • geolayers_2d_physical_group_Right.vtu

  • geolayers_2d_physical_group_Top.vtu