IEEE39节点潮流计算代码
时间: 2023-11-13 14:25:52 浏览: 143
matlab里面matpower3.2包,可以解决各个节点的电力潮流计算,例如9节点、14节点、30节点、39节点等等
5星 · 资源好评率100%
以下是Python实现IEEE39节点潮流计算的代码示例:
```python
import numpy as np
# 负荷数据
Pd = np.array([0.0, 21.7, 2.4, 7.6, 94.2, 0.0, 22.8, 30.0, 0.0, 5.8, 11.2, 6.2, 8.2, 3.5, 9.0, 3.2, 9.5, 2.2, 17.5, 0.0, 3.2, 2.3, 0.0, 2.3, 3.5, 2.4, 0.0, 0.0, 0.0, 0.0, 2.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
Qd = np.array([0.0, 12.7, 1.2, 1.6, 19.0, 0.0, 10.9, 0.0, 0.0, 1.8, 7.5, 1.6, 2.5, 1.8, 3.9, 0.9, 2.2, 0.7, 11.2, 0.0, 1.6, 1.2, 0.0, 0.9, 1.8, 1.2, 0.0, 0.0, 0.0, 0.0, 0.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
# 发电机数据
Pg = np.array([0.0, 0.0, 40.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
Vg = np.array([1.060, 1.045, 1.010, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
# 线路数据
Z = np.array([[0.0, 0.0576+0.088j, 0.0586+0.092j, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0576+0.088j, 0.0, 0.013+0.019j, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0586+0.092j, 0.013+0.019j, 0.0, 0.0493+0.073j, 0.047+0.07j, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0493+0.073j, 0.0, 0.0312+0.046j, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.047+0.07j, 0.0312+0.046j, 0.0, 0.0581+0.0845j, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0581+0.0845j, 0.0, 0.0119+0.0172j, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0119+0.0172j, 0.0, 0.0234+0.0338j, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0234+0.0338j, 0.0, 0.0454+0.068j, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0454+0.068j, 0.0, 0.0162+0.0214j, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0162+0.0214j, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]])
Y = np.linalg.inv(Z)
# 节点导纳矩阵
n = Pd.size
Ybus = np.zeros((n,n), dtype=complex)
for i in range(n):
for j in range(n):
if i == j:
for k in range(n):
Ybus[i,j] += Y[i,k]
else:
Ybus[i,j] = -Y[i,j]
# 潮流计算
tolerance = 1e-6
max_iter = 50
iter_count = 0
converged = False
V = Vg
while iter_count < max_iter and not converged:
iter_count += 1
P = np.zeros(n)
Q = np.zeros(n)
for i in range(n):
for j in range(n):
P[i] += V[i]*np.conj(V[j])*Ybus[i,j].real
Q[i] += V[i]*np.conj(V[j])*Ybus[i,j].imag
P[i] -= Pg[i]
Q[i] -= Qd[i]
deltaPQ = np.concatenate((P[1:], Q[1:]))
mismatch = np.max(np.abs(deltaPQ))
if mismatch < tolerance:
converged = True
else:
J11 = np.zeros((n-1, n-1))
J12 = np.zeros((n-1, n-1))
J21 = np.zeros((n-1, n-1))
J22 = np.zeros((n-1, n-1))
for i in range(1,n):
for j in range(1,n):
J11[i-1,j-1] = -V[i]*V[j]*Ybus[i,j].imag
J12[i-1,j-1] = V[i]*Ybus[i,j].real
J21[i-1,j-1] = V[i]*Ybus[i,j].imag
J22[i-1,j-1] = V[i]*Ybus[i,j].real
J = np.concatenate((np.concatenate((J11, J12), axis=1), np.concatenate((J21, J22), axis=1)), axis=0)
deltaV = np.linalg.solve(J, deltaPQ)
V[1:] += deltaV[:n-1] + 1j*deltaV[n-1:]
if converged:
print('潮流计算收敛!')
print('节点电压幅值:', np.abs(V))
print('节点相角:', np.angle(V)/np.pi*180)
for i in range(n):
P[i] = V[i]*np.conj(np.sum(V*Ybus[i,:]))
Q[i] = V[i]*np.conj(np.sum(V*Ybus[i,:]*1j))
print('有功功率:', P)
print('无功功率:', Q)
else:
print('潮流计算未收敛!')
```
该代码实现了IEEE 39节点系统的潮流计算,通过迭代法求解节点电压幅值和相角,计算各节点的有功和无功功率。在求解过程中,需要注意潮流计算是否收敛的问题,一般采用误差判断法或迭代次数限制法来判断。
阅读全文