scicospuffindownload

Simple tank model development - Part 1

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

[This is part 1: part 2 adds a control valve model, part 3 adds a controller.]

Consider a simple tank as follows ...

item1

How do we develop a dynamic Scilab model of this?

You can download the completed version with this link.

scicospuffindownload

Step 1: Classify variables

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

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

Step 2: Draw a data-flow diagram (DFD)

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.

item2

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.

Step 3: Translate DFD to Scilab model

Building this DFD in Xcos leads to...

XcosTankModel

Step 4: Test the model - does it behave like real life?

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;

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...

XcosTankModelTest1

And I used context variables as follows...

XcosTankModelContext

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

FlowIn = FlowOut

XcosTankModelTestResults1

As expected - flat.

FlowIn > FlowOut

XcosTankModelTestResults2

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...

XcosTankModelTestResults2Correction

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

XcosTankModelTestResults2Corrected

FlowOut > FlowIn

XcosTankModelTestResults3

That looks correct.

FlowIn sine wave test

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...

XcosTankModelTest4Modification

 

And with some suitable values you get...

XcosTankModelTestResults4

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

Conclusion

Our tank model passes the tests so we can now develop it further;