# Gmsh Functions 1

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

In this blog, quick reference notes about OpenFOAM are posted in a form of a summary to address a specific topic per post.
Rate this Entry

# Gmsh Functions 1

Posted January 21, 2013 at 06:18 by Hisham
Tags gmsh

Gmsh is a powerful mesh generator. One of its strength points is the use of both scripting and GUI functionality. Scripting has two neat features: Function : lets one define a function and call it several times. Include : lets one include other scripts into the geometry file script.

Assume we have a Mesh.geo file that we have for the geometry. You can start off by:

Code:
`Include "Functions.geo" ;`
The Functions.geo file is a file that has some function definitions. In this post, I wrote some easy functions. Hope to extend them in future posts (any suggestions are welcome)

The Functions.geo file:

Code:
```Function Quadrangle

/*
* X, Y, Z, lc
* point   dX    dY
* 1       0     0
* 2       dX2   dY2
* 3       dX3   dY3
* 4       dX4   dY4
*
* Transfinite:
* Horizontal: N_H
* Vertical: N_V
*/
p1 = newp; Point(p1) = {X,Y,Z,lc};
p2 = newp; Point(p2) = {X+dX2,Y+dY2,Z,lc};
p3 = newp; Point(p3) = {X+dX3,Y+dY3,Z,lc};
p4 = newp; Point(p4) = {X+dX4,Y+dY4,Z,lc};

l1= newl; Line(l1) = {p1, p2} ;
l2= newl; Line(l2) = {p2, p3} ;
l3= newl; Line(l3) = {p3, p4} ;
l4= newl; Line(l4) = {p4, p1} ;

Transfinite Line {l1, l3} = N_H;
Transfinite Line {l2, l4} = N_V;

ll1 = newll; Line Loop(ll1) = {l1, l2, l3, l4};

pl1 = news;

Plane Surface (pl1) = {ll1};

Transfinite Surface {pl1};

Recombine Surface {pl1};

Return

Function Rectangle

dX3=dX2;
dX4=0;
dY2=0;
dY4=dY3;

Return

Function Square

dY3=dX2;
N_V = N_H;
Call Rectangle ;

Return

Function ExtrudeFunc

myExt[]=Extrude {ExX, ExY, ExZ}{
Surface{pl1};
Layers{ExLayers};
Recombine;
};

Return

Function Cuboid
Call ExtrudeFunc;
Return

Function RectCuboid
Call Rectangle;
Call ExtrudeFunc;
Return

Function Cube
Call Square;
ExLayers = N_H;
ExZ=dX2;
Call ExtrudeFunc;
Return

/******************************************************************************\
Define/Change Parameters Before Calling Functions
\******************************************************************************/

lc = 0.1;
X = 0;
Y = 0;
Z = 0;
dX2 = 1;
dX3 = 0.9;
dX4= 0.4;
dY2= 0.05;
dY3= 0.2;
dY4= 0.18;

N_V=5;
N_H=20;

//Call Rectangle ;

//Call Square ;

ExX = 0;
ExY = 0;
ExZ = 2;

ExLayers = 30;

//Call Cube;

//Call Cuboid;

//Call RectCuboid;

// Automatically Assign Physical Volume to the Extrude
// Physical Volume ("myVolName") = {myExt[1]};
// myExt[0] is the ID of the opposite new surface

// Physical Surfaces are to be defined manually for the whole geometry```
Hisham El Safti
Posted in Uncategorized
Views 3105 Comments 0
« Prev     Main     Next »