Equation Reference

Tecplot RS allows you to use equations to create new variables in both XY and Grid data. The equation syntax is identical for both and is documented here. The dialog you use to enter and edit equations contains buttons to help enter equations, or you can simply type the equation if you are familiar with the syntax. For more information on the two types of equations, see:

Equation Syntax

Equations take the form of an assignment of a value to a variable. The variable in which the value will be stored is stated first, followed by an = sign, followed by an expression. The expression to the right of the = sign may be a mix of operations (addition, subtraction, etc.) and calls to built-in functions. For example:

     {GOR} = {GPR} / {OPR}

This equation defines a new variable named GOR as the ratio between the gas production rate and the oil production rate.

You can also include constants in your calculations:

     {WCT} = 100.0 {WPR} / ({WPR} + {OPR})

Note the use of parentheses in this example to force the {WPR} + {OPR} portion of the equation to be evaluated before the division.

If the variable specified to hold the result already exists in the loaded data set, Tecplot RS uses the equation to modify that variable. If the variable does not already exist, Tecplot RS uses the equation to create a new variable as a function of existing variable(s) or value(s).

As shown, variable names must be enclosed in braces: {…​}. They are not case-sensitive. You can include any number of spaces within the equation, but do not include any spaces between the letters of built-in function names or inside variable names.

Applying an equation exclusively to specific grids

A grid equation may be applied exclusively to one or more grids by enclosing the grid name(s) in angle brackets preceding the equation followed by a colon. Multiple grid names are separated by commas.

Apply the grid equation "{VARNAME}={SOIL}*2" exclusively to the grid "LGR1":

     <LGR1>:{VARNAME} = {SOIL}*2

Apply the grid equation "{VARNAME}={SOIL}*2" exclusively to the grids "LGR1" and "LGR2":

     <LGR1,LGR2>:{VARNAME} = {SOIL}*2

Specifying a timestep for a time variable

For grid equations, a timestep may be specified for a time variable on the right side of the equals sign. Timesteps are enclosed in square brackets immediately after the variable name, and numbered starting at 1. For example:

Set {VARNAME} equal to the value of {SOIL} at time step 3 multiplied by 2:

     {VARNAME} = {SOIL[3] * 2}

Set {VARNAME} equal to the valid of {SOIL} at time step 1 plus the value of {SGAS} at time step 5:

     {VARNAME} = {SOIL[1]} + {SGAS[5]}

If an equation with a timestep fails, you can hover the mouse over the equation for more information on the cause of the failure.

Time step variables are constant and cannot be assigned data values. They may only be used on the right hand side of the equals sign:

     {SOIL[2]} = 5      [This will generate an error]

Timesteps within square brackets must be integers between 1 and the number of timesteps in the dataset. Integer expressions are not supported:

     {VARNAME1}={SOIL[10 - 6 + 2]}      [This will generate an error]

On the 2D and 3D sidebars, you can hover the mouse over the timestep date to display the current timestep.

Operations

In an equation, the following symbols represent mathematical operations between two numbers, which may be specified as literal numbers, variables, or sub-expressions.

+

Addition

-

Subtraction

*

Multiplication

/

Division. Division by 0 results in 0 if the value being divided is zero, or -999999 otherwise (this behavior can be disabled for XY Equations).

**

Exponentiation

The - symbol may also be used with a single number to negate it. For example, - {DEPTH} negates the value DEPTH.

Binary operators have the following precedence:

**

Highest precedence

*,/

+,-

Lowest precedence

Tecplot RS evaluates operators from left to right within a precedence level. Parentheses may be used to force a desired order of evaluation, with the expressions in the innermost set of parentheses evaluated first.

Mathematical Functions

Tecplot RS supports the following mathematical functions (except where noted, all require a single argument). Trigonometric functions require values in units of radians.

SIN

Sine (angle must be specified in radians)

COS

Cosine (angle must be specified in radians)

TAN

Tangent (angle must be specified in radians)

ABS

Absolute value

ASIN

Arcsine (result is given in radians)

ACOS

Arccosine (result is given in radians)

ATAN

Arctangent (result is given in radians)

ATAN2(A,B)

Arctangent of A/B (result is given in radians)

SQRT

Returns the positive square root

LOG

Natural logarithm (base e)

LOG10

Logarithm base 10

EXP

Exponentiation (base e); EXP(V1)=e**(V1)

MIN(A, B)

Minimum of A or B

MAX(A, B)

Maximum of A or B

SIGN

Returns -1 if argument is negative, +1 otherwise

ROUND

Round off to the nearest integer

TRUNC

Remove fraction part of a value

To call an intrinsic function, place its argument within parentheses. For example, to set V4 to the arctangent of V1, use:

     {V4} = ATAN({V1})

Conditional Expressions

Conditional expressions may be written using the IF function.

IF(P, T, F)

If the predicate expression P is true (has a non-zero value), returns the value of expression T, otherwise returns the value of expression F. Both T and F are fully evaluated regardless of the value of P; there is no "short-circuiting."

The predicate expression may include comparison and Boolean operators, as summarized in the following table.

Operator

Description

Example

==

Equal To

{A} = IF({B}==2.0, 3, 4) assigns to variable A: 3 if B equals 2.0, otherwise 4

!=

Not Equal To

{A} = IF({B} != {C}, {D}, 2) assigns to variable A: D if B does not equal C, otherwise 2

>

Greater Than

{A} = IF({B} > 1.0, 4, 5) assigns to variable A: 4 if B > 1.0, otherwise 5

>=

Greater Than or Equal To

{A} = IF({B} >= {C}, 4, {D}) assigns to variable A: 4 if B >= C, otherwise D

<

Less Than

{A} = IF({B} < {C}, 4, {D}) assigns to variable A: 4 if B < C otherwise D

<=

Less Than or Equal To

{A} = IF({B} <= {C}, 4, {D}) assigns to variable A: 4 if B <= C, otherwise D

&&

Logical AND

{A} = IF({B} < {C} && {B} > 3, 8, 9) assigns to variable A: 8 if B < C AND B > 3, otherwise 9

||

Logical OR

{A} = IF({B} == 2 || {B} > 3, 5, 6) assigns to variable A: 5 if B == 2 OR B > 3, otherwise 6

Comparison operators are valid only within the first argument of an IF function. They may not be used elsewhere in an expression. For example, {A} = {B} > 1 is invalid. Instead, use {A} = IF({B} > 1, 1, 0) or similar.

Python-style operator chaining (such as {A} < {B} < {C}) is not supported. Although this construction is syntactically valid, it will not produce the expected result. Use {A} < {B} && {B} < {C} instead.

&& has a higher precedence than (will be evaluated before) ||. When in doubt, use parentheses.

Derivative and Difference Functions

You can use a derivative function in the same manner as other intrinsic functions. Tecplot RS can calculate derivative and difference functions with respect to the following variables:

Table 1. Derivative and Difference Function Variables

Variable

Definition

x, y, z

variable assigned to the x-axis, y-axis or z-axis, respectively. If you have multiple x-axes or y-axes in an XY line plot, the variables assigned to the x and y-axis in the first available mapping will be used.

i, j, k

index range (XY data only)

To notate a first or second-order derivative or difference functions, use the following applicable function call:

Table 2. Derivative Functions

Type

Function Call

First Order

ddx, ddy, ddz

Second Order

dx2, dy2, dz2

Second-Order (cross derivatives)

dxy, dyz, dxz

Tecplot RS uses the derivative function ddx to calculate dx2 calculates , and dxy calculates .

Table 3. Difference Functions

Type

Function Call

First Order

ddi, ddj

Second Order

di2, dj2

Second Order (cross derivatives)

dij

The difference functions ddi, di2, and so forth, calculate centered differences of their argument with respect to the indexes I and J based on the indexes of the point. For example:

Boundary Values

Boundary values for first-derivative and difference functions (ddx, ddy, ddz, ddi, ddj, and ddk) of ordered zones are evaluated by one of two methods: simple (default) or complex.

  • For simple boundary conditions, the boundary derivative is determined by the one-sided first derivative at the boundary. This is the same as assuming that the first derivative is constant across the boundary (i.e., the second derivative is equal to zero).

  • For complex boundary conditions, the boundary derivative is extrapolated linearly from the derivatives at neighboring interior points. This is the same as assuming that the second derivative is constant across the boundary (i.e. the first derivative varies linearly across the boundary).

The $!INTERFACE parameter in the configuration file tecplot.cfg selects the method to use:

$!INTERFACE DATA {DERIVATIVEBOUNDARY=SIMPLE}

Change the parameter SIMPLE to COMPLEX to use the complex boundary condition.

Index Specification

For XY data only, you can specify indexes by following a variable reference with parentheses. Indexes can be absolute or an offset from the current index.

Index offsets are specified by using the appropriate index "i", "j" or "k" followed by a "+" or "-" and then an integer constant. Any integer offsets may be used. If the offset moves beyond the end of the zone, the boundary value is used. For example, {V3}(i+2) uses the value {V3}(IMAX) when I=IMax-1 and I=IMax. {V3}(I-2) uses the value of {V3}(1) when I=1 or I=2.

Absolute indexes are specified by using a positive integer constant only. For example, {V3}(2) references {V3} at index 2, regardless of the current i index.

If the indexes are not specified, the current index values are used.

Index Restriction

You can override a specified index restriction on an equation by equation basis. To specify restrictions for a single equation add the colon character (:) at the end of the equation followed by one or more of the following:

Equation Restrictor

Comments

<I=start[,end[,skip]]>

Restrict the I-range.

<J=start[,end[,skip]]>

Restrict the J-range.

<K=start[,end[,skip]]>

Restrict the K-range.

<D=datatype>

Set the data type for the variable on the left hand side. This only applies if a new variable is being created.

The following example adds one to a variable V for every other I-index. Note that zero represents the maximum index.

     {V}={V}+1:<I=1,0,2>

The next example creates a new variable of type Byte:

     {NewV}=X-Y:<D=Byte>

Macros and Equations

Tecplot RS allows you to put your equations in macros. In fact, we sometimes refer to a macro with just equations as an equation file. An equation in a macro file is specified using the $!ALTERDATA macro command. Equation files may also include comment lines and must start with the comment #!MC 1120, like other macro files. If you are performing complex operations on your data, and/or the operations are repeated frequently, equation files can be very helpful.

You can create equation files from scratch using an ASCII text editor, or you can create your equations interactively by using the Grid Equations dialog or the XY Equations dialog and then saving the resulting equations. Use .eqn as the standard file name extension for equation files.

For example, you might define an equation to compute the magnitude of a 3D vector. In the Grid Equations dialog, it would have the following form:

     {Mag} = sqrt(U*U + V*V + W*W)

In a macro file, it would have the following form:

#!MC 1120
$!ALTERDATA
 EQUATION = "{Mag} = sqrt(U*U + V*V + W*W)"

The interactive form of the equation must be enclosed in double quotes and supplied as a value to the EQUATION parameter of the $!ALTERDATA macro command.

To read an equation file, click Load in the XY Equations or Grid Equations dialog. In the Data Equations dialog, navigate to and choose an equation file that contains a set of equations that you wish to apply to your data. Tecplot RS will add the equations in the equation file to the list of equations in the dialog.

In the XY Equations dialog, Tecplot RS applies all equations to your data when you click the Apply button. In the Grid Equations dialog, Tecplot RS applies all equations when you click OK.

Tecplot RS can calculate equations in equation files somewhat differently depending on whether it receives the equation within an Equations dialog or by running the equation file as a macro. When loaded into an Equations dialog, equations that do not contain index restrictions use the current index restrictions shown in the dialog. When processed as a macro file, the equations apply to all data points. To include index restrictions, you must include them in the equation file as part of the $!ALTERDATA command. Refer to the Tecplot 360 Scripting Guide (available on the Tecplot Web site) for more information on working with the $!ALTERDATA command.

Equation Examples

This section includes various equation examples. You can use or refer to them to gain experience writing equations.

The following equation sets the value of a variable called Density to 205. A new variable is created if a variable called Density does not exist.

     {Density} = 205

In the next equation, the values for Y (the variable assigned to the Y-axis) are replaced by the negative of the square of the values of X (the variable assigned to the X-axis):

     {Y} = -{X}**2

The following equation replaces the values of V3 with the values of V2 rounded off to the nearest integer. A new variable is created if there are only two variables currently in the data set.

     {V3} = round({V2})

In the following equation, the values of the fourth variable in the data set are replaced by the log (base 10) of the values of the third variable.

     {V4} = LOG10({V3})

Suppose that the third and fourth variables are the X and Y-components of velocity and that there are currently a total of five variables. The following examples create a new variable (V6) that is the magnitude of the components of velocity.

     {V6} = ({V3}*{V3}+{V4}*{V4})**0.5

or

     {V6} = sqrt({V3}**2+{V4}**2)

You can also accomplish the above operation with the following equation (assuming you have already defined the vector components for the active frame):

     {Mag} = sqrt({U}*{U} + {V}*{V})

The following equation sets the value of a variable named diff to the truncated value of a variable named depth subtracted from the existing value of depth:

     {diff} = {depth} - trunc({depth})

In the next equation, C (the contour variable) is set to the absolute value of S (the scatter-sizing variable), assuming both C and S are defined:

     C = abs(S)

In the following example, a new variable is created (assuming that only seven variables initially existed in the data file). The value for V8 (the new variable) is calculated from a function of the existing variables:

     {V8} = SQRT(({V1}*{V1}+{V2}*{V2}+{V3}*{V3})/(287.0*{V4}*{V6}))

The following equation replaces any value of a variable called TIME that is below 5.0 with 5.0. In other words, the values of TIME are replaced with the maximum of the current value of TIME and 5.0:

     {TIME} = max({TIME},5)

The following equation creates variable V4 which has values of X at points where X<0; at other points, it has a value of zero (this does not affect any values of X):

     {V4} = min({X},0)

Another example using intrinsic functions is shown below:

     {V8} = 55.0*SIN({V3}*3.14/180.0) + LOG({V4}**3/({V1}+1.0))

You can also reference the I and J indices in an XY equation. For example, if you wanted to cut out a section of your plot using value blanking, you could create a new variable that is a function of the I and J indices. Then, by using value-blanking, you could remove certain cells where the value of the value-blanking variable was less than or equal to the value blanking cut-off value.

Here is an example for calculating a value-blanking variable that is zero in a block of cells from I=10 to 30, and is equal to one in the other cells:

     {V3} = min((max({I},30)-min({I},10)-20),1)

The following equation replaces the values of V3 with the average of the values of V3 at the four adjacent data points:

     {V3} = ({V3}({I}+1,{J})+{V3}({I}-1,{J})+{V3}({I},{J}+1)+{V3}({I},{J}-1))/4

The following equation sets the values of a variable called TEMP to the product of the values of a variable called T measured in four places: in zone 1 at two index values before the current data point, in the current zone at an absolute index of 3, in zone 4 at the current data point, and in the current zone at the current data point.

     {TEMP} = {T}[1](i-2) * {T}(3) * {T}[4] * {T}