Understanding How Elements
Inside a Looping Container are Updated
The elements inside the Container An element that acts like a "box" or a "folder" into which other elements can be placed. It can be used to create hierarchical models. are updated as follows during the loops:
- On the first loop, the elements are moved forward in time to the next scheduled timestep A discrete interval of time used in dynamic simulations.;
- On subsequent loops, the elements are updated again without advancing time.
Hence, in order for the loops after the first to have any impact on the model, they must contain at least one state variable The output of an element in GoldSim whose value is computed based on the historical value of the element’s inputs (as opposed to only being a function of the current value of the element’s inputs). State variables have well-defined initial conditions. Feedback loops can only be created if they contain at least one state variable. that changes with each loop.
As an example, if a looping Container contained the simple system below, consisting of one Data element An input element intended to represent constant inputs in a model. and one Expression (neither of which output a state variable), after the first loop, the system would not change at all:
Hence, it would serve no purpose to place a calculation such as this within a looping Container.
The most common application of a looping Container is to use it to carry out an iteration utilizing a Previous Value element An element that outputs the value of its input from the previous model update.. That is, some variable (e.g., X) would be computed each loop based on its value during the previous loop:
The looping system shown here would be updated every loop (changing X , and hence the previous value of X). Typically, you would specify that the looping continue until the difference between X and the previous value of X was within some specified tolerance.
When a Previous Value element is included inside a looping Container, it takes on a special property. In particular, an additional input option is added to the dialog that specifies how the Initial Value is to be treated:
If Reinitialize when looping starts is cleared (the default), the Initial Value specified in the field is only used at the beginning of the realization A single model run within a Monte Carlo simulation. It represents one possible path the system could follow through time. (when the Container is updated for the first time), and never again.
If Reinitialize when looping starts is checked, the value specified in the Initial Value field is used for the first loop every time the looping Container begins its calculations (i.e., it does not "remember" the value from the previous timestep).
Another common application of a looping Container is to use it to carry out multiple discrete transactions in a single timestep. In the simple example below, items are moved from one Reservoir A stock element that integrates and conserves flows of materials. to another (via discrete changes) until the first Reservoir is empty:
Examples of both of these types of applications (LoopingContainer.gsm) can be found in the Containers subfolder of the General Examples folder in your GoldSim directory (accessed by selecting File | Open Example... from the main menu).