Skip to content

Commit

Permalink
Support for N-x contingencies
Browse files Browse the repository at this point in the history
  • Loading branch information
michel2323 committed Feb 3, 2023
1 parent b6ca825 commit 4bfe8aa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
22 changes: 13 additions & 9 deletions src/OPF/opfdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function opf_loaddata(raw::RawData;
load_scale::Float64=1.0,
ramp_scale::Float64=0.0,
corr_scale::Float64=0.1,
lineOff=Line(),
lineOff=nothing,
genOff::Vector{Int}=Int[])
#
# load buses
Expand Down Expand Up @@ -278,15 +278,19 @@ function opf_loaddata(raw::RawData;
#
branch_arr = raw.branch_arr
num_lines = size(branch_arr, 1)
lines_on = findall((branch_arr[:,11] .> 0) .& ((branch_arr[:,1].!=lineOff.from) .| (branch_arr[:,2].!=lineOff.to)) )
num_on = length(lines_on)

if lineOff.from> 0 && lineOff.to > 0
# println("opf_loaddata: was asked to remove line from,to=", lineOff.from, ",", lineOff.to)
end
if length(findall(branch_arr[:,11].==0))>0
# println("opf_loaddata: ", num_lines-length(findall(branch_arr[:,11].>0)), " lines are off and will be discarded (out of ", num_lines, ")")
lines_on = findall((branch_arr[:,11] .> 0))
if !isa(lineOff, Nothing)
for line in lineOff
intersect!(lines_on, findall((branch_arr[:,11] .> 0) .& ((branch_arr[:,1].!=line.from) .| (branch_arr[:,2].!=line.to)) ))
if line.from> 0 && line.to > 0
# println("opf_loaddata: was asked to remove line from,to=", lineOff.from, ",", lineOff.to)
end
if length(findall(branch_arr[:,11].==0))>0
# println("opf_loaddata: ", num_lines-length(findall(branch_arr[:,11].>0)), " lines are off and will be discarded (out of ", num_lines, ")")
end
end
end
num_on = length(lines_on)

lines = Array{Line}(undef, num_on)
ncols_lines = size(branch_arr, 2)
Expand Down
4 changes: 2 additions & 2 deletions src/OPF/opfmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function opf_model_add_block_constraints(opfmodel::JuMP.Model, opfdata::OPFData,
@views for t=1:T, k=1:K
opfdata_c = (k == 1) ? opfdata :
opf_loaddata(rawdata;
lineOff = opfdata.lines[rawdata.ctgs_arr[k - 1]],
lineOff = opfdata.lines[rawdata.ctgs_arr[k - 1],:],
time_horizon_start = modelinfo.time_horizon_start + t - 1,
time_horizon_end = modelinfo.time_horizon_start + t - 1,
load_scale = modelinfo.load_scale,
Expand All @@ -130,7 +130,7 @@ function opf_model_add_block_constraints(opfmodel::JuMP.Model, opfdata::OPFData,
@views for t=1:T, k=1:K
opfdata_c = (k == 1) ? opfdata :
opf_loaddata(rawdata;
lineOff = opfdata.lines[rawdata.ctgs_arr[k - 1]],
lineOff = opfdata.lines[rawdata.ctgs_arr[k - 1],:],
time_horizon_start = modelinfo.time_horizon_start + t - 1,
time_horizon_end = modelinfo.time_horizon_start + t - 1,
load_scale = modelinfo.load_scale,
Expand Down
4 changes: 2 additions & 2 deletions src/OPF/opfsolution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ function write(runinfo::ProxALProblem, nlp::AbstractNLPEvaluator, filename::Stri
modelinfo = nlp.modelinfo
x = runinfo.x
λ = runinfo.λ
if isa(comm, MPI.Comm)
if isa(comm, MPI.Comm) && comm_ranks(comm) != 1
info = MPI.Info()
ff = h5open(filename, "w", comm, info)
elseif isa(comm, Nothing)
elseif isa(comm, Nothing) || comm_ranks(comm) == 1
ff = h5open(filename, "w")
else
error("Wrong type of comm")
Expand Down
2 changes: 1 addition & 1 deletion src/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function init!(block::JuMPBlockBackend, algparams::AlgParams)
end
opfdata_c = (j == 1) ? opfdata :
opf_loaddata(block.rawdata;
lineOff = opfdata.lines[block.rawdata.ctgs_arr[j - 1]],
lineOff = opfdata.lines[block.rawdata.ctgs_arr[j - 1],:],
time_horizon_start = modelinfo.time_horizon_start + t - 1,
time_horizon_end = modelinfo.time_horizon_start + t - 1,
load_scale = modelinfo.load_scale,
Expand Down
4 changes: 2 additions & 2 deletions src/blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ function OPFBlocks(
t, k;
decompCtgs=false,
)
lineOff = Line()
lineOff = nothing
if length(rawdata.ctgs_arr) < k - 1
error("Not enough contingencies in .ctg file while trying to read contingency $(k-1).")
end
if decompCtgs
if k > 1
lineOff = opfdata.lines[rawdata.ctgs_arr[k - 1]]
lineOff = opfdata.lines[rawdata.ctgs_arr[k - 1,:]]
end
end
data = opf_loaddata(
Expand Down

0 comments on commit 4bfe8aa

Please sign in to comment.