Difference between revisions of "User Defined Functions"
Line 17: | Line 17: | ||
Note that commands that allow functions may only allow a subset of these variables (due to command context). You can refer to each command for the allowed variables. When a function is used, it will be calculated using these variables and should return a results in the units expected by the command. | Note that commands that allow functions may only allow a subset of these variables (due to command context). You can refer to each command for the allowed variables. When a function is used, it will be calculated using these variables and should return a results in the units expected by the command. | ||
If a polar function is more appropriate for 2D analyses, the function can be of <tt>D</tt> and <tt>T</tt>, where <tt>D</tt> is distance from the origin to the <tt>(x,y)</tt> (or <tt>(R,Z)</tt> if axisymmetric) point (in mm) and <tt>T</tt> is counter-clockwise angle (in radians) from the positive <tt>x</tt> (or <tt>R</tt> if axisymmetric) axis to the point. | |||
The time, time step, and rotation variables (<tt>t</tt>, <tt>dt</tt>, and <tt>q</tt>) options are for MPM commands only. Some MPM options (as detailed in their documentation) require the function to depend <i>only</i> on time. Particle based MPM boundary conditions let the function depend on clockwise particle rotational angle <tt>q</tt> about the <tt>z</tt> axis (in radians), which allows rotation of the bondary conditions with the particle. Note that <tt>q</tt> is particle rotation since the start of the simulation and will differ from material angle if the particle started with a non-zero orientation angle (the current material angle is the sum of <tt>q</tt> and its initial angle). | The time, time step, and rotation variables (<tt>t</tt>, <tt>dt</tt>, and <tt>q</tt>) options are for MPM commands only. Some MPM options (as detailed in their documentation) require the function to depend <i>only</i> on time. Particle based MPM boundary conditions let the function depend on clockwise particle rotational angle <tt>q</tt> about the <tt>z</tt> axis (in radians), which allows rotation of the bondary conditions with the particle. Note that <tt>q</tt> is particle rotation since the start of the simulation and will differ from material angle if the particle started with a non-zero orientation angle (the current material angle is the sum of <tt>q</tt> and its initial angle). | ||
== Function Format == | == Function Format == |
Revision as of 11:42, 18 November 2013
Some commands let you set properties using a function that is evaluated at run time.
Function Variables
When a function option is allowed in any command, you can enter any valid function of the following variable
- x - particle, element, or nodal x position in mm
- y - particle, element, or nodal y position in mm
- z - particle, element, or nodal z position in mm
- R - particle, element, or nodal radial position in mm for axisymmetric calculation; R is a synonym for x, which also works
- Z - particle, element, or nodal axial position in mm for axisymmetric calculation; Z is a synonym for y, which also works
D
- distance from origin to the particle, element, or node (i.e., r in polar coordinates).T
- counter-clockwise angle (in radians) from the positive x axis to a vector from the origin to the particle, element, or nodal (i.e., θ in polar coordinates)- t - current time in ms
- dt - the time step in ms
- q - particle rotation in radians about the z (or θ if axisymmetric) axis
Note that commands that allow functions may only allow a subset of these variables (due to command context). You can refer to each command for the allowed variables. When a function is used, it will be calculated using these variables and should return a results in the units expected by the command.
If a polar function is more appropriate for 2D analyses, the function can be of D and T, where D is distance from the origin to the (x,y) (or (R,Z) if axisymmetric) point (in mm) and T is counter-clockwise angle (in radians) from the positive x (or R if axisymmetric) axis to the point.
The time, time step, and rotation variables (t, dt, and q) options are for MPM commands only. Some MPM options (as detailed in their documentation) require the function to depend only on time. Particle based MPM boundary conditions let the function depend on clockwise particle rotational angle q about the z axis (in radians), which allows rotation of the bondary conditions with the particle. Note that q is particle rotation since the start of the simulation and will differ from material angle if the particle started with a non-zero orientation angle (the current material angle is the sum of q and its initial angle).
Function Format
Some details on entering functions are:
- In scripted files, the function must be enclosed in quotes (e.g., "
x^2+y^2
") to prevent it from being evaluated as a command expression prior to being used in the analysis. - Enter variables simply as x, y, etc., and not with the preceding "#" used for command expression variables.
- Operators: The function uses standard operators + - * / and ^ with standard operator precedence for addition, subtraction, multiplication, division, and raising to a power.
- The function can contain the following defined functions:
- sin(x), cos(x), and tan(x) - trigonometric function of angle in radians.
- asin(x), acos(x), and atan(x) - inverse trigonometric function with result in radians.
- sqrt(x) - square root.
- log(x) and ln(x) - log base 10 and natural log, respectively (note these are different than log functions used in command expressions in scripted files due to different math expression parser in the code engines).
- exp(x) - exponential of x.
- abs(x) - absolute value of x.
- int(x) - integer part of x as next lower integer. For negative numbers, it is next lower integer or int(-3.4)=-4.
- sign(x) - 1 if
x
is greater than zero or 0 if x is negative or equal to zero. - Sinh(x), Cosh(x), and Tanh(x) - hyperbolic trigonometric functions. (note the initial uppercase is needed here, and differs from scripted command expressions due to different math expression parser in the code engines).
- Functions can include pi (or Pi or PI) for the number π.
- Exponential Notation: numbers can have "e" or "E" for powers of ten such as 1.4e3 for <cttde>1400.
- Extra spaces in the function are ignored.