Array calculations

Reves DSE is able to perform index wise array calculations with array parameters and scalar-array parameter combinations.

Create array parameters

To enable the array functionality in Reves DSE you first have to create array parameters.  This currently can be done only with existing parameters. In the parameter overview you can select which parameters are array parameters by:

  1. Checking the “Array” column.
  2. Setting the array length in the “Array length” column.
Reves DSE will recognize new array parameters in the expression code of flow expression to accommodate the use of new array parameters in multiple line expression. After finishing the expression, you are still required to correct the parameter setting for these new array parameters since this cannot be done automatically.

Syntax

After the parameter is defined as an array parameter you can type the parameter symbol to use the array parameter itself or use the notation ‘PAR[index]’ to use one of the index parameters of the array parameter. This index should be evaluated as an integer and currently supports the following notations:

  • Integer parameters
  • Integer values
  • Simple equations with + or – that contain only integer parameters or values
  • Functions that return an integer value:
    • int(),
      • explicitly converts the content between this brackets to an integer. The content between the brackets is rounded to a integer using the floor() function.
    • floor()
    • ceiling()

The value of the index cannot be evaluated when the model is created and thus it is important to make sure that the index stays in range of the array length. For the index a zero-based numbering is used, this means that the first index item of the array is at position zero, ‘PAR[0]’ and thus the last item is at located at position ‘length-1‘. Any index out of range errors during calculations with array parameters are handled by the application but will hinder the solution generation.

Procedure syntax

In the procedures and flow expressions you can use the array syntax similar to the regular expressions. Any global array parameter used inside the code can be used for array calculations. To defined local array parameters you can use the following syntax:

  1. Declare the type of the parameter (int/double), add  square brackets ‘[]’ directly to the type definition and set a parameter symbol : ‘int[] PAR‘ or ‘double[] PAR‘.
  2. Initialize the array parameter with a length and value:
    • Assign another array parameter to the new parameters
    • Assign an array of values using the [val;val;etc] notation. This value array can be of any length as long as all values are separated by a semicolon.
    • Assign an array of a single value with the array(length;val) notation. The first argument is the array length and the second value is the initial value for all index positions.

In the procedures and flow expressions it is also possible to use array parameters in a for loop and access the index values using the for loop iterator. The for loop iterator is considered to be an integer parameter and thus can be used in the index notation with array parameters. When using the for loop iterator as array parameter indexer it is important to match the from and to value to the array length to prevent any index out of range errors. The from and to values have to be integers and can also be simple equations which can be immediately evaluated as an integer. To loop over the values of an array in a for loop you can use the length() function to get the length of an array parameter since the length have to declared when the array parameter is made. To iterate until the last array parameter you can define your to value as: length(PAR)-1.

for i from 0 to length(PAR)-1
   ...
   a = PAR[i]
   ...
end

Plotting arrays

You can create a line plot of an array parameter or an expression containing array parameters by using the array index  notation: “arrayPar[index]“. In this the index item is either the variable “t” or “x” depending on the line plot type. Since the index is required to be an integer, you have to enable the Use integer steps option in the General options section.  With this the range definition of the “t” or “x” will be integer steps of step size 1 between the from and to values.

If you use the y(t),  x(t) expression configuration with the integer step option you can change the displayed step size on the x axis from 1 to the desired display steps with the expression t_val*display_step_size.  This way you can change the x-axis display if the plotted array parameters contains data points from specific time points.

Library functions

Library functions also support the use of array parameters in the function code. The function code syntax follows the same rules as the procedure syntax. To define a function argument to be an array parameter you can use the “arg[length]” syntax instead of the regular “arg” syntax. The “length” number between the brackets defines the array argument length:

Python functions

In DSE, you have the option to pass a DSE array parameter to your Python function and/or assign the results of your Python function back to a DSE array parameter. DSE performs the conversion between the array information written in C# and its equivalent data type in Python, and vice versa for the output.

However, during this translation, there are instances where the data type of the output is not correctly interpreted. In such cases, DSE interprets the output as multiple individual values instead of an array. To prevent unexpected model results it is recommended to test the Python function in the Test tab. For array parameters, the expected results should be displayed in a single row with a ‘;’ separating the values. If each value appears in its own row, this indicates that DSE could not detect the array type.

In most cases, this issue can be resolved in the python script by putting the array notation ‘[]’ brackets around the parameter, as illustrated in the example below:

return [par]