Here are some basics you should know about scripting state variables in ResSim:

  • The Scripts — State Variable have three scripts, each of which represents all or part of a compute function of the state variable object in ResSim. These scripts are referred to as:
    • Init: The Initialization script is called by the initialization function of the state variable, which is executed only once per run, early in the regulated compute. This script is where you should create the persistent local variables that you may need to hold data between executions of the Main script.
    • Main: The Main script is executed by the evaluate function of the state variable, which is executed at least once per timestep of the regulated compute. This script is where your code to determine the value of the state variable for the current timestep should be located.
    • CleanUp: The CleanUp script is executed by the function of the state variable that tidies up after the compute. This method is only executed once per compute, at the end of the regulated compute. This script is where you should perform the tasks that should be
  • Templates—each of the three scripts you can write for your state variables gets started with a template for you to write you script into.
    • Init: The Initialization script template includes an import statement and the function definition for the initStateVariable method, and some instructive comments describing the arguments that ResSim will send into the function ("Figure: The Initialization Script Template").

      Figure: The Initialization Script Template


    • Main: The Main script template is all comments describing the three variables (arguments) that ResSim will provide to the main script and the method call you need to include in your script in order to store the computed value for the state variable for each timestep ("Figure: The Main Script Template").

      Figure: The Main Script Template



    • CleanUp: The CleanUp script template also has an import statement and some comments describing the two variables (arguments) that ResSim will provide to your CleanUp script ("Figure: The Cleanup Script Template").

      Figure: The Cleanup Script Template


  • Arguments—each script receives some variables that are provided by ResSim so that it can access model elements and their objects for use in computing the value of the state variable. The three variables that may be provided are described below. All three scripts are provided the first two. The third is provided only to the Main script.
    • currentVariableis a reference to the current state variable object itself. currentVariable is conceptually equivalent to the this keyword in Java or the self keyword in Python.
    • network—is a reference to the object that holds the reservoir network. It can be used to access to all the elements of your network and their model variables such as pool elevations, inflow, diversions, etc.… It can also be used to access the current alternative and its properties.
    • currentRuntimestep—is a reference to the object that holds the timestep being evaluated. The actual date & time of the timestep, as well as the sequence number of the timestep and the run time window are accessed through this object. This object is used, among other things, to determine where (or is that when) to store the computed value of the state variable.

The StateVariable.setValue method—the Main script template of your state variable instructs you to include the following line in your script to store the compute value of your state variable for the current timestep:

currentVariable.setValue(currentRuntimestep, newValue)

Where newValue is the value, or local variable that holds the value, to be stored.