GmshParametricModelling

Using scripting files. Other scripting file can be "included" and piece of code can be reused by "macros"

Inculde

/*
          Include Parameter file 
 */
Include "Param.geo";

User Defined Function (Macros)

User defined functions can be defined inside the scripting file allowing to reuse the same code anywhere inside the scripting file. The function definition shall follow the below syntax:

Function string

Gmsh command
........

Return

Call string ; Executes the body of a (previously defined) function named string.

Warning: all variable are public inside the scripting file

Accessing Gmsh generated entity IDs

As in described in example t2.geo
// Using the graphical user interface to obtain the ids of newly
// created entities can sometimes be cumbersome. It can then be
// advantageous to use the return value of the transformation commands
// directly. For example, the Translate command returns a list
// containing the ids of the translated entities. For example, we can
// translate copies of the two surfaces 6 and 11 to the right with the
// following command:

my_new_surfs[] = Translate {0.12, 0, 0} { Duplicata{ Surface{6, 11}; } };

// my_new_surfs[] (note the square brackets) denotes a list, which in
// this case contains the ids of the two new surfaces (check
// ‘Tools->Message console’ to see the message):

and even better in t3.geo
out[] = Extrude { {-2*h,0,0}, {1,0,0} , {0,0.15,0.25} , Pi/2 } {
Surface{144}; Layers{10}; Recombine;
};
// In this last extrusion command we retrieved the volume number
// programatically by using the return value (a list) of the Extrude
// command. This list contains the "top" of the extruded surface (in
// out[0]), the newly created volume (in out[1]) and the ids of the
// lateral surfaces (in out[2], out[3], ...)

-- RobertoBernetti - 03 Mar 2017
Topic revision: r4 - 04 Feb 2020, RobertoBernetti
This site is powered by FoswikiCreative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License1999-2025
Ideas, requests, problems regarding this site? Send feedback