www.delorie.com/gnu/docs/mcsim/mcsim_20.html   search  
 
Buy GNU books!


MCSim User' Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.2.5 Dynamics specifications

The dynamics specification section begins with the keyword Dynamics and is enclosed in curly braces. The equations given in this section will be called by the integrator at each integration step.

Additional variables to those declared in the global section may be used for any calculations within the section. They will be declared as local temporary variables. (Note, for example, the use of `Cout_fat' and `Cout_wp' in the `perc.model' sample file). Local variables are not accessible from the simulation program, or from other sections of the model definition file, so don't try to output them.

Each state variable declared in the global section must have one corresponding state equation in the Dynamics section. If a state equation is missing, mod issues an error message such as:

 
Error: State variable 'Q_foo' has no dynamics.

If one or more differential equations are missing, no program file will be created. Most error messages are self-explanatory. Where appropriate, they also show a line number in the input file where the error occurred. Beware, however, of cascades of errors generated as a consequence of a first one; so don't panic: start by fixing the first one and rerun mod.

The derivative of a state variable is defined using the dt() operator, as shown here:

 
dt(state-variable) '=' constant-value-or-expression ';'

The right-hand side can be any valid C expression, including standard math library calls and the special functions mentioned above (see section 5.2.3 Special functions). Note, however, that no syntactic check is performed on the library function calls. Their correctness is your responsibility.

The dt() operator can also be used in the right-hand side of equations in the dynamics section to refer to the value of a derivative at that point in the calculations. For example:

 
dt(Qm_in) = Qmetabolized - dt(Qm_out);

The integration variable (e.g., time) can be accessed if referred to as t, as in:

 
dt(Qm_in) = Qmetabolized - t;

Output variables can also be made a function of t in the Dynamics section.

Note that while state variables, input variables and model parameters can indeed be used on the right-hand side of equations, they cannot be assigned values in the Dynamics section. If you need a parameter to change with time, declare it as output variable in the global section. Assignments to inputs or parameters in this section causes an error message like the following to be issued:

 
Error: line 48: 'YourParm' used in invalid context.
Parameters cannot be defined in Dynamics{} section.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003