manpagez: man pages & more
info gmsh
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2.1 Floating point expressions

Floating point expressions (or, more simply, “expressions”) are denoted by the metasyntactic variable expression (remember the definition of the syntactic rules in Syntactic rules used in the manual), and are evaluated during the parsing of the script file:

  real |
  string |
  string ~ { expression }
  string [ expression ] |
  # string [ ] |
  ( expression ) |
  operator-unary-left expression |
  expression operator-unary-right |
  expression operator-binary expression |
  expression operator-ternary-left expression operator-ternary-right expression |
  built-in-function |
  real-option |
  StrFind(char-expression, char-expression) |
  StrCmp(char-expression, char-expression) |
  TextAttributes(char-expression<,char-expression…>) |
  GetValue("string", expression)

Such expressions are used in most of Gmsh’s scripting commands. When ~{expression} is appended to a string string, the result is a new string formed by the concatenation of string, _ (an underscore) and the value of the expression. This is most useful in loops (see section Loops and conditionals), where it permits to define unique strings automatically. For example,

For i In {1:3}
  x~{i} = i;

is the same as

x_1 = 1;
x_2 = 2;
x_3 = 3;

The brackets [] permit to extract one item from a list and to get the size of a list, respectively. The operators operator-unary-left, operator-unary-right, operator-binary, operator-ternary-left and operator-ternary-right are defined in Operators. For the definition of built-in-functions, see Built-in functions. The various real-options are listed in Options. StrFind searches the first char-expression for any occurrence of the second char-expression. StrCmp compares the two strings (returns an integer greater than, equal to, or less than 0, according as the first string is greater than, equal to, or less than the second string). TextAttributes creates attributes for text strings.

The last case in the definition allows to ask the user for a value interactively. For example, inserting GetValue("Value of parameter alpha?", 5.76) in an input file will query the user for the value of a certain parameter alpha, assuming the default value is 5.76. If the option General.NoPopup is set (see section General options list), no question is asked and the default value is automatically used.

List of expressions are also widely used, and are defined as:

  expression-list-item <, expression-list-item> …


  expression |
  expression : expression |
  expression : expression : expression |
  string [ ] | 
  string ( ) |
  List [ string ] |
  string [ { expression-list } ] | 
  string ( { expression-list } ) |
  Point { expression } |
  transform |
  Point { expression } |
  Point|Line|Surface|Volume "*" |
  Physical Point|Line|Surface|Volume { expression-list }

The second case in this last definition permits to create a list containing the range of numbers comprised between two expressions, with a unit incrementation step. The third case also permits to create a list containing the range of numbers comprised between two expressions, but with a positive or negative incrementation step equal to the third expression. The fourth, fifth and sixth cases permit to reference an expression list. The seventh and eight cases permit to reference an expression sublist (whose elements are those corresponding to the indices provided by the expression-list). The next two cases permit to retrieve the indices of entities created through geometrical transformations and extrusions (see Transformations, and Extrusions). The last three cases permit to retrieve the coordinates of a given geometry point (see section Points), to retrieve the id numbers of all points, lines, surfaces or volumes in the model, or to retrieve the elementary entities making up physical groups.

To see the practical use of such expressions, have a look at the first couple of examples in Tutorial. Note that, in order to lighten the syntax, you can omit the braces {} enclosing an expression-list if this expression-list only contains a single item. Also note that a braced expression-list can be preceded by a minus sign in order to change the sign of all the expression-list-items.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on February 9, 2014 using texi2html 5.0.

© 2000-2019
Individual documents may contain additional copyright information.