System Dynamics element. Stock as well as flow is a fundamental element of stock and flow diagram.
In System Dynamics stocks (also known as levels, accumulations, or state variables) are used to represent the real-world processes (e.g. stocks of material, knowledge, people, money). Stocks define static part of the system. Flows define how values of stocks change in time and thus define the dynamics of the system.You can find more information on stocks and flows in wikipedia: http://en.wikipedia.org/wiki/Stock_and_flow.
Here are some examples of stocks and flows:
|housing stock||housing investment||housing depreciation|
|CO2 in atmosphere||tons emitted||tons sequestered|
|fuel tank||refueling||fuel consumption|
In AnyLogic, equations for stocks are constructed automatically from the graphical structure, and optionally can be typed manually. The default mode for stock equation is classic (automatic). In this mode, each incoming flow is added to the stock derivative expression, and each outgoing flow is subtracted. Therefore, the resulting equation is a linear combination of flows always conforming with the graphical structure.
If you switch the radio button Equation mode in the stock properties to Custom mode, you will be able to manually type a freeform expression. The expression can then contain arbitrary arithmetic operations and function calls. This mode is used more frequently in dynamic (physical) systems models than in system dynamics.
The expression for stock derivative typed in custom mode is still checked for conformance with the graphics – namely, for each instance of a variable in the expression there should be an incoming link or flow from that variable to the stock, and vice versa.
Equations for flows and other variables are freeform. They are typed manually and checked for conformance with the graphical structure in the same manner. If discrepancy is detected, a problem item appears in the Problems view and a small red sign is displayed next to the equation. To view the error description, move the mouse cursor over the sign.
To add a stock
Name – The name of the stock. The name is used to identify and access the stock in formulas.
Show name – If selected, the name of the stock is displayed on the presentation.
Ignore – If selected, the stock is excluded from the model.
Visible on upper agent – If selected, the variable is also visible on the upper agent where this agent lives.
Show at runtime – If selected, the stock is visible on the presentation at runtime.
Color – The fill color of the stock icon.
Array – If selected, the stock may have several dimensions - it is an array. Properties for array variables look slightly different. Instead of one field defining the formula for the stock, there can be several fields defining formulas for some particular elements or sub-arrays. To add new section allowing to define one more formula, click the Add formula button. Defining formulas for array elements and sub-arrays is described here.
– The initial value of the stock.
In the case the stock is a scalar, just type here the value. If none is specified, the stock is initiliazed with 0.
In the case the stock is an array, initialize it as described here. If initial value is not specified, all elements of the array are initialized with zeros.
Equation mode – Here you can choose the equation definition mode, either Classic or Custom. In Classic modethe stock formula is non-editable, it is automatically generated according to the stock and flow diagram created by the user. In Custom modethe formula of the stock is editable, the user can use any variables nad functions there without any limitations. Equation modes are described in details here.
[Enabled if the
Custom] The right hand of the differential equation defining how the stock value will change.
In the case this flow is of array type,there can be several fields defining formulas for some particular elements or sub-arrays of the array. To add new section allowing to define one more formula, click the Add formula button. Defining formulas for array elements and sub-arrays is described here.
Array properties are available only if this stock is of array type. To make the variable an array, select the Array check box on the General property page.
Available dimensions – The list of dimensions defined in this model.
Selected dimensions – The list of dimensions that will act as dimensions of this array variable.
These properties are used to define dimensions of the array variable.
Please refer to the Defining an array variable section for details.
Commonly there are flows going in or/and out of the stock. You can find the full information on creating stock-flow dependencies here. The complete process of creating a simple system dynamics model is described in the System dynamics tutorial.
AnyLogic supports two alternative modes of defining stock formula: Classic and Custom.
AnyLogic automatically generates a formula for a stock according to the stock-and-flow diagram created by the user.
Stock value is calculated according to flows inflowing and outflowing the stock. The value of inflows i.e. flows that increase stock value, are added and the value of outflows, i.e. flows that decrease the stock are subtracted from the current value of the stock:
inflow1 inflow2 … - outflow1 - outflow2 …
In the classic system dynamics notation only flows can appear in the formula. The formula is non-editable and no other elements except for flows flowing in and out the stock can appear in the formula.
Sometimes you may need to overcome the limitations of the classic system dynamics notation and use some other elements in stock formula or e.g. add some ratio factors for the existing flows. You may need this e.g. if you model a dynamic system with a differential equation system. For this case Anylogic supports Custom equation style that enables the user to modify the stock formula and does not imply any limitations on types of elements used in the formula.
In the custom equation mode the formula of the stock is editable, the user can write any expression (actually the right hand of the differential equation) in the stock's d(stock_name)/dt = formula field.
You can customize the stock appearance: namely, you can change the fill color and resize the stock. These changes are reflected either in the graphical editor and at the model runtime.
To change the stock color
To resize a stock
Optionally you can associate some custom graphics with a stock so that it will reflect the value of the stock. Please have a look at the following demo model to get idea on the implementation:
Simple demo model: Stock of Money Animation
System Dynamics tutorial
System Dynamics modeling
Viewing variables at runtime
Modifying variables at runtime