Global RPL Functions
Global functions allow you to define a function in one location and then use it in any of the RPL applications including Rulesets, Optimization Goal Sets, Object Level Accounting Method Set, Initialization Rules, MRM Rules, and RPL Expressions Slots.
Global RPL Functions exist within Global Functions Sets, organized in Global Utility Groups. Multiple Global Function Sets can be opened within a RiverWare session.
A RPL set is considered global when it is opened as a Global Set and any RPL Set file can be loaded as a Global Function RPL Set. Only the RPL Set’s Utility Groups—and not its Policy Groups—are relevant in Global Function Sets.
Global RPL Functions can be called from RPL Functions and Rules (and other forms of RPL Blocks) in any open RPL Set. Global Functions can call other Global Functions, either in the same Global Function Set, or a different Global Function Set.
Creating a New Global RPL Function Set
A new Global RPL Function Set can be created from the RiverWare Workspace menu, with the following menu selection:
Policy, then Global Function Set, then New
This opens up a Global Function Set editor. This is a RPL Set Editor for Global Function Sets, distinguished with a green globe icon in the upper-left area of the editor dialog.
As with all RPL Sets, a Global Utility Group must first be added before new user-defined RPL Functions can be defined. In a Global RPL Function Set, this is done from the RPL Set Editor’s menu item, as follows:
Set, then Add Global Utility Group
Any function added to the new Global Utility Group is, by definition, a Global Function. A Global Function can be created in any of the following ways (not illustrated):
• From the RPL Set editor, with the desired Global Utility Group selected, using the Set, then Add Global Function (Ctrl+F) menu item.
• From the RPL Set editor, using the Context menu (right-click) on the desired Global Utility Group item, Add, then Global Function.
• From the Global Utility Group Editor, using the Group, then Add Global Function (Ctrl+F) menu item.
• From the Global Utility Group Editor, using the Context Menu (right-click) anywhere within the function list, Add, then Global Function.
• By Copying a Function from another RPL Group or RPL Set, and Appending into the Global Utility Group, using Context Menu operations.
• By Dragging a Function from another RPL Group or RPL Set into the Global Utility Group.
Note: The Drag-and-drop functionality currently implemented in the RPL Set and RPL Group editors has some limitations, including the availability of that operation only if the target function list already has at least one function.
• By importing Utility Groups from a RPL Set file. This is done from the RPL Set editor, File, then Import Set menu item.
Only one instance of a function can occur within all loaded RPL sets and Global Function Sets. For example, you cannot have a function named GetMinimumFlow in a utility group in your ruleset and another named GetMinimumFlow in an open Global Function Set. An error will occur in this case.
Opening an Existing Global Function Set
The RiverWare Workspace Policy menu supports the opening of a RPL Set as a Global Function Set in ways similar to opening other RPL Set files.
Figure 2.26
Any RPL Set file can be loaded as a Global Function Set, however only the Utility Groups within the RPL Sets loaded as Global Function RPL Sets are usable; rules (or other forms of RPL Blocks) within the set’s Policy Groups are not. If a RPL Set file containing Policy Groups is opened as a Global Function Set, the warning dialog shown in
Figure 2.27 appears, and a similar warning message is written to the RiverWare diagnostics output.
Figure 2.27
Note: It is important to open any Global Function Sets before trying to load a ruleset that uses functions in a global set.
Using Global RPL Functions
When editing a RPL Expression, any Global Function in any open Global RPL Set can be called. The standard way of adding a call to any user defined function is with the RPL Palette User-Defined Functions tab.
Within the User-Defined Function list, global functions are indicated with one of two globe icons:
• White globe. Indicates an external Global Function i.e. a global function in a RPL Set other than the set containing the RPL expression being edited.
• Green globe. Indicates a local Global Function i.e. a global function within the same RPL Set as the one containing the RPL expression being edited.
During evaluation of a Global RPL Function, the specific behavior is consistent with the caller’s RPL Application. For example, “@t” (the current timestep) represents the Rulebased Simulation Controller’s current timestep when the function is called from an Rule. But when called from a Series Slot with RPL Expression, “@t” (current timestep) represents a particular series timestep date/time.