Write equations for robust solving
- Last UpdatedAug 13, 2024
- 2 minute read
Equations that have disparate scaling are harder to solve than equations that are scaled consistently. Model Writers should scale equations so that each side of the equation has approximate unity, so that they can all be efficiently solved together with adequate precision.
Example: Difficult equations
The following set of equations represents compressible flow through a valve.
|
3600 * W = 2.73 * A * Cv * Y * sqrt(x * P * R) |
(1) |
|
Y = max(Yk, 0.667) |
(2) |
|
Fk = CpCv/1.4 |
(3) |
|
P*X = DP |
(4) |
When the solver attempts to solve these equations, it iterates until the residual error, as defined by the left hand side of the equation minus its right hand side, is less than a typical convergence tolerance of about 10-6.
|
Residual Error = LHS – RHS |
(5) |
In the case of equation 1, the left hand side, or 3600 * W, is about 100,000 for typical industrial valve flowrates in AVEVA Process Simulation units of kg/hr, while equations 2-4 have values on the order of 1 to 100. The overall set of equations is difficult to solve as some equations are impacted more than other equations to changes in the other variables.
Example: Re-written equation
By moving 3600 to the denominator or the right hand side, you do not change the solution, but merely scale the equation so it is consistent with the other equations. You also preserve the significance of the numbers as 3600 is a known conversion from seconds to hours.
|
W = 2.73 * A * Cv * Y * sqrt(x * P * R) / 3600 |
(1A) |
With the above modification, the simulation converges in 4 iterations, compared with 45 iterations in the non-scaled case. It is not advisable to place variables in the denominators due to the potential of dividing by zero.
Best practice recommendations
The Model Writer should scale equations such that the each side of each equation:
-
Is in approximately the same order of magnitude to reduce the number of iterations.
-
Is around unity (1 to 100) so that values are solved with adequate precision.