4. Scaling

Many physical models contains variables with values that differs several orders of magnitude. A typical example is thermodynamic models containing pressures, temperatures and mass flows. Such large differences in values may have a severe deteriorating effect on the performance of numerical algorithms, and may in some cases even lead to the algorithm failing. In order to relieve the user from the burden of manually scaling variables, Modelica offers the nominal attribute, which can be used to automatically scale a model. Consider the Modelica variable declaration:

Real pressure(start=101.3e3, nominal=1e5);

Here, the nominal attribute is used to specify that the variable pressure takes on values which are about 1e5. In order to use nominal attributes for scaling, the compiler option enable_variable_scaling is set to True, see Section 2.2.2. All variables with a nominal attribute set to true, is then scaled by dividing the variable value with its nominal value, i.e., from an algorithm point of view, all variables will take on values close to one. Notice that variables typically vary during a simulation or optimization and that it is therefore not possible to obtain perfect scaling. In order to ensure that model equations are fulfilled, each occurrence of a variable is multiplied with its nominal value in equations. For example, the equation:

T = f(p)

is replaced by the equation

T_scaled*T_nom = f(p_scaled*T_nom)

when enable_variable_scaling is set to true.

For debugging purposes, is is sometimes useful to write a simulation/optimization/initialization result to file in scaled format, in order to detect if there are some variables which requires additional scaling. The option write_scaled_result has been introduced as an option to the initialize, simulate and optimize methods of JMUModel for this purpose.