6.4.10 Mass-Balance Testing
In system dynamics modelling, the arithmetic treatment of key variables is as sequences of flows. These flows most frequently involve material or physical flows although they may include information. The intent of applying mass-balance tests is to ensure that the functions performed by inappropriately specified algebraic operators do not result in the inadvertent creation or destruction of flows. These tests are generally applied by focusing on the flows into and out of each stock (level or accumulator). A mass-balance test will also identify rounding errors created by use of functions such as FLOOR, CEIL, ROUND, INTEGER.
Checking Mass-balance—An Example
A fundamental check of the correct function of a module, and indeed every model, is that flows across the boundary drawn around the module do not result in net growth or net decline of the mass of the flows. Alternatively stated, flows must occur in such a way that does not permit material to be neither created nor destroyed within the module: whatever flows into a module must either flow out or accumulate within the module.
As each module is being constructed, it is essential to check the mass balance. The simplest scheme for doing this is depicted diagrammatically at Figure 6-5. (Also see Figure 5-6.)

The general scheme for checking mass-balance is:
- The stock (level or accumulator) of interest is STOCK.
- One co-flow is created for each inflow to count all flows in. In our example, the stock which accumulates the count of flows is COUNT OF FLOWS IN.
- Each flow across the problem boundary is counted. This is achieved by replacing the clouds representing the problem boundary by stocks which accumulate each of the outflows. In our example, these are COUNT OUTFLOW1 and COUNT OUTFLOW2.
- An auxiliary called Delta Check takes values from each of the stocks according to the scheme:
Delta Check = 'Initial Contents of Stock'
–STOCK
+ 'COUNT OF FLOWS IN'
–'COUNTOUTFLOW '
–'COUNT OUTFLOW 2'
Note: Delta Check must have a value of zero throughout the entire simulation and for each timestep. If it does not, there is a mass-balance error.
