The elements inside the Container are updated as follows during the loops:
1. On the first loop, the elements are moved forward in time to the next scheduled timestep;
2. 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 that changes with each loop.
As an example, if a looping Container contained the simple system below, consisting of one Data element 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. 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 (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 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).
Learn more about:
Understanding State Variables in GoldSim