PFA – Power Flow Analysis of Power System in C++ Visual Sudio

Research work Nº1 – POWER I “EE-353”
Introduction
This is an undergraduate research work, assigned to me when I took the Power I course at the National University of Engineering (Lima-Peru), in the year 2000, which consisted in doing an academic level study of the power flow of an electrical power system of 7 busbars, 2 generators, 2 transformers and 2 loads.
In order for each student to have a unique solution and to ensure that each student would work on his own “without copying from another classmate”, the professor chose to make the electrical parameters of the system dependent on the digits of the student’s UNI ID.
The initial idea was to solve the power system in Visual C++, with a friendly user interface to enter the electrical parameters, but due to tight deadlines the Visual C++ project was left unfinished and was shelved, opting for plan B which was to code all the power flow resolution algorithms of the electrical system in a Matlab script.
In the year 2024, after almost 24 years, I have completed the software in Visual C++, as I wanted to present it to the professor at the time.
Problem to solve
In the electrical system shown,
Determine:
a) The voltages in all the buses in kV and d
b) The power flow in MW and MVAR through the power lines
c) The balance of active and reactive power of the network (MW and MVAR)

Technical aspects
The same program has been developed in 2 different languages: Matlab and Visual C++, that solves the load flow of an electrical power system at an academic level, using systems of matrix equations in complex variable and the Newton-Raphson iterative numerical method to quickly reach the solution.
PFA Power Flow Analysis – Visual C++ version
PFA Power Flow Analysis – Matlab version
You can download the software executable for FREE from here:
Get the SOURCE CODE of “PFA software” and increase your programming experience:
Source code available in Matlab (.m file) and in Visual C++ 2017 project.
By exploring the source code you will learn:
- Get access to the research work document in PDF format (30 pages). Includes original version in Spanish language and version in English language.
- Data entry of the electrical parameters of the system, resistances, impedances, voltage levels, generator powers and active and reactive powers of the loads.
- Swing bus definition.
- Initial scaling: Conversion of the nominal values of the electrical parameters to unit values, or pu values.
- Creation of the admittance matrix of the electrical power system.
- Creation of the Jacobian matrix in complex variable, to apply the Newton-Raphson iterative method.
- Solving the power flow, from a system of matrix equations in complex variable, using the Jacobian matrices and the Newton-Raphson algorithm.
- Final scaling: Conversion of unit or pu values to nominal values of all electrical parameters and unknowns of the system.
- Reporting of the system unknowns: such as current and voltages in each bus of the system.
Developed by:
YACSHA – Software & Desing, since 1999, Lima – Perú
The World of Chaos – EL MUNDO DEL CAOS – Unlimited Programming
HISTORY
Version 2 – 20-VI-2024
- Porting to VC++ 2017 – rev1
- Improvement: The CMatrix class is renamed CMatrixT, which is a template class, which allows working with elements of the type specified in the template. In addition, the .h and .cpp files are merged into a single hpp file.
- Improvement: The CMatrix class is used to work with matrix with elements of the complex type and also to work with matrix with elements of the double type.
- Fix: Dynamically created CMatrixT objects are deleted, because these were never destroyed. Now they are declared as temporary variables that expire at the end of the function where they are created, and that are returned by value in their respective method.
- CMatriz is renamed to CMatrix
- Improvement: The code that solves the power flow problem “Trabajo-Potencia I.pdf” from Matlab “SEP(Potencia I MATLAB).m” has been migrated to C++. Which was unfinished in the original C++ program.
- Improvement: The data type of matrix containers is optimized. Some matrices were defined as complex type, when in reality they only needed to be defined as double type.
- Improvement: The CalculateEPSParameters method is created to calculate the parameters of the electrical power system, required before starting the power flow calculation.
- Improvement: The CalculatePowerFlow method is created to calculate the Power Flow. This calculation is migrated from its previous location in CPFADlg::OnCalcular().
- Improvement: The PowerFlowAnalisys class is created to contain all calculations related to power flow.
- Improvement: An icon is added for the program, which corresponds to the symbol of an alternating current generator.
- Improvement: Added credits and software information in the main interface and in the “About” dialog box
- Improvement: The example electrical system is drawn and inserted in the main dialog box, as a bitmap in 256 colors, so that the user can be guided on how to enter the data.
- Improvement: A control is inserted to recalculate the input parameters according to the UNI code entered, since the teacher did it this way so that people do not copy and each student has different solutions
- Improvement: The main dialog box user interface controls are created to enter the input parameters of the Electrical Power System
- Improvement: Added the project calculations report in C++ and Matlab (calculations.txt)
- Improvement: English and Spanish versions of the document “Research Work Potencia I (Power Flow of an EPS)” are included, which includes the statement of the problem to be solved, the subject of this research work.
- Improvement: The project is reordered and separated into PFA-cpp, which includes the project in Visual C++; PFA-Matlab, which includes the project in Matlab and Documents, which contains the documentation of the research work of this project.
- The calculations.txt report is generated in English
- Improvement: Research Work Documents are updated. A date is added to the first page, and the submission date of the final part of the document is updated. The teacher’s full name is added.
Version 1 – 09-X-2000
- Original version for VC++ 6.0