Simple tank model development

Building the ubiquitous standard tank model in Scilab. Used in later articles to investigate control options.

Consider a simple tank as follows ...

How do we develop a dynamic Scilab model of this?

You can download the completed version with this link.

By this I mean which are given and which need to be determined by the model. In this case;

- FlowIn, FlowOut will be specified by input variables to the model
- Density, tank height, tank diameter are fixed and defined by the plant specification
- Liquid height and height in percent will be determined by the model

In other words, given the variations of flow in and flow out the model will determine how the liquid height changes over time.

The data-flow diagram helps to determine the calculation order and I find it a useful step between the calculations and how they are implemented in Xcos.

This step identifies a model variable since the integration function needs an initial value. This initial value represents the starting state of the tank In this case we will decide to provide the initial tank mass as the initial value for the integral function.

Building this DFD in Xcos leads to...

This is of course the most important part. Is your model good enough for the purpose intended?

I have found the best approach is to derive test data with expected results once the previous step is complete. Experience helps in deriving test data but the aim should be to exercise all the modes of operation, which in this case is;

- FlowIn = FlowOut: should give steady level
- FlowIn > FlowOut: tank should fill to its maximum height at a steady rate
- FlowOut > FlowIn: tank should empty to zero at a steady rate
- FlowIn a sine wave, FlowOut fixed: tank level should be a sine wave

In order to perform the test we have to add some bits to our tank model. I did this by making the Xcos tank model a superblock and then added the inputs to set the flow in and flow out together with a trend so I can see the tank height. This resulted in...

And I used context variables as follows...

So what does this test data produce on our model above.

As expected - flat.

**Wrong!** The level is decreasing even though our flow in is greater than our flow out. A check of the model reveals the wrong sign used to generate the Te/s value. Changing these round to...

...yields the correct result. Note too that there is a ceiling at 100% - which is correct.

That looks correct.

We need a quick modification to be able to do this test. You can't get a sine block to oscillate around a central value so you have to add a sine block output to a constant like this...

And with some suitable values you get...

Which is correct too. A sine wave flow in of low-ish frequency should produce a sine wave effect on the level.

Our tank model passes our tests so we can now use it to develop control schemes such as;