Concepts

Stocks and flows

Updated 3 November 2026 · 4 min read

Every model in the builder is made of things that accumulate and the rates that change them. This page explains why that one idea carries epidemics, inventories, drug doses and oil fields, and how to decide which is which when you start a model.

The bathtub#

A bath with the tap running and the plug out holds some amount of water. Over the next minute, the amount changes by what comes in through the tap minus what goes down the drain. The water in the bath is a stock. The tap and the drain are flows.

Put that way it sounds too simple to be useful. Three things about it are not obvious, and they are why the method works.

A stock can only change through its flows. You cannot set the level of the bath directly. You can only change the tap or the drain and wait. Every system you model has this property somewhere. A government can’t set the number of trained nurses, only the intake and the rate at which they leave. A field can’t set its reservoir pressure, only how fast it produces.

A stock remembers. The flows can change in an instant; the stock changes only as fast as the flows fill or drain it. Turn the tap off and the bath doesn’t empty. That memory is where delays, momentum and overshoot come from.

A stock separates its flows. The tap doesn’t need to know about the drain. Each flow depends on what the system looks like now, the stocks, and the stocks absorb the difference. That is what lets you build a model one flow at a time.

What the solver does with them#

Written as mathematics, a stock is an integral:

or, the same thing said as a rate, dStock/dt = inflows − outflows. A model with several stocks is a set of these equations, one per stock, and the flows tie them together. You draw the equations; the builder writes them out, and you can read them in the Equations tab. SepalSolver’s ODE solvers then step the stocks forward through time, a small step at a time, recomputing every flow from the stocks at each step.

StockStockan amount at a momentFlowa rate in or outVariableVariableworked out each stepConstanta number with a sliderLinkis used by
The five parts of a diagram. Stocks hold the state; everything else is worked out from it.

Deciding what is a stock#

When you start a model, list the things that matter and ask of each: could I count or measure this at a single moment, if time stopped?

QuantityAt one moment?So it is
People illYes, 1,200 todayA stock
New infectionsNo, it needs “per day”A flow
Money in an accountYesA stock
Interest earnedNo, it needs “per year”A flow
Oil in the reservoirYesA stock
Production rateNo, it needs “per year”A flow
Contact rate, interest rate, a priceIt is a number you assumeA constant
Crowding, profit, concentrationWorked out from stocks at the momentA variable

The units say the same thing. A stock’s unit has no time in it: people, dollars, barrels. A flow’s unit is the stock’s unit per unit of time. If you find yourself giving a stock a unit like “people per day”, it is a flow.

Conservation, and how to use it#

A flow from one stock to another moves its quantity without making or destroying any: what leaves Susceptible arrives in Infected. So a model built only from such flows conserves its total. In the outbreak, Susceptible + Infected + Recovered stays at 10,000 for the whole run.

That makes a free check. Add up the stocks that should be conserved and see whether the total holds. If it drifts, a flow is leaving one stock without arriving in another, or a formula is counting something twice.

Flows to and from clouds are where the model meets the world outside it: births and deaths, deliveries and sales, oil leaving for the pipeline. Draw them deliberately. Each cloud is a statement that you are not tracking where something came from or went to.

Starting small#

Most good models start with one to three stocks. Find the quantities that pile up, connect them with the flows between them, and run it before adding anything. A model with three stocks that you understand is worth more than one with thirty that you don’t, and the three-stock model is the one you will be able to explain when its answer surprises you.