It is important that you correctly account for flows in and out of flow systems in GoldSim models, especially when events are occurring between time steps (for overflows, etc.). GoldSim does not provide continuity of mass checking for your models so additional logic must be added to your model to perform this check and ensure the model is accounting for gains and losses from the system. The approach used in this model can account for continuous flows and discrete changes, independently of the time step. If the flows are not balanced, a run time error or warning is issued to inform the modeler.
A simple reservoir model is used to test the mass balance checking functions. The mass balance check uses Integrators so that continuous and discrete amounts are accounted for.
The general equation for checking mass balance is as follows:
∫ Qin dt + Vin - [ ∫ Qout dt + Vout ] - (Si - S0) ≈ 0
Where Qin and Qout represents flows in and out of the system, Vin and Vout are any discrete changes, and S is the storage (Si is current storage and S0 is initial storage). You can specify an allowable error to allow for numerical (i.e. round off) errors in the model. In this particular model, you should expect to see errors on the order of about 1e-14 m3.
The reservoir calculations in this model are used only for demonstration to show how you might actually check for continuity of inflows, outflows and change in storage. In reality, you might have many reservoirs and many more flows that you are accounting for. This model represents a reservoir that receives inflows and outflows that are continuous and discrete. Mass balance is calculated in the Mass_Balance container. The discrete change "Test_Error_Check" is used to test the error checking in this model. To avoid the error, change the amount in "Test_Error_Check" to 0 m3.
The container called "MassBalance_Check" includes the functions that account for flows and volumes to ensure there is mass balance. If the mass balance error exceeds a criterion specified, then an error message is displayed and the simulation is interrupted.