v0.14.0
Loading...
Searching...
No Matches
MSH-2: Create a 3D mesh from Gmsh
Note
Prerequisite of this tutorial is MSH-1: Create a 2D mesh from Gmsh


Note
Intended learning outcome:
  • create a 2D mesh using Gmsh
  • create a seperate config file to add attributes to blocksets
  • use a MoFEM tool called read_med to generate a MoFEM-compatible input mesh

Introduction

This tutorial shows how to create a simple 3D square mesh in Gmsh with some physical groups and then use the MoFEM tool read_med to generate a MoFEM-compatible input mesh for analysis. This would be largely the same as those presented in MSH-1: Create a 2D mesh from Gmsh which readers are recommended to have a look at first.

The steps presented in this turorial are as follows

  • Create geometry, physical group and mesh in Gmsh
  • Create a seperate config file to add attributes to blocksets (physical group)
  • Use read_med to generate a MoFEM-compatible input mesh

The data presented in this tutorial can be found at the directory /mofem_install/mofem-cephas/mofem/users_modules/tutorials/msh-2

Geometry and physical group

Geometry

In order to create a geometry of a square, from the panel on the left, choose Modules -> Geometry -> Elementary entities -> Add -> Box. Then provide the geometry inputs including location (X, Y, Z) and dimensions (DX, DY, DZ) as shown in Figure 1 and click Add and then press q on the keyboard to finish.

Figure 1: Input location (X, Y, Z) and dimensions (DX, DY, DZ) for the cube.

Physical group

As discussed in MSH-1: Create a 2D mesh from Gmsh, physical groups are used to define groups of entities that later will be given attributes which will be read by MoFEM during analysis.

As a demonstration, physical groups of edges, surface and volume of the created cube will be defined as shown in Figure 2, Figure 3, Figure 4, Figure 5, and Figure 6. It can be done by choosing, from the left panel, Modules -> Geometry -> Physical groups -> Add -> Curve/Surface/Volume. Then give name of a physical groups in the box Name, select entities to add to the corresponding groups and finally press e to end the selection.

Figure 2: Define physical group of the top edges.

Figure 3: Define physical group of the bottom edges.

Figure 4: Define physical group of the top surface.

Figure 5: Define physical group of the bottom surface.

Figure 6: Define physical group of the volume.

Mesh generation

Create the mesh

Go to Tools -> Options -> Mesh, in the General tab, choose the meshing algorithms and change the element size factor, e.g. 1 as shown in Figure 7, then close the window. To create the 2D mesh for the square, on the left panel, choose Modules -> Mesh -> 3D.

Figure 7: Mesh generation.

Export mesh in MED format

A preferred mesh format that will be exported is MED. This can be done by go to File -> Export ... then choose the file type Mesh - MED (*.med) and give a file name, e.g. cube.med

MoFEM-compatible input mesh

This section would be very similar to the one presented in MSH-1: Create a 2D mesh from Gmsh. The following steps will be presented

  • Create a config file to add information (block name, material properties, boundary conditions, loadings) to the defined physical groups (blocksets)
  • Generate MoFEM-compatible input mesh in *.h5m format using read_med tool

Create config file

As the mesh created by Gmsh does not contains attributes that may be needed for some tasks for analysis in MoFEM, e.g. blockset with a specific name to add material properties, boundary conditions, loadings. We need to know the exact ID of the physical group (blockset) in the MED file in order to add attributes to that blockset, we can check the IDs by running the read_med as follows

read_med -med_file cube.med

which would show that the defined physical groups along with their IDs as in the following output message

[0] <inform> MoFEM version 0.11.0 (MOAB 5.2.1 Petsc Release Version 3.11.4, Sep, 28, 2019 )
[0] <inform> git commit id 0ac8895b15c4ad41ea5e7077c4d011f7efb50f13
[0] <inform> [MedInterface] Reading MED file V4.1.0 using MED library V4.1.0
[0] <inform> [MedInterface] Check mesh cube nsteps 1
[0] <inform> [MedInterface] Reading mesh cube nsteps 1
[0] <inform> [MedInterface] Read number of nodes 364
[0] <inform> [read_med] Print all meshsets (old and added from meshsets configurational file
[0] <inform> [read_med] meshset 12682136550675316737 type BLOCKSET UNKNOWNNAME msId 1 name cube
[0] <inform> [read_med] meshset 12682136550675316738 type BLOCKSET UNKNOWNNAME msId 2 name bottom_edges
[0] <inform> [read_med] meshset 12682136550675316739 type BLOCKSET UNKNOWNNAME msId 3 name bottom_surface
[0] <inform> [read_med] meshset 12682136550675316740 type BLOCKSET UNKNOWNNAME msId 4 name top_edges
[0] <inform> [read_med] meshset 12682136550675316741 type BLOCKSET UNKNOWNNAME msId 5 name top_surface
[0] <inform> [read_med] meshset 12682136550675316742 type BLOCKSET UNKNOWNNAME msId 6 name volume
@ UNKNOWNNAME
@ BLOCKSET
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10

We would then use these IDs in the config file, named cube.config, as below to add materials properties (for block_1), add a specific name that can be used later in the source code to do certain operations (for block_2), directly add boundary conditions/constraints or springs (for block_3), and loading such as pressure (for block_5)

[block_1]
# `cube` (1) or `volume` (6) block - Add isotropic elastic material properties
id=100
name=MAT_ELASTIC
young=1
poisson=0.1
[block_2]
# `bottom_edges` block - Add block and give it a specific name
id=110
name=BOUNDARY_CONDITION
[block_3]
# `bottom_surface` block - Add block and apply displacement constraints
id=120
add=NODESET
disp_flag1=1
disp_ux=0.0
disp_flag2=1
disp_uy=0.0
disp_flag3=1
disp_uz=0.0
[block_3]
# `bottom_surface` block - Add block and apply springs (if no other boundary conditions)
#id=121
#add=BLOCKSET
#name=SPRING_BC
#user1=1 # Spring stiffness in normal direction
#user2=0.1 # Spring stiffness in tangential direction
[block_5]
# `top_surface` block - Add block and apply pressure
id=130
pressure_flag2=1
pressure_magnitude=0.1
@ NODESET
@ SIDESET

Generate MoFEM-compatible mesh

Once the MED file and config file are ready, the final mesh file in *.h5m format that contains necessary information and can read by MoFEM can be generated by running the command below

read_med -med_file cube.med -meshsets_config cube.config -output_file cube.h5m

After running this command, the cube.h5m file will be created and the main part of the output message would look like this

[0] <inform> [read_med] Print all meshsets (old and added from meshsets configurational file
[0] <inform> [read_med] meshset 12682136550675316737 type BLOCKSET UNKNOWNNAME msId 1 name cube
[0] <inform> [read_med] meshset 12682136550675316738 type BLOCKSET UNKNOWNNAME msId 2 name bottom_edges
[0] <inform> [read_med] meshset 12682136550675316739 type BLOCKSET UNKNOWNNAME msId 3 name bottom_surface
[0] <inform> [read_med] meshset 12682136550675316740 type BLOCKSET UNKNOWNNAME msId 4 name top_edges
[0] <inform> [read_med] meshset 12682136550675316741 type BLOCKSET UNKNOWNNAME msId 5 name top_surface
[0] <inform> [read_med] meshset 12682136550675316742 type BLOCKSET UNKNOWNNAME msId 6 name volume
[0] <inform> [read_med] meshset 12682136550675316743 type BLOCKSET MAT_ELASTICSET msId 100 name MAT_ELASTIC
[0] <inform> [read_med] meshset 12682136550675316744 type BLOCKSET UNKNOWNNAME msId 110 name BOUNDARY_CONDITION
[0] <inform> [read_med] meshset 12682136550675316745 type NODESET DISPLACEMENTSET msId 120
[0] <inform> [read_med] meshset 12682136550675316746 type SIDESET PRESSURESET msId 130
@ PRESSURESET
@ MAT_ELASTICSET
block name is "MAT_ELASTIC"
@ DISPLACEMENTSET

As can be seen, along with the original blocksets 1 to 6, the output mesh cube.h5m now contains the three new blocksets 100, 110, 120 and 130 with additional attributes. Using the same concept, more blocksets for different purposes can be added to the mesh.

Once the final cube.h5m mesh is generated, it can be used directly as an input in MoFEM programs, e.g. elasticity or SCL-1: Poisson's equation (homogeneous BC).