CPD320 Simulation Project

From Chemical Engineering @ UP wiki
Revision as of 10:07, 18 September 2009 by AndreC (Talk | contribs) (CPD Simulation project page)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page contains common problems concerning the CPD simulation project. I will update this page as new problems present themselves - so have a look at this page before contacting me or Carl, the answer to your question/error might just be here.

If this page has not helped you, and you still require help, feel free to make an appointment with me. I'm usually on campus between 09:00 and 14:00, and till about 18:00 on Wednesdays and Fridays. But if you don't have an appointment, I can't promise that I'll have time to help you at that moment.

eMail: ahcampher@tuks.co.za

André

Common mistakes

Integration

Remember that you're working with one system. The states of the system affect each other - you will therefore need to integrate all the states at once. Splitting the differential equations and integrating them one at a time, will create problems as you'll assuming certain set profiles for variables (the pre-integrated states) and not allowing them to change according to the equations.

Diverging (unstable) differentials

If you notice that your system seems to be unstable (after integration) just check that you've not created a system which is inherently unstable. A few things to check include:

  • Check that your balances hold - are you removing mass/energy?
  • Check parameters - bad parameter choices can make the system seem unstable (due a very slow nature or steady-state being at very high values).
  • Are your equations working as you expect?
  • Is the control valve open? (x > 0)

Test your functions

Make sure that your functions return the values you expect them to by giving them known values and checking the output.

Be consistent

If you decide to use different functions for each differential equation, be consistent when specifying the order of the arguments to those functions. Its easy to make mistakes when you need to pass the arguments in a different order each time.

Variable names

Make sure that you don't use the same name for variables and functions, this will cause Octave to handle calls to your function/variable differently than you might expect. It will only call the function if the variable (which has the same name) does not exist.

Time

Take note that lsode does not make a number of integration steps equal to the size of the timespan you defined. Therefore, if you want to use time in any of your equations, you can not count on the n'th time step to correspond to the n'th element in your timespan vector (this will almost always be the case).

Common errors

Function outputs

Remember that when you define a function with an output:

function thisout = functionname (thisin)

you have to give the output (thisout) a value. Results of calculations stay within functions unless their explicitly set to an output.

Undefined variables

By default, variables are private to the functions in which they are used. Therefore, if you want to use a variable within a function, pass it as an input. If you want to use a variable outside of a function, set it as an output.

Size of derivative vectors

The following error,

error: lsode: evaluation of user-supplied function failed
error: lsode: inconsistent sizes for state and derivative vectors

can be caused by two problems - the most likely being a mismatch between your system differentials' output size and the starting value vector size, when calling lsode. Make sure that there is a starting value for each of the states for which your system function calculates a derivative.

The second case is when you have a derivative output which (for some obscure reason) grows in size (dimensions).