Skip to content

Using Gmsh to Create Geometry, Meshes; An Open Source Workflow

Justin Clough edited this page Jun 20, 2019 · 6 revisions

Overview

Gmsh is an open source geometry modeling and mesh generating software. Albany can read and work with version 4.1 meshes generated by Gmsh. Usage and basic abilities are outlined below. An example workflow with commented fragments of input files are shown as well.

Usage and Abilities

The details of geometry and mesh generation with Gmsh are left to their own manual. This wiki assumes that you already have a geometry and mesh you would like to use with Albany. Three topics are discussed:

  1. Assigning Boundary Conditions
  2. Defining Element Order and Type
  3. Assigning Multiple Materials/Material Models (In progress as of 06/19/2019).

To use a Gmsh mesh, set the Discretization: Method to Gmsh and Gmsh Input Mesh File Name to your .msh file within your Albany input file.

Boundary Conditions

Neumann and Dirichlet boundary conditions both depend on the boundary of interest having a Physical Label assigned by Gmsh. Boundaries in this sense are features one dimension less than the rest of the problem. E.g., a volume has the boundaries of surfaces; a face has boundaries of edges. The physical label is treated as a string literal and used to define boundary condition names. A boundary label called foo will created two boundaries in Albany:

  1. BoundaryNodeSet_foo which has all nodes on that surface. Use these for Dirichlet conditions.
  2. BoundarySideSet_foo which has all element surfaces on that surface. Use these for Neumann conditions.

Note that the element surfaces within a physical surface must be contiguous.

Defining Element Order and Type

By default, Gmsh will create first order tetrahedral elements of volumes. To create a second order tetrahedral mesh, use the command line arguments:

gmsh your_geo_file.geo -3 -order 2

where gmsh is the Gmsh binary, -3 requests a 3D mesh, and -order 2 defines the second order tetrahedral elements. Hexahedral meshes can be generated by setting Mesh.Hexahedra=1 in the input .geo file.

Albany can use first and second order tetrahedral (tet-4 and tet-10) elements. The tet-10 elements have been demonstrated for traditional quadratic and newer composite shape functions. Only linear hexahedral elements are currently available. (A note to future developers, the Gmsh node ordering is similar but not the same as the STK node ordering that Albany uses.)

Assigning Multiple Materials/Material Models

This work is in progress as of 06/19/2019. Progress can be followed on the add_multiple_elem_blocks_to_gmsh_4_1_reader branch.

Example

An example set of Gmsh and Albany input files are shown below. This example creates a unit cube and labels boundaries of interest in Gmsh; the cube then undergoes a simple linear extension due to an applied traction.

An example .geo file is shown below (copied from tests/small/LCM/Read_Gmsh_4_1_tet10/box.geo):

// box.geo
// This script creates a unit cube.
// The min x,y, and z faces are labeled.
// The max x face is labeled as well.

// Set the geometry kernel
SetFactory("OpenCASCADE");

// Set mesh output style: 
// 1 for .msh, 16 for .vtk (for use with paraview)
Mesh.Format = 1;

// Characteristic length
l = 1.0;

// Create the unit cube
box_corner  = {0, 0, 0};
box_extents = {l, l, l};
box_v       = newv;
Box (box_v) = { box_corner[0],  box_corner[1],  box_corner[2], 
                box_extents[0], box_extents[1], box_extents[2]};

// Label surfaces to use with Albany boundary conditions
Physical Surface("max_x") = {2};
Physical Surface("min_x") = {1};
Physical Surface("min_z") = {5};
Physical Surface("min_y") = {3};

// Save all elements to file, not just labeled ones
Mesh.SaveAll=1;

Use the command line options gmsh box.geo -3 -order 2 to create a mesh of this box with second order tet elements. This mesh is then written to disk as box.geo.

The surface numbers used to label Physical Surfaces (the right hand values) are taken from the Gmsh GUI.

In your Albany input file, use the following block to use the Gmsh file:

...
  Dirichlet BCs:
      SDBC on NS BoundaryNodeSet_min_x for DOF X: 0.00000000e+00
      SDBC on NS BoundaryNodeSet_min_y for DOF Y: 0.00000000e+00
      SDBC on NS BoundaryNodeSet_min_z for DOF Z: 0.00000000e+00
    Neumann BCs:
      'NBC on SS BoundarySideSet_max_x for DOF all set (t_x, t_y, t_z)': [1.0, 0.0, 0.0]
    MaterialDB Filename: 'material.yaml'
  Discretization: 
    Method: Gmsh
    Gmsh Input Mesh File Name: box.msh
...

The full Albany input file is available in test/small/LCM/Read_Gmsh_4_1_tet10/input.yaml. From here, Albany can be run as usual with

mpirun -n <n> Albany input.yaml
Clone this wiki locally