The core elements of a Silico simulation are the Variables, Stocks and Flows.
Variables allow you to define a formula or hold some data, and then refer to it from elsewhere. If you only have a formula, you can think of a Variable like a column in a spreadsheet. When you add Actuals to the variable, then it's more like a group of columns, all under the same name.
The value of a variable at any point in time is what its Formula evaluates to. If the formula is blank, then the current value of the actuals will be used instead, and if there's no actuals, then the value will be 0.
Conceptually a variable is anything in a simulation which is derived from the tangibles (Stocks) that hold the state of the system being described, intermediate calculations, as well as external factors or controls that can be set in an arbitrary way (as opposed to accumulating or depleting over time).
While variables are very similar to a column in a spreadsheet with a dynamic formula, stocks are more special. A stock in itself only has a single simulated value you can set directly, which is its initial value. Past that point, the Stocks value can only be changed by connected flows (described below). You can still have Actuals associated with a stock, but they will only be used to set the initial value (if there is actual data at the start time of the project).
Conceptually a Stock represents tangible assets in a system, such as a bank balance or customers, which accumulate or deplete through time.
Act as Variable
Sometimes it's useful to have the visual style of a Stock, but without the special associated behaviour. In this case you can enable 'act as variable' mode on the Stock. This will make a Stock act identically to a similarly configured Variable. Any flows connected to the Stock will not have any impact on its value.
Flows in themselves are identical to Variables, as they have a dynamic formula which is updated through time, as well as associated actuals. A Flow is special in having two connected links, which control the Stocks that the flow is moving material from and to. A flow into a stock will accumulate the Flows value at each tick in the simulation, and a flow from a stock will deplete it.
Conceptually flows are the drivers of change in a simulation, such as money being deposited or withdrawn, or customers won and lost.
Connecting Stocks with Flows
Stocks and flows by themselves don't add any behaviour above a simple calculation based on the current values as you might do in a spreadsheet. What bringing stocks and flows together enables is the calculation of values through time, with the Flow representing the current 'flow' or rate of change at any point in time, and the Stock acting as the accumulation of those changes.
- As a concrete (and quite literal) example, the flow of water through a tap is a Flow, which accumulates into a bathtub Stock (assuming the plug is in!)
- In mathematical terms, you could view this as a Flow being some x and the Stock as the integral over that x.
Order of Calculations
As flows 'move' values in/out of stocks, the order of their calculations is very important for correctness. The semantics are as follows:
- The simulation moves forward in 'ticks', which are the smallest unit of time processed by the simulation.
- Within a tick, Flows are all calculated without the value of the flows affecting any stocks. Stocks are then updated 'between' ticks. Precisely, a Flow cannot affect the stocks it is connected to until the *next* tick.
- If you need multiple flows affecting the same stock, but taking into account other flows (e.g. to ensure that multiple flows don't drain a stock below 0, or another invariant), then their formulae should explicitly refer to the other Flows. This allows the maximum flexibility for choosing their behaviour.
- As a concrete example, if you have two Flows, A and B, and B should take any Stock left that A does not take, and not lowering Stock below 0, then B should have a formula of
max(0, "Stock" - "A").
Immediate Flows (advanced)
While the above semantics match closely the usual update of values through time, sometimes you need flows to act within a single tick. The immediate mode of flows enables this option, but comes with the caveat of more complicated semantics.
- Immediate flows update their connected stocks at the point they are calculated, instead of between ticks. For means a Stock initialised at value 100, and an immediate flow draining by 10, would show a value of 90 even in the very tick entry of data for the model.
- As they are calculated within a tick, the ordering between flows becomes very important. Immediate inflows are calculated before immediate outflows, and the order of inflows and outflows is not defined, but stable for a particular project.
- When considering whether calculations are circular, referring to the value of a stock can be thought of as dependent upon the immediate flows as well (as they must be calculated to know the stocks value within a tick). Immediate flows are allowed to refer to the value of the stock without circularity, and outflows can also refer to the value of inflows.
- The above means that a main of stocks connected with immediate flows are all connected when thinking about circular calculations. This means immediate flows make circular calculations much easier to run into, and more care must be taken to avoid them.