CFD Online Logo CFD Online URL
Home > Forums > Open Source Meshers: Gmsh, Netgen, CGNS, ...

Scripted version of "2D Mesh Generation Tutorial for GMSH"

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 3 Post By laubeg

LinkBack Thread Tools Display Modes
Old   April 2, 2013, 09:02
Default Scripted version of "2D Mesh Generation Tutorial for GMSH"
New Member
Gerrit Laube
Join Date: Feb 2013
Posts: 5
Rep Power: 6
laubeg is on a distinguished road

I came across the 2d mesh generation tutorial for gmsh by aeroslacker:
which was very useful as a first step with gmsh/openfoam.

I just didn't like the thought of using both the graphical user interface (GUI) and the Editor so I changed it a tiny bit to make scripting possible. The main difference is the usage of "vector[] = Extrude {...}{...}" instead of "Extrude {...}{...}", where "vector[]" is a vector containing the surfaces and volumes created by the Extrude-command. This way, you get rid of the intransparent numbering of the surfaces.

I also added an optional structuring of the mesh, just as a hint that structuring is possible. Here is all the code:

// sripted version of "2D Mesh Tutorial using GMSH" by CFD-online Member "aeroslacker", taken from
// All numbering counterclockwise from bottom-left corner
Point(1) = {-100, -100, 0, 1e+22};
Point(2) = {100, -100, 0, 1e+22};
Point(3) = {100, 100, 0, 1e+22};
Point(4) = {-100, 100, 0, 1e+22};
Line(1) = {1, 2};                // bottom line
Line(2) = {2, 3};                // right line
Line(3) = {3, 4};                // top line
Line(4) = {4, 1};                // left line
Line Loop(5) = {1, 2, 3, 4};     
// the order of lines in Line Loop is used again in surfaceVector[]
Plane Surface(6) = {5};

/* start optional: structured mesh */
// Transfinite Surface{surface}={edge points}; forces later meshing to contain structured triangles
Transfinite Surface{6} = {1,2,3,4};
Recombine Surface{6}; //combine triangles to quadrangles
/* end optional */

surfaceVector[] = Extrude {0, 0, 10} {
/* surfaceVector contains in the following order:
[0] - front surface (opposed to source surface)
[1] - extruded volume
[2] - bottom surface (belonging to 1st line in "Line Loop (6)")
[3] - right surface (belonging to 2nd line in "Line Loop (6)")
[4] - top surface (belonging to 3rd line in "Line Loop (6)")
[5] - left surface (belonging to 4th line in "Line Loop (6)") */
Physical Surface("front") = surfaceVector[0];
Physical Volume("internal") = surfaceVector[1];
Physical Surface("bottom") = surfaceVector[2];
Physical Surface("right") = surfaceVector[3];
Physical Surface("top") = surfaceVector[4];
Physical Surface("left") = surfaceVector[5];
Physical Surface("back") = {6}; // from Plane Surface (6) ...

// File must end with a free line to avoid errors! So insert line below this comment!
Do you think I should add this "scripted" version of the Tutorial as an optional way to the openfoamwiki?

In my opinion programming geometry has some advantages over using the GUI, especially when you keep in mind, that the .geo-format is more of a programming language (including loops, if/else...) than just a point-list. In my case, one boundary is described by a sine-wave, which is hard to implement via GUI.

wyldckat, JR22 and fportela like this.
laubeg is offline   Reply With Quote

Old   April 14, 2013, 08:32
Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 9,801
Blog Entries: 39
Rep Power: 108
wyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of light
Greetings Gerrit,

Many thanks for adding this to the wiki page!

Best regards,
wyldckat is offline   Reply With Quote


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Mesh Layers doesnt work on the whole surface Kryo OpenFOAM Native Meshers: snappyHexMesh and Others 8 September 13, 2012 09:28
[ICEM] Need urgent help for hybrid mesh generation Pursuor ANSYS Meshing & Geometry 1 August 29, 2012 16:04
snappyHexMesh won't work - zeros everywhere! sc298 OpenFOAM Native Meshers: snappyHexMesh and Others 2 March 27, 2011 21:11
external flow with snappyHexMesh chelvistero OpenFOAM 11 January 15, 2010 20:43
3-d elliptic generation mesh Gang Sun Main CFD Forum 5 September 16, 1998 00:24

All times are GMT -4. The time now is 10:37.