# Modelling a flushing toilet in Dymola using Modelica Fluids

A few weeks ago, I was tasked with learning more about fluids modelling within Dymola. Complete with fluids component models, the Modelica Standard Library can be used to model 0-dimensional (0D) and 1-dimensional (1D) fluid systems.
As with most things, learning by doing is a good idea. I therefore needed a simple, well understood system to recreate in Dymola.

My colleague jokingly suggested a flushing toilet, but why not! Consisting essentially of two tanks, one higher than the other, the flushing toilet is one of the simple systems we take for granted on a daily basis. When you press the flush lever/button, the contents of the higher (cistern) tank of water is emptied into another, below it (the toilet bowl). With the height differential comes a difference in pressure. The contents of the lower tank are forced out and away down the sewer, as the pressure in the lower tank is now higher than the pressure at the exit boundary of the lower tank. That’s it. A float valve, opened as the cistern contents are evacuated, is then closed when the cistern is full.

In reality, the flush process is aided by the exit pipe, which as can be seen above, is not full of water. When the toilet is flushed, this pipe fills with water (forced out of the bowl), which creates a suction effect which evacuates all fluid from the bowl. In our simple model, this effect will not be modelled, rather the pressure required to fill the exit pipe will be considered the boundary pressure of the system.

## Modelling the cistern

In essence, the cistern is a tank, placed higher than the toilet bowl, with an automatically controlled refill mechanism. Actuated by a float valve, when a flush is initiated the ‘flapper’ in figure 1 is opened, causing the tank contents to drop, along with the level of the float. Once the float has dropped sufficiently, the valve on the refill pipe can open to refill the cistern.

Instead of a user operated handle or chain, the flushes in this model are initiated by the pulse source flushAction which opens the flushValve, causing fluid to drop out of the tank. The tank model, using a Modelica.Fluid.Vessels.OpenTank, calculates the level internally. A public variable, this parameter can be used by models outside of the tank. Here it is evaluated against an arbitrary value representative of the full level of the tank. This controls the float valve, which controls whether fluid from the water main boundary flows into the tank.

One feature of the tank is that the heights of the input and output fluid ports can be specified, along with the initial height of the fluid in the tank. If the fluid level exceeds the specified top of the tank, the simulation is ended with an assert statement.

## Modelling the connector pipe

In many toilet designs, the cistern and the bowl are connected by a single pipe with a 90 degree bend.

Of interest here is the pipe model, pipe1, and the modelStructure variable. In Modelica fluids modelling, there are two types of models; a volume model and an orifice model. For the translated model to be of an efficient construction, it is advisable that a volume model is connected to a orifice model (also known as a flow model), which is in-turn connected to a volume model and so forth. The reasons for this are how the acausal flow variables are calculated, and the impact this has on the equation chains created by Dymola when translating the model.

Therefore, as different system components will either be a flow model or volume, setting the modelStructure variable determines the methodology of modelling at each connector of the pipe. In effect, this enables the pipe to connect to any configuration of flow model/volume model on each side in an efficient way. As the curvedBend is a a flow model, and the exit port of the tank model in figure 1, the pipe is set to have an v_v structure, denoting that each of it’s connectors will be considered volumes.

## Modelling the bowl

Essentially, the toilet bowl can be considered a tank, which has an exit pipe to an external pressure boundary, as described above. This means it can be modelled in a simple way.

The exitPipe is configured to model a pipe which is higher at the exit boundary than the inlet, like a toilet exit pipe. Static pressure in the Modelica.Fluid.Sources.Boundary_pT model exitPipePressureBoundary is tuned to enable the fluid level in the bowl to remain approximately constant/static.

As with pipe1 in the connector pipe model, the exitPipe features a modelStructure set to provide an efficient model. With the bowl and exitPipePressureBoundary both considered to be volume models, the exitPipe is set in the _v_ structure, indicating there is a flow model at each of the pipe connectors.

## Simulation and results

All the above models can be combined (after generating the adequate icons!) into one model of a toilet. At the top level, a system control block Modelica.Fluid.System is added at the top level, to define ambient system properties. All fluid medium parameters were linked together, with the Modelica.Media.Water.StandardWater option chosen.

With the pulse signal connected to the flush valve, the cistern flushValve will open for 5s in every 15s second period. This duration has been calculated to enable the full contents of the cistern to be evacuated and refilled before the next flush is commenced.

As shown, when the cistern flush valve is opened, the level of the bowl does not rise above a certain level; this is the level at which the fluid is in equilibrium, flowing both into and out of the bowl at a similar rate. Once the cistern has been emptied, the fluid finds a new equilibrium with the outlet pressure boundary.

## Final thoughts

Whilst not a fully fledged 3D mixed-media fluid simulation, this simple model provides useful information regarding performance of various toilet configurations, as the inlet dimensions are able to be varied, as are the pipe diameters, lengths and heights. This model could be used to understand and quantify the effects of various grades of pipe roughness in the system, component placement and dimensions as well as calibration of the cistern refill system. As water saving is becoming an ever more pressing environmental issue, such models can help designers and engineers to design more efficient systems.

It also serves the purpose of a simple and fun teaching tool!

Written by: Theodor Ensbury – Project Engineer

Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion