tdynreference manual


Function Syntax

Some of the material and data fields of Tdyn may be defined by functions (see Materials fields Viscosity, Density, Compressibility, VelX Field, VelY Field, VelZ Field, Pres Field, Temp Field, Kenr Field, Elen Field, AccOX Field, AccOY Field,AccOZ Field and others).

This chapter gives a brief explanation of the syntax of the functions used in Tdyn.

Variables:

The variables that can be used for the definition of the functions are:

 

Remarks:

Variables are used in functions without taking into accout its units. Their values are obtained using IS [m], [s], [Kg] unit system.

Available in any case:

t : Total (physical) time

it : Interval time. Time from the last restarting of the problem.

rand : Random number.

Available for fluid domains:

x : X coordinate of the point 

y : Y coordinate of the point 

z : Z coordinate of the point 

nx : X component of the point normal 

ny : Y component of the point normal

nz : Z component of the point normal

vx : X velocity component at the point

vy : Y velocity component at the point

vz : Z velocity component at the point

pr : Pressure of the point

vt : Eddy viscosity at the point (only available if turbulence model is selected)

ke : Eddy kinetic energy at the point (only available if turbulence model, based in the k equation is selected)

ep : Epsilon value at the point (only available if k-epsilon turbulence model is selected)

om : Omega  value at the point (only available if k-omega turbulence model is selected)

kt : Ktau (k*tau) value at the point (only available if k-ktau turbulence model is selected)

bt : Beta (wave elevation) value at the point (only available if transpiration solver is selected)

tm : Temperature of the point

sp : Concentration of the corresponding species at the point. Number of species must be indicated after sp (i.e. sp1, sp7)

dn : Density of the point

ds : Distance of the point to the closest wall

vs : Viscosity of the point

cm : Compressibility factor at the point

Remarks:

Variables are evaluated at the previous time step (t-dt).

Available for solid domains:

x : X coordinate of the point 

y : Y coordinate of the point 

z : Z coordinate of the point 

tm : Temperature of the point

dn : Density of the point

Remarks:

Variables are evaluated at the previous time step (t-dt).

Examples:

x+y

0.1*vx*vx

120.0*(tm-25)

0.1*sp2

sin(x-t)*log(y^2)

Constants:

The constants defined for functions internal compilation  are:

pi : 3.1415926535897932385

exp(1) : 2.7182818284590452354

dt : Time increment of the problem

Function operators:

The function operators calculate the value of a standard function at the point defined by the given argument. The function operators that can be used for the definition of the Tdyn functions are:

 

sqrt : the sqrt function calculates the square root of the argument. Syntax: sqrt(·)

abs : the abs function calculates the absolute value of the argument. Syntax: abs(·)

ln : logarithm of the argument, e base. Syntax: ln(·)

log : logarithm of the argument, decimal base. Syntax: log(·)

fac : factorial of the argument. Syntax: fac(·)

sin : sine of the argument. Syntax: sin(·) (argument given in radians).

cos : cosine of the argument. Syntax: cos(·) (argument given in radians).

tan : tangent of the argument. Syntax: tan(·) (argument given in radians).

asin : The asin function returns the arcsine of the argument in the range –π/2 to π/2 radians. Syntax: asin(·).

acos : The acos function returns the arccosine of the argument in the range 0 to π radians. Syntax: acos(·).

atan : The atan function returns the arctangent of the argument in the range –π/2 to π/2 radians. Syntax: atan(·) (result given in radians).

sinh : hyperbolic sine of the argument. Syntax: sinh(·).

cosh : hyperbolic cosine of the argument. Syntax: cosh(·).

tanh : hyperbolic tangent of the argument. Syntax: tanh(·).

exp : the exp function calculates the exponential value of the argument. Syntax: exp(·).

Interpolate : performs a linear interpolation, based on the given data. Two arguments are required: a list of pairs (x,h), defining the a polylineal curve, and a function defining the x value where the evaluation is done. Syntax: interpolate(#x1,h1,x2,h2,x3,h3,…# ·).

srand : The rand function returns a pseudorandom integer in the range 0 to 1, based on the argument given as seed. Syntax: srand(·).

- : change sign operator. Syntax: (-expression).

Examples:

2*sqrt(y)

x*fac(5)

srand(0)

log(abs(x))

exp(5)

interpolate(#1.0,2.0,2.0,2.5,3.0,2.0#t^2)

Operators:

Operators that can be used for Tdyn functions definitions are:

+ : adding operator.

  Syntax: [adding_expression] + [adding_expression].

- : substraction operator.

  Syntax: [substraction_expression] – [substraction_expression].

^ : exponent operator.

  Syntax: [exponent_expression] ^ [function_expression].

* : multiplicative operator.

  Syntax: [multiplicative_expression] * [multiplicative _expression].

/ : division operator.

  Syntax: [multiplicative_expression] / [quotient_expression].

div : integer division operator.

  Syntax: [multiplicative_expression] div [quotient_expression].

mod : division module operator.

  Syntax: [multiplicative_expression] mod

max : maximum operator.

  Syntax: [expression] max [expression]

min : minimum operator.

  Syntax: [expression] min [expression]

 ~ : not operator.

  Syntax: ~[function_expression].

Examples:

(2*y)

(5*(y+1))/2

((z*y)mod5)

(5^4)

Relational operators:

The relational (binary) operators compare their first operand with their second operand to test validity of the specified relationship. The result of the relational expression is 1 if the tested relationship is true and 0 if it is false. The binary operators that can be used for Tdyn functions definitions are:

< : less than operator.

  Syntax: [expression] <  [expression].

< = : less or equal than operator.

  Syntax: [expression] <= [expression].

>= : greater or equal than operator.

  Syntax: [expression] >= [expression].

> : greater than operator.

  Syntax: [expression] > [expression].

= : equal operator.

  Syntax: [expression] = [expression].

!= : not equal operator.

  Syntax: [expression] != [expression].

& : and operator.

  Syntax: [expression] & [expression].

| : and operator.

  Syntax: [expression] | [expression].

Examples:

(y>2)

(x<=1)

(x!=1)

(y>2)&(x>2)&(x<3)&(y<3)

Cartesian derivatives:

It is also possible to use cartesian derivatives to evaluate functions in solid and fluid domains. The Cartesian derivative operators that can be used for Tdyn functions definitions are:

dx : X Cartesian derivative. The argument must be a variable defined in the whole domain (not a function).

dy : Y Cartesian derivative. The argument must be a variable defined in the whole domain (not a function).

dz : Z Cartesian derivative. The argument must be a variable defined in the whole domain (not a function).

Examples:

vx*dx(vx)

nx*dx(vx)+ny*dy(vx)

if-else statement:

The if statement controls conditional branching. The body of the if statement (elif_expression) is executed if the value of the expression is non zero. The syntax for the if statement is the following:

if(expression)then(elif_expression)else(next_expression)endif

being elif_expression an additional expression that may include an elif clause with next form:

(expression2)elif(elif_expression2)then(next_expression2)

Examples:

if(y>2)then(if(x<1)then(1)else(0)endif)else(0)endif

if(y>2)then(1)elif(x<1)then(2)else(0)endif

Figure 24. Function Editor

Function editor:

In order to easily edit and insert the functions in the corresponding materials and boundaries fields, a Function editor (see Figure 24) is available in any Fluid Material, Solid Material, Boundaries and PROBLEM window (see Figure 25).

Figure 25. Access to the Function editor in the Material window