As long as a model is causal, Vensim can determine the values of all variables. Vensim uses the causal structure to determine the appropriate sequence of computation. The order in which you define the variables makes no difference to the computational sequence. Vensim performs the following steps in simulating a model:
1 - Preparation
All the Constants are set to the values specified for them and any changes files or spreadsheet references for Constants are processed.. All Data (both exogenous variables and data needed for payoff computation) are read, the values loaded and data equations computed. This includes data that are read from spreadsheets. The value of the initial time is computed and all the Data variables are set to their values at this time.
At the end of preparation all Constants and Data will have values assigned.
2 - Initialization
For each level in the model Vensim determines the initial value for that level by looking at the variables used in the initial part of the equation for that level. If a variable used in the equation has not been computed, Vensim uses the equation for that variable to compute its value. This process is performed recursively until only constants or data appear on the right hand side, or a circle is detected. If a circle is detected, Vensim issues a simultaneous initial equation error message.
At the end of initialization all the Levels in the model will have values. In the process of computing these values, some Auxiliaries might also have values assigned.
3 - Storage of Results (Diff only)
If the Integration type Diff (for Difference Equation) is selected results will be stored at this point. Note that on the first pass this can mean that some Auxiliaries have not been computed and will be recorded with a missing value. The recorded results are the Levels (at a particular time) and the Auxiliaries that resulted in those Levels.
4 - Computation of Auxiliaries
For each Auxiliary in the model, the Auxiliary's value is computed by looking at its equation. If an input to the equation has not been computed, it's value is computed before proceeding. This process is again recursive and ends when the variables to be used are Constants, Data, or Levels. If a circle is detected, a simultaneous equation error is issued. For obvious computational reasons this ordering of computation occurs in advance of the actual simulation.
If an Auxiliary variable was computed in step 2 above it is possible that it will be computed to have a different value in this step. This will only occur if an ACTIVE INITIAL equation is used. If this does happen, and the difference is bigger than the threshold value specified in the Options dialog, this condition will be reported in an error window.
In Reality Check mode if a variable has an active test input the value for that variable is first computed using its normal equation and then overridden using the test input. This overriding occurs before the variable is used in any other equation.
At the end of this step all the model variables will have a value.
5 - Storage of Results (normal)
For all integration types except Diff the results of all the previous steps computations are stored at this point. The values that are stored are those of the Levels and of the Auxiliaries that result from those Levels.
6 - Computation of Net Rates
Based on the Auxiliaries, the net rate of change for each Level in the model is computed.
7 - Integration
For Euler Integration, the results of step 6 are multiplied by TIME STEP and added to the values of the Levels. For Runge-Kutta Integration, steps 4 and 6 are repeated a number of times (but no information is stored during this computation). The book Numerical Recipes in C cited in the bibliography contains more information on these integration techniques.
At the end of this step, Time has advanced by TIME STEP and the values of the Levels at the new time have been computed.
9 - Continuation
Steps 3,4,5,6 and 7 are repeated until time reaches FINAL TIME.