-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathY_Bus_MAtrix.py
115 lines (99 loc) · 3.02 KB
/
Y_Bus_MAtrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
nb=int(input("Enter the number of buses including reference bus :"))
ne=int(input("Enter the number of elements :"))
nla=int(input("Enter the number of elements have line charging admittance :"))
mat=[]
lca=[]
ybus=[]
def end1():
print ("INVALID DATA !")
exit()
for i in range(nb):
ybus.extend([[0]])
for j in range(nb-1):
ybus[i].extend([0])
#print(ybus)
if nla>0:
opl=input("Enter whether the line charging values are line charging admittance or half line charging admittance (LA/HLA) :")
if((opl!='la'and opl!='LA') and(opl!='hla'and opl!='HLA')):
end1()
opa=input("Enter whether the line charging values are in Impedance or Admittance (Z/Y) :")
if((opa!='z'and opa!='Z') and(opa!='y'and opa!='Y')):
end1()
op=input("Enter whether the values are in Impedance or Admittance (Z/Y) :")
if((op!='z'and op!='Z') and(op!='y'and op!='Y')):
end1()
print("Enter the connections between buses :")
print("-------------------")
for i in range(ne):
F=int(input("FROM :"))
T=int(input("TO :"))
if F==T:
End1()
X=float(input("Real Part :"))
Y=float(input("Imaginary part :"))
Vr=complex(X,Y)
if (op=='z'or op=='Z'):
V=1/Vr
if (op=='y'or op=='Y'):
V=Vr
mat.extend([[F,T,V]])
print("-------------------")
for i in range(ne):
print(mat[i])
print ("*******************")
for i in range(nla):
f=int(input("FROM :"))
t=int(input("TO :"))
if t==f:
end1()
x=float(input("Real Part :"))
y=float(input("Imaginary part :"))
vr=complex(x,y)
if (opa=='z'or opa=='Z'):
v=1/vr
if (opa=='y'or opa=='Y'):
v=vr
if (opl=='la' or opl=='LA'):
v=vr/2
lca.extend([[f,t,v]])
print("-------------------")
for i in range(nla):
print(lca[i])
print ("*******************")
for k in range(nb+1):
for I in range(ne):
for j in range(2):
if(k==mat[i][j]):
#print(mat[i][j],"@@@@@@@@@",k)
ybus[k-1][k-1]=ybus[k-1][k-1]+mat[i][2]
for i in range(1,nb+1):
for j in range(1,nb+1):
if i!=j:
for a in range(ne):
#print(I,j, "₹₹₹₹",mat[a][0],mat[a][1])
if(i==mat[a][0])and(j==mat[a][1]):
#print(I,j,"::::::",mat[a][0],mat[a][1])
ybus[i-1][j-1]=(-1)*mat[a][2]
ybus[j-1][i-1]=(-1)*mat[a][2]
for u in range(nla):
for v in range(2):
for i in range(1,nb+1):
for j in range(1,nb+1):
#print(I,j,"-----"",u,v)
if (i==lca[u][v]or j==lca[u][v]):
#print(I,j,"++++++",u,v)
ybus[i-1][j-1]=ybus[i-1][j-1]+lca[u][2]
n=0
for i in range(ne):
for j in range(2):
#print(I,j)
if mat[i][j]==0:
n=1
break
if n==1:
for i in range(nb-1):
del ybus[i][nb-1]
del ybus[nb-1]
print("Y bus :")
for i in range(nb-n):
print(ybus[i])