/Multi-machine-System-Analyzer

A program to calculate Oscillation modes for the IEEE-WSCC (Western System Coordinating Council) multi-machine system.

Primary LanguagePythonMIT LicenseMIT

Small Signal Stability Analysis Project for Multi-Machine Power Systems

Description

This repository contains a Python project designed to analyze small signal stability in multi-machine power systems. The project is structured into three main modules, each focusing on a specific phase of the analysis.

Modules

  1. Calculation of Nodal Admittance Matrix (Y bus)

    • This module calculates the nodal admittance matrix necessary for stability analysis. It takes in a numpy array with system line information and the number of nodes in the system. The Ybus matrix is a complex matrix representing the admittance between nodes in the system.
  2. Power Flow Calculation using Newton-Raphson Method

    • This module implements the Newton-Raphson method for power flow calculation in the multi-machine power system. It uses the Newton-Raphson method to calculate the power flow in the system.
  3. Determination of Oscillation Modes and Associated Graphs

    • In this module, the system's oscillation modes are determined, and graphs are generated for visualization. It uses the Ybus matrix and power flow information to perform the calculations.

Technologies Used

  • Python
  • Libraries: pandas, numpy, matplotlib, among others.

Ybus Matrix Calculation Module (y_bus.py)

This module is responsible for creating the Ybus matrix from a given numpy array that contains the Power System (PS) information. The Ybus matrix is a fundamental element in power system analysis, particularly in load flow studies.

Description

The Ybus class in this module takes in a numpy array with system line information and the number of nodes in the system. It calculates the Ybus matrix, which is a complex matrix representing the admittance between nodes in the system.

Usage

  1. Import the Ybus class from the y_bus.py module.

    from y_bus import Ybus
  2. Create a numpy array with system line information and specify the number of nodes.

    path = 'nodes.xlsx'
    nodes = pd.read_excel(path)
    n_nodes = max(nodes.NodoRec.max(), nodes.NodoEnv.max())
    impedances = nodes.to_numpy()
  3. Instantiate the Ybus class with the system line information and the number of nodes.

    ybus = Ybus(impedances, n_nodes)

Note

The numpy array with system line information should have the following structure:

  • The first two columns represent the sending and receiving nodes, respectively.
  • The third and fourth columns represent the resistance and reactance, respectively.
  • The last column represents the shunt admittance. The Ybus class calculates the off-diagonal and diagonal elements of the Ybus matrix based on this information.

Power Flow Calculation Module (power_flow.py)

This module is responsible for calculating the power flow for a given Electrical Power System. It uses the Newton-Raphson method for power flow calculation in the multi-machine power system.

Description

The PowerFlow class in this module takes in system line information, the number of nodes, nodal system powers, the number of generator nodes including the Slack node, and the magnitude voltage values for Slack and PV nodes. It calculates the power flow for the given system.

Usage

  1. Import the PowerFlow class from the power_flow.py module.

    from power_flow import PowerFlow
  2. Create a numpy array with system line information and specify the number of nodes, nodal system powers, the number of generator nodes including the Slack node, and the magnitude voltage values for Slack and PV nodes.

    path = 'nodes.xlsx'
    lines = pd.read_excel(path)
    n_nodes = max(lines.NodoRec.max(), lines.NodoEnv.max())
    impedances = lines.to_numpy()
    nodes = pd.read_excel(path, sheet_name='power')
    powers_array = nodes.to_numpy(dtype=np.complex_)[:, 1].reshape((len(nodes['Node']), 1))
    gen_nodes = 3
    initial_voltages = [1.04, 1.025, 1.025]
  3. Instantiate the PowerFlow class with the system line information, the number of nodes, nodal system powers, the number of generator nodes, and the magnitude voltage values for Slack and PV nodes.

    power_flow = PowerFlow(impedances, n_nodes, powers_array, gen_nodes, initial_voltages)
  4. Call the export_data method to export the power flow data to an Excel file.

    power_flow.export_data(path)

Multi-Machine System Analysis Module (multi_machine_sys.py)

This module is responsible for calculating the oscillation modes for the IEEE-WSCC multi-machine system for a 9 nodes system. It uses the Ybus matrix and power flow information to perform the calculations.

Description

The MultiMachine class in this module takes in the total system nodes, Ybus system matrix, power flow information, generator information, load nodes, and system frequency. It calculates the oscillation modes for the given system.

Usage

  1. Import the MultiMachine class from the multi_machine_sys.py module.

    from multi_machine_sys import MultiMachine
  2. Create a numpy array with system line information and specify the number of nodes, nodal system powers, the number of generator nodes including the Slack node, and the magnitude voltage values for Slack and PV nodes.

    path = 'nodes.xlsx'
    nodes = pd.read_excel(path, sheet_name='lines')
    n_nodes = max(nodes.NodoRec.max(), nodes.NodoEnv.max())
    nodes_array = nodes.to_numpy()
    y_bus = Ybus(nodes_array, n_nodes).get_Ybus()
    power_flow = pd.read_excel(path, sheet_name='PowerFlow', dtype=np.complex_, index_col=0)
    power_flow = power_flow.to_numpy(dtype=np.complex_)
    loads_nodes = [5, 6, 8]
    gen_info = pd.read_excel(path, sheet_name="GenInfo")
    gen_info = gen_info.to_numpy()
  3. Instantiate the MultiMachine class with the system line information, the number of nodes.

    mmachine_sys = MultiMachine(n_nodes, y_bus.copy(), power_flow, gen_info, loads_nodes)
  4. Call the plot_oscillation_modes method to plot the oscillation modes for the given system.

    mmachine_sys.plot_oscillation_modes()
  5. Call the get_oscillation_modes method to get the oscillation modes for the given system.

    print("Oscillation Modes: \n", mmachine_sys.get_osscilation_modes().reshape((9, 1)))

Contributions

Contributions are welcome! Here are a few ways you can help:

  1. Report bugs: If you find a bug, please create a new issue in the GitHub issue tracker. Describe the problem in detail so that it can be reproduced. Include information about your operating system and Python version.

  2. Suggest enhancements: If you have an idea for a new feature or an improvement to an existing feature, please create a new issue in the GitHub issue tracker. Describe your idea in detail and explain how it would benefit the project.

  3. Contribute code: If you're able to write code and want to fix a bug or implement a new feature, we would be happy to accept your contribution. Here's how you can do it:

    • Fork the repository on GitHub.
    • Clone your forked repository to your local machine.
    • Create a new branch for your changes.
    • Write the code for your changes. Make sure to follow the existing coding style and comment your code.
    • Test your changes to ensure they work correctly and don't introduce new bugs.
    • Commit your changes and push them to your forked repository.
    • Submit a pull request with your changes.

    Please note that by contributing code, you agree to license your contribution under the terms of the MIT license.

  4. Improve documentation: Good documentation is just as important as good code. If you can improve the README, add comments to the code, or write tutorials or guides, your contribution would be very valuable.

Remember, the best way to get your changes included is to submit a pull request. We look forward to your contributions!

License

This project is licensed under the MIT License - see the LICENSE file for details.