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|
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 level – If selected, the variable is also visible on the upper level 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 mode the stock formula is non-editable, it is automatically generated according to the stock and flow diagram created by the user. In Custom mode the 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 Equation mode is 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.
properties are used to define dimensions of the array
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.
Please note that choosing Custom equation mode, you become responsible for stock formulas validity. This means that when you rename some element mentioned in the formula of a custom-mode stock, you should use refactoring to rename that element in the stock formula too.
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
To resize a
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