Try frequency control simulation with Python

Introduction

I recently read a book called "Introduction to Control Engineering with Python". I'd like to try the Python-Control that comes out in it, so I'm going to try a frequency control simulation. Although it is included in the title of control, the main topic is power engineering.

・ Explanation of power system and frequency control ・ Try using Python-Control

It will be the contents.

What is frequency

The 100V electricity we use at home is not always 100V, but vibrates at regular intervals as shown in the figure below. At this time, the time change of voltage $v(t) = 100\sqrt 2 \sin(2\pi f t)  [\rm{V}]$ Is expressed as. Here, $ f \ $ is called frequency and represents how many times it vibrates per second. And this frequency is 50Hz in eastern Japan and 60Hz in western Japan. image.png

For those who use electricity, the frequency of electricity is often treated as constant at 50 or 60Hz. However, the actual frequency is constantly changing, and if the frequency changes significantly, it may adversely affect electrical equipment. Therefore, the operator of the power system (that is, the power company) needs to control the frequency so that it does not fluctuate significantly.

Relationship between supply and demand balance and frequency

Power system supply and demand

Before explaining why the frequency fluctuates, let's first briefly explain the power system. The power system consists of a power plant that supplies power, consumers who consume power, and a transmission and distribution network that connects them. An important property of the power system is the principle of "simultaneous equal amount" (because electricity is difficult to store), where the power $ P_G $ supplied and the power $ P_L $ consumed must always match. However, the side that uses electricity (customers) wants to use as much electricity as they want, when they want, so the power plant must always match the generated power with the power consumption in order to achieve the same amount at the same time.

image.png

So how does the power plant adjust the generated power to the power consumption? It is not possible to grasp the power consumption of all consumers in real time. Therefore, ** frequency control ** becomes important.

Generator sway equation

The types of power plants are thermal power, hydroelectric power, and nuclear power generation. Recently, solar power generation and wind power generation are increasing, but I will not think about it this time. These power generation methods differ only in the part of how to obtain rotational energy (mechanical energy), but all the parts that convert mechanical energy to electrical energy are the same, and a "synchronous generator" is used. image.png As shown in the figure, by installing a generator on the same axis as the steam turbine, the mechanical output of the turbine is converted into electrical energy. At this time, the following relationship holds between the rotation speed of the rotor $ \ omega_m \ [\ rm {rad / s}] $ and the frequency $ f \ [\ rm {Hz}] $ of the voltage induced by the generator. I will. $\omega_m=2\pi f/p$ Here, $ p $ is called the pole logarithm, and it has a fixed value depending on the generator ($ p = 1 $ is often used for thermal power). Therefore, the electrical frequency and the rotation speed of the generator / turbine are the same. Since the frequency is the same value for the entire power system, all the generators connected to the system rotate at the same speed. In other words, controlling the number of revolutions of a generator is the same as controlling the frequency of the entire power system. The change in the rotation speed (= frequency) of the generator is expressed by the following ** sway equation **. $M\frac{df}{dt}=P_m-P_g$ Here, $ M $ is called the inertia constant and is a parameter like the moment of inertia of a rotating body. The value of the mechanical output $ P_m $ is a controllable value determined by the flow rate of steam, etc., but the electric output $ P_g $ is determined by the power demand $ P_L $ of the power system ($ P_g if the system loss is ignored). = P_L $). From this sway equation, the following can be said.

-When $ P_m> P_g $, the frequency rises (oversupply) -When $ P_m = P_g $, the frequency is constant (supply and demand are balanced) -When $ P_m <P_g $, the frequency drops (insufficient supply)

In other words, it is necessary to measure the frequency of the power system, decrease the output of the generator when the frequency increases, and increase the output of the generator when the frequency decreases. Frequency control is feedback control that utilizes the relationship between supply and demand balance and frequency.

Overview of frequency control

Block Diagram

This time, let's consider the case where the generators of the entire power system are integrated into one unit. The block diagram of frequency control is as follows. The difference between the generator output and the load affects the frequency fluctuation. The system frequency characteristics in the figure take into account the frequency characteristics of the load in addition to the inertia of the generator. There are two main types of feedback loops, local control loops and global control loops.

image.png

Local control

In the local control loop, the generator governor (governor) measures the frequency and adjusts the amount of steam flowing into the turbine according to the frequency deviation. This makes it possible to maintain a balance between supply and demand even when the load fluctuates. However, even if the supply-demand balance can be maintained with only local control, the frequency will converge to a value deviated from $ 50 \ rm {Hz} $ due to a steady-state deviation.

Global control

Global control is controlled from the central power supply command center, which manages the power plant. The frequency deviation will occur only with local control, but here we will use integral control to command each generator to return the frequency to $ 50 \ rm {Hz} $ (this time one generator). ).

In addition, although simple integral control is used this time, the output is determined by comprehensively considering the speed characteristics and fuel cost of each generator in the actual system.

Try using Python-Control

I referred to this article for how to use Python-Control. Get the response to the sine wave with PythonControl.

Calculate transfer function

Now, I would like to simulate the frequency fluctuation with respect to the load fluctuation in Python. The sample code is put together at the end. First, as shown in the figure below, the control block is simplified and represented by a single transfer function. Using Python-Control makes it easier to handle transfer functions. image.png

Condition setting

The simulation time is 100 seconds and the step is 0.01 seconds. It is assumed that the load fluctuation will increase by 10% 10 seconds after the start of the simulation. image.png

simulation

Shows the time change of frequency deviation when load fluctuation is applied. The first is for local control only ($ K_I = 0 $). You can see that there is a steady-state deviation. image.png

Next is the case of adding global control. It came back to 50Hz properly. image.png

In this way, the power system constantly monitors the frequency and keeps adjusting the output of the power plant so that it can maintain 50Hz or 60Hz. However, it is difficult to control the output of renewable energy (wind power and solar power) power sources, which have been increasing in recent years, and this is a factor that reduces the frequency control capability. It seems that electric power companies are also struggling to cope with the ever-increasing number of renewable energy sources.

at the end

Actually, I wanted to make a simulation of the Hokkaido blackout in September 2018, but it was complicated and I didn't understand. So this time I tried the simplest frequency control one. I want to increase what I can do little by little.

If you are interested, please read this material. The frequency fluctuation just before the blackout is listed. What kind of phenomenon is blackout? -Institute of Electrical Engineers of Japan

Sample code

import numpy as np
from control.matlab import *
import matplotlib.pyplot as plt


def main():
    #parameter settings
    M = 10  #Inertia constant
    D = 2  #Dumping
    K_gov = 20  #Proportional control gain
    K_I = 2  #Integral control gain

    #Transfer function settings
    System_frequency = tf(1, [M, D])  #System frequency characteristics
    Governor = tf(K_gov, 1)  #Governor control block
    LFC = tf(K_I, [1, 0])  #LFC control block
    G = - feedback(System_frequency, Governor + LFC)  #System-wide transfer function

    #Simulation settings
    T = np.arange(0, 100, 0.01)  # 0~100 seconds
    dPL = np.array([0 if t < 10 else 0.1 for t in T])  #Load fluctuation setting(Step variation)

    #Calculation
    df, T, _ = lsim(G, dPL, T)

    #plot
    plt.figure(figsize=(9, 4))
    plt.plot(T, dPL)  #Load fluctuation
    plt.grid()
    plt.xlim(0, 100)

    plt.figure(figsize=(9, 4))
    plt.plot(T, (df+1)*50)  #Frequency deviation
    plt.grid()
    plt.xlim(0, 100)


if __name__ == '__main__':
    main()
    plt.show()

Recommended Posts

Try frequency control simulation with Python
Try scraping with Python.
Try Python output with Haxe 3.2
First neuron simulation with NEURON + Python
Try face recognition with Python
Try scraping with Python + Beautiful Soup
Try to operate Facebook with Python
Try singular value decomposition with Python
Try python
Try face recognition with python + OpenCV
Try to reproduce color film with Python
Try logging in to qiita with Python
Exclusive control with lock file in Python
Try mathematical formulas using Σ with python
Try working with binary data in Python
Try using Python with Google Cloud Functions
[Python / PyRoom Acoustics] Room acoustic simulation with Python
Create a word frequency counter with Python 3.4
Try HTML scraping with a Python library
Try calling Python from Ruby with thrift
Try drawing a map with python + cartopy 0.18.0
[ev3dev × Python] SSH Control (remote control with keyboard)
[Continued] Try PLC register access with Python
Try assigning or switching with Python: lambda
[For beginners] Try web scraping with Python
Statistics with python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
Python> try: / except:
AES256 with python
Tested with Python
python starts with ()
ambisonics simulation python
with syntax (Python)
Install Python Control
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
nginxparser: Try parsing nginx config file with Python
Try it with Word Cloud Japanese Python JupyterLab.
Try running Google Chrome with Python and Selenium
Try to solve the man-machine chart with Python
Precautions when dealing with control structures in Python 2.6
Try to make a "cryptanalysis" cipher with Python
Try to automatically generate Python documents with Sphinx
Try working with Mongo in Python on Mac
[Python3] [Ubuntu16] [Docker] Try face recognition with OpenFace
Let's control EV3 motors and sensors with Python
Try to make a dihedral group with Python
Try to detect fish with python + OpenCV2.4 (unfinished)
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
[Python] Try optimizing FX systole parameters with random search
Scraping with Python (preparation)
Learning Python with ChemTHEATER 03