From 182278e0d15bca2a2069496865eeec25b33ae7e3 Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Thu, 19 May 2022 13:09:42 -0500 Subject: [PATCH 1/6] add fields to branch for transformers --- Project.toml | 2 +- src/FullNetworkSystems.jl | 2 +- src/accessors.jl | 4 ++++ src/system.jl | 33 +++++++++++++++++++++++++++++++-- test/system.jl | 21 +++++++++++++++++---- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index 0337056..c52cdf1 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/FullNetworkSystems.jl b/src/FullNetworkSystems.jl index 7db6e38..c3e57ab 100644 --- a/src/FullNetworkSystems.jl +++ b/src/FullNetworkSystems.jl @@ -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 diff --git a/src/accessors.jl b/src/accessors.jl index 9f6d0fa..45c57fb 100644 --- a/src/accessors.jl +++ b/src/accessors.jl @@ -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 diff --git a/src/system.jl b/src/system.jl index d57b9c5..ef5e5e9 100644 --- a/src/system.jl +++ b/src/system.jl @@ -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 +points which is why the `break_points` and `penalties` fields contain variable length `Tuple`s. Fields: $TYPEDFIELDS @@ -99,6 +99,35 @@ struct Branch break_points::Tuple{Float64, Float64} "Price penalties for each of the break points of the branch (\$)" penalties::Tuple{Float64, Float64} + "Boolean indicating whether the branch is a transformer" + is_transformer::Bool + "Resistance of the transformer (Ohm)" + resistance::Union{Missing, Float64} + "Ratio between the nominal winding one and two voltages of the transformer" + tap::Union{Missing, Float64} + "Phase shift angle (degrees)" + 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(name, to_bus, from_bus, rate_a, rate_b, is_monitored, break_points, penalities) + return Branch( + name, + to_bus, + from_bus, + rate_a, + rate_b, + is_monitored, + break_points, + penalities, + false, + missing, + missing, + missing + ) end ###### Time Series types ###### diff --git a/test/system.jl b/test/system.jl index 22bdf64..5531638 100644 --- a/test/system.jl +++ b/test/system.jl @@ -14,7 +14,7 @@ ids=gen_ids, datetimes=datetimes ) - branch_names = string.([1, 2, 3]) + branch_names = string.([1, 2, 3, 4]) bus_names = ["A", "B", "C"] @testset "Zone" begin @@ -35,6 +35,12 @@ @testset "Branch" begin branch1 = Branch("1", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0)) @test branch1 isa Branch + @test !branch1.is_transformer + + transformer1 = Branch( + "1", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), true, 1.0, 1.0, 30.0 + ) + @test transformer1 isa Branch end @testset "System" begin @@ -59,6 +65,9 @@ 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( + "4", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), true, 1.0, 1.0, 30.0 + ) ] ) @@ -70,9 +79,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, @@ -136,6 +145,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 @@ -165,7 +178,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 From 9eb302add3ea8c98a509c8270f139ba0f3e64a92 Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Fri, 20 May 2022 10:17:19 -0500 Subject: [PATCH 2/6] add another constructor --- src/system.jl | 33 +++++++++++++++++++++++++++++---- test/system.jl | 16 ++++++++++------ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/system.jl b/src/system.jl index ef5e5e9..d2d4eba 100644 --- a/src/system.jl +++ b/src/system.jl @@ -99,13 +99,15 @@ 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 (Ohm)" + resistance::Float64 + "Reactance of the transformer or branch (Ohm)" + reactance::Float64 "Boolean indicating whether the branch is a transformer" is_transformer::Bool - "Resistance of the transformer (Ohm)" - resistance::Union{Missing, Float64} "Ratio between the nominal winding one and two voltages of the transformer" tap::Union{Missing, Float64} - "Phase shift angle (degrees)" + "Phase shift angle (radians)" angle::Union{Missing, Float64} end @@ -113,7 +115,9 @@ end Constructor for a non-transformer branch which sets `is_transformer` to `false` and transformer specific variables to `missing`. """ -function Branch(name, to_bus, from_bus, rate_a, rate_b, is_monitored, break_points, penalities) +function Branch( + name, to_bus, from_bus, rate_a, rate_b, is_monitored, break_points, penalities, resistance, reactance +) return Branch( name, to_bus, @@ -123,8 +127,29 @@ function Branch(name, to_bus, from_bus, rate_a, rate_b, is_monitored, break_poin is_monitored, break_points, penalities, + resistance, + reactance, false, missing, + missing + ) +end + +function Branch( + name, to_bus, from_bus, rate_a, rate_b, is_monitored, break_points, penalities +) + return Branch( + name, + to_bus, + from_bus, + rate_a, + rate_b, + is_monitored, + break_points, + penalities, + 0.0, + 0.0, + false, missing, missing ) diff --git a/test/system.jl b/test/system.jl index 5531638..e0aef1e 100644 --- a/test/system.jl +++ b/test/system.jl @@ -33,12 +33,16 @@ 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), true, 1.0, 1.0, 30.0 + "1", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), 1.0, 1.0, true, 0.5, 30.0 ) @test transformer1 isa Branch end @@ -62,11 +66,11 @@ 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), true, 1.0, 1.0, 30.0 + "4", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), 1.0, 1.0, true, 0.5, 30.0 ) ] ) From ba03ff7049bc2a4279e3a7c2af134a42deb89566 Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Mon, 23 May 2022 10:47:47 -0500 Subject: [PATCH 3/6] single branch constructor --- src/system.jl | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/system.jl b/src/system.jl index d2d4eba..3719df9 100644 --- a/src/system.jl +++ b/src/system.jl @@ -99,9 +99,9 @@ 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 (Ohm)" + "Resistance of the transformer (pu)" resistance::Float64 - "Reactance of the transformer or branch (Ohm)" + "Reactance of the transformer or branch (pu)" reactance::Float64 "Boolean indicating whether the branch is a transformer" is_transformer::Bool @@ -116,7 +116,7 @@ Constructor for a non-transformer branch which sets `is_transformer` to `false` transformer specific variables to `missing`. """ function Branch( - name, to_bus, from_bus, rate_a, rate_b, is_monitored, break_points, penalities, resistance, reactance + name, to_bus, from_bus, rate_a, rate_b, is_monitored, break_points, penalities, resistance=0.0, reactance=0.0, is_transformer=false, tap=missing, angle=missing ) return Branch( name, @@ -129,29 +129,9 @@ function Branch( penalities, resistance, reactance, - false, - missing, - missing - ) -end - -function Branch( - name, to_bus, from_bus, rate_a, rate_b, is_monitored, break_points, penalities -) - return Branch( - name, - to_bus, - from_bus, - rate_a, - rate_b, - is_monitored, - break_points, - penalities, - 0.0, - 0.0, - false, - missing, - missing + is_transformer, + tap, + angle ) end From 3763444d1d4232d677721445a505b20fb2ae88e7 Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Tue, 24 May 2022 10:50:34 -0500 Subject: [PATCH 4/6] line/transformer constructors --- src/system.jl | 46 +++++++++++++++++++++++++++++++++++++++++++++- test/system.jl | 4 ++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/system.jl b/src/system.jl index 3719df9..cac711b 100644 --- a/src/system.jl +++ b/src/system.jl @@ -116,8 +116,52 @@ Constructor for a non-transformer branch which sets `is_transformer` to `false` transformer specific variables to `missing`. """ function Branch( - name, to_bus, from_bus, rate_a, rate_b, is_monitored, break_points, penalities, resistance=0.0, reactance=0.0, is_transformer=false, tap=missing, angle=missing + 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, diff --git a/test/system.jl b/test/system.jl index e0aef1e..0e8d902 100644 --- a/test/system.jl +++ b/test/system.jl @@ -42,7 +42,7 @@ @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, true, 0.5, 30.0 + "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 @@ -70,7 +70,7 @@ 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, true, 0.5, 30.0 + "4", "A", "C", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), 1.0, 1.0, 0.5, 30.0 ) ] ) From b6f95fb1740b4b5039e4cd98275ecdcfd7b4ac8e Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Tue, 24 May 2022 18:03:49 -0500 Subject: [PATCH 5/6] branch constructors --- src/system.jl | 20 +++++++++++++++----- test/system.jl | 5 ++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/system.jl b/src/system.jl index cac711b..f832b21 100644 --- a/src/system.jl +++ b/src/system.jl @@ -73,7 +73,7 @@ end """ $TYPEDEF -Type for static non-transformer branch attributes. Branches may have between 0 and 2 break +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. Fields: @@ -86,9 +86,9 @@ struct Branch to_bus::BusName "Name of the bus the branch goes from" from_bus::BusName - "Power flow limit for the base case (MVA)" + "Power flow limit for the base case (pu)" rate_a::Float64 - "Power flow limit for contingency scenario (MVA)" + "Power flow limit for contingency scenario (pu)" rate_b::Float64 "Boolean defining whether the branch is monitored" is_monitored::Bool @@ -112,8 +112,18 @@ struct Branch end """ -Constructor for a non-transformer branch which sets `is_transformer` to `false` and -transformer specific variables to `missing`. +Constructors for a `Branch`. The user has the option to define a `Branch` as a line e.g. +``` +line1 = Branch("1", "A", "B", 10.0, 10.0, true, (100.0, 102.0), (5.0, 6.0), 1.0, 1.0) +``` +where the final two values (`resistance` and `reactance`) can be left unspecified. Or the +user can define a `Branch`` as a transformer: +``` +trnasformer1 = 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 +) +``` +where two extra parameters are provided as the end representing `tap` and `angle`. """ function Branch( name, diff --git a/test/system.jl b/test/system.jl index 0e8d902..b1f503b 100644 --- a/test/system.jl +++ b/test/system.jl @@ -14,9 +14,6 @@ ids=gen_ids, datetimes=datetimes ) - branch_names = string.([1, 2, 3, 4]) - bus_names = ["A", "B", "C"] - @testset "Zone" begin zone1 = Zone(1, 1.0, 1.0, 1.0) @test zone1 isa Zone @@ -58,11 +55,13 @@ end gens = Dictionary(gen_ids, gen_types) + bus_names = ["A", "B", "C"] bus_types = map(bus_names) do name Bus(name, 100.0) end buses = Dictionary(bus_names, bus_types) + branch_names = string.([1,2,3,4]) branches = Dictionary( branch_names, [ From 135b2caaeb0ba26e650818657d62c0188f0449d5 Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Wed, 25 May 2022 11:28:45 -0500 Subject: [PATCH 6/6] transformer to branch in docstring --- src/system.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/system.jl b/src/system.jl index f832b21..fab9296 100644 --- a/src/system.jl +++ b/src/system.jl @@ -99,9 +99,9 @@ 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 of the branch (pu)" resistance::Float64 - "Reactance of the transformer or branch (pu)" + "Reactance of the branch (pu)" reactance::Float64 "Boolean indicating whether the branch is a transformer" is_transformer::Bool