Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/PowerOperationsModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ProgressMeter
import PowerSystems
import PowerSystems: get_component
import Serialization
import SparseArrays
import TimerOutputs
import InteractiveUtils: methodswith

Expand Down
50 changes: 33 additions & 17 deletions src/ac_transmission_models/AC_branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -755,26 +755,48 @@ function add_constraints!(
end

function _make_flow_expressions!(
jump_model::JuMP.Model,
name::String,
time_steps::UnitRange{Int},
ptdf_col::AbstractVector{Float64},
ptdf_col::Vector{Float64},
nodal_balance_expressions::Matrix{JuMP.AffExpr},
)
@debug "Making Flow Expression on thread $(Threads.threadid()) for branch $name"
nz_idx = [i for i in eachindex(ptdf_col) if abs(ptdf_col[i]) > PTDF_ZERO_TOL]
hint = length(nz_idx)
expressions = Vector{JuMP.AffExpr}(undef, length(time_steps))
for t in time_steps
expressions[t] = JuMP.@expression(
jump_model,
sum(
ptdf_col[i] * nodal_balance_expressions[i, t] for
i in 1:length(ptdf_col)
acc = IOM.get_hinted_aff_expr(hint)
@inbounds for i in nz_idx
JuMP.add_to_expression!(acc, ptdf_col[i], nodal_balance_expressions[i, t])
end
expressions[t] = acc
end
return name, expressions
end

function _make_flow_expressions!(
name::String,
time_steps::UnitRange{Int},
ptdf_col::SparseArrays.SparseVector{Float64, Int},
nodal_balance_expressions::Matrix{JuMP.AffExpr},
)
@debug "Making Flow Expression on thread $(Threads.threadid()) for branch $name"
nz_idx = SparseArrays.nonzeroinds(ptdf_col)
nz_val = SparseArrays.nonzeros(ptdf_col)
hint = length(nz_idx)
expressions = Vector{JuMP.AffExpr}(undef, length(time_steps))
for t in time_steps
acc = IOM.get_hinted_aff_expr(hint)
@inbounds for k in eachindex(nz_idx)
JuMP.add_to_expression!(
acc,
nz_val[k],
nodal_balance_expressions[nz_idx[k], t],
)
)
end
expressions[t] = acc
end
return name, expressions
# change when using the not concurrent version
# return expressions
end

function _add_expression_to_container!(
Expand All @@ -789,7 +811,6 @@ function _add_expression_to_container!(
name = PSY.get_name(reduction_entry)
if name in branches
branch_flow_expr[name, :] .= _make_flow_expressions!(
jump_model,
name,
time_steps,
ptdf_col,
Expand All @@ -812,7 +833,6 @@ function _add_expression_to_container!(
for name in names
if name in branches
branch_flow_expr[name, :] .= _make_flow_expressions!(
jump_model,
name,
time_steps,
ptdf_col,
Expand All @@ -837,7 +857,6 @@ function _add_expression_to_container!(
for name in names
if name in branches
branch_flow_expr[name, :] .= _make_flow_expressions!(
jump_model,
name,
time_steps,
ptdf_col,
Expand Down Expand Up @@ -873,13 +892,10 @@ function add_expressions!(
time_steps,
)

jump_model = get_jump_model(container)

tasks = map(collect(name_to_arc_map)) do pair
tasks = map(name_to_arc_map) do pair
(name, (arc, _)) = pair
ptdf_col = ptdf[arc, :]
Threads.@spawn _make_flow_expressions!(
jump_model,
name,
time_steps,
ptdf_col,
Expand Down
18 changes: 10 additions & 8 deletions src/ac_transmission_models/branch_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ function construct_device!(
)
end

add_branch_parameters!(
container,
DynamicBranchRatingTimeSeriesParameter,
devices,
device_model,
network_model,
)
if haskey(get_time_series_names(device_model), DynamicBranchRatingTimeSeriesParameter)
add_branch_parameters!(
container,
DynamicBranchRatingTimeSeriesParameter,
devices,
device_model,
network_model,
)
end

if haskey(
get_time_series_names(device_model),
Expand Down Expand Up @@ -260,7 +262,7 @@ function construct_device!(

add_constraints!(
container,
PostContingencyEmergencyRateLimitConstrain,
PostContingencyEmergencyRateLimitConstraint,
branches,
branches_outages,
device_model,
Expand Down
Loading
Loading