% Vztazny vykon [MVA]]
Sv=255

% Vztazne napeti [kV]]
Uv=215

% Napeti jemnovite na vedeni [kV]]
Uns=248

% Napeti jemnovite generatoru vedeni [kV]]
Ung=10.5;

% Transformator T1 Snt1 360 MVA, Uk1 12%, p1 Ung/Uns kV
Snt1=360
Uk1=12
p1=Ung/Uns
Xt1=(Uk1/100)*(Uns^2/Snt1)*(Sv/Uv^2)

% Transformator T2 Snt2 340 MVA, Uk2 12%, p2 220/121 kV
Snt2=340
Uk2=12
p2=220/121
Xt2=(Uk2/100)*(220^2/Snt2)*(Sv/Uv^2)

% Napeti site
Us=118/Uv*p2

% Vykony dodavane do site Ps 220 MW, CosFi 0.9
Ps=225/Sv
Qs=Ps*tan(acos(0.9))

% Generator Sng 400 MVA, Ung 10.5 kV, Xdc 23.5%, X2 16.4 %
Sng=400;
Xdc=(23.5/100)*(Ung^2/Sng)*(Sv/Uv^2)*(Uns^2/Ung^2)
X2=(16.4/100)*(Ung^2/Sng)*(Sv/Uv^2)*(Uns^2/Ung^2)
Tm=7*Sng/Sv

% Vedeni Xv 0.4 Ohm/km
delka=255
Xv=0.5*delka*0.4*(Sv/Uv^2)
Xv0=3*Xv

% Zatez Pz 50 MW CosFi 0.85
Pz=50/Sv
Qz=Pz*tan(acos(0.85))

% Vnejsi reaktance
Xvn=Xt1+Xv+Xt2

% Svorkove napeti generatoru
Ug=sqrt((Us+Xvn*Qs/Us)^2+(Xvn*Ps/Us)^2)
FiS=atan((Xvn*Ps/Us)/(Us+Xvn*Qs/Us))*180/pi
FiS2=asin((Xvn*Ps/Us)/Ug)*180/pi

% Impedance zateze
Zz=Ug^2/(Pz-i*Qz)

% Jalove ztraty na vnejsi reaktanci
deltaQvn=Xvn*(sqrt(Ps^2+Qs^2)/Us)^2

% Vystupni vykon generatoru
Pg=Pz+Ps
Qg=Qz+Qs+deltaQvn
Sg=Pg+i*Qg

% Prechodne elektromotoricke napeti generatoru
Uec=sqrt((Ug+Xdc*Qg/Ug)^2+(Xdc*Pg/Ug)^2)
deltaFi=atan((Xdc*Pg/Ug)/(Ug+Xdc*Qg/Ug))*180/pi
deltaFi2=asin((Xdc*Pg/Ug)/Uec)*180/pi

% Uhel mezi Uec a Us
Fi=FiS+deltaFi

% Vlastni a vzajemne nahradni vypoctove impedance a admitance
% Bezporuchovy stav
Z11=i*Xdc+i*Xvn*Zz/(i*Xvn+Zz)
Y11=1/Z11
Y11abs=abs(Y11)
Y11faze=angle(Y11)*180/pi
Z12=i*Xdc+i*Xvn+i*Xdc*i*Xvn/Zz
Y12=1/Z12
Y12abs=abs(Y12)
Y12faze=angle(Y12)*180/pi

% Priprava zpetne nahradni impedance
Zz2=0.35*Zz
Z2=1/(1/(i*Xt1+1/(1/(i*X2)+1/Zz2))+1/(i*Xv+i*Xt2))

% Priprava netocive nahradni impedance
Z0=1/(1/(i*Xt1)+1/(3*i*Xv+i*Xt2))

% Ekvivalentni impedance
Zekv=1/(1/Z2+1/Z0)

% Urceni nahradnich poruchovych impedanci metodou jednotkoveho proudu
I4=1
Ub=I4*(i*Xv+i*Xt2)
I6=Ub/Zekv
I2=I4+I6
deltaU2=I2*i*Xt1
Ua=Ub+deltaU2
I5=Ua/Zz
I1=I2+I5
deltaU1=I1*i*Xdc
UecPom=Ua+deltaU1
Z11c=UecPom/I1
Y11c=1/Z11c
Y11cabs=abs(Y11c)
Y11cfaze=angle(Y11c)*180/pi
Z12c=UecPom/I4
Y12c=1/Z12c
Y12cabs=abs(Y12c)
Y12cfaze=angle(Y12c)*180/pi

% Urceni nahradnich impedanci po vypnuti
Xvncc=Xt1+2*Xv+Xt2
Z11cc=i*Xdc+i*Xvncc*Zz/(i*Xvncc+Zz)
Y11cc=1/Z11cc
Y11ccabs=abs(Y11cc)
Y11ccfaze=angle(Y11cc)*180/pi
Z12cc=i*Xdc+i*Xvncc+i*Xdc*i*Xvncc/Zz
Y12cc=1/Z12cc
Y12ccabs=abs(Y12cc)
Y12ccfaze=angle(Y12cc)*180/pi
