See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/339602342 PyPSAL - Python Power System Analysis Library Preprint · March 2020 DOI: 10.13140/RG.2.2.36254.48969 CITATION READS 1 2,292 1 author: Olav Bjarte Fosso Norwegian University of Science and Technology 178 PUBLICATIONS 3,294 CITATIONS SEE PROFILE All content following this page was uploaded by Olav Bjarte Fosso on 01 March 2020. The user has requested enhancement of the downloaded file. PyPSAL - Power System Analysis Library Olav Bjarte Fosso Department of Electric power Engineering Norwegian University of Science and Technology (NTNU) Norway Email: olav.fosso@ntnu.no Abstract—This paper describes a library for power system analysis. It is based on an object-oriented representation of the transmission system components and the design of the library is also object-oriented. The data description is connected to a CSV-file format where either Microsoft Excel or Open Office Spreadsheet may be used. Currently the tools available for load flows are Newton-Rhapson, Decoupled Power Flow, DC Power Flow, Continuation Power Flow, Contingency Analysis, SecurityConstrained DC Power Flow. The program frame work is written in Python 3.6 and and it is tested on Windows 10 and Ubuntu 18.04. The main motivation for the work has been to establish a flexible library with a significant number of functions working seamlessly on the same data representation to facilitate rapid development of new methods based on existing functionality. Keywords—Continuation Power Flow, Contingency Analysis, Power Flows, Python, Object-oriented programming, Securityconstrained optimization, Bender’s decomposition I. I NTRODUCTION A number of toolboxes are available today for different kind of power system network analysis where Python, Matlab and other languages are used. Examples are PSAT and DOME [1], PyPSA [2], MatPower [3]. PyPSAL (Fig. 1 and Fig 2) is a library with its origin on a program system developed by the author in Fortran 77 [4], which was designed to work on large scale systems. Therefore, state-of-the-art for sparse matrix representation, efficient numerical solvers and Inverse Matrix Modification Lemma (IMML) [5] were used for making the computations faster. This new implementation is using similar techniques as in [4] but has its advantage in using the Python programming language with an object-oriented design. This makes the development to be fast and flexible. The key is to have an effective object-oriented model and topology representation to organize the calculations from. It is here chosen to have the full AC, the decoupled representation (DEC) and the DC representation as main classes while the different implementations are organized as sub-classes. II. U SER I NTERFACE The library is currently not provided a graphical interface. However, the data is connected to a spreadsheet representation in a CSV-format. The routines for running the main applications are supplied with a number of options for controlling the cases. Each option is supplied with a default value, which can be user controlled when defining the total sequence of studies. Examples of such user controlled options are sparse/non-sparse solvers and which solver to use, to verify the contingency cases with full AC load flow, the amount of summary provided during the simulation/optimization and the way of presenting data or results (graphical tables or summary to screens). Fig. 1. System Objects of PyPSAL A. External data format The data representation is closely connected to the IEEEformat, the representation used in Matpower and the PSSE Rawd. To avoid being too strongly connected with a specific representation of the data format, a representation where each case is given by individual sheets within a spreadsheet file as shown in Fig 3, is chosen. The sheets in Excel are currently: Parameters, Buses, Loads, Transmission lines, Generators, Shunts and Transformers. The data within each sheet follows essentially the format of IEEE and the representation used in Matpower. When importing such a description into a spreadsheet in a CSV-format, it is easy to copy the blocks into the right component sheet. For some data there are routines for automatic conversion of data. B. Internal object representation For each electrical component, the required data is read from each cell of the relevant sheet using Python library functions for working on spreadsheets. As mentioned, there are sheets for the main component classes of a power system. However, the design of the interface is flexible and new classes and component attributes can easily be added. Additionally, there are a number of methods defined under each class Fig. 2. Fig. 3. Classes and subclasses of PyPSAL Fig. 4. Bus loads Fig. 5. Transmission line flows Transmission line representation in Excel A. AC Power Flow of components transforming the data to a useful internal representation. The main system objects with some of the system variables are shown in Fig. 1. C. Topology representation When creating the instances of each object class, the instance is added to a list of same type of objects. On toplevel there are lists such as: GenList, BusList, TransList and LoadList. These are holding the instances for each class. Additionally, there are a number of pointers making it fast to identify associated objects in the topology. Iteration over any of these lists, will effectively identify the relevant objects and associated parameters of each task. III. M ODULE DESCRIPTIONS This section describes the individual modules implemented and the methods which can be used in other computational schemes. The main classes and sub-classes are shown in Fig. 2. The AC Power Flow is implemented through the object ACPowerFlow with a wide range of methods appropriate to deal with such cases. There are methods for calculating the classical Jacobian matrix, net power injections, mismatches, activation and deactivation of reactive limits of generators, flow calculations, flow violations using different flow criteria and ratings. The storage scheme when building the system matrices is based on a list of sub-lists where each sub-list is the matrix element along with its matrix coordinates. Such a storage scheme makes it simple to map the sparse matrix structure into either a full matrix description, the sparse rowwise format(CSR) and the sparse column-wise format(CSC) [6]. The last two formats are widely used in equation solvers for sparse systems. Currently, solvers used are from the linalg and sparse.linalg modules of the Scientific Python (Scipy) but there are also interfaces to solvers from CVXOPT [7]. The user can chose which solver to use when calling the individual modules. The individual methods are supplied with user controlled parameters for choosing solvers, maximum number of iterations and the amount and style of result presentation. Both input data and the results can be presented either as standard output to screen or in a standardised graphical table format. Examples are given in Fig. 4 and Fig. 5. One of the methods implemented is the standard NewtonRhapson power flow method. The component models used in the implementations are similar to those described in [8]. B. Decoupled Power Flow There are three methods for decoupled power flow implemented, reflecting different assumptions in simplifying the matrices. The methods included are the XX, BX and XB where X and B reflects the assumptions made in developing the matrices of the active power and the reactive power load flow matrices. This is further discussed in [9] and [10]. The experience shows different behaviour on different system characteristics as when there are lines with low X/R-ratios and there are cases where the standard decoupled power flow fails in convergence while one of the others has excellent performance. Essentially the same methods are available for the decoupled power flow but in a decoupled manner. C. DC Power Flow The DC Power Flow uses a simple flow representation where the losses are represented as equivalent loss vectors on the individual buses [9]. In other words, after the power flow calculation, the losses of each transmission line are estimated and 50% allocated to each node [17]. This is a widely used but very simple representation. The methods relevant for result and data representation are the same as the ones for the AC and decoupled methods. D. Contingency Analysis The contingency analysis are based on the decoupled power flow model. The implementation is much in line with what is presented in [11]. The user can choose the sparse/nonsparse representation, the maximum number of iterations of each case, reactive limits enforcement of generators as well as the amount of results presented during the analysis. There is also an option to check contingency cases with a regular load flow. This is also user-controlled and is a useful option in case one of the contingency cases fails to converge, to check specific solutions or in the case of multiple contingencies. The standard technique for solving contingencies are based on the Inverse Matrix Modification Lemma (IMML) as described in [5] where the pre-compensation technique is used on iterative cases. This approach also effectively identifies cases causing separation in the grid. The user can specify which solver to use (sparse/non-sparse). The fact that the same matrices are used for all contingencies is utilized by doing the preparatory work as LU-decomposition before the contingency analysis starts. In such a case, only a forward and backward substitution is used in the iterative solution as well as for calculating the required inverse factors for compensation. E. Continuation Power Flow The implementation of the Continuation Power Flow essentially follows the implementations as described in [12] and [13]. Besides the methods inherited from the ACPowerFlow class, there are own methods within this class for administration of the continuation parameters, for deciding on the loading profile, implementing the prediction and the correction steps as well as a method implementing this into a increased system loading from a voltage collapse viewpoint. However, there is also an implementation of the technique as a tool for performing system simulations according to a time varying load and generation profile. The advantage of the method is the ability to, in a quasi-static procedure, follow the tap-changing of transformers, system overloads and possible discrete actions as tripping of equipment. F. Security-constrained Economic Dispatch The security-constrained economic dispatch is based on a DC-formulation of the power flow equations [14] and [15]. However, there are options for using the standard DC, the incremental and the hot-start alternative. The incremental and the hot-start [17] can be combined with an AC load flow and will therefore give an improved accuracy as it gives an accurate loss and initial flows for the transmission lines at the linearization point. The optimization is based on a compact formulation where the flow on the individual transmission lines is expressed as a function of the net-injection on the individual nodes. This is the well-known distribution factor formulation [18] and [19] but implemented in a scheme as given in [20]. Only the transmission lines experiencing overload will be included in the calculations and the distribution factors for each line is calculated by a forward and backward substitution when it is needed. For the contingency cases, it may either be chosen a preventive strategy or a post-contingency rescheduling approach. In the case of a preventive approach, the flow after a contingency is calculated using the IMML, but in this case the postcompensation method is used. For transmission lines experiencing flow violation, a constraint is formulated and corrected based on the IMML and next added to the main optimization problem. After all the constraints are added, a new optimization is conducted before the post-contingency flows are checked in a new contingency analysis. In this process, the user can choose which rating or which multiplier to used for the post-contingency flow. The output of such a study is a base case which keeps the flow after contingencies under a user-defined level. The other option is to use the post-contingency rescheduling based on Bender’s decomposition as described in [20] and [21]. The approach here is to formulate a sub-problem according to a minimized deviation from the initial generation profile and to solve this using the permitted free rescheduling options given. Based on the result of this optimization, a new constraint may be formulated indicating how the base case problem could be changed to make the sub-problem feasible. This constraint is known as Bender’s Cut [20]. Both these approaches for taking into account the contingencies, have demonstrated excellent performance. Several optimization packages are available under this scheme and depending on the formulation it may be convenient to use LP, QP, MILP or Barrier. For large systems, the computation time may be significant since this will involve a large number of optimization cases. Solvers available are LPSOLVE [23], COIN [24] and GLPK [25]. An option is also to use Interior solvers interface through CVXOPT [7]. IV. C ONCLUSION The paper describes an implementation of a set of library functions for power system analysis. It is implemented in Python and contains standard modules such as: AC Power Flow, Decoupled, Decoupled Power Flow, Continuation Power Flow, Contingency Analysis and Security-constrained Economic Dispatch. The data representation is object-oriented and this is also true for the design of the modules. The Python library is interfaced to a spreadsheet in CSV-format. The modules are tested on the following test systems: IEEE 9-bus, IEEE 14-bus, IEEE 30-bus and the IEEE 118-bus systems. The modules implemented are verified to give the same voltage profiles and power flow results as the ones published in the literature on these systems. The main features of this library is its flexibility as it provides a framework for rapid development of new tools, expansion of functionalities of existing techniques, and for modelling new electrical components to enhance utilization of the power system. The common data structure with the object-oriented design is a main contributor to the flexibility as it makes it possible to work on local copies and to compare alternatives. The number of specialized solvers make it possible to choose the right solver for the current case and by this it may reduce the computation time significantly. In addition, it increases the portability between different operating systems and between Python versions as there may be delays in development on different platforms. R EFERENCES [1] Federico Milano - PSAT and DOME: http://faraday1.ucd.ie/software.html [2] Thomas Brown, Jonas Hörsch, David Schlachtberger: PyPSA: Python for Power System Analysis, https://openresearchsoftware.metajnl.com/articles/10.5334/jors.188/ [3] MATPOWER: https://matpower.org/ [4] Fosso, Olav Bjarte: Power System Operation in Normal and Alert State with emphasis on steady state security assessment and control., Dr.ingthesis, Te Norwegian Institute of Technology (NTH), March 1989, ISBN 82-7119-090-3. [5] O. Alsac ; B. Stott ; W. F. Tinney: Sparsity-Oriented Compensation Methods for Modified Network Solutions,DOI: 10.1109/TPAS.1983.318045, IEEE Transactions on Power Apparatus and Systems ( Volume: PAS102 , Issue: 5 , May 1983 ) [6] S, Pissanetzky, Sparse Matrix Technology, Academic Press, 1984. [7] CVXOPT - Python Software for Convex Optimization - https://cvxopt.org/ [8] Gerald T. Heydt, Computer Analysis Methods for Power Systems, Macmillan Publishing Company, 1986, ISBN 0023528605, 9780023528606 [9] Stott, B. and Alsac, O. Fast Decoupled Load Flow. IEEE Transactions on Power Apparatus and Systems, PAS-93, 859-869, 1974 [10] A.J. Monticelli ; A. Garcia ; O.R. Saavedra, Fast decoupled load flow: hypothesis, derivations, and testing, DOI: 10.1109/59.99396, IEEE Transactions on Power Systems ( Volume: 5 , Issue: 4 , Nov. 1990 ) [11] EPRI EL-5291 Vol 1-2, Jan. 1988: Reliability Evaluation for LargeScale Bulk Transmission Systems [12] V. Ajjarapu, C. Christy: The continuation power flow: a tool for steady state voltage stability analysis, DOI: 10.1109/59.141737, IEEE Transactions on Power Systems ( Volume: 7 , Issue: 1 , Feb. 1992 ) [13] Olav B. Fosso, Continuation Power Flow – Applications, Implementation and Experiences, DOI: 10.13140/RG.2.2.28752.30720, ResearchGate, October 2016. [14] Brian Stott, Eric Hobson: Power System Security Control Calculations Using Linear Programming, Part I and 2, IEEE Transactions on Power Apparatus and Systems ( Volume: PAS-97 , Issue: 5 , Sept. 1978) [15] B. Stott ; J.L. Marinho ; O. Alsac: Review Of Linear Programming Applied To Power System Rescheduling, DOI: 10.1109/PICA.1979.720058, IEEE Conference Proceedings Power Industry Computer Applications Conference, 1979. PICA-79. View publication stats [16] B. Stott ; O. Alsac ; A.J. Monticelli: Security analysis and optimization, DOI: 10.1109/PROC.1987.13931, Proceedings of the IEEE ( Volume: 75 , Issue: 12 , Dec. 1987 ) [17] Brian Stott, Jorge Jardim, Ongun Alsaç: DC Power Flow Revisited, IEEE TRANSACTIONS ON POWER SYSTEMS, VOL. 24, NO. 3, AUGUST 2009 [18] A.J. Wood and B.F. Wollenberg: Power Generation, Operation and Control New York: Wiley, 1996. [19] Henrik Ronellenfitsch, Marc Timme, Dirk Witthaut: A Dual Method for Computing Power Transfer Distribution Factors, DOI: 10.1109/TPWRS.2016.2589464, arXiv:1510.04645 [cs.SY] [20] Pereira M.V.F, Monticelli, A., Pinto L.M- .V.G. :, Security-Constrained Dispatch with Corrective Rescheduling, IFAC 1985, Rio de Janeiro, Brazil. [21] Granville, S., Pereira, M.V.F., Dantzig, G.B., Avi-Itzhak, B., Avriel, M., Monticelli, A., and Pinto, L.M.V.G. Mathematical decomposition techniques for power system expansion planning: Volume 1, Decomposition methods and uses: Final report, Volume 2. Analysis of the linearized power flow model using the bender decomposition technique, Volume 3. An integrated methodology for VAR sources planning, Volume 4. Security-constrained optimal power flow with post-contingency corrective rescheduling, Volume 5. Use of parallel computers for multi-area expansion planning : preliminary results. United States: N. p., 1988. [22] Florin Capitanescu, Louis Wehenkel: A New Iterative Approach to the Corrective Security-Constrained Optimal Power Flow Problem, IEEE TRANSACTIONS ON POWER SYSTEMS, VOL. 23, NO. 4, NOVEMBER 2008. [23] LPSOLVE- Reference Guide: http://lpsolve.sourceforge.net/5.5/ [24] COIN-OR Documentation: https://www.coin-or.org/documentation.html [25] GLPK GNU Linear Programming Kit: https://www.gnu.org/software/glpk/
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )