Difference between revisions of "User Defined Functions"

From OSUPDOCS
Jump to navigation Jump to search
 
(69 intermediate revisions by the same user not shown)
Line 1: Line 1:
This document needs conversion to Wiki format
Some commands let you set properties using a function that is evaluated at run time.


<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>
== Function Variables ==


<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.
When a user-defined function option is allowed in any command, you can enter any valid function of the following variables when doing MPM simulations:
</p>


<p> 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 <i>only</i> on time. Particle based MPM boundary conditions let the function depend on clockwise particle rotational angle <code>q</code> about the <code>z</code> axis (in radians), which allows rotation of the bondary conditions with the particle. Note that <code>q</code> 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 <code>q</code> and its initial angle) (<font color="red">warning</font>: this definition of <code>q</code> was changed in NairnMPM 8.0.1, while before <code>q</code> was the sum of initial angle and rotation angle).
* <tt>x</tt> - <tt>x</tt> position in [[ConsistentUnits Command#Legacy and Consistent Units|length units]]
</p>
* <tt>y</tt> <tt>y</tt> position in [[ConsistentUnits Command#Legacy and Consistent Units|length units]]
* <tt>z</tt> - <tt>z</tt> position in [[ConsistentUnits Command#Legacy and Consistent Units|length units]]
* <tt>t</tt> - current time in [[ConsistentUnits Command#Legacy and Consistent Units|alt time units]]
* <tt>dt</tt> - the time step in [[ConsistentUnits Command#Legacy and Consistent Units|alt time units]]
* <tt>q</tt> - particle rotation in radians about the <tt>z</tt> (or &theta; if axisymmetric) axis


<p>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> (or <code>(R,Z)</code> if axisymmetric) point (in mm) and <code>T</code> is counter-clockwise angle (in radians) from the positive <code>x</code> (or <code>R</code> if axisymmetric) axis to the point.
For FEA calculations, the following variables are allowed and may refer to position of element centroid or node depending on the command:
</p>


<p>Some details on entering functions are:</p>
* <tt>x</tt> - <tt>x</tt> position in [[ConsistentUnits Command#Legacy and Consistent Units|length units]]
* <tt>y</tt> -  <tt>y</tt> position in [[ConsistentUnits Command#Legacy and Consistent Units|length units]]
* <tt>r</tt> - radial position of axisymmetric calculations in [[ConsistentUnits Command#Legacy and Consistent Units|length units]] (synonym for <tt>x</tt>).
* <tt>z</tt> -  axial position of axisymmetric calculations in [[ConsistentUnits Command#Legacy and Consistent Units|length units]] (synonym for <tt>x</tt>)
 
When a user-defined function is used, it will be calculated using these variables and should return a result 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. For example, 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 <tt>q</tt> about the <tt>z</tt> axis (in radians), which allows rotation of the boundary 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 (''i.e.'', the current material angle is the sum of <tt>q</tt> and its initial angle). 
 
When setting up MPM simulations or FEA calculations, a few more variables are sometimes allowed:
 
* <tt>R</tt> - radial position in [[ConsistentUnits Command#Legacy and Consistent Units|length units]] for axisymmetric calculation; <tt>R</tt> is a synonym for <tt>x</tt>, which also works
* <tt>Z</tt> - axial position in [[ConsistentUnits Command#Legacy and Consistent Units|length units]] for axisymmetric calculation; <tt>Z</tt> is a synonym for <tt>y</tt>, which also works
* <tt>D</tt> - distance from origin [[ConsistentUnits Command#Legacy and Consistent Units|length units]]
* <tt>T</tt> - counter-clockwise angle (in radians) from the positive x axis  (''i.e.'', &theta; in polar coordinates)
 
Here <tt>(R,Z)</tt> are axisymmetric coordinates and <tt>(D,T)</tt> are polar coordinates, where <tt>D</tt> is distance from the origin to the <tt>(x,y)</tt> (or <tt>(R,Z)</tt> if axisymmetric) point (in [[ConsistentUnits Command#Legacy and Consistent Units|length units]]) 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. These extra variables are only allowed in:
 
* [[MPM Region and Hole Commands|MPM Region commands or <Body> blocks]] to set initial particle velocity, angular momentum, or rotation angle (also for development membranes in [[OSParticulas]].
* [[Transform Command#Transforming Created Particles in XML Files|<Deform> block]] to set initial particle displacement.
* [[Area Command|FEA Area command or <Area> block]] to set initial material angle.
* [[Thermal FEA Calculations|FEA Temperature command or <Temperature> element]] to set initial temperature on the nodes.
 
== Function Format ==
 
Some details on entering functions are:


<ul>
<ul>


<li>The function must be enclosed in quotes (<i>e.g.</i>, &quot;<code>x^2+y^2</code>&quot;) to prevent it from being evaluated as a <a href="expression.html#expr">command expression</a> prior to being used in the analysis.
<li>In scripted files, the function must be enclosed in quotes (<i>e.g.</i>, "<tt>x^2+y^2</tt>") to prevent it from being evaluated as a command expression prior to being used in the analysis.
</li>


<li>Enter variables simply as <code>x</code>, <code>y</code>, <i>etc.</i>, and not with the preceding &quot;<code>#</code>&quot; used for <a href="expression.html#expr">command expression variables</a>.
<li>Enter variables simply as <tt>x</tt>, <tt>y</tt>, <i>etc.</i>, and not with the preceding "<tt>#</tt>" used for command expression variables.
</li>


<li>Operators: The function uses standard operators + - * / and ^ with standard operator precedence for addition, subtraction, multiplication, division, and raising to a power.
<li>Operators: The function uses standard operators + - * / and ^ with standard operator precedence for addition, subtraction, multiplication, division, and raising to a power.
</li>


<li>The function can contain the following defined functions:
<li>The function can contain the following defined functions:
<ul>
<ul>


<li><tt>sin(x)</tt>, <tt>cos(x)</tt>, and <tt>tan(x)</tt> - trigonometric function of angle in radians.


<li><code>sin(x)</code>, <code>cos(x)</code>, and <code>tan(x)</code> - trigonometric function of angle in radians.
<li><tt>asin(x)</tt>, <tt>acos(x)</tt>, and <tt>atan(x)</tt> - inverse trigonometric function with result in radians.
</li>
 
<li><tt>sqrt(x)</tt> - square root.
 
<li><tt>log(x)</tt> and <tt>ln(x)</tt> - 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).
 
<li><tt>exp(x)</tt> - exponential of <tt>x</tt>.


<li><code>asin(x)</code>, <code>acos(x)</code>, and <code>atan(x)</code> - inverse trigonometric function with result in radians.
<li><tt>abs(x)</tt> - absolute value of <tt>x</tt>.
</li>


<li><code>sqrt(x)</code> - square root.
<li><tt>int(x)</tt> - integer part of <tt>x</tt> as next lower integer. For negative numbers, it is next lower integer or <tt>int(-3.4)=-4</tt>.
</li>


<li><code>log(x)</code> and <code>ln(x)</code> - 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).
<li><tt>Sinh(x)</tt>, <tt>Cosh(x)</tt>, and <tt>Tanh(x)</tt> - 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).
</li>


<li><code>exp(x)</code> - exponential of <code>x</code>.
<li><tt>erf(x)</tt> and <tt>erfc(x)</tt> - error function and error function complement.
</li>


<li><code>abs(x)</code> - absolute value of <code>x</code>.
</ul>
</li>


<li><code>int(x)</code> - integer part of <code>x</code> as next lower integer. For negative numbers, it is next lower integer or <code>int(-3.4)=-4</code>.
<li>The following functions are helpful if creating boundary conditions:


<li><code>sign(x)</code> - 1 if <code>x</code> is greater than zero or 0 if <code>x</code> is negative or equal to zero.
<ul>


<li><code>Sinh(x)</code>, <code>Cosh(x)</code>, and <code>Tanh(x)</code> - 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).
<li><math>{\rm ramp}(A,x) = \left\{\begin{array}{ll} 0 & x\le 0 \\
          Ax & 0<x<1 \\
          A & x \ge 1 \end{array}\right.</math>
</li>
<li><math>{\rm cosramp}(A,x) = \left\{\begin{array}{ll} 0 & x\le 0 \\
          {A\over 2}\left(1-\cos(\pi x)\right) & 0<x<1 \\
          A & x \ge 1 \end{array}\right.</math>
</li>
<li><math>{\rm box}(A,x) = \left\{\begin{array}{ll} 0 & x\le 0 \\
          A & 0<x<1 \\
          0 & x \ge 1 \end{array}\right.</math>
</li>
<li><math>{\rm sinbox}(A,x) = \left\{\begin{array}{ll} 0 & x\le 0 \\
          A\sin(\pi x) & 0<x<1 \\
          0 & x \ge 1 \end{array}\right.</math>
</li>
<li><math>{\rm sgn}(x) = \left\{\begin{array}{ll} -1 & x < 0 \\
          0 & x = 0 \\
          +1 & x >0 \end{array}\right.</math>
</li>
<li><math>{\rm sign}(x) = \left\{\begin{array}{ll} 0 & x < 0 \\
          1 & x \ge0 \end{array}\right.</math>
</li>
<li><math>{\rm tri}(x) = \left\{\begin{array}{ll} 1-|x| & |x| < 1 \\
          0 & |x| \ge1 \end{array}\right.</math>
</li>
<li><math>{\rm mod}(x,y) = {\rm fmod}(x,y) = x-{\rm floor}(x/y)*y</math>
</li>
</li>
</ul>
</ul>
For example, to apply a ramp from 0 to t<sub>f</sub>, use x = t/t<sub>f</sub>; to apply a ramp from t<sub>s</sub> to t<sub>f</sub>,use x = (t-t<sub>s</sub>)/(t<sub>f</sub>-t<sub>s</sub>).


<li>Functions can include <code>pi</code> (or <code>Pi</code> or <code>PI</code>) for the number &pi;.
<li>Functions can include <tt>pi</tt> (or <tt>Pi</tt> or <tt>PI</tt>) for the number &pi;.
</li>


<li>Exponential Notation: numbers can have &quot;<code>e</code>&quot; or &quot;<code>E</code>&quot; for powers of ten such as <code>1.4e3</code> for <code>1400</code>.
<li>Exponential Notation: numbers can have "<tt>e</tt>" or "<tt>E</tt>" for powers of ten such as <tt>1.4e3</tt> for <tt>1400</tt>.
</li>


<li>Extra spaces in the function are ignored.
<li>Extra spaces in the function are ignored.
</li>


</ul>
</ul>
== Notes ==
=== Integrals and Derivatives ===
The cosramp(A,x) and sinbox(A,x) are useful for gradually applying velocity or displacement at the start of the simulation rather than instantaneously applying some velocity or displacement at time zero. To interchange between velocity and displacement, it is useful to evaluate their integrals and derivatives:
&nbsp;&nbsp;&nbsp;&nbsp;
<math>\int_0^x {\rm sinbox}(A,u)du = {A\over\pi}\bigl(1-\cos(\pi x)\bigr) = {\rm cosramp}\left({2A\over\pi},x\right)</math>
&nbsp;&nbsp;&nbsp;&nbsp;
<math>\int_0^x {\rm cosramp}(A,u)du =
    \left\{\begin{array}{ll} {A\over 2}\left(x-{\sin(\pi x)\over \pi}\right) & x<1 \\
          A\left(x-{1\over 2}\right) & x \ge 1 \end{array}\right.
    = {A\over 2}\bigl(x + (x-1){\rm sign}(x-1)\bigr) - {\rm sinbox}\left({A\over2\pi},x\right)</math>
&nbsp;&nbsp;&nbsp;&nbsp;
<math>{d\bigl({\rm cosramp}(A,x)\bigr)\over dx} = {A\pi\over 2}\sin(\pi x) = {\rm sinbox}\left({A\pi\over 2},x\right)</math>
&nbsp;&nbsp;&nbsp;&nbsp;
<math>{d\bigl({\rm sinbox}(A,x)\bigr)\over dx} = \left\{\begin{array}{ll} 0 & x\le0 \\ {A\pi}\cos(\pi x) & 0<x<1 \\
          0 & x \ge 1 \end{array}\right. = \pi A\thinspace {\rm sign}(x) - {\rm cosramp}(2\pi A,x)</math>
=== Cosine Ramp to Desired Velocity ===
In problems with constant velocity loading, it might be preferable to ramp velocity to the desired velocity V over some ramp time t<sub>r</sub> rather start the problem at time zero with velocity V. The ramped-up velocity can be done using the cosramp(A,x) function by setting A = V and x = t/t<sub>r</sub> or:
&nbsp;&nbsp;&nbsp;&nbsp;
<math>v(t) = {\rm cosramp}\left(V,{t\over t_r}\right)</math>
Integrating this velocity, the resulting displacement is:
&nbsp;&nbsp;&nbsp;&nbsp;
<math>d(t) = \left\{\begin{array}{ll} {V\over 2}\left(t-{t_r\over \pi}\sin\left({\pi t\over t_r}\right)\right) & t<t_r \\
          V\left(t-{t_r\over 2}\right) & t \ge t_r \end{array}\right.</math>
In terms of defined functions, this displacement can be written
&nbsp;&nbsp;&nbsp;&nbsp;<math>d(t) = {Vt_r\over2}\left[\frac{t}{t_r} + \left(\frac{t}{t_r}-1\right){\rm sign}\left(\frac{t}{t_r}-1\right) - {\rm sinbox}\left({1\over\pi},{t\over t_r}\right)\right]</math>
For example, to ramp to V and then hold constant velocity until reaching desired displacement d<sub>max</sub>, the simulation time should be set to:
&nbsp;&nbsp;&nbsp;&nbsp;<math>t_{max} = {d_{max}\over V} + {t_r\over 2}</math>
The first term is the simulation time using constant velocity while the second term is the extra time needed because the velocity was ramped to velocity V over time t<sub>r</sub>.
=== Cosine Ramp to Desired Displacement ===
Rather that apply displacement instantaneously, which would be an impact problem, it might be preferable to ramp to displacement d over ramp time t<sub>r</sub>. A displacement function would be
&nbsp;&nbsp;&nbsp;&nbsp;
<math>d(t) = {\rm cosramp}\left(d,{t\over t_r}\right)</math>
Differentiating this displacement to get velocity that must be applied as a boundary condition gives
&nbsp;&nbsp;&nbsp;&nbsp;
<math>v(t) = {\pi d\over 2t_r}\sin\left({\pi t\over t_r}\right) = {\rm sinbox}\left({\pi d\over 2t_r},{t\over t_r}\right)</math>
The maximum velocity used during this loading is
&nbsp;&nbsp;&nbsp;&nbsp;
<math>v_{max} = {\pi d\over 2t_r}</math>
=== Linear Ramp to Desired Displacement ===
To ramp to a displacement d over time t<sub>r</sub> with a constant velocity, the ramp velocity is
&nbsp;&nbsp;&nbsp;&nbsp;
<math>v(t) = {\rm box}\left({d\over t_r},{t\over t_r}\right)</math>
The displacement corresponding to this velocity is
&nbsp;&nbsp;&nbsp;&nbsp;
<math>d(t) = {\rm ramp}\left(d,{t\over t_r}\right)</math>
=== Loading and Unloading Cycles ===
To ramp at velocity v<sub>r</sub> from t<sub>0</sub> and t<sub>0</sub>+t<sub>r</sub> then unload using the reverse velocity from t<sub>0</sub>+t<sub>r</sub> to t<sub>0</sub>+2t<sub>r</sub>, the velocity is:
&nbsp;&nbsp;&nbsp;&nbsp;
<math>v(t) = {\rm box}\left(v_r,{t-t_0\over t_r}\right)-{\rm box}\left(v_r,{t-t_0-t_r\over t_r}\right)
        = {\rm box}\left(v_r,{t-t_0\over 2t_r}\right){\rm sgn}(t_0+t_r-t)</math>
The displacement corresponding to this velocity is
&nbsp;&nbsp;&nbsp;&nbsp;
<math>d(t) = v_rt_r {\rm tri}\left({t-t_0\over t_r}-1\right)</math>
A sequence of loading and unloading steps can be created by defining periodic function as explained in the next section.
=== Periodic Boundary Condition Function ===
The <tt>mod(A,x)</tt> function is useful for defining any periodic boundary condition function of time. First create any function of time that is well defined over a given cycle time <tt>t<sub>c</sub></tt>. To define a periodic function replace every "<tt>t</tt>" in that function with "<tt>mod(t,t<sub>c</sub>)</tt>". The result will be a periodic function that will repeat the same defined cycle as long as the simulations keeps running. For example, a sequence of triangular displacements from the previous section's example staring at the beginning (t<sub>0</sub>=0) could be defined with:
&nbsp;&nbsp;&nbsp;&nbsp;
<math>v(t) = {\rm box}\left(v_r,{{\rm mod}(t,2t_r)\over t_r}\right)-{\rm box}\left(v_r,{{\rm mod}(t,2t_r)-t_r\over t_r}\right)</math>
=== Rigid Rotation ===
See [[Rigid Material#Rotation of Rigid Object|Rigid Material]] documentation for details on moving a plot of rigid particles in rigid rotation about a point.

Latest revision as of 10:31, 16 November 2024

Some commands let you set properties using a function that is evaluated at run time.

Function Variables

When a user-defined function option is allowed in any command, you can enter any valid function of the following variables when doing MPM simulations:

For FEA calculations, the following variables are allowed and may refer to position of element centroid or node depending on the command:

When a user-defined function is used, it will be calculated using these variables and should return a result 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. For example, 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 boundary 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 (i.e., the current material angle is the sum of q and its initial angle).

When setting up MPM simulations or FEA calculations, a few more variables are sometimes allowed:

  • R - radial position in length units for axisymmetric calculation; R is a synonym for x, which also works
  • Z - axial position in length units for axisymmetric calculation; Z is a synonym for y, which also works
  • D - distance from origin length units
  • T - counter-clockwise angle (in radians) from the positive x axis (i.e., θ in polar coordinates)

Here (R,Z) are axisymmetric coordinates and (D,T) are polar coordinates, where D is distance from the origin to the (x,y) (or (R,Z) if axisymmetric) point (in length units) and T is counter-clockwise angle (in radians) from the positive x (or R if axisymmetric) axis to the point. These extra variables are only allowed in:

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.
    • 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).
    • erf(x) and erfc(x) - error function and error function complement.
  • The following functions are helpful if creating boundary conditions:
    • [math]\displaystyle{ {\rm ramp}(A,x) = \left\{\begin{array}{ll} 0 & x\le 0 \\ Ax & 0\lt x\lt 1 \\ A & x \ge 1 \end{array}\right. }[/math]
    • [math]\displaystyle{ {\rm cosramp}(A,x) = \left\{\begin{array}{ll} 0 & x\le 0 \\ {A\over 2}\left(1-\cos(\pi x)\right) & 0\lt x\lt 1 \\ A & x \ge 1 \end{array}\right. }[/math]
    • [math]\displaystyle{ {\rm box}(A,x) = \left\{\begin{array}{ll} 0 & x\le 0 \\ A & 0\lt x\lt 1 \\ 0 & x \ge 1 \end{array}\right. }[/math]
    • [math]\displaystyle{ {\rm sinbox}(A,x) = \left\{\begin{array}{ll} 0 & x\le 0 \\ A\sin(\pi x) & 0\lt x\lt 1 \\ 0 & x \ge 1 \end{array}\right. }[/math]
    • [math]\displaystyle{ {\rm sgn}(x) = \left\{\begin{array}{ll} -1 & x \lt 0 \\ 0 & x = 0 \\ +1 & x \gt 0 \end{array}\right. }[/math]
    • [math]\displaystyle{ {\rm sign}(x) = \left\{\begin{array}{ll} 0 & x \lt 0 \\ 1 & x \ge0 \end{array}\right. }[/math]
    • [math]\displaystyle{ {\rm tri}(x) = \left\{\begin{array}{ll} 1-|x| & |x| \lt 1 \\ 0 & |x| \ge1 \end{array}\right. }[/math]
    • [math]\displaystyle{ {\rm mod}(x,y) = {\rm fmod}(x,y) = x-{\rm floor}(x/y)*y }[/math]

    For example, to apply a ramp from 0 to tf, use x = t/tf; to apply a ramp from ts to tf,use x = (t-ts)/(tf-ts).

  • 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.

Notes

Integrals and Derivatives

The cosramp(A,x) and sinbox(A,x) are useful for gradually applying velocity or displacement at the start of the simulation rather than instantaneously applying some velocity or displacement at time zero. To interchange between velocity and displacement, it is useful to evaluate their integrals and derivatives:

     [math]\displaystyle{ \int_0^x {\rm sinbox}(A,u)du = {A\over\pi}\bigl(1-\cos(\pi x)\bigr) = {\rm cosramp}\left({2A\over\pi},x\right) }[/math]

     [math]\displaystyle{ \int_0^x {\rm cosramp}(A,u)du = \left\{\begin{array}{ll} {A\over 2}\left(x-{\sin(\pi x)\over \pi}\right) & x\lt 1 \\ A\left(x-{1\over 2}\right) & x \ge 1 \end{array}\right. = {A\over 2}\bigl(x + (x-1){\rm sign}(x-1)\bigr) - {\rm sinbox}\left({A\over2\pi},x\right) }[/math]

     [math]\displaystyle{ {d\bigl({\rm cosramp}(A,x)\bigr)\over dx} = {A\pi\over 2}\sin(\pi x) = {\rm sinbox}\left({A\pi\over 2},x\right) }[/math]

     [math]\displaystyle{ {d\bigl({\rm sinbox}(A,x)\bigr)\over dx} = \left\{\begin{array}{ll} 0 & x\le0 \\ {A\pi}\cos(\pi x) & 0\lt x\lt 1 \\ 0 & x \ge 1 \end{array}\right. = \pi A\thinspace {\rm sign}(x) - {\rm cosramp}(2\pi A,x) }[/math]

Cosine Ramp to Desired Velocity

In problems with constant velocity loading, it might be preferable to ramp velocity to the desired velocity V over some ramp time tr rather start the problem at time zero with velocity V. The ramped-up velocity can be done using the cosramp(A,x) function by setting A = V and x = t/tr or:

     [math]\displaystyle{ v(t) = {\rm cosramp}\left(V,{t\over t_r}\right) }[/math]

Integrating this velocity, the resulting displacement is:

     [math]\displaystyle{ d(t) = \left\{\begin{array}{ll} {V\over 2}\left(t-{t_r\over \pi}\sin\left({\pi t\over t_r}\right)\right) & t\lt t_r \\ V\left(t-{t_r\over 2}\right) & t \ge t_r \end{array}\right. }[/math]

In terms of defined functions, this displacement can be written

    [math]\displaystyle{ d(t) = {Vt_r\over2}\left[\frac{t}{t_r} + \left(\frac{t}{t_r}-1\right){\rm sign}\left(\frac{t}{t_r}-1\right) - {\rm sinbox}\left({1\over\pi},{t\over t_r}\right)\right] }[/math]

For example, to ramp to V and then hold constant velocity until reaching desired displacement dmax, the simulation time should be set to:

    [math]\displaystyle{ t_{max} = {d_{max}\over V} + {t_r\over 2} }[/math]

The first term is the simulation time using constant velocity while the second term is the extra time needed because the velocity was ramped to velocity V over time tr.

Cosine Ramp to Desired Displacement

Rather that apply displacement instantaneously, which would be an impact problem, it might be preferable to ramp to displacement d over ramp time tr. A displacement function would be

     [math]\displaystyle{ d(t) = {\rm cosramp}\left(d,{t\over t_r}\right) }[/math]

Differentiating this displacement to get velocity that must be applied as a boundary condition gives

     [math]\displaystyle{ v(t) = {\pi d\over 2t_r}\sin\left({\pi t\over t_r}\right) = {\rm sinbox}\left({\pi d\over 2t_r},{t\over t_r}\right) }[/math]

The maximum velocity used during this loading is

     [math]\displaystyle{ v_{max} = {\pi d\over 2t_r} }[/math]

Linear Ramp to Desired Displacement

To ramp to a displacement d over time tr with a constant velocity, the ramp velocity is

     [math]\displaystyle{ v(t) = {\rm box}\left({d\over t_r},{t\over t_r}\right) }[/math]

The displacement corresponding to this velocity is

     [math]\displaystyle{ d(t) = {\rm ramp}\left(d,{t\over t_r}\right) }[/math]

Loading and Unloading Cycles

To ramp at velocity vr from t0 and t0+tr then unload using the reverse velocity from t0+tr to t0+2tr, the velocity is:

     [math]\displaystyle{ v(t) = {\rm box}\left(v_r,{t-t_0\over t_r}\right)-{\rm box}\left(v_r,{t-t_0-t_r\over t_r}\right) = {\rm box}\left(v_r,{t-t_0\over 2t_r}\right){\rm sgn}(t_0+t_r-t) }[/math]

The displacement corresponding to this velocity is

     [math]\displaystyle{ d(t) = v_rt_r {\rm tri}\left({t-t_0\over t_r}-1\right) }[/math]

A sequence of loading and unloading steps can be created by defining periodic function as explained in the next section.

Periodic Boundary Condition Function

The mod(A,x) function is useful for defining any periodic boundary condition function of time. First create any function of time that is well defined over a given cycle time tc. To define a periodic function replace every "t" in that function with "mod(t,tc)". The result will be a periodic function that will repeat the same defined cycle as long as the simulations keeps running. For example, a sequence of triangular displacements from the previous section's example staring at the beginning (t0=0) could be defined with:

     [math]\displaystyle{ v(t) = {\rm box}\left(v_r,{{\rm mod}(t,2t_r)\over t_r}\right)-{\rm box}\left(v_r,{{\rm mod}(t,2t_r)-t_r\over t_r}\right) }[/math]

Rigid Rotation

See Rigid Material documentation for details on moving a plot of rigid particles in rigid rotation about a point.