Skip to content

Commit c65b650

Browse files
jd-laram-bossart
andauthored
missing 3wt methods (#211)
* add missing 3wt transformer methods * add missing predicates * formatter * add missing 3WT methods * add new struct * update common to return the correct type * update tests * use get for filters --------- Co-authored-by: m-bossart <bossart.matt@gmail.com>
1 parent ec4bc7b commit c65b650

8 files changed

Lines changed: 236 additions & 57 deletions

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ KLU = "^0.6"
2828
LinearAlgebra = "1"
2929
MKL = "0.9"
3030
Pardiso = "1"
31-
PowerSystems = "5"
31+
PowerSystems = "^5.2"
3232
SparseArrays = "1"
3333
julia = "^1.6"

src/BranchesSeries.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function add_to_map(series_circuit::BranchesSeries, filters::Dict)
181181
end
182182
return true
183183
else
184-
filter = filters[first(keys(series_circuit.branches))]
184+
filter = get(filters, first(keys(series_circuit.branches)), x -> true)
185185
return all([filter(device) for device in first(values(series_circuit.branches))])
186186
end
187187
error("Invalid condition reached in add_to_map for BranchesSeries")

src/EquivalentBranch.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
EquivalentBranch
3+
4+
Represents the equivalent parameters of a network branch for power flow calculations.
5+
6+
# Fields
7+
- `equivalent_r::Float64`: Equivalent series resistance (p.u.)
8+
- `equivalent_x::Float64`: Equivalent series reactance (p.u.)
9+
- `equivalent_g_from::Float64`: Equivalent shunt conductance at the "from" bus (p.u.)
10+
- `equivalent_b_from::Float64`: Equivalent shunt susceptance at the "from" bus (p.u.)
11+
- `equivalent_g_to::Float64`: Equivalent shunt conductance at the "to" bus (p.u.)
12+
- `equivalent_b_to::Float64`: Equivalent shunt susceptance at the "to" bus (p.u.)
13+
- `equivalent_tap::Float64`: Equivalent transformer tap ratio
14+
- `equivalent_shift::Float64`: Equivalent phase shift angle (radians)
15+
"""
16+
mutable struct EquivalentBranch
17+
equivalent_r::Float64
18+
equivalent_x::Float64
19+
equivalent_g_from::Float64
20+
equivalent_b_from::Float64
21+
equivalent_g_to::Float64
22+
equivalent_b_to::Float64
23+
equivalent_tap::Float64
24+
equivalent_shift::Float64
25+
end
26+
27+
get_equivalent_r(eb::EquivalentBranch) = eb.equivalent_r
28+
get_equivalent_x(eb::EquivalentBranch) = eb.equivalent_x
29+
get_equivalent_g_from(eb::EquivalentBranch) = eb.equivalent_g_from
30+
get_equivalent_b_from(eb::EquivalentBranch) = eb.equivalent_b_from
31+
get_equivalent_g_to(eb::EquivalentBranch) = eb.equivalent_g_to
32+
get_equivalent_b_to(eb::EquivalentBranch) = eb.equivalent_b_to
33+
get_equivalent_tap(eb::EquivalentBranch) = eb.equivalent_tap
34+
get_equivalent_shift(eb::EquivalentBranch) = eb.equivalent_shift

src/NetworkReductionData.jl

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ get_removed_buses(rb::NetworkReductionData) = rb.removed_buses
301301
get_removed_arcs(rb::NetworkReductionData) = rb.removed_arcs
302302
get_added_admittance_map(rb::NetworkReductionData) = rb.added_admittance_map
303303
get_added_branch_map(rb::NetworkReductionData) = rb.added_branch_map
304-
get_name_to_arc_map(rb::NetworkReductionData) = rb.name_to_arc_map
305304
get_all_branch_maps_by_type(rb::NetworkReductionData) = rb.all_branch_maps_by_type
305+
306306
"""
307307
get_reductions(rb::NetworkReductionData)
308308
@@ -316,6 +316,15 @@ Get the reduction container from NetworkReductionData.
316316
"""
317317
get_reductions(rb::NetworkReductionData) = rb.reductions
318318

319+
get_name_to_arc_maps(rb::NetworkReductionData) = rb.name_to_arc_map
320+
321+
get_name_to_arc_map(rb::NetworkReductionData, ::Type{T}) where {T <: PSY.ACTransmission} =
322+
rb.name_to_arc_map[T]
323+
get_name_to_arc_map(
324+
rb::NetworkReductionData,
325+
::Type{ThreeWindingTransformerWinding{T}},
326+
) where {T <: PSY.ThreeWindingTransformer} = rb.name_to_arc_map[T]
327+
319328
has_radial_reduction(rb::NetworkReductionData) = has_radial_reduction(rb.reductions)
320329
has_degree_two_reduction(rb::NetworkReductionData) = has_degree_two_reduction(rb.reductions)
321330
has_ward_reduction(rb::NetworkReductionData) = has_ward_reduction(rb.reductions)
@@ -370,15 +379,16 @@ Gets the concrete types of all AC transmission branches included in an instance
370379
- `Set{DataType}`: Vector of the retained branch types.
371380
"""
372381
function get_ac_transmission_types(network_reduction_data::NetworkReductionData)
373-
direct_types = Set(typeof.(keys(network_reduction_data.reverse_direct_branch_map)))
382+
direct_types =
383+
Set(typeof.(keys(network_reduction_data.reverse_direct_branch_map)))
374384
parallel_types =
375-
Set(typeof.(keys(network_reduction_data.reverse_parallel_branch_map)))
376-
series_types = Set(typeof.(keys(network_reduction_data.reverse_series_branch_map)))
377-
transformer_3w_devices =
378-
Set(
379-
first(tuple) for tuple in keys(network_reduction_data.reverse_transformer3W_map)
385+
Set{DataType}(typeof.(keys(network_reduction_data.reverse_parallel_branch_map)))
386+
series_types =
387+
Set{DataType}(typeof.(keys(network_reduction_data.reverse_series_branch_map)))
388+
transformer_3W_types =
389+
Set{DataType}(
390+
get_transformer_type.(keys(network_reduction_data.reverse_transformer3W_map)),
380391
)
381-
transformer_3W_types = typeof.(transformer_3w_devices)
382392
return union(direct_types, parallel_types, series_types, transformer_3W_types)
383393
end
384394

src/PowerNetworkMatrices.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import LinearAlgebra: LAPACK.getrf!, LAPACK.getrs!
7575
include("PowerNetworkMatrix.jl")
7676
include("ThreeWindingTransformerWinding.jl")
7777
include("definitions.jl")
78+
include("EquivalentBranch.jl")
7879
include("BranchesSeries.jl")
7980
include("BranchesParallel.jl")
8081
include("NetworkReduction.jl")

src/ThreeWindingTransformerWinding.jl

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ end
2121

2222
get_transformer(tw::ThreeWindingTransformerWinding) = tw.transformer
2323
get_winding_number(tw::ThreeWindingTransformerWinding) = tw.winding_number
24+
get_transformer_type(
25+
::ThreeWindingTransformerWinding{T},
26+
) where {T <: PSY.ThreeWindingTransformer} = T
2427

2528
function get_name(three_wt_winding::ThreeWindingTransformerWinding)
2629
transformer = get_transformer(three_wt_winding)
@@ -34,6 +37,70 @@ function get_series_susceptance(segment::ThreeWindingTransformerWinding)
3437
return PSY.get_series_susceptances(tfw)[winding_int]
3538
end
3639

40+
"""
41+
get_equivalent_r(tw::ThreeWindingTransformerWinding)
42+
43+
Get the resistance for a specific winding of a three-winding transformer.
44+
Returns the winding-specific series resistance.
45+
"""
46+
function get_equivalent_r(tw::ThreeWindingTransformerWinding)
47+
tfw = get_transformer(tw)
48+
winding_num = get_winding_number(tw)
49+
50+
if winding_num == 1
51+
return PSY.get_r_primary(tfw)
52+
elseif winding_num == 2
53+
return PSY.get_r_secondary(tfw)
54+
elseif winding_num == 3
55+
return PSY.get_r_tertiary(tfw)
56+
else
57+
throw(ArgumentError("Invalid winding number: $winding_num"))
58+
end
59+
end
60+
61+
"""
62+
get_equivalent_x(tw::ThreeWindingTransformerWinding)
63+
64+
Get the reactance for a specific winding of a three-winding transformer.
65+
Returns the winding-specific series reactance.
66+
"""
67+
function get_equivalent_x(tw::ThreeWindingTransformerWinding)
68+
tfw = get_transformer(tw)
69+
winding_num = get_winding_number(tw)
70+
71+
if winding_num == 1
72+
return PSY.get_x_primary(tfw)
73+
elseif winding_num == 2
74+
return PSY.get_x_secondary(tfw)
75+
elseif winding_num == 3
76+
return PSY.get_x_tertiary(tfw)
77+
else
78+
throw(ArgumentError("Invalid winding number: $winding_num"))
79+
end
80+
end
81+
82+
"""
83+
get_equivalent_b(tw::ThreeWindingTransformerWinding)
84+
85+
Get the susceptance for a specific winding of a three-winding transformer.
86+
For the primary winding (winding 1), returns the shunt susceptance from the transformer.
87+
For secondary and tertiary windings, returns 0.0 as the shunt is only on the primary side.
88+
"""
89+
function get_equivalent_b(tw::ThreeWindingTransformerWinding)
90+
tfw = get_transformer(tw)
91+
winding_num = get_winding_number(tw)
92+
93+
if winding_num == 1
94+
# Only the primary winding has the shunt susceptance
95+
return (from = PSY.get_b(tfw), to = 0.0)
96+
elseif winding_num == 2 || winding_num == 3
97+
# Secondary and tertiary windings don't have shunt susceptance
98+
return (from = 0.0, to = 0.0)
99+
else
100+
throw(ArgumentError("Invalid winding number: $winding_num"))
101+
end
102+
end
103+
37104
"""
38105
get_equivalent_rating(tw::ThreeWindingTransformerWinding)
39106
@@ -107,6 +174,52 @@ function get_arc_tuple(tr::ThreeWindingTransformerWinding)
107174
end
108175
end
109176

177+
"""
178+
get_equivalent_tap(tw::ThreeWindingTransformerWinding)
179+
180+
Get the tap (turns ratio) for a specific winding of a three-winding transformer.
181+
Returns the winding-specific turns ratio for phase shifting transformers.
182+
"""
183+
function get_equivalent_tap(
184+
tw::ThreeWindingTransformerWinding{PSY.PhaseShiftingTransformer3W},
185+
)
186+
tfw = get_transformer(tw)
187+
winding_num = get_winding_number(tw)
188+
189+
if winding_num == 1
190+
return PSY.get_primary_turns_ratio(tfw)
191+
elseif winding_num == 2
192+
return PSY.get_secondary_turns_ratio(tfw)
193+
elseif winding_num == 3
194+
return PSY.get_tertiary_turns_ratio(tfw)
195+
else
196+
throw(ArgumentError("Invalid winding number: $winding_num"))
197+
end
198+
end
199+
200+
"""
201+
get_equivalent_α(tw::ThreeWindingTransformerWinding)
202+
203+
Get the phase angle (α) for a specific winding of a three-winding transformer.
204+
Returns the winding-specific phase shift angle for phase shifting transformers.
205+
"""
206+
function get_equivalent_α(
207+
tw::ThreeWindingTransformerWinding{PSY.PhaseShiftingTransformer3W},
208+
)
209+
tfw = get_transformer(tw)
210+
winding_num = get_winding_number(tw)
211+
212+
if winding_num == 1
213+
return PSY.get_α_primary(tfw)
214+
elseif winding_num == 2
215+
return PSY.get_α_secondary(tfw)
216+
elseif winding_num == 3
217+
return PSY.get_α_tertiary(tfw)
218+
else
219+
throw(ArgumentError("Invalid winding number: $winding_num"))
220+
end
221+
end
222+
110223
function add_to_map(device::ThreeWindingTransformerWinding, filters::Dict)
111224
return add_to_map(get_transformer(device), filters)
112225
end

src/common.jl

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ end
308308
"""
309309
get_equivalent_physical_branch_parameters(equivalent_ybus::Matrix{ComplexF32})
310310
311-
Takes as input a 2x2 Matrix{ComplexF32} representing the Ybus contribution of either a
312-
BranchesParallel or BranchesSeries object.
313-
Returns a dictionary of equivalent parameters, matching the PowerModels data format.
311+
Takes as input a 2x2 Matrix{ComplexF32} representing the Ybus contribution of either a
312+
BranchesParallel or BranchesSeries object.
313+
Returns a dictionary of equivalent parameters, matching the PowerModels data format.
314314
"""
315315
function _get_equivalent_physical_branch_parameters(equivalent_ybus::Matrix{ComplexF32})
316316
y_11, y_12, y_21, y_22 = equivalent_ybus
@@ -337,14 +337,5 @@ function _get_equivalent_physical_branch_parameters(equivalent_ybus::Matrix{Comp
337337
b_from = imag(y_11 - y_l)
338338
g_to = real(y_22 - y_l)
339339
b_to = imag(y_22 - y_l)
340-
return Dict{Symbol, Float64}(
341-
:r => r,
342-
:x => x,
343-
:g_from => g_from,
344-
:b_from => b_from,
345-
:g_to => g_to,
346-
:b_to => b_to,
347-
:tap => tap,
348-
:shift => shift,
349-
)
340+
return EquivalentBranch(r, x, g_from, b_from, g_to, b_to, tap, shift)
350341
end

0 commit comments

Comments
 (0)