Difference between revisions of "User Defined Functions"

From OSUPDOCS
Jump to navigation Jump to search
Line 1: Line 1:
This document needs conversion to Wiki format
This document needs conversion to Wiki format


<p>Some commands let you set properties using a function. When a function option is allowed, enter a valid function of <code>x</code>, <code>y</code>, <code>z</code> (postions in mm), <code>R</code>, <code>Z</code> (synonyms for <code>x</code> and <code>y</code> if axisymmetric), <code>t</code> (time in ms), <code>q</code> (particle rotation in radians about the <code>z</code> (or &theta; if axisymmetric) axis), <code>D</code>, or <code>T</code> (polar coordinates in <code>x</code>-<code>y</code> (or <code>R</code>-<code>Z</code> if axisymmetric) plane in mm (D) and radians (T)), . The function will be evaluated to calculate the value of the property to be assigned. Not all variables can be used for all functions. Refer the command that allows a function to see what variables are allowed.</p>
<p>Some commands let you set properties using a function. When a function option is allowed, enter a valid function of <code>x</code>, <code>y</code>, <code>z</code> (postions in mm), <code>R</code>, <code>Z</code> (synonyms for <code>x</code> and <code>y</code> if axisymmetric), <code>t</code> (time in ms), <code>dt</code> (time step in ms), <code>q</code> (particle rotation in radians about the <code>z</code> (or &theta; if axisymmetric) axis), <code>D</code>, or <code>T</code> (polar coordinates in <code>x</code>-<code>y</code> (or <code>R</code>-<code>Z</code> if axisymmetric) plane in mm (D) and radians (T)), . The function will be evaluated to calculate the value of the property to be assigned. Not all variables can be used for all functions. Refer the command that allows a function to see what variables are allowed.</p>


<p>(also?) For 3D MPM, <code>z</code> refers to the <code>z</code> coordinate. For 2D axisymmetric analyses, <code>R</code> and <code>Z</code> refer to radial and axial positions in the 2D plane (although <code>x</code> and <code>y</code> will work too). If a polar function is more appropriate for 2D analysis, the function can be of <code>D</code> and <code>T</code>, where <code>D</code> is distance from the origin to the <code>(x,y)</code> point (in mm) and <code>T</code> is counter-clockwise angle (in radians) from the positive <code>x</code> axis to the point.
<p>(also?) For 3D MPM, <code>z</code> refers to the <code>z</code> coordinate. For 2D axisymmetric analyses, <code>R</code> and <code>Z</code> refer to radial and axial positions in the 2D plane (although <code>x</code> and <code>y</code> will work too). If a polar function is more appropriate for 2D analysis, the function can be of <code>D</code> and <code>T</code>, where <code>D</code> is distance from the origin to the <code>(x,y)</code> point (in mm) and <code>T</code> is counter-clockwise angle (in radians) from the positive <code>x</code> axis to the point.

Revision as of 10:28, 18 November 2013

This document needs conversion to Wiki format

Some commands let you set properties using a function. When a function option is allowed, enter a valid function of x, y, z (postions in mm), R, Z (synonyms for x and y if axisymmetric), t (time in ms), dt (time step in ms), q (particle rotation in radians about the z (or θ if axisymmetric) axis), D, or T (polar coordinates in x-y (or R-Z if axisymmetric) plane in mm (D) and radians (T)), . The function will be evaluated to calculate the value of the property to be assigned. Not all variables can be used for all functions. Refer the command that allows a function to see what variables are allowed.

(also?) For 3D MPM, z refers to the z coordinate. For 2D axisymmetric analyses, R and Z refer to radial and axial positions in the 2D plane (although x and y will work too). If a polar function is more appropriate for 2D analysis, the function can be of D and T, where D is distance from the origin to the (x,y) point (in mm) and T is counter-clockwise angle (in radians) from the positive x axis to the point.

The time options is for MPM options that allow the function to depend on time. 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) (warning: this definition of q was changed in NairnMPM 8.0.1, while before q was the sum of initial angle and rotation angle).

If a polar function is more appropriate for 2D analysis, 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.

Some details on entering functions are:

  • The function must be enclosed in quotes (e.g., "x^2+y^2") to prevent it from being evaluated as a <a href="expression.html#expr">command expression</a> prior to being used in the analysis.
  • Enter variables simply as x, y, etc., and not with the preceding "#" used for <a href="expression.html#expr">command expression variables</a>.
  • 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 <a href="expression.html#expr">command expressions</a> 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 <a href="expression.html#expr">command expressions</a> 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 1400.
  • Extra spaces in the function are ignored.