.PowerGrids.UsersGuide.ToolSupport

Information

Modelica Tool Support

General Information

The PowerGrid library has been developed using the OpenModelica tool and has been tested extensively using that tool. The library was written in standard Modelica language, so it is expected to work with any Modelica tool that fully supports the standard, in particular Complex numbers and the homotopy() operator.

The power system models that can be built with this library have a different structure compared to the models that are normally simulated by Modelica tools, due to the large number of coupled implicit algebraic equations stemming from the phasor-based representation of most grid elements, such as transmission lines, transformers, and loads. This may require some special set-up of the tool to generate efficient and numerically robust code to simulate the models. These aspects are now briefly discussed.

The first aspect concerns the structure of the system mathematical models. The original formulation of the system model is a system of differential-algebraic equations (DAE), which has a sparse structure, since every physical component is connected to a limited number of neighbouring components. The conventional approach used by Modelica tools to solve these DAEs is to first transform them into ordinary differential equations (ODE), in a process known as causalization that requires to solve the DAEs for the state derivatives, and then to use an ODE solver to perform time integration. Note that this approach is followed even if the solver which is eventually used is DASSL. The reason why DASSL is often used in Modelica tools is that it is very robust and efficient and has a very good event detection capabilities, but normally it is employed to solve the causalized ODEs, not the original DAEs.

Unfortunately, this approach is highly inefficient in the case of PowerGrids system models: it is well known from the swing equation theory that if a quasi-static phasor approximation of the grid elements is used, then the derivative of the shaft angular velocity of each synchronous generator instantaneously depends on all the rotor angles of all other synchronous generators which are connected through the grid. Hence, although the DAEs are sparse, the causalized ODE representation is not. This makes the causalization process highly inefficient, because the computation of the right-hand side of the ODE formulation requires the computation of a large number of Jacobian matrix elements, as well as the solution of a large dense nonlinear system. 

This means that, except for very simple systems with a few synchronous generators, the so called DAE-mode solution method should be selected, which avoids the standard ODE causalization and uses a native numerical DAE solver to simulate the system. The use of a sparse DAE solver is recommended. In case causalization is employed, the use of sparse solvers for the implicit nonlinear equations (a.k.a. algebraic loops) is mandatory for reasons of efficiency, since the size of those systems can be quite large, while the number of variables involved in each equation is normally limited to a few units.

The second aspect regards the initial guess for the solver of the initialization problems. As discussed further in the Tutorial, the PowerSystems library was designed to make sure that proper start values are computed, starting from the power flow results, for all the nonlinear variables that influence the Jacobian of the initialization problem, while there is no need to care about the initial values of variables appearing linearly in the models. Following this approach guarantees the convergence of the Newton algorithm to solve the initialization problem, as long as the problem is kept in its original formulation.

However, Modelica tools often employ a method, known as tearing, to reduce the size of the actual nonlinear implicit system to be solved, thus making the solution process more efficient. Unfortunately, the choice of nonlinear variables as torn variables leads to the loss of their initial guess values, potentially hampering the convergence.

A brute-force method to avoid this problem is to disable the tearing algorithm and enable sparse solvers for the nonlinear systems of equations, using suitable tool flags. More advanced tools may automatically avoid selecting nonlinear unknowns as torn variables, thus preserving the start value information, and also automatically select sparse solvers based on the observed large size and low density of the equation system; in this case, there is no need to set special flags to achieve robust and fast simulation.

The library uses SI units for physical quantities on connectors, to enhance clarity and avoid ambiguity regaring the base quantities for per-unit variables. In order to achieve good numerical scaling in the solution process, the Modelica tool should use the nominal attributes of variables for automatic scaling.

Finally, the homotopy operator is used in several places of the library, in particular for the robust solution of the nonlinear implicit equations relating internal and external parameters of the synchronous machine models. It is also used to initially remove the nonlinear elements due to actuator saturations in the control system models, making the corresponding equations linear and thus avoiding the need to provide start values for all their variables, which could be quite inconvenient.

Hence, it is essential that the homotopy operator is indeed used in the solution process of the initialization problem, in order to avoid solver convergence problems.

Using PowerGrids with OpenModelica

In the case of the OpenModelica compiler, version 1.18.0, these requirements can be met by selecting the following flags:

When creating new models, these settings can be saved into custom annotations of the model by checking the "Save translation flags" and "Save simulation flags" options in Simulation Setup, so that they are automatically set when the model is re-opened and re-simulated later on. The existing example models and test models in the PowerSystems library already have __OpenModelica custom annotations to set those flags when compiling and running the model.

All other requirements are automatically fulfilled by OpenModelica. Please note that future versions of OpenModelica may no longer require these flags to be set at all.

If you are interested at running PowerGrids in other Modelica tools and are having trouble, please contact the authors for assistance.


Generated at 2024-05-24T18:15:57Z by OpenModelicaOpenModelica 1.22.4 using GenerateDoc.mos