Flows

A flow transports a material from one stock to another. As a model designer, you must enter the rate of the flow. So, for instance, in our river example the magnitude of the flow could be a million gallons of water and the period over which it flows could be one day: in effect a million gallons per day. Flows may connect two stocks together. Alternatively, a flow can lack a start or an end. In this case, the unconnected end acts as an unlimited stock of material.

As with the initial value of a stock, the rate of a flow can be a simple number or a more complex equation. The equation can be based on many factors including the values of the stocks the flow is connected to and the current time. For example, if we had a stock representing the population of rabbits (called Rabbit Population), we could make the flow into the stock be the number of rabbits times a constant birth rate. This equation results in geometric growth in the rabbit population. The model below does that, with a matching Deaths flow draining the stock.

{ "engine": "SIMULATION_PACKAGE", "name": "Rabbit Population Growth", "simulation": { "algorithm": "RK1", "time_start": 0, "time_length": 20, "time_step": 0.25, "time_units": "YEARS" }, "elements": [ { "type": "STOCK", "name": "Rabbit Population", "behavior": { "initial_value": "200", "non_negative": true } }, { "type": "VARIABLE", "name": "Birth Rate", "behavior": { "value": "0.2" }, "display": { "interactive": true, "interactive_min": 0, "interactive_max": 0.5 } }, { "type": "VARIABLE", "name": "Death Rate", "behavior": { "value": "0.15" }, "display": { "interactive": true, "interactive_min": 0, "interactive_max": 0.5 } }, { "type": "FLOW", "name": "Births", "from": null, "to": "Rabbit Population", "behavior": { "value": "[Rabbit Population] * [Birth Rate]", "non_negative": true } }, { "type": "FLOW", "name": "Deaths", "from": "Rabbit Population", "to": null, "behavior": { "value": "[Rabbit Population] * [Death Rate]", "non_negative": true } }, { "type": "LINK", "from": "Birth Rate", "to": "Births" }, { "type": "LINK", "from": "Death Rate", "to": "Deaths" } ], "visualizations": [ { "name": "Rabbit Population", "type": "TIME_SERIES", "elements": [ "Rabbit Population" ] }, { "name": "Births", "type": "TIME_SERIES", "elements": [ "Births" ] }, { "name": "Deaths", "type": "TIME_SERIES", "elements": [ "Deaths" ] } ] }

Alternatively, if we had a flow representing rainfall, we could set the flow rate to be based on the current time of the year. Rainfall over the course of a year can be approximated using a sinusoidal function like the following, simulated two years week by week so the annual cycle is visible:

{"time_units": "WEEKS", "time_length": 104} sin(2 * pi * (Weeks() + 10) / 52) * 30 + 35

Where weeks is an Insight Maker function that automatically takes on the value of the current simulation time measured in weeks, pi is the constant 3.14159, and sin is another Insight Maker function that applies the trigonometric sine function to an angle inputted using radians.

A flow can be restricted to positive flows only. In this case, the flow will only be applied if the calculated magnitude of the flow rate is positive. This restriction would be applicable for both our rabbit and rain examples. We know that neither of the flows should ever be negative (you cannot have negative births or negative rain) so we might want to set them to only allow positive flows just to ensure that such an impossible event never happens (though it never will in any event given the equations we specified).