# How to perform an Overall Mass Balance

Jump to navigation
Jump to search

**Navigation: PGMs ➔ Example PGM Files ➔ Steady-State Mass Balance**

Simple Examples | Subroutines Examples | Dynamic Examples | Steady State Overall Mass Balance | Array and Matrix Examples | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

Basic Layout | Simple Calculations | Initialise PreStart | Multi-Step Trigger | Checking Project | Counter, While and Random | Belt Filter Wash Loss | Startup Actions | Mass Balance | Mass Balance | Species Balance | Elemental Balance | Lookup Value | Set Values | Tridiagonal System |

**Related Links:** PGM Files using Class and Functions, TagSelect Class

# Steady-State Project Overall Mass Balance

It is often important to perform an overall mass balance to account for the total inputs and total outputs. Here we will show how to obtain a quick balance of the overall mass by adding a PGM file using the TagSelect Class to sum up the total in and out and perform a balance.

The following two examples show how the Tag Select Class could be used to perform a simple mass balance in a steady-state project.

NOTES:

- the total input is calculated by adding all the feeders and makeup sources.
- the total output is calculated by adding all the Outputs(FeederSink).
- The Reaction Block (RB) sources and sinks are NOT included in this calculation, but could easily be extended with an additional TagSelect call, please see How to perform a Species Mass Balance for more information on this topic.
- This would best be performed after the last iteration using the Terminate Solution sub-routine.

## Example 1: Steady-State Project Mass Balance

```
PageLabel "MassBalance"
TagSelect Inputs, Outputs
Array InputFlows, OutputFlows
real FlowIn@("Qm","t/h"), FlowOut@("Qm","t/h"), Balance@("Qm","t/h")
CheckBox InOK@, OutOK@
Sub CalcMassBalance()
; find all true feeders (not connected) and makeup sources
InOK = Inputs.Exec("([UnitType]=='FeederSink' AND ([State]==1 AND [Operation]!=11)) OR ([UnitType] == 'MakeupSource')", false, false)
; retrieve values of all individual inputs
Inputs.GetValues(".QProd.Qm (t/h)", InputFlows)
; sum all input flows
FlowIn = InputFlows.Sum()
; find all true sinks (not connected)
OutOK = Outputs.Exec("(([UnitType]=='FeederSink' AND [State]==2) OR ([UnitType] == 'DiscardSink') )", false, false)
; retrieve values of all individual outputs
Outputs.GetValues(".QProd.Qm (t/h)", OutputFlows)
; sum all output flows
FlowOut = OutputFlows.Sum()
; perform mass balance
Balance = FlowIn - FlowOut
EndSub
Sub TerminateSolution()
;--- Logic executed after last iteration (when solver is stopped)
CalcMassBalance()
EndSub
$ ; --- end of file ---
```