add Wiki authored by Uwe Bau's avatar Uwe Bau
### Events
Avoid events where possible.
### Division
Only divide by quantities that cannot take on zero. For example, if `x` may take on zero, use `y=x`, not `1=y/x`, as the second version indicates to a simulator that it is save to divide by `x`.
### Assert
Use the `assert` function to check for invalid values of parameters or variables, i.e. use
`assert(phi>=0, "Relative humidity must not be negative.")`
### Continuously Differentiable Equations
For computational efficiency, equations shall where possible be differentiable and have a continuous first derivative.
### Replacing Equations
Do not replace an equation by a constant for a single value, unless the derivative of the original equation is zero for this value. If computing a pressure `drop_dp` may involve computing a long equation, but one knows that the result is always zero if the volume flow rate `V_flow` is zero, one may be inclined to use a construct of the form:
`dp = smooth(1, if V_flow == 0 then 0 else f(V_flow));`
The problem with this formulation is that for `V_flow=0`, the derivative is `dp/dV_flow = 0`. However, the limit `dp/dV_flow`, as `|V_flow|` tends to zero, may be non-zero. Hence, the first derivative has a discontinuity at `V_flow=0`, which can cause a solver to fail to solve the equation because the `smooth` statement declared that the first derivative exists and is continuous.
### Bounded Equations
Make sure that the derivatives of equations are bounded on compact sets, i.e., instead of using `y=sign(x) * sqrt(abs(x))`, approximate the equation with a differentiable function that has a finite derivative near zero.
### Numerical Jacobians
Whenever possible, a Modelica tool should not have to do numerical differentiation.
For example in Dymola, if your model translation log shows `Number of numerical Jacobians: 1` (or any number other than zero), then enter on the command line `Hidden.PrintFailureToDifferentiate = true;`.
Next, translate the model again to see what functions cannot be differentiated symbolically. Then, implement symbolic derivatives for this function.
***
go to [Functions](home/modelica guidelines/functions)
\ No newline at end of file