ogstools.msh2vtu package#

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

Authors:

Dominik Kern (TU Bergakademie Freiberg)

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#

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] [-g] [-r] [-a] [-d DIM] [-o OUTPUT] [-z] [-s] [-v]
               filename

Positional Arguments#

filename

Gmsh mesh file (*.msh) as input data

Named Arguments#

-g, --ogs

rename “gmsh:physical” to “MaterialIDs” for domains and change type of corresponding cell data to INT32

Default: False

-r, --rdcd

renumber domain cell data, physical IDs (cell data) of domains get numbered beginning with zero

Default: False

-a, --ascii

save output files (*.vtu) in ascii format

Default: False

-d, --dim

spatial dimension (1, 2 or 3), trying automatic detection, if not given

Default: 0

-o, --output

basename of output files; if not given, then it defaults to basename of inputfile

Default: “”

-z, --delz

deleting 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

-v, --version

show program’s version number and exit

API usage#

In addition it may be used as Python module with an emulated command line call:

from ogstools.msh2vtu import run  # to run mesh conversion
import argparse  # to parse emulated command line call

parser = argparse.ArgumentParser()

# generate a mesh, e.g. my_mesh.msh with Gmsh

args = argparse.Namespace(
    filename="my_mesh.msh",
    output="",
    dim=0,
    delz=False,
    swapxy=False,
    rdcd=True,
    ogs=True,
    ascii=False,
)
run(args)

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 from the input file geolayers_2d.msh:

  • 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

ogstools.msh2vtu.find_cells_at_nodes(cells, node_count, cell_start_index)#
ogstools.msh2vtu.find_connected_domain_cells(boundary_cells_values, domain_cells_at_node)#
ogstools.msh2vtu.my_remove_orphaned_nodes(my_mesh)#

Auxiliary function to remove points not belonging to any cell

ogstools.msh2vtu.print_info(mesh)#
ogstools.msh2vtu.run(args)#

Subpackages#