Using GMSH for preprocessing of OOFEM solver

A simple 2D case of modeling using Salome is provided as the official manual of preprocessing models for OOFEM solver. Also, a simple 3D case was formerly provided in this blog. However, the installation of Salome can be cumbersome while GMSH can easily run on Windows, macOS, and Linux machines.

Here I first try to preprocess a simple 2D case using GMSH, if needed a 3D preprocessing case will also be tested in the future. If you have not downloaded the GMSH, you can do it from here.

Part1: Simple 2D model preprocessing

  1. Create an empty .geo file in the desired location (e.g. make an empty .txt file and change appendix to .geo) and open the file with GMSH.

2. Create the following points using Geometry>Elementary entities>Add>Point and following the instructions to input the coordinates of each point:

Point(1) = {40, -40, 0, 1.0};
Point(2) = {60, -40, 0, 1.0};
Point(3) = {100, 0, 0, 1.0};
Point(4) = {0, 0, 0, 1.0};
Point(5) = {0, 200, 0, 1.0};
Point(6) = {100, 200, 0, 1.0};
Point(7) = {60, 240, 0, 1.0};
Point(8) = {40, 240, 0, 1.0};

wherein Point(i) = {x, y, z, 1.0}, x and y and z are the coordinates and 1.0 is the default prescribed mesh size.

Geometry>Elementary entities>Add>Point

3. Create lines using created points by Geometry>Elementary entities>Add>Line tool

Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Line(5) = {3, 6};
Line(6) = {6, 5};
Line(7) = {5, 4};
Line(8) = {6, 7};
Line(9) = {7, 8};
Line(10) = {8, 5};

4. Next, create Plane surface using Geometry>Elementary entities>Add>Plane surface and selecting

Plane 1: Lines 1, 2, and 3 (line 4 will be selected automatically)

Plane 2: Lines 3, 5, 6, and 7

Plane 3: Lines 6 and 8 (lines 9 and 10 will be selected automatically)

Planes 1 to 3

5. Double click on the view and select the Global mesh size factor to set the global multiplier for the discretization dimension. I set it to 5 for the following model.

Double click to show the pop-up menu

6. If you want to see more meshing options, double click the view again and this time select All mesh options....

In this dialog window, you can change the meshing algorithm. I set it to Frontal-Delaunay for Quads (experimental) for this tutorial. Note that experimental meshing algorithms may be unstable.

Setting meshing algorithm

7. Next we make physical groups so that we can use them in the analysis.

From left panel select Geometry>Physical groups>Add>Curve and enter Top_ridge as the Name then select Line 9 and press E on your keyboard to execute adding “Line 9” as the “Top_ridge” group. In a similar way add “Line 1” as the “Bot_ridge”. Press Q to quit the command.

8. Use Geometry>Physical groups>Add>Surface and create physical groups for Plane 1 as Bot_cap, Plane 2 as Specimen, and Plane 3 as Top_cap.

Tip: select dashed lines to select the Planes.

List of Physical groups for Planes

9. Press key 2 on your keyboard to create the 2D mesh.

The number key 2, is the keyboard shortcut for 2D meshing

10. Next export the mesh of the model (from the File menu) using universal format (.unv). Check the option for saving group nodes.

Tip: model definition is .geo while the mesh can have different formats such as .msh, .bdf, or .unv.
by default, your changes are automatically saved in the empty .geo file you created.

Part2: making the Control file

The control file is where you can define the Boundary Conditions, Materials, and the Solver type for the simulation. The Control file will be provided to the UNV2OOFEM (UNV to OOFEM) script which will convert the .unv file into .in file that can be passed to OOFEM solver for performing the analysis.

  1. The first line of the control file gives the output file name (.out) that contains analysis logs and outcome,

The second line is a description of the model,

The third line is analysis type. In this case static structural solver:

capped_specimen.out
A specimen between two trapezoid caps
StaticStructural nsteps 10 nmodules 0

2) We continue by adding domain type and required outputs to the control file:

domain 3d
OutputManager tstep_all dofman_all element_all

and number of defined cross section, materials, boundary conditions, initial conditions, load-time functions, sets, etc in the input file:

ncrosssect 3 nmat 2 nbc 2 nic 0 nltf 1 nset 5

3) Comments can be added by using a hashtag (#) and useful to keep the file more readable. So we define simple sections with a comment like this:

# .: Section :.
# < 1. Specimen >
SimpleCS 1 thick 1.0 width 1.0 material 1 set 1
# < 2. Cap      >
SimpleCS 2 thick 1.0 width 1.0 material 2 set 2
SimpleCS 3 thick 1.0 width 1.0 material 2 set 3

4) Sections are referring to materials 1 and 2, so we define them like this:

# .: Material :.
# < 1. Specimen >
IsoLE 1 d 1. E 30.e3  n 0.2  tAlpha 1.2e-5
# < 2. Cap      >
IsoLE 2 d 1. E 200.e3 n 0.3  tAlpha 1.2e-5

5) Next comes the BCs

# .: Boundary Condition :.
# < Displacement-control BC >
BoundaryCondition 1 loadTimeFunction 1  dofs 6  1 2 3 4 5 6  values 6  0. -1. 0. 0. 0. 0.  set 4
BoundaryCondition 2 loadTimeFunction 1  dofs 6  1 2 3 4 5 6  values 6  0. 0. 0. 0. 0. 0.  set 5
# < Loade-Time Function >
PiecewiseLinFunction 1 nPoints 2 t 2 0. 10. f(t) 2 0. 1.

You probably have noticed how we use “sets” to define materials and BCs. The most important part of control file and the job of UNV converter script is to define these sets using the groups we defined in the UNV file.

6) Sets 1 & 2 are referring to the elements of specimen and caps, sets 2 & 3 are nodes of the loading boundary. We define placeholder for sets in the control file like this:

Set 1 elements
Set 2 elements
Set 3 elements
Set 4 nodes
Set 5 nodes

Next assign each group to corresponding set, remember the names we used in part 1, we are going to use them in the next step;

7-A) Assign groups for element sets:

group Specimen
elemprop set 1
etype[91] TrPlaneStress2d

group Top_cap
elemprop set 2
etype[91] TrPlaneStress2d

group Bot_cap
elemprop set 3
etype[91] TrPlaneStress2d

In above, etype[91] TrPlaneStress2d tells the UNV converter script to use type 91 universal elements as oofem three-node plain-stress-triangular elements. For the partial list of UNV file element tags see here.

Tip: Note that type 91 is not in the table, but it can be confirmed with the universal format that 91 is a triangular shell element. GMSH uses this type for making .unv files. If you want to check it for your self open the unv file in a text editor and find the line that says 2412; this is the code for beginning of elements definition in universal format. Find elements with second column that says 21; this is the code for beam elements in universal format.

Each beam in universal format has code 21 and 3 lines of information, scroll down to find triangle elements with code 91

Each beam has 3 lines of data, after beam elements you will see type 91 elements that each have two lines of data.

7-B) for nodes with specified displacements:

group Top_ridge
nodeprop set 4

group Bot_ridge
elemprop set 5

The complete control file will be like this:

capped_specimen.out
A specimen between two trapezoid caps
StaticStructural nsteps 10 nmodules 0
#
domain 3d
OutputManager tstep_all dofman_all element_all
#
ncrosssect 3 nmat 2 nbc 2 nic 0 nltf 1 nset 5
#
# .: Section :.
# < 1. Specimen >
SimpleCS 1 thick 1.0 width 1.0 material 1 set 1
# < 2. Cap      >
SimpleCS 2 thick 1.0 width 1.0 material 2 set 2
SimpleCS 3 thick 1.0 width 1.0 material 2 set 3
#
# .: Material :.
# < 1. Specimen >
IsoLE 1 d 1. E 30.e3  n 0.2  tAlpha 1.2e-5
# < 2. Cap      >
IsoLE 2 d 1. E 200.e3 n 0.3  tAlpha 1.2e-5
#
# .: Boundary Condition :.
# < Displacement-control BC >
BoundaryCondition 1 loadTimeFunction 1  dofs 6  1 2 3 4 5 6  values 6  0. -1. 0. 0. 0. 0.  set 4
BoundaryCondition 2 loadTimeFunction 1  dofs 6  1 2 3 4 5 6  values 6  0. 0. 0. 0. 0. 0.  set 5
# < Loade-Time Function >
PiecewiseLinFunction 1 nPoints 2 t 2 0. 10. f(t) 2 0. 1.
#
Set 1 elements
Set 2 elements
Set 3 elements
Set 4 nodes
Set 5 nodes

group Specimen
elemprop set 1
etype[91] TrPlaneStress2d

group Top_cap
elemprop set 2
etype[91] TrPlaneStress2d

group Bot_cap
elemprop set 3
etype[91] TrPlaneStress2d

group Top_ridge
nodeprop set 4

group Bot_ridge
nodeprop  set 5

8) With the latest version of OOFEM you can skip this step, come back here if you get “ValueError: could not convert string to float” or “I need at least 6 entries on dataline ...” errors at step 9.

8-A) Before we continue to the next step, we need to make some corrections to the UNV file. If you are using OORBS’s UNV2OOFEM, you can skip this step. But at the time of writing this tutorial, OOFEM’s UNV converter script cannot detect the double floats inside the UNV file (eg. 4D+01). If you try to run the UNV2OOFEM python script using a GMSH-generated UNV file (see next step) you will get this error (give it a try and see if the problem is resolved by the time you read this or not):

ValueError: could not convert string to float: '4.0000000000000000D+01'

so you need to replace D+ with E+ (that is change 4.D+01 to 4.E+01).

Tip: You can simply make that edit using a text editor with find and replace all function. Note that using Salome instead of GMSH, you probably don’t need to worry about this since Salome usually uses “E” for exponential numbers.

All D+ replaced with E+ as a workaround for the python script limitation

8-B) The next problem is OOFEM cannot detect universal element type 21 (1D beam). By the time you read this, this problem may also be resolved, otherwise, you will see this error:

I need at least 6 entries on dataline ...

One solution is if you don’t need those elements in the analysis, delete the 1D elements before exporting the .unv file by GMSH or delete the type 21 elements manually in the UNV file after exporting. Another option is to use the modified UNV2OOFEM script of OORBS instead of OOFEM’s, in which this problem is resolved.

9) Finally you can pass the .unv file and .ctrl file as input to UNV2OOFEM python script, e.g.:

unv2oofem.py capped_specimen.unv capped_specimen.ctrl capped_specimen.in

and if everything goes well capped_specimen.in file will be generated as the output of this script.

One thought on “Using GMSH for preprocessing of OOFEM solver

Leave a comment

Design a site like this with WordPress.com
Get started