@@ -88,6 +88,7 @@ struct ABA_Matrix{
88
88
axes:: Ax
89
89
lookup:: L
90
90
ref_bus_positions:: Set{Int}
91
+ ref_bus_numbers:: Set{Int}
91
92
K:: F
92
93
radial_network_reduction:: RadialNetworkReduction
93
94
end
@@ -122,7 +123,11 @@ function ABA_Matrix(
122
123
ABA = calculate_ABA_matrix (A, BA, ref_bus_positions)
123
124
124
125
bus_ax = [PSY. get_number (bus) for bus in buses]
125
- bus_ax_ = setdiff (bus_ax, ref_bus_positions)
126
+ ref_bus_numbers = Set ([
127
+ PSY. get_number (bus) for bus in buses
128
+ if PSY. get_bustype (bus) == PSY. ACBusTypes. REF
129
+ ])
130
+ bus_ax_ = setdiff (bus_ax, ref_bus_numbers)
126
131
axes = (bus_ax_, bus_ax_)
127
132
bus_ax_ref = make_ax_ref (bus_ax_)
128
133
lookup = (bus_ax_ref, bus_ax_ref)
@@ -136,6 +141,7 @@ function ABA_Matrix(
136
141
axes,
137
142
lookup,
138
143
ref_bus_positions,
144
+ ref_bus_numbers,
139
145
K,
140
146
rb,
141
147
)
@@ -154,6 +160,7 @@ function factorize(ABA::ABA_Matrix{Ax, L, Nothing}) where {Ax, L <: NTuple{2, Di
154
160
deepcopy (ABA. axes),
155
161
deepcopy (ABA. lookup),
156
162
deepcopy (ABA. ref_bus_positions),
163
+ deepcopy (ABA. ref_bus_numbers),
157
164
klu (ABA. data),
158
165
deepcopy (ABA. radial_network_reduction),
159
166
)
@@ -181,16 +188,20 @@ function Base.getindex(
181
188
return A. data[bus_number, line_number]
182
189
end
183
190
191
+ _is_ref_bus (bus:: Int , ref_bus_numbers:: Set{Int} ) = (bus in ref_bus_numbers)
192
+ _is_ref_bus (bus:: PSY.ACBus , ref_bus_numbers:: Set{Int} ) =
193
+ (PSY. get_number (bus) in ref_bus_numbers)
194
+ _is_ref_bus (:: Colon , :: Set{Int} ) = false
184
195
# get_index functions: ABA_Matrix stores a square matrix whose number of rows
185
196
# and column is equal to the number of the system's buses minus the slack ones,
186
- # NOTE: bus_1, bus_2 are bus numbers not row and column indices!
197
+ # NOTE: bus_1, bus_2 are bus numbers (or PSY.ACBus objects) not row and column indices!
187
198
function Base. getindex (A:: ABA_Matrix , bus_1, bus_2)
188
- if bus_1 in A . ref_bus_positions || bus_2 in A . ref_bus_positions
199
+ if _is_ref_bus ( bus_1, A . ref_bus_numbers) || _is_ref_bus ( bus_2, A . ref_bus_numbers)
189
200
err_msg = string (
190
201
" Rows and columns related to slack buses are not defined for the ABA matrix. \n " ,
191
202
" Indices must be referred to any bus number that is not a slack one. \n " ,
192
203
" For the current Systems the reference slack buses are: " ,
193
- collect (A. ref_bus_positions ), " . \n " )
204
+ collect (A. ref_bus_numbers ), " . \n " )
194
205
error (err_msg)
195
206
else
196
207
i, j = to_index (A, bus_1, bus_2)
0 commit comments