3. Operands#
3.1. Definition of the function#
The body of the function is a Python algebraic expression represented by a string. It must be evaluable: that is to say respect Python syntax and the functions, constants or other objects necessary for its evaluation must be defined as arguments.
Example:
alpha = 1.23
form = FORMULE (NOM_PARA =”X”, VALE =”sin (X) * alpha”, alpha=alpha)
The expression for the formula is “sin (X) * alpha”. To evaluate it, X is the variable in the formula. The sin function is provided by the math module (see below). The alpha constant is defined in the command file. It is therefore necessary to define it as an argument and to provide its value. In this way, the formula can be evaluated anywhere.
Attention
Python functions, classes (and other objects) defined in the command file are not available in POURSUITE (Python cannot « pickle » them) .
In order for formulas using this type of complementary arguments to be evaluated again in POURSUITE, you must redefine functions, classes (and other Python objects) to POURSUITE and declare them to formulas by setContext.
If VALE is used, the formula produced has a real value (formula-like concept). If VALE_C is used, the formula has a complex value (formula_c concept).
In both cases, the parameters are real. The names of the parameters needed to evaluate the formula are provided behind the NOM_PARA keyword.
In the event of a syntax error, the Python language emits the error message and not*Code_Aster* itself.
Note
The order of the parameters (keyword NOM_PARA ) is important. If you create a two-parameter formula to produce a sheet, the first parameter is the parameter of the sheet, the second is the parameter of the functions that make up the sheet.
3.2. Standard functions#
In addition to the ordinary algebraic signs + -/* **, standard functions (builtins) are also available: min, max, abs, float…
Attention, the division sign here refers to the real division:
1/2 = 0.5
If you want to do an integer division operation, you must use the//operator:
1//2 = 0
3.3. Math functions#
All Python math module functions are imported by default. They can therefore be used directly in the body of the formulas.
http://docs.python.org/lib/module-math.html
Sin |
Sinh |
cos |
cosh |
Tan |
Tanh |
Satan |
sqrt |
atan2 |
log |
asin |
log10 |
acos |
exp |
In addition, the constant pi, from the same module, is also available.
Attention:
The trigonometric functions are therefore those of Python and expect angles expressed in radians. You have to be careful about consistency with simple keywords ANGL_du command language which generally require angles in degrees.