Skip to content

Commit

Permalink
Merge pull request #691 from NREL-SIIP/jd/performance_patch3
Browse files Browse the repository at this point in the history
performance patch3
  • Loading branch information
jd-lara authored May 26, 2021
2 parents dd32cb2 + 9a159dc commit ba73ac5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mutable struct OptimizationContainer <: AbstractModelContainer
aux_variables::Dict{AuxVarKey, AbstractArray}
constraints::Dict{Symbol, AbstractArray}
cost_function::JuMP.AbstractJuMPScalar
expressions::Dict{Symbol, JuMP.Containers.DenseAxisArray}
expressions::DenseAxisArrayContainer
parameters::ParametersContainer
initial_conditions::InitialConditions
pm::Union{Nothing, PM.AbstractPowerModel}
Expand Down
31 changes: 26 additions & 5 deletions src/devices_models/devices/AC_branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ function branch_rate_constraints!(
return
end

function _branch_flow_constraint!(
jump_model::JuMP.Model,
ptdf_col::Vector{Float64},
nodal_balance_expressions,
flow_variables,
t::Int,
)
return JuMP.@constraint(
jump_model,
sum(ptdf_col[i] * nodal_balance_expressions[i, t] for i in 1:length(ptdf_col)) -
flow_variables[t] == 0.0
)
end

function branch_flow_values!(
optimization_container::OptimizationContainer,
devices::IS.FlattenIteratorWrapper{B},
Expand All @@ -159,12 +173,19 @@ function branch_flow_values!(
nodal_balance_expressions = optimization_container.expressions[:nodal_balance_active]
flow_variables = get_variable(optimization_container, FLOW_ACTIVE_POWER, B)
jump_model = get_jump_model(optimization_container)
for t in time_steps, br in devices
for br in devices
name = PSY.get_name(br)
branch_flow[name, t] = JuMP.@constraint(
jump_model,
sum(ptdf[name, i] * nodal_balance_expressions[i, t] for i in ptdf.axes[2]) == flow_variables[name, t]
)
ptdf_col = ptdf[name, :]
flow_variables_ = flow_variables[name, :]
for t in time_steps
branch_flow[name, t] = _branch_flow_constraint!(
jump_model,
ptdf_col,
nodal_balance_expressions.data,
flow_variables_,
t,
)
end
end
end

Expand Down

0 comments on commit ba73ac5

Please sign in to comment.