ParX

Model Equations

The equation section of the model description is preceded by the keyword equations: followed by a number of assignments. The keyword must be on a separate line. The assignments can be to intermediate variables, but must finally be to the residuals. All residuals must be assigned.

A simple example:


                                    
                                        

The available arithmetic operators are:

operators
+ addition
- subtraction
* multiplication
/ division
^ exponentiation, or to the power of

Normal operator precedence rules apply with some caveats: Subtraction and unary minus come before addition. Division comes before multiplication. Exponentiation is left-associative, so 2^1^2 = 4. Also note that the unary minus is treated as a subtraction from zero, so -2^2 = -4. Use parentheses ( ) where required or for disambiguation and readability.


The available special functions are:

functions
sin( ) sine function
cos( ) cosine function
tan( ) tangent function
asin() arc sine function
acos( ) arc cosine function
atan( ) arc tangent function
sinh( ) hyperbolic sine function
cosh( ) hyperbolic cosine function
tanh( ) hyperbolic tangent function
exp( ) exponential function
erf( ) error function
ln( ) natural logarithm function, base e
log( ) natural logarithm function, base e (alt)
log10( ) common logarithm function, base 10
sqrt( ) square root function
abs( ) absolute value function
sign( ) sign function, returns 1 or -1

Conditional evaluation is also supported:


                                                if (condition)
                                                    assignments
                                                fi
                                            

or:


                                                if (condition)
                                                    assignments
                                                else
                                                    assignments
                                                fi
                                            

All keywords must be on a separate line.

When assigning variables, care must be taken that they receive a value in every conditional branch of the model. The used-before-assigned errors are only caught during runtime, which means that there are no actionable diagnostics available. The simulator and optimizer will simply skip the regions, and the data points respectively, where these errors occur. The same holds true for the residuals.


The available conditional operators are:

conditional operators
== equal to
!= unequal to
> larger than
< smaller than
>= larger than or equal to
<= smaller than or equal to
! not
not( ) not (alt)
& and
| or

The operator precedence rules are: comparison before not before and, or.


Error exit:

When the evaluation of the model can't continue under certain conditions, this can be signaled by calling error or assert. These functions take a conditional expression as their argument. The call error(condition) will exit when the conditional expression evaluates to true, while assert(condition) will exit when the conditional expression evaluates to false.

For backward compatibility, the old syntax is still supported:


                                                if (condition)
                                                    error(1)
                                                fi
                                            

or for assert:


                                                if (condition)
                                                    assignments
                                                else
                                                    error(1)
                                                fi
                                            

The available special numbers are:

Special numbers (and physical constants) start with an underscore and can be prefixed with a number as a multiplier.

special numbers
_pi π
_pi_2 π/2
_pi_4 π/4
_1_pi 1/π
_2_pi 2/π
_sqrtpi √π
_sqrt2pi √2π
_1_sqrtpi 1/√π
_2_sqrtpi 2/√π
_e e
_ln2 ln(2)
_ln10 ln(10)
_log10e log10(e)
_sqrt2 √2
_sqrt1_2 √1/2
physical constants
_k Boltzman constant
_q elementary charge
_c light speed in vacuum
_G gravitational constant
_h Planck constant
_F Faraday constant
_R gas constant
_NA Avogadro number
_0C 0°C in Kelvin = 273.15 K
_eps0 electric constant
_mu0 magnetic constant

A constant of can be specified as: 2_pi.