Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Branch definition to include transformers #6

Merged
merged 6 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FullNetworkSystems"
uuid = "877b7152-b508-43dc-81fb-72341a693988"
authors = ["Invenia Technical Computing Corporation"]
version = "1.0.0"
version = "1.1.0"

[deps]
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
Expand Down
2 changes: 1 addition & 1 deletion src/FullNetworkSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export System, SystemDA, SystemRT
export Zone, Generator, Bus, Branch
export GeneratorTimeSeries, GeneratorStatus, GeneratorStatusDA, GeneratorStatusRT
export gens_per_zone, branches_by_breakpoints, get_datetimes
export get_zones, get_buses, get_generators, get_branches
export get_zones, get_buses, get_generators, get_branches, get_lines, get_transformers
export get_regulation_requirements, get_operating_reserve_requirements, get_good_utility_requirements
export get_gens_per_bus, get_loads_per_bus, get_incs_per_bus, get_decs_per_bus, get_psds_per_bus
export get_ptdf, get_lodf
Expand Down
4 changes: 4 additions & 0 deletions src/accessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ get_buses(system::System) = system.buses
get_generators(system::System) = system.generators
"Returns a `Dictionary` of `Branch` objects in the `System` indexed by branch name."
get_branches(system::System) = system.branches
"Returns a `Dictionary` of branches that are not transformers in the `System` indexed by name."
get_lines(system::System) = filter(br -> !br.is_transformer, system.branches)
"Returns a `Dictionary` of transformers in the `System` indexed by name."
get_transformers(system::System) = filter(br -> br.is_transformer, system.branches)

"Returns a `Dictionary` of unit codes at each bus."
get_gens_per_bus(system::System) = system.gens_per_bus
Expand Down
82 changes: 80 additions & 2 deletions src/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ end
"""
$TYPEDEF

Type for static branch attributes. Branches may have between 0 and 2 break points
which is why the `break_points` and `penalties` fields contain variable length `Tuple`s.
Type for static non-transformer branch attributes. Branches may have between 0 and 2 break
nickrobinson251 marked this conversation as resolved.
Show resolved Hide resolved
points which is why the `break_points` and `penalties` fields contain variable length `Tuple`s.

Fields:
$TYPEDFIELDS
Expand All @@ -99,6 +99,84 @@ struct Branch
break_points::Tuple{Float64, Float64}
"Price penalties for each of the break points of the branch (\$)"
penalties::Tuple{Float64, Float64}
"Resistance of the transformer (pu)"
resistance::Float64
"Reactance of the transformer or branch (pu)"
reactance::Float64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that transformer is a subset of branch, I'd just say "branch" here – "transformer or branch" is confusing

I'd also say branch for the resistance as it makes sense for lines to have resistance even though we don't use it in the formulation or to compute shift factors

"Boolean indicating whether the branch is a transformer"
is_transformer::Bool
"Ratio between the nominal winding one and two voltages of the transformer"
tap::Union{Missing, Float64}
"Phase shift angle (radians)"
angle::Union{Missing, Float64}
end

"""
Constructor for a non-transformer branch which sets `is_transformer` to `false` and
transformer specific variables to `missing`.
"""
function Branch(
nickrobinson251 marked this conversation as resolved.
Show resolved Hide resolved
name,
to_bus,
from_bus,
rate_a,
rate_b,
is_monitored,
break_points,
penalities,
resistance=0.0,
reactance=0.0
)
tap = missing
angle = missing
is_transformer = false
return Branch(
name,
to_bus,
from_bus,
rate_a,
rate_b,
is_monitored,
break_points,
penalities,
resistance,
reactance,
is_transformer,
tap,
angle
)
end

function Branch(
name,
to_bus,
from_bus,
rate_a,
rate_b,
is_monitored,
break_points,
penalities,
resistance,
reactance,
tap::Float64,
angle::Float64
)
is_transformer = true
return Branch(
name,
to_bus,
from_bus,
rate_a,
rate_b,
is_monitored,
break_points,
penalities,
resistance,
reactance,
is_transformer,
tap,
angle
)
end

###### Time Series types ######
Expand Down
33 changes: 25 additions & 8 deletions test/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ids=gen_ids, datetimes=datetimes
)

branch_names = string.([1, 2, 3])
branch_names = string.([1, 2, 3, 4])
nickrobinson251 marked this conversation as resolved.
Show resolved Hide resolved
bus_names = ["A", "B", "C"]

@testset "Zone" begin
Expand All @@ -33,8 +33,18 @@
end

@testset "Branch" begin
branch1 = Branch("1", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0))
branch1 = Branch("1", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), 1.0, 1.0)
@test branch1 isa Branch
@test !branch1.is_transformer

branch2 = Branch("2", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0))
@test branch2 isa Branch
@test !branch2.is_transformer

transformer1 = Branch(
"1", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), 1.0, 1.0, 0.5, 30.0
)
@test transformer1 isa Branch
end

@testset "System" begin
Expand All @@ -56,9 +66,12 @@
branches = Dictionary(
branch_names,
[
Branch("1", "A", "B", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0)),
Branch("2", "B", "C", 10.0, 10.0, false, (100.0, 0.0), (5.0, 0.0)),
Branch("3", "C", "A", 10.0, 10.0, true, (0.0, 0.0), (0.0, 0.0)),
Branch("1", "A", "B", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), 1.0, 1.0),
Branch("2", "B", "C", 10.0, 10.0, false, (100.0, 0.0), (5.0, 0.0), 1.0, 1.0),
Branch("3", "C", "A", 10.0, 10.0, true, (0.0, 0.0), (0.0, 0.0), 1.0, 1.0),
Branch(
"4", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), 1.0, 1.0, 0.5, 30.0
)
]
)

Expand All @@ -70,9 +83,9 @@

lodf = Dictionary(
["CONTIN_1"],
[KeyedArray(rand(3, 1); branches=branch_names, branch=[first(branch_names)])]
[KeyedArray(rand(4, 1); branches=branch_names, branch=[first(branch_names)])]
)
ptdf = KeyedArray(rand(3, 3); row=branch_names, col=bus_names)
ptdf = KeyedArray(rand(4, 3); row=branch_names, col=bus_names)

generator_time_series = GeneratorTimeSeries(
fake_vec_ts,
Expand Down Expand Up @@ -136,6 +149,10 @@
@test get_buses(system) == buses
@test get_generators(system) == gens
@test get_branches(system) == branches
@test get_lines(system) == Dictionary(
["1", "2", "3"], [branches["1"], branches["2"], branches["3"]]
)
@test get_transformers(system) == Dictionary(["4"], [branches["4"]])

@test get_gens_per_bus(system) == gens_per_bus
@test get_loads_per_bus(system) == loads_per_bus
Expand Down Expand Up @@ -165,7 +182,7 @@
zero_bp, one_bp, two_bp = branches_by_breakpoints(da_system)
@test zero_bp == ["3"]
@test one_bp == String[] #unmonitored
@test two_bp == ["1"]
@test two_bp == ["1", "4"]
end

@testset "SystemDA only accessors" begin
Expand Down