Difference between revisions of "CPD320 Simulation Project"

From Chemical Engineering @ UP wiki
Jump to: navigation, search
(Common errors)
(Deleted contact information for André)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
This page contains common problems concerning the CPD simulation project. I will update this
+
This page contains common problems concerning the CPD simulation project.
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
+
== Mistakes specific to CPD project ==
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 ===
 
=== Integration ===
 
Remember that you're working with one system. The states of the system affect each other - you will
 
Remember that you're working with one system. The states of the system affect each other - you will
Line 46: Line 36:
 
be the case).
 
be the case).
  
== Common errors ==
+
=== Common Octave errors ===
=== Function outputs ===
+
There is a separate page for [[Common Matlab/Octave errors]].
Remember that when you define a function with an output:
+
function thisout = functionname (thisin)
+
you have to give the output (<tt>thisout</tt>) 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,
+
<pre>
+
error: lsode: evaluation of user-supplied function failed
+
error: lsode: inconsistent sizes for state and derivative vectors
+
</pre>
+
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 <tt>lsode</tt>. 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).
+
 
+
=== Strange size errors ===
+
A very common error found that can be hard to track down is shown below:
+
<pre>
+
octave> a = [1 -(1+2); 3]
+
error: number of columns must match (1 != 2)
+
</pre>
+
 
+
The problem is that Octave is interpreting the - as a negation (making it negative) rather than a subtraction, so there are actually two elements in the first row.  The best way to avoid this problem is to use spaces on both sides of + and - signs at all times.
+

Latest revision as of 10:58, 3 March 2011

This page contains common problems concerning the CPD simulation project.

Mistakes specific to CPD project

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 Octave errors

There is a separate page for Common Matlab/Octave errors.