Contents     Functions              PDF Index

## fe_gmsh

Purpose

Information about GMSH can be found at http://www.geuz.org/gmsh/

To call the GMSH mesher from SDT.

Syntax

```  model=fe_gmsh(command,model,...);
```

Description

The main operation is the automatic meshing of surfaces.

### Example

This example illustrates the automatic meshing of a plate

``` FEnode = [1 0 0 0  0 0 0; 2 0 0 0  1 0 0; 3 0 0 0  0 2 0];
femesh('objectholeinplate 1 2 3 .5 .5 3 4 4');
model=femesh('model0');
model.Elt=feutil('selelt seledge ',model);
model.Node=feutil('getnode groupall',model);
model.Node(:,4)=0; % reset default length
mo1=fe_gmsh('write temp.geo -lc .3 -run -2 -v 0',model);
delete('temp.msh');delete('temp.geo');feplot(mo1)
```

This other example makes a circular hole in a plate

```% Hole in plate :
model=feutil('Objectquad 1 1',[0 0 0; 1 0 0;1 1 0;0 1 0],1,1); %
model=fe_gmsh('AddFullCircle -loop2',model,[.5 .5 0; .4 .5 0; 0 0 1]);

model.Stack{end}.PlaneSurface=[1 2];
mo1=fe_gmsh('write tmp.geo -lc .02 -run -2 -v 0',model)
delete('temp.msh');delete('temp.geo');feplot(mo1)
```

To allow automated running of GMSH from MATLAB, this function uses a info,GMSH stack entry with the following fields

 .Line one line per row referencing NodeId. Can be defined using addline commands. .Circle define properties of circles. .LineLoop rows define a closed line as combination of elementary lines. Values are row indices in the .Line field. One can also define LineLoop from circle arcs (or mixed arcs and lines) using a cell array whose each row describes a lineloop as {'LineType',LineInd,...} where LineType can be Circle or Line and LineInd row indices in corresponding .Line or .Circle field. .TransfiniteLines Defines lines which seeding is controlled. .PlaneSurface rows define surfaces as a combination of line loops, values are row indices in the .LineLoop field. Negative values are used to reverse the line orientation. 1st column describes the exterior contour, and followings the interiors to be removed. As .PlaneSurface is a matrix, extra columns can be filled by zeros. .EmbeddedLines define line indices which do not define mesh contours but add additional constrains to the final mesh (see Line In Surface in the gmsh documentation. .SurfaceLoop rows define a closed surface as combination of elementary surfaces. Values are row indices in the .PlaneSurface field.

The local mesh size is defined at nodes by GMSH. This is stored in column 4 of the model.Node. Command option -lcval in the command resets the value val for all nodes that do not have a prior value.

Typical calls are of the form [mdl,RO]=fe_gmsh('Add Cmd',mdl,data). The optional second output argument can be used to obtain additional information like the LoopInfo. Accepted command options are

• -loop i is used to add the given geometries and append the associated indices into the LineLoop(i).
• FullCircle defines a circle defined using data with rows giving center coordinates, an edge node coordinates and the normal in the last row. 4 arcs of circle are added. In the LineLoop field the entry has the form {'Circle',[ind1 ind2 ind3 ind4]} where indi are the row indices of the 4 arcs of circle created in .Circle field.
• CircleArc defines a circle arc using data with rows giving center coordinates, second and third rows are respectively the first and second edges defined by node coordinates. One can also give 3 NodeId as a column instead of x y z.
• Disk ...
• Line accepts multiple formats. data can be a 2 column matrix which each row defines a couple of points from their NodeId.

data can also be a 2 by 3 matrix defining the coordinates of the 2 extremities.

data can also be a string defining a line selection.

• It is possible to specify a seeding on the line for further meshing operation using additional arguments seed and the number of nodes to seed on the line. E.g.: mdl=fe_gmsh('AddLine',mdl,data,'seed',5); will ask gmsh to place 5 nodes on each line declared in data.
• It is possible to define line constrains in mesh interiors using embedded lines (depending on the gmsh version). mdl=fe_gmsh('AddLine',mdl,data,'embed',1); will thus declare the edges found in data not as line loops defining surfaces, but as interior mesh constrains. This feature is only supported for lines specified as selections.
• AddLine3 can be used to declare splines instead of lines in the geometry. For this command to work, beam3 elements must be used, so that a middle node exists to be declared as the spline control point. For this command, data can only be an element string selection.

### config

The fe_gmsh function uses the OpenFEM preference to launch the GMSH mesher.

``` setpref('OpenFEM','gmsh','\$HOME_GMSH/gmsh.exe')
```

### Ver

Command Ver returns the version of gmsh, the version is transformed into a double to simplify hierarchy handling (e.g. version 2.5.1 is transformed into 251). This command alos provides a good test to check your gmsh setup as the output will be empty if gmsh could not be found.

### Write

fe_gmsh('write FileName.geo',model); writes a model (.Node, .Elt) and geometry data in model.Stack'info','GMSH' into a .geo file which root name is specified as FileName.

• Command option -lc allows specifying a characteristic length.
• Command option -multiple can be used for automated meshing of several closed contours. The default behavior will define a single Plane Surface combining all contours, while -mutliple variant will declare each contour as a single Plane Surface.
• Command option -keepContour can be used to force gmsh not to add nodes in declared line objects (Transfinite Line feature).
• Command option -spline can be used (when lines have been declared using command AddLine3 from beam3 elements) to write spline objects instead of line objects in the .geo file
• .stl writing format is also supported, by using extension .stl instead of .geo in the command line.
• Command option -run allows to run gmsh on the written file for meshing. All characters in the command after -run will be passed to the gmsh batch call performed. fe_gmsh then outputs the model processed by gmsh, which is usually written in .msh file format.

All text after the -run is propagated to GMSH. In particular (-1 or -2 or -3) specifies the meshing dimension. -order 2 uses quadratic elements. -v 0 makes a silent run.
It also possible to add a different output file name NewFile.msh, using model=fe_gmsh('write NewFile.msh -run','FileName.stl').

• Conversion of files through fe_gmsh into .msh, or SDT/OpenFEM format is possible, for all input files readable by gmsh. Use command option -run and specify in second arguement the file name.
For example: model=fe_gmsh('write -run','FileName.stl') convert .stl to .mesh then open into SDT/OpenFem. Some warning can occur if no FileName.mesh is given, but without effect on the result.