From c0654b0f805ae849d5b99cc7f9731d4dc659de78 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 25 May 2021 21:43:32 -0700 Subject: [PATCH 1/2] some improvements in ptdf performance --- src/devices_models/devices/AC_branches.jl | 31 +++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/devices_models/devices/AC_branches.jl b/src/devices_models/devices/AC_branches.jl index 384dd188d2..83d9a43854 100644 --- a/src/devices_models/devices/AC_branches.jl +++ b/src/devices_models/devices/AC_branches.jl @@ -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}, @@ -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 From 9a159dc9c293f66f189af8410b3069f7b8d07048 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 25 May 2021 21:43:40 -0700 Subject: [PATCH 2/2] use alias --- src/core/optimization_container.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 4a91dd182b..249500791a 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -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}