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

Add add_tl_lengths!, get_underground_tl and disable_branches!

parent 0474bea4
No related branches found
No related tags found
No related merge requests found
......@@ -4,11 +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 add_locs!(
network_data::Dict{String,<:Any},
csvfile::String
)
function add_locs!(network_data::Dict{String,<:Any}, csvfile::String)
pos = Dict{String,Any}(
"baseMVA" => 100.0,
"bus" => Dict{String,Any}(),
......@@ -32,6 +28,34 @@ end
#*------------------------------------------------------------------------------
function add_tl_lengths!(network_data::Dict{String,<:Any}, csvfile::String)
len = Dict{String,Any}(
"baseMVA" => 100.0,
"branch" => Dict{String,Any}(),
"per_unit" => true
)
BranchData::DataFrame = CSV.File(csvfile) |> DataFrame!
N = size(BranchData, 1) # number of branches
sizehint!(len["branch"], N)
for branch in eachrow(BranchData)
from, to = branch[:BusNumFrom], branch[:BusNumTo]
indices = findall(
b -> ((b["f_bus"], b["t_bus"]) == (from, to)
|| (b["f_bus"], b["t_bus"]) == (to, from)), network_data["branch"]
)
for index in indices
len["branch"][index] = Dict("length" => branch[:GICLineDistanceKm])
end
end
update_data!(network_data, len) # add positions to network_data
return network_data
end
#*------------------------------------------------------------------------------
#=
Determines voltage levels of transmission lines and adds them to the NDD.
=#
......@@ -121,3 +145,87 @@ function get_bustypes(network_data::Dict{String,<:Any})
"Empty bus" => empty
)
end
#*------------------------------------------------------------------------------
#=
Returns the (string) indices of transmission lines in the network data dictionary that would be considered as underground lines depending on the used maximum length of underground lines and minimum MW-load served. If mode = :sum, the sum of MW-loads of both ends of a line has to exceed min_MW_load, and if mode = :single, one end alone has to exceed min_MW_load.
=#
function get_underground_tl(
network_data::Dict{String,<:Any},
max_length = 12.875, # in km
min_MW_load = 2.; # in per-unit (assumed 100 MW base)
mode = :sum # :sum or :single
)
MW_loads = get_MW_loads(network_data) # dictionary of MW loads
underground_tl = []
if mode == :single # one end alone has to exceed min_MW_load
filter!(load -> last(load) >= min_MW_load, MW_loads)
large_MW_loads = collect(keys(MW_loads))
println(large_MW_loads)
counter = 0
### Go through branches and identify underground transmission lines
for (i, branch) in network_data["branch"]
if branch["transformer"] == false && branch["length"] < max_length
from, to = branch["f_bus"], branch["t_bus"]
if from in large_MW_loads || to in large_MW_loads
push!(underground_tl, i)
counter += 1
end
end
end
println(counter)
elseif mode == :sum # both ends together have to exceed min_MW_load
### Go through branches and identify underground transmission lines
for (i, branch) in network_data["branch"]
if branch["transformer"] == false && branch["length"] < max_length
from, to = branch["f_bus"], branch["t_bus"]
sum_MW_load = 0.
if haskey(MW_loads, from)
sum_MW_load += MW_loads[from]
end
if haskey(MW_loads, to)
sum_MW_load += MW_loads[to]
end
if sum_MW_load >= min_MW_load
push!(underground_tl, i)
end
end
end
else
throw(ArgumentError("Unknown mode $mode."))
end
return underground_tl
end
#=
Returns a dictionary with load bus indices (Int64) as keys and their respective MW load as values.
=#
function get_MW_loads(network_data::Dict{String,<:Any})
load_dict = Dict{Int64,Float64}()
for (i, load) in network_data["load"]
sub_dict = Dict(load["load_bus"] => load["pd"])
merge!(+, load_dict, sub_dict)
end
return load_dict
end
#*------------------------------------------------------------------------------
#=
Deactivates branches that have been overloaded due to a power flow redistribution (flow/capacity > 1.). The branches are identified by their string indices in branch_ids. The status of these branches is set to 0 in network_data. Parallel branches are not automatically deactivated.
=#
function disable_branches!(
network_data::Dict{String,<:Any},
branch_ids::Array
)
### Go through branches to deactivate
for id in branch_ids
network_data["branch"][id]["br_status"] = 0 # deactivate branch
end
return network_data
end
\ No newline at end of file
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