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#

SettingWhat it is
NameWhat you read on the canvas. In formulas the name becomes one word, Coffee temperature → CoffeeTemperature, shown under the title.
UnitWhat 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 flowsThe stock’s equation, written from its flows, like dCoffeeTemperature/dt = −HeatLoss. You don’t edit it; you change it by drawing flows.
Starting valueIts value at the start of the run: a number, or a formula of constants, like Population - InitiallyInfected.
OutputMarks 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 with Min.

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().