Functions#

Description#

Functions have been generalized to feature a natural syntax and are now applied more broadly throughout the program. They can be defined in terms of predefined functions (sin, log, etc) and named parameters of the problem. The parameters that are available and allowed for use depend on the application. In addition to coefficient definitions, functions may now be used to define load waveforms, used in the optimizer, etc. More applications will be added as well.

Syntax#

Functions follow a C-like syntax. At the end of the function definition, a semi-colon must be added to terminate the reading of the function. Many operators exist, which have the same meaning and order of selection as in C. Coefficients which are defined as functions still require the keyword function to follow the coefficient name, but are otherwise generally given in terms of the relevant parameters.

The following operators are defined in functions:

:= == >= <= + - * / ^ > <

as are the following functions:

asinh acosh atanh sinh cosh tanh asin acos atan sin cos tan
sign floor ceil sqrt sqr neg abs exp ln Hx H min max
triangle top_triangle urandom

Most of these functions take on the classical meaning from standard C programming syntax. Pre-defined functions may take complex arguments of other expressions or functions.

sqr square of the parameter (is equivalent to ^2)

sqrt square-root of the parameter

triangle function used to make a sawtooth waveform with period 1 of the parameter.

floor largest integral value not greater than x. H Heaviside function. Equal to \(1\) for \(x \ge 0\) and \(0\) otherwise.

Hx Heaviside of its parameter times its parameter. Equal to \(x\) for \(x>0\) and \(0\) otherwise.

urandom(a,b) Uniform random distribution that returns values between \(a\) and \(b\)

Example#

Here are three typical examples using functions (a mesher, a calcul and a behavior):

% create a bset based on coordinates
**bset edge *function (y>=5.0)*(z>=10) ;

% define a loading table as a function of time:
***function load_tab sin(6.28319*time);

% define a material coefficient depending on a parameter:
***elasticity
   young function 2.e6-100.*temperature -2.*temperature^2.;
   poisson 0.3

Note that test operations can be achieved by using the equivalence operators, such as (x>=5.0)*(z>=0.0);.

Adding new functions#

Global function definitions is often useful when complex functions are required, or as a means to adjust local parameters (e.g. in a material) via the input file. There are three places to make function declarations. One is by using the ***-level command ***function_declarations in the main problem input file, one is in the material file itself using the command **functions command, and the last is in an external file loaded via the -learn command-line argument.

For example:

****calcul
 ***function_declarations
    TR := 250.0;
    pi := 3.14159265359;
...
***behavior gen_evp
 **functions
   zmax := (a>b)*a + (a<=b)*b;
   zmin := (a<b)*a + (a>=b)*b;
   lfunc := zmax( a , 1.e-6 ) ;
Zrun -learn my_functions.txt calcul.inp

where my_functions.txt is for instance:

T   := x^2 * exp(y) * cos(z);
LT  := 2* exp(y)* cos(z);