Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A function can reference other variables, and also other functions within the same scenario, including itself. When a function references itself, the initial value is used for the first evaluation of the function.

For example: $Function1 = $Function1 + $Function2
In this case, $Function1 will use its previous evaluation value to calculate its new one.

Notice that the list shown in Figure 6 contains $Function1 as an option. 

Info
iconfalse
Note: Circular references are prohibited between multiple functions. That is, $Function1 = $Function2 + 4, and $Function2 = $Function1 + 6 is not allowed, and Source will give an error if you run a model with this setup.

Anchor
TestingFunctions
TestingFunctions
Testing Functions

Once you have defined a function, you can test its operation using the Parser (Figure 8). You can enter values for the variables and functions called by your function and confirm that the result of evaluating your function with those values is what you expect. The Parser is used as follows:

  • Select the function you wish to test within the Function Editor,

  • The Parser interface is collapsed by default, click on the arrow next to Parser (indicated in Figure 6) to display it. 

  • The expanded Parser interface (shown in Figure 8) provides a table of all the variables and functions used in the selected function. If the variables/functions used in the function are not listed, click Update and Parse.

  • Enter values you wish to test (double-click on the cell, then enter a number);

  • Click Update and Parse again and

  • The test result will be displayed in the cell under the Update and Parse button.

To close the Parser interface, click on the same arrow.

If the function cannot be parsed, you will get an error icon next to the function in the Function Manager. Additionally, an error in the Log Reporter will be available at run time to indicate the same.


Figure 11. Function Editor (Parse)

Recording Functions

When functions are assigned to a model component, the function values may be used for further calculations and are not necessarily recorded explicitly. If you wish to view the function outputs over the model run, you can enable recording of a function using the Project Explorer (choose Miscellaneous » Functions). To record functions which are not used by a model element Force Evaluation will need to be turned on.

In the Function Editor you can log the result of a function in the Log Reporter for any day during the model run, by right clicking the function and using the Add Log Date contextual menu item

Anchor
FunctionLogging
FunctionLogging
Function Logging

In addition to recording functions, function values may also be used for two types of logging to the Log Reporter during the run:

  • Log Date – The result of a function can be logged in the Log Reporter for a given day, by using the Add Log Date contextual menu item for the function (Figure 8). This will output a log entry for each date specified, and will include the result of the function, as well as all the functions and variables it uses at each time of evaluation; and
  • Custom Log – Based on the result of a function different log messages can be logged in the Log Reporter during the run. The custom message and notification level may be set for integral result values by using the Add Custom Logs contextual menu item for the function (Figure 8). When the function's result is one of the defined integral values a message at the specified notification level will be logged in the Log Reporter. If the level is Fatal, it will stop the run. All other function results which are not defined are ignored. Functions used for custom logs are typically written using If statements. Force Evaluation will need to be enabled if the function is not used by a model element.
Figure 12. Custom Logs