Converter tool

System Dynamics Simulator

Write stocks, flows and equations in a small model language, integrate with Euler or fourth-order Runge-Kutta, sweep a parameter, and check a run against a closed-form solution.

Stocks, flows, constants and equations

1. Model

One definition per line, # starts a comment. stock Name = initial, flow Name: Source -> Target = equation (a stock name or cloud at each end), name = equation for constants and auxiliaries, table Name(x) = (0, 0), (1, 0.5), (2, 1) for a graphical function. Operators + - * / ^ and comparisons and && || !. Functions: MIN, MAX, ABS, SQRT, EXP, LN, LOG10, SIN, COS, TAN, ATAN, ROUND, FLOOR, CEIL, SIGN, POW, IF(cond, a, b), STEP(height, time), PULSE(start, width, every), RAMP(slope, start), SMOOTH(input, tau), DELAY1(input, tau), DELAY3(input, delay). Built-in names: TIME, DT, STARTTIME, STOPTIME, PI, E.

Time and integration

2. Run settings

What the simulator covers

Limits

Equations are read by the page's own parser against an allowlist of functions and your model's names; nothing is evaluated as script. Algebraic loops are reported by name. A stock's initial value may use constants. STEP, PULSE and IF are evaluated at the stage times of Runge-Kutta, so pick a DT that lands on their switch times.

Not included: units and dimension checks, XMILE import and export, Monte Carlo bands, non-negative stock clamps. Up to 200 variables and 200,000 steps.

System Dynamics Simulator

Operator: Abdulla Al Fahad. How tools are built and checked

A system dynamics model describes how a few accumulations, such as a population, an inventory or a pool of customers, change through flows that depend on the accumulations themselves. The feedback is what makes the behaviour hard to guess: growth that slows as a limit nears, stock that overshoots after a delayed reaction, a product that spreads faster as more people have it.

Write the model as plain text, one definition per line: stocks with their starting value, flows between stocks, and constants and equations. The page integrates it with Euler or fourth-order Runge-Kutta, draws the results, sweeps a constant across a range, and can compare a run with a closed-form formula you type, which is the quickest way to see whether your step size is small enough.

Equations are read by the page's own parser and checked against a list of allowed functions and the names your model defines. Nothing you type is ever handed to eval or to a function constructor.

Key features

  • Stocks, flows with a source and target (a stock or cloud), constants, auxiliary equations and piecewise-linear table functions
  • Functions MIN, MAX, IF, STEP, PULSE, RAMP, SMOOTH, DELAY1 and DELAY3, plus the usual maths functions and the names TIME, DT, PI and E
  • Euler or Runge-Kutta 4 with a DT you choose, up to 200,000 steps, run in the background
  • A sweep of any constant over 2 to 30 values with the runs overlaid for one variable
  • A check of any variable against a closed-form formula in TIME, reporting the largest difference over the run

The model language, the built-in functions and the integration methods

One definition per line; text after # or // is a comment. stock Population = 10 defines a stock and its initial value, which may use constants. flow births: cloud -> Population = r * Population defines a flow from a source to a target, where each end is a stock name or the word cloud for something outside the model. r = 0.5 defines a constant, and any other name = equation defines an auxiliary. table Effect(x) = (0, 1), (5, 0.5), (10, 0) defines a graphical function that interpolates linearly and holds its end values outside the range.

Operators are + - * / ^, comparisons, && || and !, with ^ binding tighter than unary minus. Names are case-sensitive, and a name may be used before it is defined. Names that clash with a function or a built-in are rejected. IF(cond, a, b) replaces IF THEN ELSE, STEP(height, time) is zero before that time, PULSE(start, width, every) is 1 during the pulse, and RAMP(slope, start) grows from the start time.

A model may have up to 200 variables and 60,000 characters, each equation up to 2,000 characters. Units and dimension checks, XMILE files and Monte Carlo runs are not supported.

How it works

Each equation is parsed into a tree and compiled to a function. Auxiliaries and flows are evaluated in dependency order, which the page finds by sorting; if two of them depend on each other with no stock or delay between them, it names the variables involved as an algebraic loop and stops. Each stock's derivative is the sum of its inflows minus its outflows. SMOOTH, DELAY1 and DELAY3 are built from hidden stocks, one for SMOOTH and DELAY1 and three equal stages for DELAY3, so a loop that passes through a delay is legal.

Euler advances every state by DT times its derivative. Runge-Kutta 4 evaluates the derivatives four times per step at the start, twice at the midpoint and at the end, and combines them; its error shrinks with the fourth power of DT, which is why a coarse RK4 step can beat a fine Euler one. A value that turns infinite or undefined stops the run with the variable and the time.

When to use it

  • A product manager loads the Bass diffusion model with a market of 10,000, innovation 0.03 and imitation 0.38. Runge-Kutta 4 at DT 0.125 gives 9,716.0964 adopters at time 15 against the formula's 9,716.0964, with a largest difference of 0.00012.
  • An analyst sweeps the growth rate r from 0.2 to 1.0 in five steps on the logistic model. The population at time 10 is 69, 355, 803, 968 and 996, which shows how little a rate above 0.8 adds once the carrying capacity is near.
  • A supply-chain student runs the inventory model, where demand steps from 100 to 125 at time 10 and orders arrive through a three-stage delay. Inventory falls from 400 to a low of 287.7 around time 17, then returns to 400 by time 60 as orders settle at 125.

Inputs

  1. Type a model or load Logistic growth, Bass diffusion or Inventory with delays.
  2. Set start, stop and DT, and choose Euler or Runge-Kutta 4.
  3. Optionally tick Sweep one constant and name the constant, its range and the variable to plot, or type a closed-form formula to check a variable.
  4. Press Run the model and tick the variables to plot, up to six.
  5. Download the saved values as CSV or XLSX, or the charts as SVG or PNG.

Worked example

Logistic growth, Runge-Kutta 4, DT 0.25, stop 20, checked against the exact solution

stock Population = 10
flow growth: cloud -> Population = r * Population * (1 - Population / K)
r = 0.5
K = 1000

Formula: 1000 / (1 + (990 / 10) * EXP(-0.5 * TIME))

Result at time 20 and the difference from the formula

Population at 20: 995.52546 (exact 995.52552)
Largest difference over the run: 0.0012
The same run with Euler: 995.78 at time 20, largest difference 49.8 (12.6% of the formula value)

Limits

A flow written as a function of a stock that it drains can push the stock negative with a large DT. The page does not clamp stocks at zero.

Checking against a formula measures integration error only. It cannot tell whether the model is the right model.

  • To pick DT, run once at your step and once at half of it. If a quantity you care about changes in the digits you need, halve it again.
  • A STEP or PULSE that switches between two steps is evaluated at the stage times of Runge-Kutta, so choose a DT whose multiples land on the switch times.

Common errors and how to fix them

Algebraic loop: x -> y depend on each other with no stock or delay in between.
Two auxiliaries define each other at the same instant. Make one depend on a stock, or pass it through SMOOTH or DELAY1 so that it uses the previous state.
Line 4 (f): the function "system" is not available.
Only the listed functions and your own tables can be called. Use the allowed names, written with parentheses, such as MAX(a, b).
f became infinite at time 0.
The equation divides by zero at the start. Guard the denominator, for example with MAX(denominator, 0.0001).

Best practices

  • Give constants a plain numeric value on their own line, such as r = 0.5. Only those can be swept, and they are easy to find later.
  • Name flows after what moves (births, shipments) and auxiliaries after what they measure, so the influence list reads as a description of the model.
  • Check each new model against a limiting case with a known formula, such as exponential growth with the limit switched off, before trusting the full model.

Why Runge-Kutta needs far fewer steps

On the logistic example, Euler at DT 0.01 (2,000 steps) is still 2.0 away from the exact curve at its worst point, while Runge-Kutta 4 at DT 0.25 (80 steps) is 0.0012 away and at DT 1 (20 steps) is 0.24 away. Each Runge-Kutta step costs four derivative evaluations, so 80 steps of it cost 320 evaluations against Euler's 2,000 and are more accurate by three orders of magnitude. Euler remains useful when a model has sharp switches, such as an IF on a threshold, where the extra smoothness that RK4 relies on does not exist.

Frequently asked questions

How do I know the integration is accurate?

Besides the formula check you can run on your own model, the built-in logistic and Bass examples are compared with their closed forms: largest differences 0.0012 and 0.00012 for Runge-Kutta 4. SMOOTH and DELAY1 of a step input match 1 minus exp(-(t - 1) / tau) to within 0.001 at the saved times with a step of 0.01.

Can I import or export a Stella or Vensim model?

No. The model language here is the page's own and XMILE files are not read or written. Equations in a similar form can be typed in by hand.

Why can a sweep only vary some names?

A sweep replaces the value of a constant, a variable defined by a plain number on its own line. Anything defined by an equation is recomputed from other values at every step, so overwriting it would break the model.