Skip to content
Snippets Groups Projects
Commit 6d93b7e6 authored by Julian Stürmer's avatar Julian Stürmer
Browse files

Add functions for TL voltages and bus types

parent d0155551
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@
#=
Reads the geographic bus locations (longitude and latitude coordinates in degrees) from a CSV file and adds them to the NDD. Returns the resulting NDD, in which each bus has a "bus_lat" and "bus_lon" entry. The columns containg the longitude and latitude coordinates in the CSV file should be called "SubLongitude" and "SubLatitude", respectively.
=#
function addlocs!(
function add_locs!(
network_data::Dict{String,<:Any},
csvfile::String
)
......@@ -33,7 +33,7 @@ end
#=
Returns a dictionary containing geographic bus locations that are included in the NDD. The dicitonary structure is bus-index => (lon, lat). If getlims=true, the minmimum and maximum longitude and latitude coordinates are returned as well. Can be useful for plotting the grid.
=#
function getlocs(network_data::Dict{String,<:Any}; getlims=false)
function get_locs(network_data::Dict{String,<:Any}; getlims=false)
pos = Dict(
parse(Int64, i) => (b["bus_lon"], b["bus_lat"])
for (i, b) in network_data["bus"]
......@@ -60,44 +60,89 @@ end
#*------------------------------------------------------------------------------
function add_tl_voltages!(network_data::Dict{String,<:Any})
voltages = Dict{String,Any}(
"baseMVA" => 100.0,
"branch" => Dict{String,Any}(),
"per_unit" => true
)
L = length(network_data["branch"])
sizehint!(voltages["branch"], L)
for (i, branch) in network_data["branch"]
if branch["transformer"] == true
### Transformers have a transmission line voltage of 0 kV
voltages["branch"][i] = Dict(
"tl_voltage" => 0.
)
else
### Transmission lines get base voltage of from bus
from = branch["f_bus"]
voltages["branch"][i] = Dict(
"tl_voltage" => network_data["bus"][string(from)]["base_kv"]
)
end
end
update_data!(network_data, voltages)
return network_data
end
#*------------------------------------------------------------------------------
#=
Returns the bus types of all buses in the NDD in form a dictionary. The different bus types are "load", "gen" (generator), "load_and_gen" and "empty".
Returns the bus types of all buses in the NDD in form an ordered dictionary. The different bus types are "Generator", "Load and generator", "Load" and "Empty bus". The ordering is fixed so that the dictionary can be used to plot the buses in a specific order.
=#
#? How to call "empty" buses? Load and generator buses in a substation are connected to these empty buses? Is there only one empty bus per substation?
function get_bustypes(network_data::Dict{String,<:Any})
### Active loads
loads = unique(
[load["load_bus"] for (i, load) in network_data["load"]
if load["status"] == 1]
load = unique(
[l["load_bus"] for l in collect(values(network_data["load"]))
if l["status"] == 1]
)
### Active generators
gens = unique(
[gen["gen_bus"] for (i, gen) in network_data["gen"]
if gen["gen_status"] == 1]
gen = unique(
[g["gen_bus"] for g in collect(values(network_data["gen"]))
if g["gen_status"] == 1]
)
### Buses with both load and generation
load_and_gen = [i for i in loads if i in gens]
load_and_gen = [i for i in load if i in gen]
### Slack bus
slack = [
b["index"] for b in collect(values(network_data["bus"]))
if b["bus_type"] == 3
]
### Remove buses with load and generation from pure loads and generators
filter!(i -> i load_and_gen, loads)
filter!(i -> i load_and_gen, gens)
filter!(i -> i load_and_gen, load)
filter!(i -> i load_and_gen, gen)
### Remove slack bus from other arrays
filter!(i -> i slack, load)
filter!(i -> i slack, gen)
filter!(i -> i slack, load_and_gen)
### Empty buses with neither load nor generation
empty = unique(
[bus["index"] for (i, bus) in network_data["bus"]
if bus["index"] vcat(loads, gens, load_and_gen)]
[b["index"] for b in collect(values(network_data["bus"]))
if b["index"] vcat(load, gen, load_and_gen, slack)]
)
### Check whether the right number of bus types was obtained
sum = (length(loads) + length(gens) + length(load_and_gen) + length(empty))
sum = (
length(load) + length(gen) + length(load_and_gen) + length(empty) + length(slack)
)
N::Int64 = length(network_data["bus"]) # number of buses
@assert sum == N "$sum bus types were obtained instead of $N"
return Dict(
"loads" => loads,
"gens" => gens,
"load_and_gen" => load_and_gen,
"empty" => empty
return OrderedDict(
"Generator" => gen,
"Load and generator" => load_and_gen,
"Load" => load,
"Slack" => slack,
"Empty bus" => empty
)
end
\ No newline at end of file
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment