1+ function [ sensitivity_of_H_to_U_taps_and_phasess ] = sensit_to_taps_and_phases( results , tap_changers , phase_shifters , Jacobian , tip_vozlisc)
2+ % sensit_to_taps_and_phases Calculates the first orded sensitivities of
3+ % regulated active powers and nodal voltages to taps and phases.
4+ % [sensitivity_of_H_to_U_taps_and_phasess] = sensit_to_taps_and_phases(results, tap_changers, phase_shifters, Jacobian , node_types)
5+ %
6+ % Inputs :
7+ % results: results from a runpf(), interanly idnexed (use ext2int())
8+ % tap_changers: tap changers data as in taps_and_phases_analysis()
9+ % phase_shifters: phase shifter data as in taps_and_phases_analysis()
10+ % Jacobian: power missmatch Jacobian matrix with the appropriate
11+ % ordering, rows go P1, Q1, P2, Q2...., columns go V1, delta1, V2,
12+ % delta2.....
13+ % tip_vozlisc: node types, 2 for PQ, 1 for PV, same as nubmer of
14+ % equations for each node, used for indexing
15+ %
16+ % Output :
17+ % sensitivity_of_H_to_U_taps_and_phasess : first order sensitivities
18+ % of p.u. changes in nodal votlages and line active powers to changes
19+ % in calculated taps and phases of transformers.
20+ %
21+ % by Gorazd Bone, Faculty of Electrical Engineering, Ljubljana
22+
23+ ind_node_eq = tip_vozlisc * 0 ;
24+ for k= 1 : size(tip_vozlisc ,1 )
25+ ind_node_eq(k ) = sum(tip_vozlisc(1 : k - 1 )) + 1 ;
26+ end
27+
28+ stevilo_tap_ch = size(tap_changers ,1 );
29+ stevilo_pha_sh = size(phase_shifters ,1 );
30+
31+ %% define named indices into bus, gen, branch matrices
32+ [PQ , PV , REF , NONE , BUS_I , BUS_TYPE , PD , QD , GS , BS , BUS_AREA , VM , ...
33+ VA , BASE_KV , ZONE , VMAX , VMIN , LAM_P , LAM_Q , MU_VMAX , MU_VMIN ] = idx_bus ; % #ok<*NASGU,*ASGLU>
34+ [F_BUS , T_BUS , BR_R , BR_X , BR_B , RATE_A , RATE_B , RATE_C , ...
35+ TAP , SHIFT , BR_STATUS , PF , QF , PT , QT , MU_SF , MU_ST , ...
36+ ANGMIN , ANGMAX , MU_ANGMIN , MU_ANGMAX ] = idx_brch ;
37+
38+ %% Define Partial derivative matrices
39+ % G is the LF problem power injection missmatch form (sum of nodal powers)
40+ GpoU = zeros(sum(tip_vozlisc ) , stevilo_tap_ch + stevilo_pha_sh ); % derivative of LF problem w.r.t. taps & phases
41+ GpoX = Jacobian ; % derivative of LF problem w.r.t. voltages and angles
42+ HpoU = zeros(stevilo_tap_ch + stevilo_pha_sh ); % derivative of criterion function w.r.t. taps & phases
43+ HpoX = zeros(stevilo_tap_ch + stevilo_pha_sh , sum(tip_vozlisc ));% derivative of criterion function w.r.t. voltages and angles
44+
45+ for k= 1 : stevilo_tap_ch % partial derivatives for taps
46+ veja = tap_changers(k ,1 );% tap branch
47+ reg_voz = tap_changers(k ,2 ); % ragulated node
48+ voz1 = results .branch(veja ,F_BUS );
49+ voz2 = results .branch(veja ,T_BUS );
50+ indeks_P1 = ind_node_eq(voz1 ); % active power and volt. amp index for f node
51+ indeks_P2 = ind_node_eq(voz2 ); % active power and volt. amp index for t node
52+ indeks_reg_voz = ind_node_eq(reg_voz );% volt. amp index for reg. node
53+
54+ Uvozi = results .bus(voz1 ,VM );
55+ Uvozj = results .bus(voz2 ,VM );
56+ di = results .bus(voz1 ,VA )/180 * pi ;
57+ dj = results .bus(voz2 ,VA )/180 * pi ;
58+ Z = results .branch(veja ,BR_R ) + 1i * results .branch(veja ,BR_X );
59+ Bsh = results .branch(veja ,BR_B );
60+ G = real(1 / Z );
61+ B = imag(1 / Z );
62+ tap = results .branch(veja ,TAP );
63+ ph = results .branch(veja ,SHIFT )/180 * pi ;
64+
65+ if tip_vozlisc(reg_voz ) == 1 % tap changer regulating PV node
66+ error_string = strcat(2 , ' Tap changer' , int2str(k ) , ' regulating the voltage of a PV node' );
67+ errordlg(error_string );
68+ return
69+ end
70+
71+ dPijdtap = (Uvozi *(-2 * G * Uvozi + G * tap * Uvozj * cos(di - dj - ph )+B * tap * Uvozj * sin(di - dj - ph )))/tap ^ 3 ;
72+ dPjidtap = (Uvozi * Uvozj *(G * cos(di - dj - ph )-B * sin(di - dj - ph )))/tap ^ 2 ;
73+ dQijdtap = (Uvozi *((2 * B + Bsh )*Uvozi - B * tap * Uvozj * cos(di - dj - ph )+G * tap * Uvozj * sin(di - dj - ph )))/tap ^ 3 ;
74+ dQjidtap = -((Uvozi * Uvozj *(B * cos(di - dj - ph )+G * sin(di - dj - ph )))/tap ^ 2 );
75+
76+ %% dG/dU
77+ GpoU(indeks_P1 , k ) = - dPijdtap ; % dGfrom / dtap
78+ if tip_vozlisc(voz1 ) == 2 % PQ type of node
79+ GpoU(indeks_P1 + 1 , k ) = - dQijdtap ;
80+ end
81+ GpoU(indeks_P2 , k ) = - dPjidtap ;% dGto / dtap
82+ if tip_vozlisc(voz2 ) == 2 % PQ type of node
83+ GpoU(indeks_P2 + 1 , k ) = - dQjidtap ;
84+ end
85+
86+ %% dH/dU
87+ HpoU(k ,k ) = 0 ;% odvod vozliscne napetosti po tap-u je 0
88+ if stevilo_pha_sh
89+ if find(phase_shifters(: ,1 ) == veja )
90+ HpoU(find(phase_shifters(: ,1 ) == veja ) + stevilo_tap_ch , k ) = dPijdtap ;% dLinePower / dtap - in case a phase shifter and tap changer are in the same line
91+ end
92+ end
93+
94+ %% dH/dX
95+ HpoX(k ,indeks_reg_voz ) = 1 ; % dRegNodeVolt / dVoltAmp = unity
96+ end
97+
98+ for k= 1 : stevilo_pha_sh % partial derivatives for phases
99+ veja = phase_shifters(k ,1 );% tap branch
100+ voz1 = results .branch(veja ,F_BUS );
101+ voz2 = results .branch(veja ,T_BUS );
102+ indeks_P1 = ind_node_eq(voz1 ); % active power and volt. amp index for f node
103+ indeks_P2 = ind_node_eq(voz2 ); % active power and volt. amp index for t node
104+
105+ Uvozi = results .bus(voz1 ,VM );
106+ Uvozj = results .bus(voz2 ,VM );
107+ di = results .bus(voz1 ,VA )/180 * pi ;
108+ dj = results .bus(voz2 ,VA )/180 * pi ;
109+ Z = results .branch(veja ,BR_R ) + 1i * results .branch(veja ,BR_X );
110+ Bsh = results .branch(veja ,BR_B );
111+ G = real(1 / Z );
112+ B = imag(1 / Z );
113+ tap = results .branch(veja ,TAP );
114+ ph = results .branch(veja ,SHIFT )/180 * pi ;
115+
116+ dPijdph = (Uvozi * Uvozj *(B * cos(di - dj - ph )-G * sin(di - dj - ph )))/tap ;
117+ dPjidph = -((Uvozi * Uvozj *(B * cos(di - dj - ph )+G * sin(di - dj - ph )))/tap );
118+ dPijUi = (2 * G * Uvozi - tap * Uvozj *(G * cos(di - dj - ph )+B * sin(di - dj - ph )))/tap ^ 2 ;
119+ dPijUj = -((Uvozi *(G * cos(di - dj - ph )+B * sin(di - dj - ph )))/tap );
120+ dPijdi = (Uvozi * Uvozj *(-B * cos(di - dj - ph )+G * sin(di - dj - ph )))/tap ;
121+ dPijdj = (Uvozi * Uvozj *(B * cos(di - dj - ph )-G * sin(di - dj - ph )))/tap ;
122+ dQijdph = (Uvozi * Uvozj *(G * cos(di - dj - ph )+B * sin(di - dj - ph )))/tap ;
123+ dQjidph = (Uvozi * Uvozj *(-G * cos(di - dj - ph )+B * sin(di - dj - ph )))/tap ;
124+
125+ %% dG/dU
126+ GpoU(indeks_P1 , k + stevilo_tap_ch ) = - dPijdph ;% dGfrom / dphase
127+ if tip_vozlisc(voz1 ) == 2 % PQ type of node
128+ GpoU(indeks_P1 + 1 , k + stevilo_tap_ch ) = - dQijdph ;% dGfrom / dphase
129+ end
130+ GpoU(indeks_P2 , k + stevilo_tap_ch ) = - dPjidph ;% dGto / dphase
131+ if tip_vozlisc(voz2 ) == 2 % PQ type of node
132+ GpoU(indeks_P2 + 1 , k + stevilo_tap_ch ) = - dQjidph ;% dGto / dphase
133+ end
134+
135+ %% dH/dU
136+ HpoU(k + stevilo_tap_ch , k + stevilo_tap_ch ) = dPijdph ;% dLinePower / dphase
137+
138+ %% dH/dX
139+ if tip_vozlisc(voz1 ) == 2 % from bus is PQ type
140+ HpoX(k + stevilo_tap_ch , indeks_P1 ) = dPijUi ;% dLinePower / dVoltAmp
141+ HpoX(k + stevilo_tap_ch , indeks_P1 + 1 ) = dPijdi ;% dLinePower / dVoltAng
142+ else % from bus is PV type
143+ HpoX(k + stevilo_tap_ch , indeks_P1 ) = dPijdi ;% dLinePower / dVoltAng
144+ end
145+
146+ if tip_vozlisc(voz2 ) == 2 % same thing as abocve for to bus
147+ HpoX(k + stevilo_tap_ch , indeks_P2 ) = dPijUj ;
148+ HpoX(k + stevilo_tap_ch , indeks_P2 + 1 ) = dPijdj ;
149+ else
150+ HpoX(k + stevilo_tap_ch , indeks_P2 ) = dPijdj ;
151+ end
152+
153+ end
154+
155+ sensitivity_of_H_to_U_taps_and_phasess = HpoU - HpoX * ( (GpoX ) \ (GpoU ) ); % total sensitivity of line active powers and nodal voltages w.r.t. all taps and phases
156+ en
0 commit comments