Reference: components
Stock
Updated 3 November 2026 · 2 min read
A stock is an amount that builds up or runs down over time. It changes only through the flows into and out of it.
Place one#
Click Stock in the components list, then click the canvas, or drag it on. It is drawn as a rounded box with its name, and once the model has run, its value at the time on the time bar and a small curve of its history.
Settings#
| Setting | What it is |
|---|---|
| Name | What you read on the canvas. In formulas the name becomes one word, Coffee temperature → CoffeeTemperature, shown under the title. |
| Unit | What the stock is measured in, with no time in it: people, °C, barrels. Its flows must be in this unit per time unit. |
| Changes only through its flows | The stock’s equation, written from its flows, like dCoffeeTemperature/dt = −HeatLoss. You don’t edit it; you change it by drawing flows. |
| Starting value | Its value at the start of the run: a number, or a formula of constants, like Population - InitiallyInfected. |
| Output | Marks the stock as a result other models can read when this one goes in as a module. |
Rules#
- A starting value may use numbers and constants only. It is fixed before the run begins, so it can’t depend on stocks or variables.
- A stock is never set directly after the start. Everything that changes it is a flow.
- The solver does what the flows say, so a stock can go negative if an outflow keeps going when it is empty. Make outflows stop on their own: drain in proportion to what is there, like
Tank / DrainTime, or cap them withMin.
In the C##
Each stock is one entry in the state vector y that the solver integrates. Evaluate reads it back by name, and Model returns its rate of change, the sum of its inflows minus its outflows:
double CoffeeTemperature = y[0];
...
return [
-HeatLoss // dCoffeeTemperature/dt
];
The starting values go into Start().
See also
- FlowA rate that fills or drains a stock, per unit of time.
- Stocks and flowsWhy a system is easier to model as what accumulates and what moves it.
- A cup of coffee coolingYour first model: one stock, one flow and two constants, checked against the exact answer.
- Spatial stockA stock spread along a line: a one-dimensional PDE.