From dd61a57dcff35d38d476800493a2a64fca04d25b Mon Sep 17 00:00:00 2001 From: David M Fobes Date: Wed, 8 May 2024 15:17:54 -0600 Subject: [PATCH 1/6] UPD: JuMP v1.15 --- CHANGELOG.md | 1 + Project.toml | 4 +- src/core/base.jl | 15 -- src/core/data.jl | 25 --- src/core/objective.jl | 48 ++--- src/core/solution.jl | 18 +- src/form/acp.jl | 424 +++++++++++++++++++++--------------------- src/form/acr.jl | 238 ++++++++++++------------ src/form/apo.jl | 10 +- src/form/bf_fbs.jl | 44 ++--- src/form/bf_mx.jl | 17 +- src/form/bf_mx_lin.jl | 26 +-- src/form/en_acr.jl | 112 +++++------ src/form/en_ivr.jl | 122 ++++++------ src/form/en_shared.jl | 52 +++--- src/form/fotp.jl | 10 +- src/form/fotr.jl | 76 ++++---- src/form/ivr.jl | 200 ++++++++++---------- src/form/shared.jl | 64 +++---- src/form/utils.jl | 4 +- 20 files changed, 729 insertions(+), 781 deletions(-) mode change 100644 => 100755 src/core/base.jl mode change 100644 => 100755 src/core/data.jl mode change 100644 => 100755 src/core/objective.jl mode change 100644 => 100755 src/core/solution.jl mode change 100644 => 100755 src/form/acp.jl mode change 100644 => 100755 src/form/acr.jl mode change 100644 => 100755 src/form/bf_fbs.jl mode change 100644 => 100755 src/form/en_acr.jl mode change 100644 => 100755 src/form/en_ivr.jl mode change 100644 => 100755 src/form/en_shared.jl mode change 100644 => 100755 src/form/fotp.jl mode change 100644 => 100755 src/form/fotr.jl mode change 100644 => 100755 src/form/ivr.jl mode change 100644 => 100755 src/form/utils.jl diff --git a/CHANGELOG.md b/CHANGELOG.md index 1977e4af0..58d79e435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## staged +- Updated to new JuMP v1.15 nonlinear constraint and expression syntax - Indicated broken tests in `"2w_dy_lead"` and `"3-bus SOCConicUBF opf_bf"` by using `@test_skip` ## v0.15.2 diff --git a/Project.toml b/Project.toml index 5ea33a264..a979e60c9 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "PowerModelsDistribution" uuid = "d7431456-977f-11e9-2de3-97ff7677985e" authors = ["David M Fobes ", "Carleton Coffrin"] repo = "https://github.com/lanl-ansi/PowerModelsDistribution.jl.git" -version = "0.15.2" +version = "0.16.0" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" @@ -29,7 +29,7 @@ Graphs = "1" InfrastructureModels = "0.7.3, 0.7.5" Ipopt = "0.9, 1.0.2, 1.1" JSON = "0.18, 0.19, 0.20, 0.21" -JuMP = "0.22, 0.23, 1" +JuMP = ">=1.15,<2" LoggingExtras = "0.4.7, 1" PolyhedralRelaxations = "0.3.5" SCS = "0.9, 1.0, 1.1" diff --git a/src/core/base.jl b/src/core/base.jl old mode 100644 new mode 100755 index 5f33c2a90..53c0f41b4 --- a/src/core/base.jl +++ b/src/core/base.jl @@ -69,21 +69,6 @@ function _check_var_keys(vars, keys, var_name, comp_name) end -""" - @smart_constraint model::JuMP.Model vars::Vector expr::JuMP.Expression - -Detection of whether a constraint should be NL or not" -""" -macro smart_constraint(model, vars, expr) - esc(quote - if _has_nl_expression($vars) - JuMP.@NLconstraint($model, $expr) - else - JuMP.@constraint($model, $expr) - end - end) -end - """ function set_lower_bound( diff --git a/src/core/data.jl b/src/core/data.jl old mode 100644 new mode 100755 index 8309af410..3e568b516 --- a/src/core/data.jl +++ b/src/core/data.jl @@ -811,31 +811,6 @@ function _make_full_matrix_variable(diag::Vector{T}, lowertriangle::Vector{T}, u return matrix end -# TODO refactor into several functions -"helper to determine if expession has any Nonlinear terms" -function _has_nl_expression(x)::Bool - if isa(x, JuMP.NonlinearExpression) - return true - elseif isa(x, Array) - if any(_has_nl_expression.(x)) - return true - end - elseif isa(x, Dict) - for i in values(x) - if _has_nl_expression(i) - return true - end - end - elseif isa(x, JuMP.Containers.DenseAxisArray) - for i in values(x.data) - if _has_nl_expression(i) - return true - end - end - end - return false -end - """ correct_mc_voltage_angle_differences!(data::Dict{String,<:Any}, default_pad::Real=deg2rad(10.0)) diff --git a/src/core/objective.jl b/src/core/objective.jl old mode 100644 new mode 100755 index 126299e52..cac3e5841 --- a/src/core/objective.jl +++ b/src/core/objective.jl @@ -247,7 +247,7 @@ end "gen connections adaptation of min fuel cost polynomial linquad objective" function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPowerModel; report::Bool=true) - pg_contains_nl_exp = any(x<:JuMP.NonlinearExpression for x in vcat([typeof.(isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg) for nw in nw_ids(pm) for (id,pg) in var(pm, nw, :pg)]...)) + pg_contains_nl_exp = any(x<:JuMP.NonlinearExpr for x in vcat([typeof.(isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg) for nw in nw_ids(pm) for (id,pg) in var(pm, nw, :pg)]...)) gen_cost = Dict() if !pg_contains_nl_exp @@ -277,7 +277,7 @@ function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPo for (i,gen) in nw_ref[:gen] bus = gen["gen_bus"] - #to avoid function calls inside of @NLconstraint: + #to avoid function calls inside of @constraint: pg = var(pm, n, :pg, i) pg = isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg @@ -285,16 +285,16 @@ function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPo if length(gen["cost"]) == 1 gen_cost[(n,i)] = gen["cost"][1] elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, gen["cost"][1]*sum(pg[i] for i in 1:int_dim) + gen["cost"][2]) + gen_cost[(n,i)] = JuMP.@expression(pm.model, (-gen["cost"][1]*sum(-pg[i] for i in 1:int_dim)) + gen["cost"][2]) elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, gen["cost"][1]*sum(pg[i] for i in 1:int_dim)^2 + gen["cost"][2]*sum(pg[i] for i in 1:int_dim) + gen["cost"][3]) + gen_cost[(n,i)] = JuMP.@expression(pm.model, gen["cost"][1]*sum(-pg[i] for i in 1:int_dim)^2 + (-gen["cost"][2]*sum(-pg[i] for i in 1:int_dim)) + gen["cost"][3]) else gen_cost[(n,i)] = 0.0 end end end - return JuMP.@NLobjective(pm.model, Min, + return JuMP.@objective(pm.model, Min, sum( sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) for (n, nw_ref) in nws(pm)) @@ -313,9 +313,9 @@ function _objective_mc_min_fuel_cost_polynomial_linquad_switch(pm::AbstractUnbal if length(gen["cost"]) == 1 gen_cost[(n,i)] = gen["cost"][1] elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = gen["cost"][1]*pg + gen["cost"][2] + gen_cost[(n,i)] = -gen["cost"][1]*(-pg) + gen["cost"][2] elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = gen["cost"][1]*pg^2 + gen["cost"][2]*pg + gen["cost"][3] + gen_cost[(n,i)] = gen["cost"][1]*pg^2 - gen["cost"][2]*(-pg) + gen["cost"][3] else gen_cost[(n,i)] = 0.0 end @@ -340,14 +340,14 @@ function _objective_mc_min_fuel_cost_polynomial_linquad_switch(pm::AbstractUnbal for (i,gen) in nw_ref[:gen] bus = gen["gen_bus"] - #to avoid function calls inside of @NLconstraint: + #to avoid function calls inside of @constraint: pg = sum(var(pm, n, :pg, i)) if length(gen["cost"]) == 1 gen_cost[(n,i)] = gen["cost"][1] elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = gen["cost"][1]*pg + gen["cost"][2] + gen_cost[(n,i)] = -gen["cost"][1]*(-pg) + gen["cost"][2] elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = gen["cost"][1]*pg^2 + gen["cost"][2]*pg + gen["cost"][3] + gen_cost[(n,i)] = gen["cost"][1]*pg^2 - gen["cost"][2]*(-pg) + gen["cost"][3] else gen_cost[(n,i)] = 0.0 end @@ -375,21 +375,21 @@ function _objective_mc_min_fuel_cost_polynomial_nl(pm::AbstractUnbalancedPowerMo cost_rev = reverse(gen["cost"]) if length(cost_rev) == 1 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1]) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1]) elseif length(cost_rev) == 2 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg))) elseif length(cost_rev) == 3 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg)) + (cost_rev[3]*pg^2)) elseif length(cost_rev) >= 4 cost_rev_nl = cost_rev[4:end] - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg)) + (cost_rev[3]*pg^2) + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) else - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0) + gen_cost[(n,i)] = JuMP.@expression(pm.model, 0.0) end end end - return JuMP.@NLobjective(pm.model, Min, + return JuMP.@objective(pm.model, Min, sum( sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) for (n, nw_ref) in nws(pm)) @@ -406,21 +406,21 @@ function _objective_mc_min_fuel_cost_polynomial_nl_switch(pm::AbstractUnbalanced cost_rev = reverse(gen["cost"]) if length(cost_rev) == 1 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1]) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1]) elseif length(cost_rev) == 2 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg))) elseif length(cost_rev) == 3 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg)) + (cost_rev[3]*pg^2)) elseif length(cost_rev) >= 4 cost_rev_nl = cost_rev[4:end] - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] + (cost_rev[2]*pg) + (cost_rev[3]*pg^2) + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) else - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0) + gen_cost[(n,i)] = JuMP.@expression(pm.model, 0.0) end end end - return JuMP.@NLobjective(pm.model, Min, + return JuMP.@objective(pm.model, Min, sum( sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) + sum( var(pm, n, :switch_state, l) for l in ids(pm, n, :switch_dispatchable)) @@ -438,7 +438,7 @@ function objective_variable_pg_cost(pm::AbstractUnbalancedIVRModel; report::Bool for (n, nw_ref) in nws(pm) gen_lines = calc_cost_pwl_lines(nw_ref[:gen]) - #to avoid function calls inside of @NLconstraint + #to avoid function calls inside of @constraint pg_cost = var(pm, n)[:pg_cost] = JuMP.@variable(pm.model, [i in ids(pm, n, :gen)], base_name="$(n)_pg_cost", ) @@ -448,7 +448,7 @@ function objective_variable_pg_cost(pm::AbstractUnbalancedIVRModel; report::Bool for (i, gen) in nw_ref[:gen] pg = var(pm, n, :pg, i) for line in gen_lines[i] - JuMP.@NLconstraint(pm.model, pg_cost[i] >= line.slope*sum(pg[c] for c in gen["connections"]) + line.intercept) + JuMP.@constraint(pm.model, pg_cost[i] >= (line.slope*sum(pg[c] for c in gen["connections"])) + line.intercept) end end end diff --git a/src/core/solution.jl b/src/core/solution.jl old mode 100644 new mode 100755 index de41154e2..d39b51661 --- a/src/core/solution.jl +++ b/src/core/solution.jl @@ -11,21 +11,9 @@ function _IM.solution_preprocessor(pm::AbstractUnbalancedPowerModel, solution::D end -"custom `build_solution_values` for multiconductor (vector) variables" -function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.VariableRef,1}) - return JuMP.value.(var.data) -end - - -"custom `build_solution_values` for multiconductor (vector) nonlinear expressions" -function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.NonlinearExpression,1}) - return JuMP.value.(var.data) -end - - -"custom `build_solution_values` for multiconductor (vector) generic affine expressions" -function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.GenericAffExpr,1}) - return JuMP.value.(var.data) +"custom `build_solution_values` for multiconductor (vector) JuMP expressions" +function _IM.build_solution_values(var::JuMP.AbstractJuMPScalar) + return JuMP.value(var) end diff --git a/src/form/acp.jl b/src/form/acp.jl old mode 100644 new mode 100755 index b70d5aaef..273cf4b6a --- a/src/form/acp.jl +++ b/src/form/acp.jl @@ -95,11 +95,6 @@ function constraint_mc_switch_state_on_off(pm::AbstractUnbalancedACPModel, nw::I for (idx,(fc,tc)) in enumerate(zip(f_connections, t_connections)) if relax - vm_fr_ub = JuMP.has_upper_bound(vm_fr[fc]) ? JuMP.upper_bound(vm_fr[fc]) : 1e20 - vm_to_lb = JuMP.has_lower_bound(vm_to[tc]) ? JuMP.lower_bound(vm_to[tc]) : -1e20 - va_fr_ub = JuMP.has_upper_bound(va_fr[tc]) ? JuMP.upper_bound(va_fr[fc]) : 1e20 - va_to_lb = JuMP.has_lower_bound(va_to[tc]) ? JuMP.lower_bound(va_to[tc]) : -1e20 - M = 1e20 JuMP.@constraint(pm.model, vm_fr[fc] - vm_to[tc] <= M * (1-z)) JuMP.@constraint(pm.model, vm_fr[fc] - vm_to[tc] >= -M * (1-z)) @@ -149,39 +144,39 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedACPModel, nw::I ungrounded_terminals = [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]] for (idx,t) in ungrounded_terminals - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - == - sum(pg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - - Pd[idx] - - ( # shunt - Gt[idx,idx] * vm[t]^2 - +sum( Gt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) - +Bt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + + Pd[idx] + + ( # shunt + (Gt[idx,idx] * vm[t]^2) + +sum( (Gt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) + +(Bt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx,u) in ungrounded_terminals if idx != jdx) ) - + p_slack[t] + - p_slack[t] + == 0.0 ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - == - sum(qg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - - Qd[idx] - - ( # shunt - -Bt[idx,idx] * vm[t]^2 - -sum( Bt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) - -Gt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + + Qd[idx] + + ( # shunt + (-Bt[idx,idx] * vm[t]^2) + -sum( (Bt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) + -(Gt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx,u) in ungrounded_terminals if idx != jdx) ) - + q_slack[t] + - q_slack[t] + == 0.0 ) push!(cstr_q, cq) @@ -223,17 +218,17 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACPModel, nw::In ungrounded_terminals = [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]] for (idx,t) in ungrounded_terminals - cp = JuMP.@NLconstraint(pm.model, - sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + cp = JuMP.@constraint(pm.model, + sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) - + sum( pt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) - - sum(pg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + + sum(pt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) + + sum(-pg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + sum(ps[s][t]*z_storage[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, d, "pd")[findfirst(isequal(t), conns)]*z_demand[d] for (d, conns) in bus_loads if t in conns) + sum(z_shunt[s] * - (ref(pm, nw, :shunt, s)["gs"][findfirst(isequal(t), conns), findfirst(isequal(t), conns)] * vm[t]^2 - +sum( ref(pm, nw, :shunt, s)["gs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * cos(va[t]-va[u]) - +ref(pm, nw, :shunt, s)["bs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * sin(va[t]-va[u]) + ((ref(pm, nw, :shunt, s)["gs"][findfirst(isequal(t), conns), findfirst(isequal(t), conns)] * vm[t]^2) + +sum( (ref(pm, nw, :shunt, s)["gs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * cos(va[t]-va[u])) + +(ref(pm, nw, :shunt, s)["bs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx, u) in ungrounded_terminals if idx != jdx ) ) for (s, conns) in bus_shunts if t in conns ) == @@ -241,17 +236,17 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, - sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + cq = JuMP.@constraint(pm.model, + sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) - + sum( qt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) - + sum( qs[s][t]*z_storage[s] for (s, conns) in bus_storage if t in conns) + + sum(qt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) + + sum(-qg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + + sum(qs[s][t]*z_storage[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)]*z_demand[l] for (l, conns) in bus_loads if t in conns) + sum(z_shunt[sh] * - (-ref(pm, nw, :shunt, sh)["bs"][findfirst(isequal(t), conns), findfirst(isequal(t), conns)] * vm[t]^2 - -sum( ref(pm, nw, :shunt, sh)["bs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * cos(va[t]-va[u]) - -ref(pm, nw, :shunt, sh)["gs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * sin(va[t]-va[u]) + ((-ref(pm, nw, :shunt, sh)["bs"][findfirst(isequal(t), conns), findfirst(isequal(t), conns)] * vm[t]^2) + -sum( (ref(pm, nw, :shunt, sh)["bs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * cos(va[t]-va[u])) + -(ref(pm, nw, :shunt, sh)["gs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx, u) in ungrounded_terminals if idx != jdx ) ) for (sh, conns) in bus_shunts if t in conns ) == @@ -304,37 +299,37 @@ function constraint_mc_power_balance_simple(pm::AbstractUnbalancedACPModel, nw:: ungrounded_terminals = [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]] for (idx,t) in ungrounded_terminals - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - == - sum(pg[g][t] for (g, conns) in bus_gens) - - sum(ps[s][t] for (s, conns) in bus_storage) - - Pd[idx] - - ( # shunt - Gt[idx,idx] * vm[t]^2 - +sum( Gt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) - +Bt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) + + sum(-pg[g][t] for (g, conns) in bus_gens) + + sum(ps[s][t] for (s, conns) in bus_storage) + + Pd[idx] + + ( # shunt + (Gt[idx,idx] * vm[t]^2) + +sum( (Gt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) + +(Bt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx,u) in ungrounded_terminals if idx != jdx) ) + == 0.0 ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum(q[a][c] for a in bus_arcs) + sum(qsw[a_sw][c] for a_sw in bus_arcs_sw) + sum(qt[a_trans][c] for a_trans in bus_arcs_trans) - == - sum(qg[g][c] for g in bus_gens) - - sum(qs[s][c] for s in bus_storage) - - Qd[idx] - - ( # shunt - -Bt[idx,idx] * vm[t]^2 - -sum( Bt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) - -Gt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) + + sum(-qg[g][c] for g in bus_gens) + + sum(qs[s][c] for s in bus_storage) + + Qd[idx] + + ( # shunt + (-Bt[idx,idx] * vm[t]^2) + -sum( (Bt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) + -(Gt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx,u) in ungrounded_terminals if idx != jdx) ) + == 0.0 ) push!(cstr_q, cq) end @@ -374,17 +369,17 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: for (idx,t) in ungrounded_terminals if any(Bs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) || any(Gs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt - +Gs[idx,idx] * vm[t]^2 - +sum( Gs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) - +Bs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) + (Gs[idx,idx] * vm[t]^2) + +sum( (Gs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) + +(Bs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx,u) in ungrounded_terminals if idx != jdx) ) == @@ -392,17 +387,17 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt - -Bs[idx,idx] * vm[t]^2 - -sum( Bs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) - -Gs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) + (-Bs[idx,idx] * vm[t]^2) + -sum( (Bs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) + -(Gs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx,u) in ungrounded_terminals if idx != jdx) ) == @@ -410,27 +405,27 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: ) push!(cstr_q, cq) else - cp = @smart_constraint(pm.model, [p, pg, ps, psw, pt, pd, vm], + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) - + Gs[idx,idx] * vm[t]^2 + + (Gs[idx,idx] * vm[t]^2) == 0.0 ) push!(cstr_p, cp) - cq = @smart_constraint(pm.model, [q, qg, qs, qsw, qt, qd, vm], + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) - - Bs[idx,idx] * vm[t]^2 + - (Bs[idx,idx] * vm[t]^2) == 0.0 ) @@ -486,7 +481,7 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In cap_state = 1.0 ncnds = length(terminals) Gs = fill(0.0, ncnds, ncnds) - Bs = convert(Matrix{JuMP.NonlinearExpression}, JuMP.@NLexpression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) + Bs = convert(Matrix{JuMP.NonlinearExpr}, JuMP.@expression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) for (val, connections) in bus_shunts shunt = ref(pm,nw,:shunt,val) for (idx,c) in enumerate(connections) @@ -495,7 +490,7 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In end for (jdx,d) in enumerate(connections) Gs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] += shunt["gs"][idx,jdx] - Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@NLexpression(pm.model, Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + shunt["bs"][idx,jdx]*cap_state) + Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@expression(pm.model, Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + (shunt["bs"][idx,jdx]*cap_state)) end end end @@ -506,17 +501,17 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In for (idx,t) in ungrounded_terminals if any(Bs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) || any(Gs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt - +Gs[idx,idx] * vm[t]^2 - +sum( Gs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) - +Bs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) + (Gs[idx,idx] * vm[t]^2) + +sum( (Gs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) + +(Bs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx,u) in ungrounded_terminals if idx != jdx) ) == @@ -524,17 +519,17 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt - -Bs[idx,idx] * vm[t]^2 - -sum( Bs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) - -Gs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) + (-Bs[idx,idx] * vm[t]^2) + -sum( (Bs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) + -(Gs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) for (jdx,u) in ungrounded_terminals if idx != jdx) ) == @@ -542,27 +537,27 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_q, cq) else - cp = @smart_constraint(pm.model, [p, pg, ps, psw, pt, pd, vm], + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) - + Gs[idx,idx] * vm[t]^2 + + (Gs[idx,idx] * vm[t]^2) == 0.0 ) push!(cstr_p, cp) - cq = @smart_constraint(pm.model, [q, qg, qs, qsw, qt, qd, vm, Bs], + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) - - Bs[idx,idx] * vm[t]^2 + - (Bs[idx,idx] * vm[t]^2) == 0.0 ) @@ -670,22 +665,22 @@ function constraint_mc_ohms_yt_from(pm::AbstractUnbalancedACPModel, nw::Int, f_b ohms_yt_p = JuMP.ConstraintRef[] ohms_yt_q = JuMP.ConstraintRef[] for (idx, (fc,tc)) in enumerate(zip(f_connections,t_connections)) - push!(ohms_yt_p, JuMP.@NLconstraint(pm.model, p_fr[fc] == (G[idx,idx]+G_fr[idx,idx])*vm_fr[fc]^2 - +sum( (G[idx,jdx]+G_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd]) - +(B[idx,jdx]+B_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd]) + push!(ohms_yt_p, JuMP.@constraint(pm.model, p_fr[fc] == ((G[idx,idx]+G_fr[idx,idx])*vm_fr[fc]^2) + +sum( ((G[idx,jdx]+G_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd])) + +((B[idx,jdx]+B_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd])) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections)) if idx != jdx) - +sum( -G[idx,jdx]*vm_fr[fc]*vm_to[td]*cos(va_fr[fc]-va_to[td]) - -B[idx,jdx]*vm_fr[fc]*vm_to[td]*sin(va_fr[fc]-va_to[td]) + +sum( (-G[idx,jdx]*vm_fr[fc]*vm_to[td]*cos(va_fr[fc]-va_to[td])) + -(B[idx,jdx]*vm_fr[fc]*vm_to[td]*sin(va_fr[fc]-va_to[td])) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections))) ) ) - push!(ohms_yt_q, JuMP.@NLconstraint(pm.model, q_fr[fc] == -(B[idx,idx]+B_fr[idx,idx])*vm_fr[fc]^2 - -sum( (B[idx,jdx]+B_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd]) - -(G[idx,jdx]+G_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd]) + push!(ohms_yt_q, JuMP.@constraint(pm.model, q_fr[fc] == (-(B[idx,idx]+B_fr[idx,idx])*vm_fr[fc]^2) + -sum( ((B[idx,jdx]+B_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd])) + -((G[idx,jdx]+G_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd])) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections)) if idx != jdx) - -sum(-B[idx,jdx]*vm_fr[fc]*vm_to[td]*cos(va_fr[fc]-va_to[td]) - +G[idx,jdx]*vm_fr[fc]*vm_to[td]*sin(va_fr[fc]-va_to[td]) + -sum((-B[idx,jdx]*vm_fr[fc]*vm_to[td]*cos(va_fr[fc]-va_to[td])) + +(G[idx,jdx]*vm_fr[fc]*vm_to[td]*sin(va_fr[fc]-va_to[td])) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections))) ) ) @@ -739,16 +734,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractUnbalancedACPModel, nw:: x = transformer["controls"]["x"][idx] # (cr+jci) = (p-jq)/(vm⋅cos(va)-jvm⋅sin(va)) - cr = JuMP.@NLexpression(pm.model, ( p_to[idx]*vm_to[tc]*cos(va_to[tc]) + q_to[idx]*vm_to[tc]*sin(va_to[tc]))/vm_to[tc]^2) - ci = JuMP.@NLexpression(pm.model, (-q_to[idx]*vm_to[tc]*cos(va_to[tc]) + p_to[idx]*vm_to[tc]*sin(va_to[tc]))/vm_to[tc]^2) + cr = JuMP.@expression(pm.model, ( (p_to[idx]*vm_to[tc]*cos(va_to[tc])) + (q_to[idx]*vm_to[tc]*sin(va_to[tc])))/vm_to[tc]^2) + ci = JuMP.@expression(pm.model, ((-q_to[idx]*vm_to[tc]*cos(va_to[tc])) + (p_to[idx]*vm_to[tc]*sin(va_to[tc])))/vm_to[tc]^2) # v_drop = (cr+jci)⋅(r+jx) - vr_drop = JuMP.@NLexpression(pm.model, r*cr-x*ci) - vi_drop = JuMP.@NLexpression(pm.model, r*ci+x*cr) + vr_drop = JuMP.@expression(pm.model, (r*cr)-(x*ci)) + vi_drop = JuMP.@expression(pm.model, (r*ci)+(x*cr)) # v_ref-δ ≤ vm_fr-(cr+jci)⋅(r+jx)≤ v_ref+δ # vm_fr/1.1 ≤ vm_to ≤ vm_fr/0.9 - JuMP.@NLconstraint(pm.model, (vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2 + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≥ (v_ref - δ)^2) - JuMP.@NLconstraint(pm.model, (vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2 + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≤ (v_ref + δ)^2) + JuMP.@constraint(pm.model, ((vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2) + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≥ (v_ref - δ)^2) + JuMP.@constraint(pm.model, ((vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2) + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≤ (v_ref + δ)^2) JuMP.@constraint(pm.model, vm_fr[fc]/1.1 ≤ vm_to[tc]) JuMP.@constraint(pm.model, vm_fr[fc]/0.9 ≥ vm_to[tc]) end @@ -782,10 +777,10 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACPModel, nw:: # e.g., for nph=3: 1->3, 2->1, 3->2 jdx = (idx-1+1)%nph+1 fd = f_connections[jdx] - vd_re[idx] = JuMP.@NLexpression(pm.model, vm_fr[fc]*cos(va_fr[fc])-vm_fr[fd]*cos(va_fr[fd])) - vd_im[idx] = JuMP.@NLexpression(pm.model, vm_fr[fc]*sin(va_fr[fc])-vm_fr[fd]*sin(va_fr[fd])) - JuMP.@NLconstraint(pm.model, vd_re[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*cos(va_to[tc])) - JuMP.@NLconstraint(pm.model, vd_im[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*sin(va_to[tc])) + vd_re[idx] = JuMP.@expression(pm.model, (vm_fr[fc]*cos(va_fr[fc]))-(vm_fr[fd]*cos(va_fr[fd]))) + vd_im[idx] = JuMP.@expression(pm.model, (vm_fr[fc]*sin(va_fr[fc]))-(vm_fr[fd]*sin(va_fr[fd]))) + JuMP.@constraint(pm.model, vd_re[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*cos(va_to[tc])) + JuMP.@constraint(pm.model, vd_im[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*sin(va_to[tc])) end p_fr = var(pm, nw, :pt, f_idx) @@ -801,8 +796,8 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACPModel, nw:: # -Im(s/v) = -(q*cos(va)-p*sin(va))/|v| for (idx,(fc,tc)) in enumerate(zip(f_connections,t_connections)) # id = conj(s_to/v_to)./tm - id_re[idx] = JuMP.@NLexpression(pm.model, (p_to[tc]*cos(va_to[tc])+q_to[tc]*sin(va_to[tc]))/vm_to[tc]/(tm_scale*tm[idx])/pol) - id_im[idx] = JuMP.@NLexpression(pm.model, -(q_to[tc]*cos(va_to[tc])-p_to[tc]*sin(va_to[tc]))/vm_to[tc]/(tm_scale*tm[idx])/pol) + id_re[idx] = JuMP.@expression(pm.model, ((p_to[tc]*cos(va_to[tc]))+(q_to[tc]*sin(va_to[tc])))/vm_to[tc]/(tm_scale*tm[idx])/pol) + id_im[idx] = JuMP.@expression(pm.model, -((q_to[tc]*cos(va_to[tc]))-(p_to[tc]*sin(va_to[tc])))/vm_to[tc]/(tm_scale*tm[idx])/pol) end for (idx, (fc,tc)) in enumerate(zip(f_connections,t_connections)) # rotate by nph-1 to get 'previous' phase @@ -811,13 +806,13 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACPModel, nw:: # s_fr = v_fr*conj(i_fr) # = v_fr*conj(id[q]-id[p]) # = v_fr*(id_re[q]-j*id_im[q]-id_re[p]+j*id_im[p]) - JuMP.@NLconstraint(pm.model, p_fr[fc] == - vm_fr[fc]*cos(va_fr[fc])*( id_re[jdx]-id_re[idx]) - -vm_fr[fc]*sin(va_fr[fc])*(-id_im[jdx]+id_im[idx]) + JuMP.@constraint(pm.model, p_fr[fc] == + (vm_fr[fc]*cos(va_fr[fc])*( id_re[jdx]-id_re[idx])) + -(vm_fr[fc]*sin(va_fr[fc])*(-id_im[jdx]+id_im[idx])) ) - JuMP.@NLconstraint(pm.model, q_fr[fc] == - vm_fr[fc]*cos(va_fr[fc])*(-id_im[jdx]+id_im[idx]) - +vm_fr[fc]*sin(va_fr[fc])*( id_re[jdx]-id_re[idx]) + JuMP.@constraint(pm.model, q_fr[fc] == + (vm_fr[fc]*cos(va_fr[fc])*(-id_im[jdx]+id_im[idx])) + +(vm_fr[fc]*sin(va_fr[fc])*( id_re[jdx]-id_re[idx])) ) end end @@ -845,25 +840,25 @@ function constraint_mc_bus_voltage_magnitude_vuf(pm::AbstractUnbalancedACPModel, a2re = real(a^2) a2im = imag(a^2) # real and imaginary components of U+ - vrepos = JuMP.@NLexpression(pm.model, - (vm_a*cos(va_a) + are*vm_b*cos(va_b) - aim*vm_b*sin(va_b) + a2re*vm_c*cos(va_c) - a2im*vm_c*sin(va_c))/3 + vrepos = JuMP.@expression(pm.model, + ((vm_a*cos(va_a)) + (are*vm_b*cos(va_b)) - (aim*vm_b*sin(va_b)) + (a2re*vm_c*cos(va_c)) - (a2im*vm_c*sin(va_c)))/3 ) - vimpos = JuMP.@NLexpression(pm.model, - (vm_a*sin(va_a) + are*vm_b*sin(va_b) + aim*vm_b*cos(va_b) + a2re*vm_c*sin(va_c) + a2im*vm_c*cos(va_c))/3 + vimpos = JuMP.@expression(pm.model, + ((vm_a*sin(va_a)) + (are*vm_b*sin(va_b)) + (aim*vm_b*cos(va_b)) + (a2re*vm_c*sin(va_c)) + (a2im*vm_c*cos(va_c)))/3 ) # square of magnitude of U+, |U+|^2 - vmpossqr = JuMP.@NLexpression(pm.model, vrepos^2+vimpos^2) + vmpossqr = JuMP.@expression(pm.model, vrepos^2+vimpos^2) # real and imaginary components of U- - vreneg = JuMP.@NLexpression(pm.model, - (vm_a*cos(va_a) + a2re*vm_b*cos(va_b) - a2im*vm_b*sin(va_b) + are*vm_c*cos(va_c) - aim*vm_c*sin(va_c))/3 + vreneg = JuMP.@expression(pm.model, + ((vm_a*cos(va_a)) + (a2re*vm_b*cos(va_b)) - (a2im*vm_b*sin(va_b)) + (are*vm_c*cos(va_c)) - (aim*vm_c*sin(va_c)))/3 ) - vimneg = JuMP.@NLexpression(pm.model, - (vm_a*sin(va_a) + a2re*vm_b*sin(va_b) + a2im*vm_b*cos(va_b) + are*vm_c*sin(va_c) + aim*vm_c*cos(va_c))/3 + vimneg = JuMP.@expression(pm.model, + ((vm_a*sin(va_a)) + (a2re*vm_b*sin(va_b)) + (a2im*vm_b*cos(va_b)) + (are*vm_c*sin(va_c)) + (aim*vm_c*cos(va_c)))/3 ) # square of magnitude of U-, |U-|^2 - vmnegsqr = JuMP.@NLexpression(pm.model, vreneg^2+vimneg^2) + vmnegsqr = JuMP.@expression(pm.model, vreneg^2+vimneg^2) # finally, apply constraint - JuMP.@NLconstraint(pm.model, vmnegsqr <= vufmax^2*vmpossqr) + JuMP.@constraint(pm.model, vmnegsqr <= vufmax^2*vmpossqr) # DEBUGGING: save references for post check #var(pm, nw_id_default, :vmpossqr)[bus_id] = vmpossqr #var(pm, nw_id_default, :vmnegsqr)[bus_id] = vmnegsqr @@ -892,16 +887,16 @@ function constraint_mc_bus_voltage_magnitude_negative_sequence(pm::AbstractUnbal a2re = real(a^2) a2im = imag(a^2) # real and imaginary components of U- - vreneg = JuMP.@NLexpression(pm.model, - (vm_a*cos(va_a) + a2re*vm_b*cos(va_b) - a2im*vm_b*sin(va_b) + are*vm_c*cos(va_c) - aim*vm_c*sin(va_c))/3 + vreneg = JuMP.@expression(pm.model, + ((vm_a*cos(va_a)) + (a2re*vm_b*cos(va_b)) - (a2im*vm_b*sin(va_b)) + (are*vm_c*cos(va_c)) - (aim*vm_c*sin(va_c)))/3 ) - vimneg = JuMP.@NLexpression(pm.model, - (vm_a*sin(va_a) + a2re*vm_b*sin(va_b) + a2im*vm_b*cos(va_b) + are*vm_c*sin(va_c) + aim*vm_c*cos(va_c))/3 + vimneg = JuMP.@expression(pm.model, + ((vm_a*sin(va_a)) + (a2re*vm_b*sin(va_b)) + (a2im*vm_b*cos(va_b)) + (are*vm_c*sin(va_c)) + (aim*vm_c*cos(va_c)))/3 ) # square of magnitude of U-, |U-|^2 - vmnegsqr = JuMP.@NLexpression(pm.model, vreneg^2+vimneg^2) + vmnegsqr = JuMP.@expression(pm.model, vreneg^2+vimneg^2) # finally, apply constraint - JuMP.@NLconstraint(pm.model, vmnegsqr <= vmnegmax^2) + JuMP.@constraint(pm.model, vmnegsqr <= vmnegmax^2) end @@ -927,16 +922,16 @@ function constraint_mc_bus_voltage_magnitude_positive_sequence(pm::AbstractUnbal a2re = real(a^2) a2im = imag(a^2) # real and imaginary components of U+ - vrepos = JuMP.@NLexpression(pm.model, - (vm_a*cos(va_a) + are*vm_b*cos(va_b) - aim*vm_b*sin(va_b) + a2re*vm_c*cos(va_c) - a2im*vm_c*sin(va_c))/3 + vrepos = JuMP.@expression(pm.model, + ((vm_a*cos(va_a)) + (are*vm_b*cos(va_b)) - (aim*vm_b*sin(va_b)) + (a2re*vm_c*cos(va_c)) - (a2im*vm_c*sin(va_c)))/3 ) - vimpos = JuMP.@NLexpression(pm.model, - (vm_a*sin(va_a) + are*vm_b*sin(va_b) + aim*vm_b*cos(va_b) + a2re*vm_c*sin(va_c) + a2im*vm_c*cos(va_c))/3 + vimpos = JuMP.@expression(pm.model, + ((vm_a*sin(va_a)) + (are*vm_b*sin(va_b)) + (aim*vm_b*cos(va_b)) + (a2re*vm_c*sin(va_c)) + (a2im*vm_c*cos(va_c)))/3 ) # square of magnitude of U+, |U+|^2 - vmpossqr = JuMP.@NLexpression(pm.model, vrepos^2+vimpos^2) + vmpossqr = JuMP.@expression(pm.model, vrepos^2+vimpos^2) # finally, apply constraint - JuMP.@NLconstraint(pm.model, vmpossqr <= vmposmax^2) + JuMP.@constraint(pm.model, vmpossqr <= vmposmax^2) end @@ -956,16 +951,16 @@ function constraint_mc_bus_voltage_magnitude_zero_sequence(pm::AbstractUnbalance (vm_a, vm_b, vm_c) = [var(pm, nw, :vm, bus_id)[i] for i in 1:3] (va_a, va_b, va_c) = [var(pm, nw, :va, bus_id)[i] for i in 1:3] # real and imaginary components of U+ - vrezero = JuMP.@NLexpression(pm.model, - (vm_a*cos(va_a) + vm_b*cos(va_b) + vm_c*cos(va_c))/3 + vrezero = JuMP.@expression(pm.model, + ((vm_a*cos(va_a)) + (vm_b*cos(va_b)) + (vm_c*cos(va_c)))/3 ) - vimzero = JuMP.@NLexpression(pm.model, - (vm_a*sin(va_a) + vm_b*sin(va_b) + vm_c*sin(va_c))/3 + vimzero = JuMP.@expression(pm.model, + ((vm_a*sin(va_a)) + (vm_b*sin(va_b)) + (vm_c*sin(va_c)))/3 ) # square of magnitude of U+, |U+|^2 - vmzerosqr = JuMP.@NLexpression(pm.model, vrezero^2+vimzero^2) + vmzerosqr = JuMP.@expression(pm.model, vrezero^2+vimzero^2) # finally, apply constraint - JuMP.@NLconstraint(pm.model, vmzerosqr <= vmzeromax^2) + JuMP.@constraint(pm.model, vmzerosqr <= vmzeromax^2) end @@ -984,8 +979,8 @@ function constraint_mc_load_current_delta(pm::AbstractUnbalancedACPModel, nw::In vm_a, vm_b, vm_c = var(pm, nw, :vm, load_bus_id) va_a, va_b, va_c = var(pm, nw, :va, load_bus_id) # v_xy = v_x - v_y - vre_xy(vm_x, va_x, vm_y, va_y) = JuMP.@NLexpression(pm.model, vm_x*cos(va_x)-vm_y*cos(va_y)) - vim_xy(vm_x, va_x, vm_y, va_y) = JuMP.@NLexpression(pm.model, vm_x*sin(va_x)-vm_y*sin(va_y)) + vre_xy(vm_x, va_x, vm_y, va_y) = JuMP.@expression(pm.model, (vm_x*cos(va_x))-(vm_y*cos(va_y))) + vim_xy(vm_x, va_x, vm_y, va_y) = JuMP.@expression(pm.model, (vm_x*sin(va_x))-(vm_y*sin(va_y))) vre_ab = vre_xy(vm_a, va_a, vm_b, va_b) vim_ab = vim_xy(vm_a, va_a, vm_b, va_b) vre_bc = vre_xy(vm_b, va_b, vm_c, va_c) @@ -993,8 +988,8 @@ function constraint_mc_load_current_delta(pm::AbstractUnbalancedACPModel, nw::In vre_ca = vre_xy(vm_c, va_c, vm_a, va_a) vim_ca = vim_xy(vm_c, va_c, vm_a, va_a) # i_xy = conj(s_xy/v_xy) - ire_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@NLexpression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*(cp_xy*vre_xy+cq_xy*vim_xy)) - iim_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@NLexpression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*(cp_xy*vim_xy-cq_xy*vre_xy)) + ire_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@expression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*((cp_xy*vre_xy)+(cq_xy*vim_xy))) + iim_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@expression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*((cp_xy*vim_xy)-(cq_xy*vre_xy))) ire_ab = ire_xy(cp_ab, cq_ab, vre_ab, vim_ab) iim_ab = iim_xy(cp_ab, cq_ab, vre_ab, vim_ab) ire_bc = ire_xy(cp_bc, cq_bc, vre_bc, vim_bc) @@ -1004,8 +999,8 @@ function constraint_mc_load_current_delta(pm::AbstractUnbalancedACPModel, nw::In # s_x = v_x*conj(i_xy-i_zx) # p_x = vm_x*cos(va_x)*(ire_xy-ire_zx) + vm_x*sin(va_x)*(iim_xy-iim_zx) # q_x = vm_x*sin(va_x)*(ire_xy-ire_zx) - vm_x*cos(va_x)*(iim_xy-iim_zx) - p_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@NLexpression(pm.model, vm_x*cos(va_x)*(ire_xy-ire_zx) + vm_x*sin(va_x)*(iim_xy-iim_zx)) - q_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@NLexpression(pm.model, vm_x*sin(va_x)*(ire_xy-ire_zx) - vm_x*cos(va_x)*(iim_xy-iim_zx)) + p_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@expression(pm.model, (vm_x*cos(va_x)*(ire_xy-ire_zx)) + (vm_x*sin(va_x)*(iim_xy-iim_zx))) + q_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@expression(pm.model, (vm_x*sin(va_x)*(ire_xy-ire_zx)) - (vm_x*cos(va_x)*(iim_xy-iim_zx))) # s_x = s_x,ref var(pm, nw, :pd_bus)[load_id] = [ p_x(vm_a, va_a, ire_ab, iim_ab, ire_ca, iim_ca), @@ -1023,20 +1018,20 @@ function constraint_mc_bus_voltage_magnitude_ll(pm::AbstractUnbalancedACPModel, # 3 conductors asserted in template already vm_ln = [var(pm, nw, :vm, bus_id)[i] for i in 1:3] va_ln = [var(pm, nw, :va, bus_id)[i] for i in 1:3] - vr_ll = JuMP.@NLexpression(pm.model, [i in 1:3], - vm_ln[i]*cos(va_ln[i]) - vm_ln[i%3+1]*cos(va_ln[i%3+1]) + vr_ll = JuMP.@expression(pm.model, [i in 1:3], + (vm_ln[i]*cos(va_ln[i])) - (vm_ln[i%3+1]*cos(va_ln[i%3+1])) ) - vi_ll = JuMP.@NLexpression(pm.model, [i in 1:3], - vm_ln[i]*sin(va_ln[i]) - vm_ln[i%3+1]*sin(va_ln[i%3+1]) + vi_ll = JuMP.@expression(pm.model, [i in 1:3], + (vm_ln[i]*sin(va_ln[i])) - (vm_ln[i%3+1]*sin(va_ln[i%3+1])) ) for c in 1:3 # factor of 3 is needed because vm_ll bounds are with respect to the # LL base, not the LN base if vm_ll_min[c] > 0 - JuMP.@NLconstraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 >= vm_ll_min[c]^2*3) + JuMP.@constraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 >= vm_ll_min[c]^2*3) end if vm_ll_max[c] < Inf - JuMP.@NLconstraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 <= vm_ll_max[c]^2*3) + JuMP.@constraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 <= vm_ll_max[c]^2*3) end end end @@ -1083,21 +1078,21 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACPModel, nw::Int, i pd_bus = a qd_bus = b else - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx, c) in enumerate(connections) - crd = JuMP.@NLexpression(pm.model, - a[idx]*vm[c]*cos(va[c])*(vm[c]^2)^(alpha[idx]/2-1) - +b[idx]*vm[c]*sin(va[c])*(vm[c]^2)^( beta[idx]/2-1) + crd = JuMP.@expression(pm.model, + (a[idx]*vm[c]*cos(va[c])*(vm[c]^2)^(alpha[idx]/2-1)) + +(b[idx]*vm[c]*sin(va[c])*(vm[c]^2)^( beta[idx]/2-1)) ) - cid = JuMP.@NLexpression(pm.model, - a[idx]*vm[c]*sin(va[c])*(vm[c]^2)^(alpha[idx]/2-1) - -b[idx]*vm[c]*cos(va[c])*(vm[c]^2)^( beta[idx]/2-1) + cid = JuMP.@expression(pm.model, + (a[idx]*vm[c]*sin(va[c])*(vm[c]^2)^(alpha[idx]/2-1)) + -(b[idx]*vm[c]*cos(va[c])*(vm[c]^2)^( beta[idx]/2-1)) ) - push!(pd_bus, JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])*crd+vm[c]*sin(va[c])*cid)) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vm[c]*cos(va[c])*cid+vm[c]*sin(va[c])*crd)) + push!(pd_bus, JuMP.@expression(pm.model, -(vm[c]*cos(va[c])*(-crd))-(vm[c]*sin(va[c])*(-cid)))) + push!(qd_bus, JuMP.@expression(pm.model, (vm[c]*cos(va[c])*(-cid))-(vm[c]*sin(va[c])*(-crd)))) end end @@ -1111,12 +1106,12 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACPModel, nw::Int, i sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*vm[c]^alpha[idx] )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*vm[c]^beta[idx] )) + push!(pd, JuMP.@expression(pm.model, a[idx]*vm[c]^alpha[idx] )) + push!(qd, JuMP.@expression(pm.model, b[idx]*vm[c]^beta[idx] )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -1139,20 +1134,20 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACPModel, nw::Int, vrd = Dict() vid = Dict() for (idx, c) in enumerate(connections) - vrd[c] = JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])-vm[next[c]]*cos(va[next[c]])) - vid[c] = JuMP.@NLexpression(pm.model, vm[c]*sin(va[c])-vm[next[c]]*sin(va[next[c]])) + vrd[c] = JuMP.@expression(pm.model, (vm[c]*cos(va[c]))-(vm[next[c]]*cos(va[next[c]]))) + vid[c] = JuMP.@expression(pm.model, (vm[c]*sin(va[c]))-(vm[next[c]]*sin(va[next[c]]))) end crd = Dict() cid = Dict() for (idx, c) in enumerate(connections) - crd[c] = JuMP.@NLexpression(pm.model, - a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1) - +b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1) + crd[c] = JuMP.@expression(pm.model, + (a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)) + +(b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) ) - cid[c] = JuMP.@NLexpression(pm.model, - a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1) - -b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1) + cid[c] = JuMP.@expression(pm.model, + (a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)) + -(b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) ) end @@ -1160,19 +1155,19 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACPModel, nw::Int, cid_bus = Dict() for (idx, c) in enumerate(conn_bus) if is_triplex - crd_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crd[1]) - cid_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cid[1]) + crd_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crd[1]) + cid_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cid[1]) else - crd_bus[c] = JuMP.@NLexpression(pm.model, crd[c]-crd[prev[c]]) - cid_bus[c] = JuMP.@NLexpression(pm.model, cid[c]-cid[prev[c]]) + crd_bus[c] = JuMP.@expression(pm.model, crd[c]-crd[prev[c]]) + cid_bus[c] = JuMP.@expression(pm.model, cid[c]-cid[prev[c]]) end end - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(conn_bus) - push!(pd_bus, JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])*crd_bus[c]+vm[c]*sin(va[c])*cid_bus[c])) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vm[c]*cos(va[c])*cid_bus[c]+vm[c]*sin(va[c])*crd_bus[c])) + push!(pd_bus, JuMP.@expression(pm.model, -(vm[c]*cos(va[c])*(-crd_bus[c]))-(vm[c]*sin(va[c])*(-cid_bus[c])))) + push!(qd_bus, JuMP.@expression(pm.model, (vm[c]*cos(va[c])*(-cid_bus[c]))-(vm[c]*sin(va[c])*(-crd_bus[c])))) end pd_bus = JuMP.Containers.DenseAxisArray(pd_bus, conn_bus) @@ -1188,8 +1183,8 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACPModel, nw::Int, pd = [] qd = [] for (idx,c) in enumerate(connections) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = pd sol(pm, nw, :load, id)[:qd] = qd @@ -1214,34 +1209,34 @@ function constraint_mc_generator_power_delta(pm::AbstractUnbalancedACPModel, nw: vrg = Dict() vig = Dict() for c in connections - vrg[c] = JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])-vm[next[c]]*cos(va[next[c]])) - vig[c] = JuMP.@NLexpression(pm.model, vm[c]*sin(va[c])-vm[next[c]]*sin(va[next[c]])) + vrg[c] = JuMP.@expression(pm.model, (vm[c]*cos(va[c]))-(vm[next[c]]*cos(va[next[c]]))) + vig[c] = JuMP.@expression(pm.model, (vm[c]*sin(va[c]))-(vm[next[c]]*sin(va[next[c]]))) end crg = Dict() cig = Dict() for c in connections - crg[c] = JuMP.@NLexpression(pm.model, (pg[c]*vrg[c]+qg[c]*vig[c])/(vrg[c]^2+vig[c]^2) ) - cig[c] = JuMP.@NLexpression(pm.model, (pg[c]*vig[c]-qg[c]*vrg[c])/(vrg[c]^2+vig[c]^2) ) + crg[c] = JuMP.@expression(pm.model, ((pg[c]*vrg[c])+(qg[c]*vig[c]))/(vrg[c]^2+vig[c]^2) ) + cig[c] = JuMP.@expression(pm.model, ((pg[c]*vig[c])-(qg[c]*vrg[c]))/(vrg[c]^2+vig[c]^2) ) end crg_bus = Dict() cig_bus = Dict() for c in conn_bus if is_triplex - crg_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crg[1]) - cig_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cig[1]) + crg_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1]) + cig_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1]) else - crg_bus[c] = JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]]) - cig_bus[c] = JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]]) + crg_bus[c] = JuMP.@expression(pm.model, crg[c]-crg[prev[c]]) + cig_bus[c] = JuMP.@expression(pm.model, cig[c]-cig[prev[c]]) end end - pg_bus = Vector{JuMP.NonlinearExpression}([]) - qg_bus = Vector{JuMP.NonlinearExpression}([]) + pg_bus = Vector{JuMP.NonlinearExpr}([]) + qg_bus = Vector{JuMP.NonlinearExpr}([]) for c in conn_bus - push!(pg_bus, JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])*crg_bus[c]+vm[c]*sin(va[c])*cig_bus[c])) - push!(qg_bus, JuMP.@NLexpression(pm.model, -vm[c]*cos(va[c])*cig_bus[c]+vm[c]*sin(va[c])*crg_bus[c])) + push!(pg_bus, JuMP.@expression(pm.model, -(vm[c]*cos(va[c])*(-crg_bus[c]))-(vm[c]*sin(va[c])*(-cig_bus[c])))) + push!(qg_bus, JuMP.@expression(pm.model, (vm[c]*cos(va[c])*(-cig_bus[c]))-(vm[c]*sin(va[c])*(-crg_bus[c])))) end pg_bus = JuMP.Containers.DenseAxisArray(pg_bus, conn_bus) qg_bus = JuMP.Containers.DenseAxisArray(qg_bus, conn_bus) @@ -1265,16 +1260,19 @@ function constraint_mc_storage_losses(pm::AbstractUnbalancedACPModel, n::Int, i: sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - JuMP.@NLconstraint(pm.model, - sum(ps[c] for c in connections) + (sd - sc) - == - p_loss + r * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections) + JuMP.@constraint(pm.model, + -sum(-ps[c] for c in connections) + (sd - sc) + - p_loss + - (r * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections)) + == 0.0 ) - JuMP.@NLconstraint(pm.model, - sum(qs[c] for c in connections) - == - qsc + q_loss + x * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections) + JuMP.@constraint(pm.model, + -sum(-qs[c] for c in connections) + - qsc + - q_loss + - (x * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections)) + == 0.0 ) end diff --git a/src/form/acr.jl b/src/form/acr.jl old mode 100644 new mode 100755 index fccc68ebe..eca287764 --- a/src/form/acr.jl +++ b/src/form/acr.jl @@ -332,12 +332,12 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedACRModel, nw::I sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(pg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - - Pd[idx] - - (vr.*(Gt*vr-Bt*vi) + vi.*(Gt*vi+Bt*vr)) - + p_slack[t] + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + + Pd[idx] + + (vr.*(Gt*vr-Bt*vi) + vi.*(Gt*vi+Bt*vr)) + - p_slack[t] + == 0.0 ) push!(cstr_p, cp) @@ -345,12 +345,12 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedACRModel, nw::I sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - - Qd[idx] - + ( vr[t] * cish - vi[t] * crsh) - + q_slack[t] + + Qd[idx] + - ( vr[t] * cish - vi[t] * crsh) + - q_slack[t] + == 0.0 ) push!(cstr_q, cq) end @@ -404,12 +404,12 @@ function constraint_mc_power_balance_simple(pm::AbstractUnbalancedACRModel, nw:: sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(pg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - - Pd[idx] - + sum(-vr[t] * sum(Gt[idx,jdx]*vr[s]-Bt[idx,jdx]*vi[s] for (jdx,s) in ungrounded_terminals) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + + Pd[idx] + - sum(-vr[t] * sum(Gt[idx,jdx]*vr[s]-Bt[idx,jdx]*vi[s] for (jdx,s) in ungrounded_terminals) -vi[t] * sum(Gt[idx,jdx]*vi[s]+Bt[idx,jdx]*vr[s] for (jdx,s) in ungrounded_terminals)) + == 0.0 ) push!(cstr_p, cp) @@ -417,12 +417,12 @@ function constraint_mc_power_balance_simple(pm::AbstractUnbalancedACRModel, nw:: sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(qg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - - Qd[idx] - + ( vr[t] * sum(Gt[idx,jdx]*vi[s]+Bt[idx,jdx]*vr[s] for (jdx,s) in ungrounded_terminals) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + + Qd[idx] + - ( vr[t] * sum(Gt[idx,jdx]*vi[s]+Bt[idx,jdx]*vr[s] for (jdx,s) in ungrounded_terminals) -vi[t] * sum(Gt[idx,jdx]*vr[s]-Bt[idx,jdx]*vi[s] for (jdx,s) in ungrounded_terminals) ) + == 0.0 ) push!(cstr_q, cq) end @@ -463,31 +463,31 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACRModel, nw::Int, i: # pd/qd can be NLexpressions, so cannot be vectorized for (idx, t) in ungrounded_terminals - cp = @smart_constraint(pm.model, [p, q, pg, qg, ps, qs, psw, qsw, pt, qt, pd, qd, vr, vi], + cp = JuMP.@constraint(pm.model, sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - == - sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) - - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) - + ( -vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) - -vi[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) + + sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) + + sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) + + sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + + ( (vr[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) + +(vi[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) ) + == 0.0 ) push!(cstr_p, cp) - cq = @smart_constraint(pm.model, [p, q, pg, qg, ps, qs, psw, qsw, pt, qt, pd, qd, vr, vi], + cq = JuMP.@constraint(pm.model, sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - == - sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) - - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) - + ( vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) - -vi[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) + + sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) + + sum(qd[load][t] for (load, conns) in bus_loads if t in conns) + + sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + - ( (vr[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) + -(vi[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) ) + == 0.0 ) push!(cstr_q, cq) end @@ -538,14 +538,14 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACRModel, nw::In # calculate Gs, Bs ncnds = length(terminals) Gt = fill(0.0, ncnds, ncnds) - Bt = convert(Matrix{JuMP.NonlinearExpression}, JuMP.@NLexpression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) + Bt = convert(Matrix{JuMP.NonlinearExpr}, JuMP.@expression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) for (val, connections) in bus_shunts shunt = ref(pm,nw,:shunt,val) for (idx,c) in enumerate(connections) cap_state = haskey(shunt,"controls") ? var(pm, nw, :capacitor_state, val)[c] : 1.0 for (jdx,d) in enumerate(connections) Gt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] += shunt["gs"][idx,jdx] - Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@NLexpression(pm.model, Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + shunt["bs"][idx,jdx]*cap_state) + Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@expression(pm.model, Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + (shunt["bs"][idx,jdx]*cap_state)) end end end @@ -557,31 +557,31 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACRModel, nw::In # pd/qd can be NLexpressions, so cannot be vectorized for (idx, t) in ungrounded_terminals - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - == - sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) - - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) - + ( -vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) - -vi[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) + + sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) + + sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) + + sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + - ( -(vr[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) + -(vi[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) ) + == 0.0 ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - == - sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) - - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) - + ( vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) - -vi[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) + + sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) + + sum(qd[load][t] for (load, conns) in bus_loads if t in conns) + + sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + - ( (vr[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) + -(vi[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) ) + == 0.0 ) push!(cstr_q, cq) end @@ -684,29 +684,29 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACRModel, nw::In # pd/qd can be NLexpressions, so cannot be vectorized for (idx, t) in ungrounded_terminals - cp = @smart_constraint(pm.model, [p, pg, ps, psw, pt], + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum(pg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + sum(ps[s][t]*zs[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, d, "pd")[findfirst(isequal(t), conns)]*zd[d] for (d, conns) in bus_loads if t in conns) - + (+vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) - +vi[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals)) + + ( (vr[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) + +(vi[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals))) == 0.0 ) push!(cstr_p, cp) - cq = @smart_constraint(pm.model, [q, qg, qs, qsw, qt], + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum(qg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + sum(qs[s][t]*zs[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, d, "qd")[findfirst(isequal(t), conns)]*zd[d] for (d, conns) in bus_loads if t in conns) - + (-vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) - +vi[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals)) + + (-(vr[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) + +(vi[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals))) == 0.0 ) @@ -780,15 +780,15 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACRModel, nw::Int, i pd_bus = a qd_bus = b else - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - crd = JuMP.@NLexpression(pm.model, a[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1)+b[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1)) - cid = JuMP.@NLexpression(pm.model, a[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1)-b[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1)) + crd = JuMP.@expression(pm.model, (a[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1))+(b[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1))) + cid = JuMP.@expression(pm.model, (a[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1))-(b[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1))) - push!(pd_bus, JuMP.@NLexpression(pm.model, vr[c]*crd+vi[c]*cid)) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vr[c]*cid+vi[c]*crd)) + push!(pd_bus, JuMP.@expression(pm.model, -(vr[c]*(-crd))-(vi[c]*(-cid)))) + push!(qd_bus, JuMP.@expression(pm.model, (vr[c]*(-cid))-(vi[c]*(-crd)))) end end @@ -802,12 +802,12 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACRModel, nw::Int, i sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vr[c]^2+vi[c]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vr[c]^2+vi[c]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -830,34 +830,34 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACRModel, nw::Int, vrd = Dict() vid = Dict() for (idx, c) in enumerate(connections) - vrd[c] = JuMP.@NLexpression(pm.model, vr[c]-vr[next[c]]) - vid[c] = JuMP.@NLexpression(pm.model, vi[c]-vi[next[c]]) + vrd[c] = JuMP.@expression(pm.model, vr[c]-vr[next[c]]) + vid[c] = JuMP.@expression(pm.model, vi[c]-vi[next[c]]) end crd = Dict() cid = Dict() for (idx, c) in enumerate(connections) - crd[c] = JuMP.@NLexpression(pm.model, a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)+b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) - cid[c] = JuMP.@NLexpression(pm.model, a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)-b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) + crd[c] = JuMP.@expression(pm.model, (a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1))+(b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1))) + cid[c] = JuMP.@expression(pm.model, (a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1))-(b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1))) end crd_bus = Dict() cid_bus = Dict() for (idx, c) in enumerate(conn_bus) if is_triplex - crd_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crd[1]) - cid_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cid[1]) + crd_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crd[1]) + cid_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cid[1]) else - crd_bus[c] = JuMP.@NLexpression(pm.model, crd[c]-crd[prev[c]]) - cid_bus[c] = JuMP.@NLexpression(pm.model, cid[c]-cid[prev[c]]) + crd_bus[c] = JuMP.@expression(pm.model, crd[c]-crd[prev[c]]) + cid_bus[c] = JuMP.@expression(pm.model, cid[c]-cid[prev[c]]) end end - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(conn_bus) - push!(pd_bus, JuMP.@NLexpression(pm.model, vr[c]*crd_bus[c]+vi[c]*cid_bus[c])) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vr[c]*cid_bus[c]+vi[c]*crd_bus[c])) + push!(pd_bus, JuMP.@expression(pm.model, -(vr[c]*(-crd_bus[c]))-(vi[c]*(-cid_bus[c])))) + push!(qd_bus, JuMP.@expression(pm.model, (vr[c]*(-cid_bus[c]))-(vi[c]*(-crd_bus[c])))) end pd_bus = JuMP.Containers.DenseAxisArray(pd_bus, conn_bus) @@ -870,11 +870,11 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACRModel, nw::Int, sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -908,34 +908,34 @@ function constraint_mc_generator_power_delta(pm::AbstractUnbalancedACRModel, nw: vrg = Dict() vig = Dict() for c in connections - vrg[c] = JuMP.@NLexpression(pm.model, vr[c]-vr[next[c]]) - vig[c] = JuMP.@NLexpression(pm.model, vi[c]-vi[next[c]]) + vrg[c] = JuMP.@expression(pm.model, vr[c]-vr[next[c]]) + vig[c] = JuMP.@expression(pm.model, vi[c]-vi[next[c]]) end crg = Dict() cig = Dict() for c in connections - crg[c] = JuMP.@NLexpression(pm.model, (pg[c]*vrg[c]+qg[c]*vig[c])/(vrg[c]^2+vig[c]^2) ) - cig[c] = JuMP.@NLexpression(pm.model, (pg[c]*vig[c]-qg[c]*vrg[c])/(vrg[c]^2+vig[c]^2) ) + crg[c] = JuMP.@expression(pm.model, ((pg[c]*vrg[c])+(qg[c]*vig[c]))/(vrg[c]^2+vig[c]^2) ) + cig[c] = JuMP.@expression(pm.model, ((pg[c]*vig[c])-(qg[c]*vrg[c]))/(vrg[c]^2+vig[c]^2) ) end crg_bus = Dict() cig_bus = Dict() for c in conn_bus if is_triplex - crg_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crg[1]) - cig_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cig[1]) + crg_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1]) + cig_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1]) else - crg_bus[c] = JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]]) - cig_bus[c] = JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]]) + crg_bus[c] = JuMP.@expression(pm.model, crg[c]-crg[prev[c]]) + cig_bus[c] = JuMP.@expression(pm.model, cig[c]-cig[prev[c]]) end end - pg_bus = Vector{JuMP.NonlinearExpression}([]) - qg_bus = Vector{JuMP.NonlinearExpression}([]) + pg_bus = Vector{JuMP.NonlinearExpr}([]) + qg_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(conn_bus) - push!(pg_bus, JuMP.@NLexpression(pm.model, vr[c]*crg_bus[c]+vi[c]*cig_bus[c])) - push!(qg_bus, JuMP.@NLexpression(pm.model, -vr[c]*cig_bus[c]+vi[c]*crg_bus[c])) + push!(pg_bus, JuMP.@expression(pm.model, -(vr[c]*(-crg_bus[c]))-(vi[c]*(-cig_bus[c])))) + push!(qg_bus, JuMP.@expression(pm.model, (vr[c]*(-cig_bus[c]))-(vi[c]*(-crg_bus[c])))) end pg_bus = JuMP.Containers.DenseAxisArray(pg_bus, conn_bus) @@ -985,16 +985,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractUnbalancedACRModel, nw:: x = transformer["controls"]["x"][idx] # (cr+jci) = (p-jq)/(vr-j⋅vi) - cr = JuMP.@NLexpression(pm.model, ( p_to[idx]*vr_to[tc] + q_to[idx]*vi_to[tc])/(vr_to[tc]^2+vi_to[tc]^2)) - ci = JuMP.@NLexpression(pm.model, (-q_to[idx]*vr_to[tc] + p_to[idx]*vi_to[tc])/(vr_to[tc]^2+vi_to[tc]^2)) + cr = JuMP.@expression(pm.model, ( (p_to[idx]*vr_to[tc]) + (q_to[idx]*vi_to[tc]))/(vr_to[tc]^2+vi_to[tc]^2)) + ci = JuMP.@expression(pm.model, (-(q_to[idx]*vr_to[tc]) + (p_to[idx]*vi_to[tc]))/(vr_to[tc]^2+vi_to[tc]^2)) # v_drop = (cr+jci)⋅(r+jx) - vr_drop = JuMP.@NLexpression(pm.model, r*cr-x*ci) - vi_drop = JuMP.@NLexpression(pm.model, r*ci+x*cr) + vr_drop = JuMP.@expression(pm.model, (r*cr)-(x*ci)) + vi_drop = JuMP.@expression(pm.model, (r*ci)+(x*cr)) # (v_ref-δ)^2 ≤ (vr_fr-vr_drop)^2 + (vi_fr-vi_drop)^2 ≤ (v_ref+δ)^2 # (vr_fr^2 + vi_fr^2)/1.1^2 ≤ (vr_to^2 + vi_to^2) ≤ (vr_fr^2 + vi_fr^2)/0.9^2 - JuMP.@NLconstraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≥ (v_ref - δ)^2) - JuMP.@NLconstraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≤ (v_ref + δ)^2) + JuMP.@constraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≥ (v_ref - δ)^2) + JuMP.@constraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≤ (v_ref + δ)^2) JuMP.@constraint(pm.model, (vr_fr[fc]^2 + vi_fr[fc]^2)/1.1^2 ≤ vr_to[tc]^2 + vi_to[tc]^2) JuMP.@constraint(pm.model, (vr_fr[fc]^2 + vi_fr[fc]^2)/0.9^2 ≥ vr_to[tc]^2 + vi_to[tc]^2) end @@ -1041,21 +1041,21 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACRModel, nw:: # -Im(s/v) = -(q*cos(va)-p*sin(va))/|v| for (idx, (fc,tc)) in enumerate(zip(f_connections,t_connections)) # id = conj(s_to/v_to)./tm - id_re[idx] = JuMP.@NLexpression(pm.model, (p_to[tc]*vr_p_to[idx]+q_to[tc]*vi_p_to[idx])/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) - id_im[idx] = JuMP.@NLexpression(pm.model, (p_to[tc]*vi_p_to[idx]-q_to[tc]*vr_p_to[idx])/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) + id_re[idx] = JuMP.@expression(pm.model, ((p_to[tc]*vr_p_to[idx])+(q_to[tc]*vi_p_to[idx]))/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) + id_im[idx] = JuMP.@expression(pm.model, ((p_to[tc]*vi_p_to[idx])-(q_to[tc]*vr_p_to[idx]))/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) end for (idx,(fc,tc)) in enumerate(zip(f_connections, t_connections)) jdx = (idx-1+nph-1)%nph+1 # s_fr = v_fr*conj(i_fr) # = v_fr*conj(id[q]-id[p]) # = v_fr*(id_re[q]-j*id_im[q]-id_re[p]+j*id_im[p]) - JuMP.@NLconstraint(pm.model, p_fr[fc] == - vr_p_fr[idx]*( id_re[jdx]-id_re[idx]) - -vi_p_fr[idx]*(-id_im[jdx]+id_im[idx]) + JuMP.@constraint(pm.model, p_fr[fc] == + (vr_p_fr[idx]*( id_re[jdx]-id_re[idx])) + -(vi_p_fr[idx]*(-id_im[jdx]+id_im[idx])) ) - JuMP.@NLconstraint(pm.model, q_fr[fc] == - vr_p_fr[idx]*(-id_im[jdx]+id_im[idx]) - +vi_p_fr[idx]*( id_re[jdx]-id_re[idx]) + JuMP.@constraint(pm.model, q_fr[fc] == + (vr_p_fr[idx]*(-id_im[jdx]+id_im[idx])) + +(vi_p_fr[idx]*( id_re[jdx]-id_re[idx])) ) end end @@ -1078,16 +1078,16 @@ function constraint_mc_storage_losses(pm::AbstractUnbalancedACRModel, i::Int; nw r = storage["r"] x = storage["x"] - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(ps[c] for c in storage["connections"]) + (sd - sc) == - p_loss + r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"])) + p_loss + (r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"]))) ) - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(qs[c] for c in storage["connections"]) == - qsc + q_loss + x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"])) + qsc + q_loss + (x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"]))) ) end @@ -1102,16 +1102,16 @@ function constraint_mc_storage_losses(pm::AbstractUnbalancedACRModel, n::Int, i: sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(ps[c] for c in connections) + (sd - sc) == - p_loss + r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections) + p_loss + (r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections)) ) - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(qs[c] for c in connections) == - qsc + q_loss + x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections) + qsc + q_loss + (x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections)) ) end diff --git a/src/form/apo.jl b/src/form/apo.jl index 018c4d980..0e38efd06 100644 --- a/src/form/apo.jl +++ b/src/form/apo.jl @@ -126,11 +126,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedActivePowerModel, nw: sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(pg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - - sum(pd[d][t] for (d, conns) in bus_loads if t in conns) - - LinearAlgebra.diag(Gt)[idx] + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + + sum(pd[d][t] for (d, conns) in bus_loads if t in conns) + + LinearAlgebra.diag(Gt)[idx] + == 0.0 ) push!(cstr_p, cp) end diff --git a/src/form/bf_fbs.jl b/src/form/bf_fbs.jl old mode 100644 new mode 100755 index c0aa6ff58..f923cb880 --- a/src/form/bf_fbs.jl +++ b/src/form/bf_fbs.jl @@ -316,13 +316,13 @@ function constraint_mc_power_balance(pm::FBSUBFPowerModel, nw::Int, i::Int, term sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - == - sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) - - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) - + ( -vr0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) + + sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) + + sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) + + sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + - ( -vr0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) -vi0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) ) + == 0.0 ) push!(cstr_p, cp) @@ -330,13 +330,13 @@ function constraint_mc_power_balance(pm::FBSUBFPowerModel, nw::Int, i::Int, term sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - == - sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) - - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) - + ( vr0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) + + sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) + + sum(qd[load][t] for (load, conns) in bus_loads if t in conns) + + sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + - ( vr0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) -vi0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) ) + == 0.0 ) push!(cstr_q, cq) end @@ -402,13 +402,13 @@ function constraint_mc_power_balance_capc(pm::FBSUBFPowerModel, nw::Int, i::Int, sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - == - sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) - - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) - + ( -vr0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) + + sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) + + sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) + + sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + - ( -vr0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) -vi0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) ) + == 0.0 ) push!(cstr_p, cp) @@ -416,13 +416,13 @@ function constraint_mc_power_balance_capc(pm::FBSUBFPowerModel, nw::Int, i::Int, sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - == - sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) - - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) - + ( vr0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) + + sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) + + sum(qd[load][t] for (load, conns) in bus_loads if t in conns) + + sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + - ( vr0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) -vi0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) ) + == 0.0 ) push!(cstr_q, cq) end @@ -827,8 +827,8 @@ function constraint_mc_generator_power_delta(pm::FBSUBFPowerModel, nw::Int, id:: crg_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1]) cig_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1]) else - crg_bus[c] = JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]]) - cig_bus[c] = JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]]) + crg_bus[c] = JuMP.@expression(pm.model, crg[c]-crg[prev[c]]) + cig_bus[c] = JuMP.@expression(pm.model, cig[c]-cig[prev[c]]) end end diff --git a/src/form/bf_mx.jl b/src/form/bf_mx.jl index 0954da408..c1e98b237 100644 --- a/src/form/bf_mx.jl +++ b/src/form/bf_mx.jl @@ -1045,10 +1045,11 @@ function constraint_mc_power_balance(pm::KCLMXModels, nw::Int, i::Int, terminals sum( P[a][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a, conns) in bus_arcs if t in conns && u in conns) # + sum( Psw[a_sw][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a_sw, conns) in bus_arcs_sw if t in conns && u in conns) # + sum(Pt[a_trans][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a_trans, conns) in bus_arcs_trans if t in conns && u in conns) - == - sum( Pg[g][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (g, conns) in bus_gens if t in conns && u in conns) - - sum( Pd[d][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (d, conns) in bus_loads if t in conns && u in conns) - - LinearAlgebra.diag(Wr*Gt'+Wi*Bt')[idx] + + + sum( -Pg[g][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (g, conns) in bus_gens if t in conns && u in conns) + + sum( Pd[d][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (d, conns) in bus_loads if t in conns && u in conns) + + LinearAlgebra.diag(Wr*Gt'+Wi*Bt')[idx] + == 0.0 ) push!(cstr_p, cp) @@ -1056,10 +1057,10 @@ function constraint_mc_power_balance(pm::KCLMXModels, nw::Int, i::Int, terminals sum( Q[a][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a, conns) in bus_arcs if t in conns && u in conns) # + sum( Qsw[a_sw][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a_sw, conns) in bus_arcs_sw if t in conns && u in conns) # + sum(Qt[a_trans][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a_trans, conns) in bus_arcs_trans if t in conns && u in conns) - == - sum( Qg[g][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (g, conns) in bus_gens if t in conns && u in conns) - - sum( Qd[d][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (d, conns) in bus_loads if t in conns && u in conns) - - LinearAlgebra.diag(-Wr*Bt'+Wi*Gt')[idx] + + sum( -Qg[g][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (g, conns) in bus_gens if t in conns && u in conns) + + sum( Qd[d][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (d, conns) in bus_loads if t in conns && u in conns) + + LinearAlgebra.diag(-Wr*Bt'+Wi*Gt')[idx] + == 0.0 ) push!(cstr_q, cq) end diff --git a/src/form/bf_mx_lin.jl b/src/form/bf_mx_lin.jl index 6891e1e45..b0e40f1ed 100644 --- a/src/form/bf_mx_lin.jl +++ b/src/form/bf_mx_lin.jl @@ -138,7 +138,7 @@ function constraint_mc_power_balance(pm::LPUBFDiagModel, nw::Int, i::Int, termin sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[d][t] for (d, conns) in bus_loads if t in conns) + sum(LinearAlgebra.diag(ref(pm, nw, :shunt, sh, "gs"))[findfirst(isequal(t), conns)]*w[t] for (sh, conns) in bus_shunts if t in conns) @@ -151,7 +151,7 @@ function constraint_mc_power_balance(pm::LPUBFDiagModel, nw::Int, i::Int, termin sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[d][t] for (d, conns) in bus_loads if t in conns) - sum(LinearAlgebra.diag(ref(pm, nw, :shunt, sh, "bs"))[findfirst(isequal(t), conns)]*w[t] for (sh, conns) in bus_shunts if t in conns) @@ -228,11 +228,11 @@ function constraint_mc_power_balance_capc(pm::LPUBFDiagModel, nw::Int, i::Int, t sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(pg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - - sum(pd[l][t] for (l, conns) in bus_loads if t in conns) - - sum((w[t] * LinearAlgebra.diag(Gt')[idx]) for (sh, conns) in bus_shunts if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + + sum(pd[l][t] for (l, conns) in bus_loads if t in conns) + + sum((w[t] * LinearAlgebra.diag(Gt')[idx]) for (sh, conns) in bus_shunts if t in conns) + == 0.0 ) push!(cstr_p, cp) @@ -257,12 +257,12 @@ function constraint_mc_power_balance_capc(pm::LPUBFDiagModel, nw::Int, i::Int, t sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(qg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - - sum(qd[l][t] for (l, conns) in bus_loads if t in conns) - - sum((-w[t] * LinearAlgebra.diag(Bt')[idx]) for (sh, conns) in uncontrolled_shunts if t in conns) - - sum(-var(pm, nw, :capacitor_reactive_power, sh)[t] for (sh, conns) in controlled_shunts if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + + sum(qd[l][t] for (l, conns) in bus_loads if t in conns) + + sum((-w[t] * LinearAlgebra.diag(Bt')[idx]) for (sh, conns) in uncontrolled_shunts if t in conns) + + sum(-var(pm, nw, :capacitor_reactive_power, sh)[t] for (sh, conns) in controlled_shunts if t in conns) + == 0.0 ) push!(cstr_q, cq) end diff --git a/src/form/en_acr.jl b/src/form/en_acr.jl old mode 100644 new mode 100755 index bd5e446d1..4ab28882d --- a/src/form/en_acr.jl +++ b/src/form/en_acr.jl @@ -57,19 +57,19 @@ function constraint_mc_generator_power_wye(pm::AbstractExplicitNeutralACRModel, vr_pn = [vr[p]-vr[n] for p in phases] vi_pn = [vi[p]-vi[n] for p in phases] - crg = JuMP.@NLexpression(pm.model, [idx in 1:P], + crg = JuMP.@expression(pm.model, [idx in 1:P], ( pg[idx]*vr_pn[idx] + qg[idx]*vi_pn[idx] )/( vr_pn[idx]^2 + vi_pn[idx]^2 ) ) - cig = JuMP.@NLexpression(pm.model, [idx in 1:P], + cig = JuMP.@expression(pm.model, [idx in 1:P], ( pg[idx]*vi_pn[idx] - qg[idx]*vr_pn[idx] )/( vr_pn[idx]^2 + vi_pn[idx]^2 ) ) pg_bus_unmerged = [ - [JuMP.@NLexpression(pm.model, vr[p]*crg[idx]+vi[p]*cig[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, vr[n]*sum(-crg[idx] for idx in 1:P)+vi[n]*sum(-cig[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr[p]*crg[idx]+vi[p]*cig[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, vr[n]*sum(-crg[idx] for idx in 1:P)+vi[n]*sum(-cig[idx] for idx in 1:P)) ] qg_bus_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr[p]*cig[idx]+vi[p]*crg[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, -vr[n]*sum(-cig[idx] for idx in 1:P)+vi[n]*sum(-crg[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr[p]*cig[idx]+vi[p]*crg[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, -vr[n]*sum(-cig[idx] for idx in 1:P)+vi[n]*sum(-crg[idx] for idx in 1:P)) ] end var(pm, nw, :pg_bus)[id] = pg_bus = _merge_bus_flows(pm, pg_bus_unmerged, connections) @@ -115,17 +115,17 @@ function constraint_mc_generator_power_delta(pm::AbstractExplicitNeutralACRModel vr_pp = [vr[c]-vr[d] for (c,d) in zip(ph,ph_next)] vi_pp = [vi[c]-vi[d] for (c,d) in zip(ph,ph_next)] - crg = JuMP.@NLexpression(pm.model, [idx in 1:P], + crg = JuMP.@expression(pm.model, [idx in 1:P], ( pg[idx]*vr_pp[idx] + qg[idx]*vi_pp[idx] )/( vr_pp[idx]^2 + vi_pp[idx]^2 ) ) - cig = JuMP.@NLexpression(pm.model, [idx in 1:P], + cig = JuMP.@expression(pm.model, [idx in 1:P], ( pg[idx]*vi_pp[idx] - qg[idx]*vr_pp[idx] )/( vr_pp[idx]^2 + vi_pp[idx]^2 ) ) - crg_bus = JuMP.@NLexpression(pm.model, [idx in 1:P], crg[idx] - crg[idxs_prev[idx]]) - cig_bus = JuMP.@NLexpression(pm.model, [idx in 1:P], cig[idx] - cig[idxs_prev[idx]]) + crg_bus = JuMP.@expression(pm.model, [idx in 1:P], crg[idx] - crg[idxs_prev[idx]]) + cig_bus = JuMP.@expression(pm.model, [idx in 1:P], cig[idx] - cig[idxs_prev[idx]]) - pg_bus_unmerged = [JuMP.@NLexpression(pm.model, vr[p]*crg_bus[idx]+vi[p]*cig_bus[idx]) for (idx,p) in enumerate(ph)] - qg_bus_unmerged = [JuMP.@NLexpression(pm.model, -vr[p]*cig_bus[idx]+vi[p]*crg_bus[idx]) for (idx,p) in enumerate(ph)] + pg_bus_unmerged = [JuMP.@expression(pm.model, vr[p]*crg_bus[idx]+vi[p]*cig_bus[idx]) for (idx,p) in enumerate(ph)] + qg_bus_unmerged = [JuMP.@expression(pm.model, -vr[p]*cig_bus[idx]+vi[p]*crg_bus[idx]) for (idx,p) in enumerate(ph)] var(pm, nw, :pg_bus)[id] = pg_bus = _merge_bus_flows(pm, pg_bus_unmerged, connections) var(pm, nw, :qg_bus)[id] = qg_bus = _merge_bus_flows(pm, qg_bus_unmerged, connections) @@ -190,8 +190,8 @@ function constraint_mc_load_power_wye(pm::AbstractExplicitNeutralACRModel, nw::I vr_pn = [vr[p]-vr[n] for p in phases] vi_pn = [vi[p]-vi[n] for p in phases] - crd = JuMP.@NLexpression(pm.model, [idx in 1:P], a[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)+b[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) - cid = JuMP.@NLexpression(pm.model, [idx in 1:P], a[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)-b[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) + crd = JuMP.@expression(pm.model, [idx in 1:P], a[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)+b[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) + cid = JuMP.@expression(pm.model, [idx in 1:P], a[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)-b[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) # if constant power load @@ -199,8 +199,8 @@ function constraint_mc_load_power_wye(pm::AbstractExplicitNeutralACRModel, nw::I pd = a qd = b else - pd = JuMP.@NLexpression(pm.model, [idx in 1:P], vr_pn[idx]*crd[idx]+vi_pn[idx]*cid[idx]) - qd = JuMP.@NLexpression(pm.model, [idx in 1:P], -vr_pn[idx]*cid[idx]+vi_pn[idx]*crd[idx]) + pd = JuMP.@expression(pm.model, [idx in 1:P], vr_pn[idx]*crd[idx]+vi_pn[idx]*cid[idx]) + qd = JuMP.@expression(pm.model, [idx in 1:P], -vr_pn[idx]*cid[idx]+vi_pn[idx]*crd[idx]) end if iszero(vr[n]) && iszero(vi[n]) @@ -208,12 +208,12 @@ function constraint_mc_load_power_wye(pm::AbstractExplicitNeutralACRModel, nw::I qd_bus_unmerged = [qd..., 0.0] else pd_bus_unmerged = [ - [JuMP.@NLexpression(pm.model, vr[p]*crd[idx]+vi[p]*cid[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, vr[n]*sum(-crd[idx] for idx in 1:P)+vi[n]*sum(-cid[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr[p]*crd[idx]+vi[p]*cid[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, vr[n]*sum(-crd[idx] for idx in 1:P)+vi[n]*sum(-cid[idx] for idx in 1:P)) ] qd_bus_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr[p]*cid[idx]+vi[p]*crd[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, -vr[n]*sum(-cid[idx] for idx in 1:P)+vi[n]*sum(-crd[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr[p]*cid[idx]+vi[p]*crd[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, -vr[n]*sum(-cid[idx] for idx in 1:P)+vi[n]*sum(-crd[idx] for idx in 1:P)) ] end var(pm, nw, :pd_bus)[id] = pd_bus = _merge_bus_flows(pm, pd_bus_unmerged, connections) @@ -258,14 +258,14 @@ function constraint_mc_load_power_delta(pm::AbstractExplicitNeutralACRModel, nw: vrd = [vr[t]-vr[connections[next(idx)]] for (idx,t) in enumerate(connections)] vid = [vi[t]-vi[connections[next(idx)]] for (idx,t) in enumerate(connections)] - crd = JuMP.@NLexpression(pm.model, [idx in 1:nph], a[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)+b[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) - cid = JuMP.@NLexpression(pm.model, [idx in 1:nph], a[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)-b[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) + crd = JuMP.@expression(pm.model, [idx in 1:nph], a[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)+b[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) + cid = JuMP.@expression(pm.model, [idx in 1:nph], a[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)-b[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) - crd_bus_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:nph], crd[idx]-crd[prev(idx)]) - cid_bus_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:nph], cid[idx]-cid[prev(idx)]) + crd_bus_unmerged = JuMP.@expression(pm.model, [idx in 1:nph], crd[idx]-crd[prev(idx)]) + cid_bus_unmerged = JuMP.@expression(pm.model, [idx in 1:nph], cid[idx]-cid[prev(idx)]) - pd_bus_unmerged = [JuMP.@NLexpression(pm.model, vr[p]*crd_bus_unmerged[idx]+vi[p]*cid_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] - qd_bus_unmerged = [JuMP.@NLexpression(pm.model, -vr[p]*cid_bus_unmerged[idx]+vi[p]*crd_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] + pd_bus_unmerged = [JuMP.@expression(pm.model, vr[p]*crd_bus_unmerged[idx]+vi[p]*cid_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] + qd_bus_unmerged = [JuMP.@expression(pm.model, -vr[p]*cid_bus_unmerged[idx]+vi[p]*crd_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] var(pm, nw, :pd_bus)[id] = pd_bus = _merge_bus_flows(pm, pd_bus_unmerged, connections) var(pm, nw, :qd_bus)[id] = qd_bus = _merge_bus_flows(pm, qd_bus_unmerged, connections) @@ -274,11 +274,11 @@ function constraint_mc_load_power_delta(pm::AbstractExplicitNeutralACRModel, nw: sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for idx in 1:nph - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -357,16 +357,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractExplicitNeutralACRModel, vr_fr_pn = [vr_fr[p]-vr_fr[f_n] for p in f_phases] vi_fr_pn = [vi_fr[p]-vi_fr[f_n] for p in f_phases] - crt_fr = [JuMP.@NLexpression(pm.model, ( pt_fr[idx]*vr_fr_pn[idx]+qt_fr[idx]*vi_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] - cit_fr = [JuMP.@NLexpression(pm.model, (-pt_fr[idx]*vi_fr_pn[idx]+qt_fr[idx]*vr_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] + crt_fr = [JuMP.@expression(pm.model, ( pt_fr[idx]*vr_fr_pn[idx]+qt_fr[idx]*vi_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] + cit_fr = [JuMP.@expression(pm.model, (-pt_fr[idx]*vi_fr_pn[idx]+qt_fr[idx]*vr_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] pt_bus_fr_unmerged = [ - [JuMP.@NLexpression(pm.model, vr_fr[p]*crt_fr[idx]+vi_fr[p]*cit_fr[idx]) for (idx,p) in enumerate(f_phases)]..., - JuMP.@NLexpression(pm.model, vr_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr_fr[p]*crt_fr[idx]+vi_fr[p]*cit_fr[idx]) for (idx,p) in enumerate(f_phases)]..., + JuMP.@expression(pm.model, vr_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)) ] qt_bus_fr_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr_fr[p]*cit_fr[idx]+vi_fr[p]*crt_fr[idx]) for (idx,p) in enumerate(f_phases)]..., - JuMP.@NLexpression(pm.model, -vr_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr_fr[p]*cit_fr[idx]+vi_fr[p]*crt_fr[idx]) for (idx,p) in enumerate(f_phases)]..., + JuMP.@expression(pm.model, -vr_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)) ] end var(pm, nw, :pt_bus)[f_idx] = pt_bus_fr = _merge_bus_flows(pm, pt_bus_fr_unmerged, f_connections) @@ -380,16 +380,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractExplicitNeutralACRModel, vr_to_pn = [vr_to[p]-vr_to[t_n] for p in t_phases] vi_to_pn = [vi_to[p]-vi_to[t_n] for p in t_phases] - crt_to = [JuMP.@NLexpression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] - cit_to = [JuMP.@NLexpression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + crt_to = [JuMP.@expression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + cit_to = [JuMP.@expression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] pt_bus_to_unmerged = [ - [JuMP.@NLexpression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(t_phases)]..., - JuMP.@NLexpression(pm.model, vr_to[t_n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-cit_to[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(t_phases)]..., + JuMP.@expression(pm.model, vr_to[t_n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-cit_to[idx] for idx in 1:P)) ] qt_bus_to_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(t_phases)]..., - JuMP.@NLexpression(pm.model, -vr_to[t_n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-crt_to[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(t_phases)]..., + JuMP.@expression(pm.model, -vr_to[t_n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-crt_to[idx] for idx in 1:P)) ] end var(pm, nw, :pt_bus)[t_idx] = pt_bus_to = _merge_bus_flows(pm, pt_bus_to_unmerged, t_connections) @@ -440,14 +440,14 @@ function constraint_mc_transformer_power_dy(pm::AbstractExplicitNeutralACRModel, vrg_fr = [vr_fr[p]-vr_fr[f_connections[next(idx)]] for (idx,p) in enumerate(f_connections)] vig_fr = [vi_fr[p]-vi_fr[f_connections[next(idx)]] for (idx,p) in enumerate(f_connections)] - crt_fr = JuMP.@NLexpression(pm.model, [idx in 1:P], (pt_fr[idx]*vrg_fr[idx]+qt_fr[idx]*vig_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) - cit_fr = JuMP.@NLexpression(pm.model, [idx in 1:P], (pt_fr[idx]*vig_fr[idx]-qt_fr[idx]*vrg_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) + crt_fr = JuMP.@expression(pm.model, [idx in 1:P], (pt_fr[idx]*vrg_fr[idx]+qt_fr[idx]*vig_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) + cit_fr = JuMP.@expression(pm.model, [idx in 1:P], (pt_fr[idx]*vig_fr[idx]-qt_fr[idx]*vrg_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) - crt_bus_fr_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:P], crt_fr[idx]-crt_fr[prev(idx)]) - cit_bus_fr_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:P], cit_fr[idx]-cit_fr[prev(idx)]) + crt_bus_fr_unmerged = JuMP.@expression(pm.model, [idx in 1:P], crt_fr[idx]-crt_fr[prev(idx)]) + cit_bus_fr_unmerged = JuMP.@expression(pm.model, [idx in 1:P], cit_fr[idx]-cit_fr[prev(idx)]) - pt_bus_fr_unmerged = [JuMP.@NLexpression(pm.model, vr_fr[p]*crt_bus_fr_unmerged[idx]+vi_fr[p]*cit_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] - qt_bus_fr_unmerged = [JuMP.@NLexpression(pm.model, -vr_fr[p]*cit_bus_fr_unmerged[idx]+vi_fr[p]*crt_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] + pt_bus_fr_unmerged = [JuMP.@expression(pm.model, vr_fr[p]*crt_bus_fr_unmerged[idx]+vi_fr[p]*cit_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] + qt_bus_fr_unmerged = [JuMP.@expression(pm.model, -vr_fr[p]*cit_bus_fr_unmerged[idx]+vi_fr[p]*crt_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] var(pm, nw, :pt_bus)[f_idx] = pt_bus_fr = _merge_bus_flows(pm, pt_bus_fr_unmerged, f_connections) var(pm, nw, :qt_bus)[f_idx] = qt_bus_fr = _merge_bus_flows(pm, qt_bus_fr_unmerged, f_connections) @@ -460,16 +460,16 @@ function constraint_mc_transformer_power_dy(pm::AbstractExplicitNeutralACRModel, vr_to_pn = [vr_to[p]-vr_to[t_n] for p in t_phases] vi_to_pn = [vi_to[p]-vi_to[t_n] for p in t_phases] - crt_to = [JuMP.@NLexpression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] - cit_to = [JuMP.@NLexpression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + crt_to = [JuMP.@expression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + cit_to = [JuMP.@expression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] pt_bus_to_unmerged = [ - [JuMP.@NLexpression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, vr_to[n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[n]*sum(-cit_to[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, vr_to[n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[n]*sum(-cit_to[idx] for idx in 1:P)) ] qt_bus_to_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, -vr_to[n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[n]*sum(-crt_to[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, -vr_to[n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[n]*sum(-crt_to[idx] for idx in 1:P)) ] end var(pm, nw, :pt_bus)[t_idx] = pt_bus_to = _merge_bus_flows(pm, pt_bus_to_unmerged, t_connections) @@ -680,7 +680,7 @@ function constraint_mc_thermal_limit_from(pm::AbstractExplicitNeutralACRModel, n if rate_a[idx]= pg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], pmin[i] <= pg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], pmax[i] >= pg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) var(pm, nw, :pg)[id] = JuMP.Containers.DenseAxisArray(pg, connections) var(pm, nw, :qg)[id] = JuMP.Containers.DenseAxisArray(qg, connections) @@ -499,38 +499,38 @@ function constraint_mc_load_current_wye(pm::AbstractExplicitNeutralIVRModel, nw: vr = var(pm, nw, :vr, bus_id) vi = var(pm, nw, :vi, bus_id) - crd = Vector{JuMP.NonlinearExpression}([]) - cid = Vector{JuMP.NonlinearExpression}([]) + crd = Vector{JuMP.NonlinearExpr}([]) + cid = Vector{JuMP.NonlinearExpr}([]) phases = connections[1:end-1] n = connections[end] for (idx, p) in enumerate(phases) - push!(crd, JuMP.@NLexpression(pm.model, - a[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1) - +b[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1) + push!(crd, JuMP.@expression(pm.model, + (a[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1)) + +(b[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1)) )) - push!(cid, JuMP.@NLexpression(pm.model, - a[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1) - -b[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1) + push!(cid, JuMP.@expression(pm.model, + (a[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1)) + -(b[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1)) )) end var(pm, nw, :crd)[id] = crd var(pm, nw, :cid)[id] = cid - crd_bus_n = JuMP.@NLexpression(pm.model, -sum(crd[i] for i in 1:length(phases))) - cid_bus_n = JuMP.@NLexpression(pm.model, -sum(cid[i] for i in 1:length(phases))) + crd_bus_n = JuMP.@expression(pm.model, -sum(crd[i] for i in 1:length(phases))) + cid_bus_n = JuMP.@expression(pm.model, -sum(cid[i] for i in 1:length(phases))) var(pm, nw, :crd_bus)[id] = crd_bus = _merge_bus_flows(pm, [crd..., crd_bus_n], connections) var(pm, nw, :cid_bus)[id] = cid_bus = _merge_bus_flows(pm, [cid..., cid_bus_n], connections) if report - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - push!(pd_bus, JuMP.@NLexpression(pm.model, vr[c]*crd_bus[c]+vi[c]*cid_bus[c])) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vr[c]*cid_bus[c]+vi[c]*crd_bus[c])) + push!(pd_bus, JuMP.@expression(pm.model, (vr[c]*crd_bus[c])+(vi[c]*cid_bus[c]))) + push!(qd_bus, JuMP.@expression(pm.model, -(vr[c]*cid_bus[c])+(vi[c]*crd_bus[c]))) end sol(pm, nw, :load, id)[:pd_bus] = JuMP.Containers.DenseAxisArray(pd_bus, connections) @@ -542,11 +542,11 @@ function constraint_mc_load_current_wye(pm::AbstractExplicitNeutralIVRModel, nw: sol(pm, nw, :load, id)[:crd_bus] = crd_bus sol(pm, nw, :load, id)[:cid_bus] = cid_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for (idx, p) in enumerate(phases) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vr[p]^2+vi[p]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vr[p]^2+vi[p]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vr[p]^2+vi[p]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vr[p]^2+vi[p]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -586,30 +586,30 @@ function constraint_mc_load_current_delta(pm::AbstractExplicitNeutralIVRModel, n vrd = [vr[c]-vr[d] for (c,d) in zip(ph,ph_next)] vid = [vi[c]-vi[d] for (c,d) in zip(ph,ph_next)] - crd = JuMP.@NLexpression(pm.model, [i in 1:P], - a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) - +b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) + crd = JuMP.@expression(pm.model, [i in 1:P], + (a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1)) + +(b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1)) ) - cid = JuMP.@NLexpression(pm.model, [i in 1:P], - a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) - -b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) + cid = JuMP.@expression(pm.model, [i in 1:P], + (a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1)) + -(b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1)) ) - crd_bus = JuMP.@NLexpression(pm.model, [i in 1:P], crd[i]-crd[idxs_prev[i]]) - cid_bus = JuMP.@NLexpression(pm.model, [i in 1:P], cid[i]-cid[idxs_prev[i]]) + crd_bus = JuMP.@expression(pm.model, [i in 1:P], crd[i]-crd[idxs_prev[i]]) + cid_bus = JuMP.@expression(pm.model, [i in 1:P], cid[i]-cid[idxs_prev[i]]) var(pm, nw, :crd_bus)[id] = _merge_bus_flows(pm, crd_bus, connections) var(pm, nw, :cid_bus)[id] = _merge_bus_flows(pm, cid_bus, connections) if report - pd_bus = JuMP.@NLexpression(pm.model, [i in 1:P], vr[i]*crd_bus[i]+vi[i]*cid_bus[i]) - qd_bus = JuMP.@NLexpression(pm.model, [i in 1:P], -vr[i]*cid_bus[i]+vi[i]*crd_bus[i]) + pd_bus = JuMP.@expression(pm.model, [i in 1:P], (vr[i]*crd_bus[i])+(vi[i]*cid_bus[i])) + qd_bus = JuMP.@expression(pm.model, [i in 1:P], -(vr[i]*cid_bus[i])+(vi[i]*crd_bus[i])) sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = JuMP.@NLexpression(pm.model, [i in 1:P], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) - qd = JuMP.@NLexpression(pm.model, [i in 1:P], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) + pd = JuMP.@expression(pm.model, [i in 1:P], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) + qd = JuMP.@expression(pm.model, [i in 1:P], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) sol(pm, nw, :load, id)[:pd] = pd sol(pm, nw, :load, id)[:qd] = qd end @@ -1101,14 +1101,14 @@ function constraint_mc_transformer_thermal_limit(pm::AbstractNLExplicitNeutralIV vit_to = [vi_to[p]-vi_to[n_to] for p in P_to] idxs = [1:length(vrt_fr)...] - pt_fr = JuMP.@NLexpression(pm.model, [i in idxs], vrt_fr[i]*crt_fr[i] + vit_fr[i]*cit_fr[i]) - qt_fr = JuMP.@NLexpression(pm.model, [i in idxs], -vrt_fr[i]*cit_fr[i] + vit_fr[i]*crt_fr[i]) - pt_to = JuMP.@NLexpression(pm.model, [i in idxs], vrt_to[i]*crt_to[i] + vit_to[i]*cit_to[i]) - qt_to = JuMP.@NLexpression(pm.model, [i in idxs], -vrt_to[i]*cit_to[i] + vit_to[i]*crt_to[i]) + pt_fr = JuMP.@expression(pm.model, [i in idxs], (vrt_fr[i]*crt_fr[i]) + (vit_fr[i]*cit_fr[i])) + qt_fr = JuMP.@expression(pm.model, [i in idxs], -(vrt_fr[i]*cit_fr[i]) + (vit_fr[i]*crt_fr[i])) + pt_to = JuMP.@expression(pm.model, [i in idxs], (vrt_to[i]*crt_to[i]) + (vit_to[i]*cit_to[i])) + qt_to = JuMP.@expression(pm.model, [i in idxs], -(vrt_to[i]*cit_to[i]) + (vit_to[i]*crt_to[i])) if sm_ub(i+nph-2)%nph+1 for i in 1:nph) next = is_triplex ? conn_bus[2] : Dict(i=>i%nph+1 for i in 1:nph) - vrd = JuMP.@NLexpression(pm.model, [i in 1:nph], vr[i]-vr[next[i]]) - vid = JuMP.@NLexpression(pm.model, [i in 1:nph], vi[i]-vi[next[i]]) + vrd = JuMP.@expression(pm.model, [i in 1:nph], vr[i]-vr[next[i]]) + vid = JuMP.@expression(pm.model, [i in 1:nph], vi[i]-vi[next[i]]) - crd = JuMP.@NLexpression(pm.model, [i in 1:nph], - a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) - +b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) + crd = JuMP.@expression(pm.model, [i in 1:nph], + (a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1)) + +(b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1)) ) - cid = JuMP.@NLexpression(pm.model, [i in 1:nph], - a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) - -b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) + cid = JuMP.@expression(pm.model, [i in 1:nph], + (a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1)) + -(b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1)) ) crd_bus = Dict() cid_bus = Dict() for (idx, c) in enumerate(conn_bus) if is_triplex - crd_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crd[1]) - cid_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cid[1]) + crd_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crd[1]) + cid_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cid[1]) else - crd_bus[c] = JuMP.@NLexpression(pm.model, crd[c]-crd[prev[c]]) - cid_bus[c] = JuMP.@NLexpression(pm.model, cid[c]-cid[prev[c]]) + crd_bus[c] = JuMP.@expression(pm.model, crd[c]-crd[prev[c]]) + cid_bus[c] = JuMP.@expression(pm.model, cid[c]-cid[prev[c]]) end end @@ -698,13 +698,13 @@ function constraint_mc_load_power_delta(pm::IVRUPowerModel, nw::Int, id::Int, bu var(pm, nw, :cid_bus)[id] = cid_bus if report - pd_bus = JuMP.@NLexpression(pm.model, [c in conn_bus], vr[c]*crd_bus[c]+vi[c]*cid_bus[c]) - qd_bus = JuMP.@NLexpression(pm.model, [c in conn_bus], -vr[c]*cid_bus[c]+vi[c]*crd_bus[c]) + pd_bus = JuMP.@expression(pm.model, [c in conn_bus], -(vr[c]*(-crd_bus[c]))-(vi[c]*(-cid_bus[c]))) + qd_bus = JuMP.@expression(pm.model, [c in conn_bus], (vr[c]*(-cid_bus[c]))-(vi[c]*(-crd_bus[c]))) sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = JuMP.@NLexpression(pm.model, [i in 1:nph], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) - qd = JuMP.@NLexpression(pm.model, [i in 1:nph], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) + pd = JuMP.@expression(pm.model, [i in 1:nph], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) + qd = JuMP.@expression(pm.model, [i in 1:nph], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) sol(pm, nw, :load, id)[:pd] = pd sol(pm, nw, :load, id)[:qd] = qd end @@ -718,12 +718,12 @@ function constraint_mc_generator_power_wye(pm::IVRUPowerModel, nw::Int, id::Int, crg = var(pm, nw, :crg, id) cig = var(pm, nw, :cig, id) - pg = Vector{JuMP.NonlinearExpression}([]) - qg = Vector{JuMP.NonlinearExpression}([]) + pg = Vector{JuMP.NonlinearExpr}([]) + qg = Vector{JuMP.NonlinearExpr}([]) for (idx, c) in enumerate(connections) - push!(pg, JuMP.@NLexpression(pm.model, vr[c]*crg[c]+vi[c]*cig[c])) - push!(qg, JuMP.@NLexpression(pm.model, -vr[c]*cig[c]+vi[c]*crg[c])) + push!(pg, JuMP.@expression(pm.model, -(vr[c]*(-crg[c]))-(vi[c]*(-cig[c])))) + push!(qg, JuMP.@expression(pm.model, (vr[c]*(-cig[c]))-(vi[c]*(-crg[c])))) end if bounded @@ -775,41 +775,41 @@ function constraint_mc_generator_power_delta(pm::IVRUPowerModel, nw::Int, id::In vrg = Dict() vig = Dict() for c in connections - vrg[c] = JuMP.@NLexpression(pm.model, vr[c]-vr[next[c]]) - vig[c] = JuMP.@NLexpression(pm.model, vi[c]-vi[next[c]]) + vrg[c] = JuMP.@expression(pm.model, vr[c]-vr[next[c]]) + vig[c] = JuMP.@expression(pm.model, vi[c]-vi[next[c]]) end - pg = Vector{JuMP.NonlinearExpression}([]) - qg = Vector{JuMP.NonlinearExpression}([]) + pg = Vector{JuMP.NonlinearExpr}([]) + qg = Vector{JuMP.NonlinearExpr}([]) for c in connections - push!(pg, JuMP.@NLexpression(pm.model, vrg[c]*crg[c]+vig[c]*cig[c])) - push!(qg, JuMP.@NLexpression(pm.model, -vrg[c]*cig[c]+vig[c]*crg[c])) + push!(pg, JuMP.@expression(pm.model, -(vrg[c]*(-crg[c]))-(vig[c]*(-cig[c])))) + push!(qg, JuMP.@expression(pm.model, (vrg[c]*(-cig[c]))-(vig[c]*(-crg[c])))) end if bounded - JuMP.@NLconstraint(pm.model, [i in 1:nph], pmin[i] <= pg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], pmax[i] >= pg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], pmin[i] <= pg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], pmax[i] >= pg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) end - crg_bus = Vector{JuMP.NonlinearExpression}([]) - cig_bus = Vector{JuMP.NonlinearExpression}([]) + crg_bus = Vector{JuMP.NonlinearExpr}([]) + cig_bus = Vector{JuMP.NonlinearExpr}([]) for c in conn_bus if is_triplex - push!(crg_bus, JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crg[1])) - push!(cig_bus, JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cig[1])) + push!(crg_bus, JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1])) + push!(cig_bus, JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1])) else - push!(crg_bus, JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]])) - push!(cig_bus, JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]])) + push!(crg_bus, JuMP.@expression(pm.model, crg[c]-crg[prev[c]])) + push!(cig_bus, JuMP.@expression(pm.model, cig[c]-cig[prev[c]])) end end - pg_bus = Vector{JuMP.NonlinearExpression}([]) - qg_bus = Vector{JuMP.NonlinearExpression}([]) + pg_bus = Vector{JuMP.NonlinearExpr}([]) + qg_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(conn_bus) - push!(pg_bus, JuMP.@NLexpression(pm.model, vr[c]*crg_bus[c]+vi[c]*cig_bus[c])) - push!(qg_bus, JuMP.@NLexpression(pm.model, -vr[c]*cig_bus[c]+vi[c]*crg_bus[c])) + push!(pg_bus, JuMP.@expression(pm.model, -(vr[c]*(-crg_bus[c]))-(vi[c]*(-cig_bus[c])))) + push!(qg_bus, JuMP.@expression(pm.model, (vr[c]*(-cig_bus[c]))-(vi[c]*(-crg_bus[c])))) end var(pm, nw, :crg_bus)[id] = JuMP.Containers.DenseAxisArray(crg_bus, conn_bus) diff --git a/src/form/shared.jl b/src/form/shared.jl index 5a3e10c10..253b98f78 100644 --- a/src/form/shared.jl +++ b/src/form/shared.jl @@ -63,24 +63,24 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedWModels, nw::In sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(pg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - - sum(ref(pm, nw, :load, l, "pd")[findfirst(isequal(t), conns)] for (l, conns) in bus_loads if t in conns) - - sum(w[t] * LinearAlgebra.diag(Gt')[idx] for (sh, conns) in bus_shunts if t in conns) - + p_slack[t] + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + + sum(ref(pm, nw, :load, l, "pd")[findfirst(isequal(t), conns)] for (l, conns) in bus_loads if t in conns) + + sum(w[t] * LinearAlgebra.diag(Gt')[idx] for (sh, conns) in bus_shunts if t in conns) + - p_slack[t] + == 0.0 ) push!(cstr_p, cp) cq = JuMP.@constraint(pm.model, sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(qg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - - sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)] for (l, conns) in bus_loads if t in conns) - - sum(-w[t] * LinearAlgebra.diag(Bt')[idx] for (sh, conns) in bus_shunts if t in conns) - + q_slack[t] + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + + sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)] for (l, conns) in bus_loads if t in conns) + + sum(-w[t] * LinearAlgebra.diag(Bt')[idx] for (sh, conns) in bus_shunts if t in conns) + - q_slack[t] + == 0.0 ) push!(cstr_q, cq) end @@ -152,22 +152,22 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedWModels, nw::Int sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(pg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - - sum(ref(pm, nw, :load, l, "pd")[findfirst(isequal(t), conns)] * z_demand[l] for (l, conns) in bus_loads if t in conns) - - sum(z_shunt[sh] *(w[t] * LinearAlgebra.diag(Gt')[idx]) for (sh, conns) in bus_shunts if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + + sum(ref(pm, nw, :load, l, "pd")[findfirst(isequal(t), conns)] * z_demand[l] for (l, conns) in bus_loads if t in conns) + + sum(z_shunt[sh] *(w[t] * LinearAlgebra.diag(Gt')[idx]) for (sh, conns) in bus_shunts if t in conns) + == 0.0 ) push!(cstr_p, cp) cq = JuMP.@constraint(pm.model, sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(qg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - - sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)]*z_demand[l] for (l, conns) in bus_loads if t in conns) - - sum(z_shunt[sh] * (-w[t] * LinearAlgebra.diag(Bt')[idx]) for (sh, conns) in bus_shunts if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + + sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)]*z_demand[l] for (l, conns) in bus_loads if t in conns) + + sum(z_shunt[sh] * (-w[t] * LinearAlgebra.diag(Bt')[idx]) for (sh, conns) in bus_shunts if t in conns) + == 0.0 ) push!(cstr_q, cq) end @@ -212,11 +212,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedWModels, nw::Int, i:: sum(LinearAlgebra.diag(P[a])[findfirst(isequal(t), conns)] for (a, conns) in bus_arcs if t in conns) + sum(LinearAlgebra.diag(Psw[a_sw])[findfirst(isequal(t), conns)] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(LinearAlgebra.diag(Pt[a_trans])[findfirst(isequal(t), conns)] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(pg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - - sum(pd[d][t] for (d, conns) in bus_loads if t in conns) - - LinearAlgebra.diag(Wr*Gt'+Wi*Bt')[idx] + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + + sum(pd[d][t] for (d, conns) in bus_loads if t in conns) + + LinearAlgebra.diag(Wr*Gt'+Wi*Bt')[idx] + == 0.0 ) push!(cstr_p, cp) @@ -224,11 +224,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedWModels, nw::Int, i:: sum(LinearAlgebra.diag(Q[a])[findfirst(isequal(t), conns)] for (a, conns) in bus_arcs if t in conns) + sum(LinearAlgebra.diag(Qsw[a_sw])[findfirst(isequal(t), conns)] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(LinearAlgebra.diag(Qt[a_trans])[findfirst(isequal(t), conns)] for (a_trans, conns) in bus_arcs_trans if t in conns) - == - sum(qg[g][t] for (g, conns) in bus_gens if t in conns) - - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - - sum(qd[d][t] for (d, conns) in bus_loads if t in conns) - - LinearAlgebra.diag(-Wr*Bt'+Wi*Gt')[idx] + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + + sum(qd[d][t] for (d, conns) in bus_loads if t in conns) + + LinearAlgebra.diag(-Wr*Bt'+Wi*Gt')[idx] + == 0.0 ) push!(cstr_q, cq) end diff --git a/src/form/utils.jl b/src/form/utils.jl old mode 100644 new mode 100755 index e426060c6..d90b83d53 --- a/src/form/utils.jl +++ b/src/form/utils.jl @@ -7,8 +7,8 @@ function _merge_bus_flows(pm::ExplicitNeutralModels, flows::Vector, connections: flows_t = flows[idxs] if length(flows_t)==1 flows_merged_t = flows_t[1] - elseif any(isa(a, JuMP.NonlinearExpression) for a in flows_t) - flows_merged_t = JuMP.@NLexpression(pm.model, sum(flows_t[i] for i in 1:length(flows_t))) + elseif any(isa(a, JuMP.NonlinearExpr) for a in flows_t) + flows_merged_t = JuMP.@expression(pm.model, sum(flows_t[i] for i in 1:length(flows_t))) else flows_merged_t = sum(flows_t) end From 0d5988bf32f82720c351e018a12c0ec90e84da76 Mon Sep 17 00:00:00 2001 From: David M Fobes Date: Thu, 9 May 2024 07:05:59 -0600 Subject: [PATCH 2/6] Update Project.toml Co-authored-by: Oscar Dowson --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index a979e60c9..c941eb3fb 100644 --- a/Project.toml +++ b/Project.toml @@ -29,7 +29,7 @@ Graphs = "1" InfrastructureModels = "0.7.3, 0.7.5" Ipopt = "0.9, 1.0.2, 1.1" JSON = "0.18, 0.19, 0.20, 0.21" -JuMP = ">=1.15,<2" +JuMP = "1.15" LoggingExtras = "0.4.7, 1" PolyhedralRelaxations = "0.3.5" SCS = "0.9, 1.0, 1.1" From 5464eecd015192c6623652c6fd14f5eb240fad4c Mon Sep 17 00:00:00 2001 From: David M Fobes Date: Thu, 9 May 2024 08:38:56 -0600 Subject: [PATCH 3/6] Revert "Update Project.toml" This reverts commit 0d5988bf32f82720c351e018a12c0ec90e84da76. --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index c941eb3fb..a979e60c9 100644 --- a/Project.toml +++ b/Project.toml @@ -29,7 +29,7 @@ Graphs = "1" InfrastructureModels = "0.7.3, 0.7.5" Ipopt = "0.9, 1.0.2, 1.1" JSON = "0.18, 0.19, 0.20, 0.21" -JuMP = "1.15" +JuMP = ">=1.15,<2" LoggingExtras = "0.4.7, 1" PolyhedralRelaxations = "0.3.5" SCS = "0.9, 1.0, 1.1" From bc753504f3d5434e058428bcb4b415cc3cd31d37 Mon Sep 17 00:00:00 2001 From: David M Fobes Date: Thu, 9 May 2024 08:39:01 -0600 Subject: [PATCH 4/6] Revert "UPD: JuMP v1.15" This reverts commit dd61a57dcff35d38d476800493a2a64fca04d25b. --- CHANGELOG.md | 1 - Project.toml | 4 +- src/core/base.jl | 15 ++ src/core/data.jl | 25 +++ src/core/objective.jl | 48 ++--- src/core/solution.jl | 18 +- src/form/acp.jl | 424 +++++++++++++++++++++--------------------- src/form/acr.jl | 238 ++++++++++++------------ src/form/apo.jl | 10 +- src/form/bf_fbs.jl | 44 ++--- src/form/bf_mx.jl | 17 +- src/form/bf_mx_lin.jl | 26 +-- src/form/en_acr.jl | 112 +++++------ src/form/en_ivr.jl | 122 ++++++------ src/form/en_shared.jl | 52 +++--- src/form/fotp.jl | 10 +- src/form/fotr.jl | 76 ++++---- src/form/ivr.jl | 200 ++++++++++---------- src/form/shared.jl | 64 +++---- src/form/utils.jl | 4 +- 20 files changed, 781 insertions(+), 729 deletions(-) mode change 100755 => 100644 src/core/base.jl mode change 100755 => 100644 src/core/data.jl mode change 100755 => 100644 src/core/objective.jl mode change 100755 => 100644 src/core/solution.jl mode change 100755 => 100644 src/form/acp.jl mode change 100755 => 100644 src/form/acr.jl mode change 100755 => 100644 src/form/bf_fbs.jl mode change 100755 => 100644 src/form/en_acr.jl mode change 100755 => 100644 src/form/en_ivr.jl mode change 100755 => 100644 src/form/en_shared.jl mode change 100755 => 100644 src/form/fotp.jl mode change 100755 => 100644 src/form/fotr.jl mode change 100755 => 100644 src/form/ivr.jl mode change 100755 => 100644 src/form/utils.jl diff --git a/CHANGELOG.md b/CHANGELOG.md index 58d79e435..1977e4af0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ ## staged -- Updated to new JuMP v1.15 nonlinear constraint and expression syntax - Indicated broken tests in `"2w_dy_lead"` and `"3-bus SOCConicUBF opf_bf"` by using `@test_skip` ## v0.15.2 diff --git a/Project.toml b/Project.toml index a979e60c9..5ea33a264 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "PowerModelsDistribution" uuid = "d7431456-977f-11e9-2de3-97ff7677985e" authors = ["David M Fobes ", "Carleton Coffrin"] repo = "https://github.com/lanl-ansi/PowerModelsDistribution.jl.git" -version = "0.16.0" +version = "0.15.2" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" @@ -29,7 +29,7 @@ Graphs = "1" InfrastructureModels = "0.7.3, 0.7.5" Ipopt = "0.9, 1.0.2, 1.1" JSON = "0.18, 0.19, 0.20, 0.21" -JuMP = ">=1.15,<2" +JuMP = "0.22, 0.23, 1" LoggingExtras = "0.4.7, 1" PolyhedralRelaxations = "0.3.5" SCS = "0.9, 1.0, 1.1" diff --git a/src/core/base.jl b/src/core/base.jl old mode 100755 new mode 100644 index 53c0f41b4..5f33c2a90 --- a/src/core/base.jl +++ b/src/core/base.jl @@ -69,6 +69,21 @@ function _check_var_keys(vars, keys, var_name, comp_name) end +""" + @smart_constraint model::JuMP.Model vars::Vector expr::JuMP.Expression + +Detection of whether a constraint should be NL or not" +""" +macro smart_constraint(model, vars, expr) + esc(quote + if _has_nl_expression($vars) + JuMP.@NLconstraint($model, $expr) + else + JuMP.@constraint($model, $expr) + end + end) +end + """ function set_lower_bound( diff --git a/src/core/data.jl b/src/core/data.jl old mode 100755 new mode 100644 index 3e568b516..8309af410 --- a/src/core/data.jl +++ b/src/core/data.jl @@ -811,6 +811,31 @@ function _make_full_matrix_variable(diag::Vector{T}, lowertriangle::Vector{T}, u return matrix end +# TODO refactor into several functions +"helper to determine if expession has any Nonlinear terms" +function _has_nl_expression(x)::Bool + if isa(x, JuMP.NonlinearExpression) + return true + elseif isa(x, Array) + if any(_has_nl_expression.(x)) + return true + end + elseif isa(x, Dict) + for i in values(x) + if _has_nl_expression(i) + return true + end + end + elseif isa(x, JuMP.Containers.DenseAxisArray) + for i in values(x.data) + if _has_nl_expression(i) + return true + end + end + end + return false +end + """ correct_mc_voltage_angle_differences!(data::Dict{String,<:Any}, default_pad::Real=deg2rad(10.0)) diff --git a/src/core/objective.jl b/src/core/objective.jl old mode 100755 new mode 100644 index cac3e5841..126299e52 --- a/src/core/objective.jl +++ b/src/core/objective.jl @@ -247,7 +247,7 @@ end "gen connections adaptation of min fuel cost polynomial linquad objective" function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPowerModel; report::Bool=true) - pg_contains_nl_exp = any(x<:JuMP.NonlinearExpr for x in vcat([typeof.(isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg) for nw in nw_ids(pm) for (id,pg) in var(pm, nw, :pg)]...)) + pg_contains_nl_exp = any(x<:JuMP.NonlinearExpression for x in vcat([typeof.(isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg) for nw in nw_ids(pm) for (id,pg) in var(pm, nw, :pg)]...)) gen_cost = Dict() if !pg_contains_nl_exp @@ -277,7 +277,7 @@ function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPo for (i,gen) in nw_ref[:gen] bus = gen["gen_bus"] - #to avoid function calls inside of @constraint: + #to avoid function calls inside of @NLconstraint: pg = var(pm, n, :pg, i) pg = isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg @@ -285,16 +285,16 @@ function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPo if length(gen["cost"]) == 1 gen_cost[(n,i)] = gen["cost"][1] elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = JuMP.@expression(pm.model, (-gen["cost"][1]*sum(-pg[i] for i in 1:int_dim)) + gen["cost"][2]) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, gen["cost"][1]*sum(pg[i] for i in 1:int_dim) + gen["cost"][2]) elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = JuMP.@expression(pm.model, gen["cost"][1]*sum(-pg[i] for i in 1:int_dim)^2 + (-gen["cost"][2]*sum(-pg[i] for i in 1:int_dim)) + gen["cost"][3]) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, gen["cost"][1]*sum(pg[i] for i in 1:int_dim)^2 + gen["cost"][2]*sum(pg[i] for i in 1:int_dim) + gen["cost"][3]) else gen_cost[(n,i)] = 0.0 end end end - return JuMP.@objective(pm.model, Min, + return JuMP.@NLobjective(pm.model, Min, sum( sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) for (n, nw_ref) in nws(pm)) @@ -313,9 +313,9 @@ function _objective_mc_min_fuel_cost_polynomial_linquad_switch(pm::AbstractUnbal if length(gen["cost"]) == 1 gen_cost[(n,i)] = gen["cost"][1] elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = -gen["cost"][1]*(-pg) + gen["cost"][2] + gen_cost[(n,i)] = gen["cost"][1]*pg + gen["cost"][2] elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = gen["cost"][1]*pg^2 - gen["cost"][2]*(-pg) + gen["cost"][3] + gen_cost[(n,i)] = gen["cost"][1]*pg^2 + gen["cost"][2]*pg + gen["cost"][3] else gen_cost[(n,i)] = 0.0 end @@ -340,14 +340,14 @@ function _objective_mc_min_fuel_cost_polynomial_linquad_switch(pm::AbstractUnbal for (i,gen) in nw_ref[:gen] bus = gen["gen_bus"] - #to avoid function calls inside of @constraint: + #to avoid function calls inside of @NLconstraint: pg = sum(var(pm, n, :pg, i)) if length(gen["cost"]) == 1 gen_cost[(n,i)] = gen["cost"][1] elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = -gen["cost"][1]*(-pg) + gen["cost"][2] + gen_cost[(n,i)] = gen["cost"][1]*pg + gen["cost"][2] elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = gen["cost"][1]*pg^2 - gen["cost"][2]*(-pg) + gen["cost"][3] + gen_cost[(n,i)] = gen["cost"][1]*pg^2 + gen["cost"][2]*pg + gen["cost"][3] else gen_cost[(n,i)] = 0.0 end @@ -375,21 +375,21 @@ function _objective_mc_min_fuel_cost_polynomial_nl(pm::AbstractUnbalancedPowerMo cost_rev = reverse(gen["cost"]) if length(cost_rev) == 1 - gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1]) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1]) elseif length(cost_rev) == 2 - gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg))) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg) elseif length(cost_rev) == 3 - gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg)) + (cost_rev[3]*pg^2)) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2) elseif length(cost_rev) >= 4 cost_rev_nl = cost_rev[4:end] - gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg)) + (cost_rev[3]*pg^2) + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) else - gen_cost[(n,i)] = JuMP.@expression(pm.model, 0.0) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0) end end end - return JuMP.@objective(pm.model, Min, + return JuMP.@NLobjective(pm.model, Min, sum( sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) for (n, nw_ref) in nws(pm)) @@ -406,21 +406,21 @@ function _objective_mc_min_fuel_cost_polynomial_nl_switch(pm::AbstractUnbalanced cost_rev = reverse(gen["cost"]) if length(cost_rev) == 1 - gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1]) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1]) elseif length(cost_rev) == 2 - gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg))) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg) elseif length(cost_rev) == 3 - gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] - (cost_rev[2]*(-pg)) + (cost_rev[3]*pg^2)) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2) elseif length(cost_rev) >= 4 cost_rev_nl = cost_rev[4:end] - gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] + (cost_rev[2]*pg) + (cost_rev[3]*pg^2) + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) else - gen_cost[(n,i)] = JuMP.@expression(pm.model, 0.0) + gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0) end end end - return JuMP.@objective(pm.model, Min, + return JuMP.@NLobjective(pm.model, Min, sum( sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) + sum( var(pm, n, :switch_state, l) for l in ids(pm, n, :switch_dispatchable)) @@ -438,7 +438,7 @@ function objective_variable_pg_cost(pm::AbstractUnbalancedIVRModel; report::Bool for (n, nw_ref) in nws(pm) gen_lines = calc_cost_pwl_lines(nw_ref[:gen]) - #to avoid function calls inside of @constraint + #to avoid function calls inside of @NLconstraint pg_cost = var(pm, n)[:pg_cost] = JuMP.@variable(pm.model, [i in ids(pm, n, :gen)], base_name="$(n)_pg_cost", ) @@ -448,7 +448,7 @@ function objective_variable_pg_cost(pm::AbstractUnbalancedIVRModel; report::Bool for (i, gen) in nw_ref[:gen] pg = var(pm, n, :pg, i) for line in gen_lines[i] - JuMP.@constraint(pm.model, pg_cost[i] >= (line.slope*sum(pg[c] for c in gen["connections"])) + line.intercept) + JuMP.@NLconstraint(pm.model, pg_cost[i] >= line.slope*sum(pg[c] for c in gen["connections"]) + line.intercept) end end end diff --git a/src/core/solution.jl b/src/core/solution.jl old mode 100755 new mode 100644 index d39b51661..de41154e2 --- a/src/core/solution.jl +++ b/src/core/solution.jl @@ -11,9 +11,21 @@ function _IM.solution_preprocessor(pm::AbstractUnbalancedPowerModel, solution::D end -"custom `build_solution_values` for multiconductor (vector) JuMP expressions" -function _IM.build_solution_values(var::JuMP.AbstractJuMPScalar) - return JuMP.value(var) +"custom `build_solution_values` for multiconductor (vector) variables" +function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.VariableRef,1}) + return JuMP.value.(var.data) +end + + +"custom `build_solution_values` for multiconductor (vector) nonlinear expressions" +function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.NonlinearExpression,1}) + return JuMP.value.(var.data) +end + + +"custom `build_solution_values` for multiconductor (vector) generic affine expressions" +function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.GenericAffExpr,1}) + return JuMP.value.(var.data) end diff --git a/src/form/acp.jl b/src/form/acp.jl old mode 100755 new mode 100644 index 273cf4b6a..b70d5aaef --- a/src/form/acp.jl +++ b/src/form/acp.jl @@ -95,6 +95,11 @@ function constraint_mc_switch_state_on_off(pm::AbstractUnbalancedACPModel, nw::I for (idx,(fc,tc)) in enumerate(zip(f_connections, t_connections)) if relax + vm_fr_ub = JuMP.has_upper_bound(vm_fr[fc]) ? JuMP.upper_bound(vm_fr[fc]) : 1e20 + vm_to_lb = JuMP.has_lower_bound(vm_to[tc]) ? JuMP.lower_bound(vm_to[tc]) : -1e20 + va_fr_ub = JuMP.has_upper_bound(va_fr[tc]) ? JuMP.upper_bound(va_fr[fc]) : 1e20 + va_to_lb = JuMP.has_lower_bound(va_to[tc]) ? JuMP.lower_bound(va_to[tc]) : -1e20 + M = 1e20 JuMP.@constraint(pm.model, vm_fr[fc] - vm_to[tc] <= M * (1-z)) JuMP.@constraint(pm.model, vm_fr[fc] - vm_to[tc] >= -M * (1-z)) @@ -144,39 +149,39 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedACPModel, nw::I ungrounded_terminals = [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]] for (idx,t) in ungrounded_terminals - cp = JuMP.@constraint(pm.model, + cp = JuMP.@NLconstraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) - + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) - + Pd[idx] - + ( # shunt - (Gt[idx,idx] * vm[t]^2) - +sum( (Gt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) - +(Bt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) + == + sum(pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + - Pd[idx] + - ( # shunt + Gt[idx,idx] * vm[t]^2 + +sum( Gt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) + +Bt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx,u) in ungrounded_terminals if idx != jdx) ) - - p_slack[t] - == 0.0 + + p_slack[t] ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, + cq = JuMP.@NLconstraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) - + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) - + Qd[idx] - + ( # shunt - (-Bt[idx,idx] * vm[t]^2) - -sum( (Bt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) - -(Gt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) + == + sum(qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + - Qd[idx] + - ( # shunt + -Bt[idx,idx] * vm[t]^2 + -sum( Bt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) + -Gt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx,u) in ungrounded_terminals if idx != jdx) ) - - q_slack[t] - == 0.0 + + q_slack[t] ) push!(cstr_q, cq) @@ -218,17 +223,17 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACPModel, nw::In ungrounded_terminals = [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]] for (idx,t) in ungrounded_terminals - cp = JuMP.@constraint(pm.model, - sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + cp = JuMP.@NLconstraint(pm.model, + sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) - + sum(pt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + + sum( pt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) + - sum(pg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + sum(ps[s][t]*z_storage[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, d, "pd")[findfirst(isequal(t), conns)]*z_demand[d] for (d, conns) in bus_loads if t in conns) + sum(z_shunt[s] * - ((ref(pm, nw, :shunt, s)["gs"][findfirst(isequal(t), conns), findfirst(isequal(t), conns)] * vm[t]^2) - +sum( (ref(pm, nw, :shunt, s)["gs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * cos(va[t]-va[u])) - +(ref(pm, nw, :shunt, s)["bs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * sin(va[t]-va[u])) + (ref(pm, nw, :shunt, s)["gs"][findfirst(isequal(t), conns), findfirst(isequal(t), conns)] * vm[t]^2 + +sum( ref(pm, nw, :shunt, s)["gs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * cos(va[t]-va[u]) + +ref(pm, nw, :shunt, s)["bs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx, u) in ungrounded_terminals if idx != jdx ) ) for (s, conns) in bus_shunts if t in conns ) == @@ -236,17 +241,17 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, - sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + cq = JuMP.@NLconstraint(pm.model, + sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) - + sum(qt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) - + sum(qs[s][t]*z_storage[s] for (s, conns) in bus_storage if t in conns) + + sum( qt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) + - sum( qg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + + sum( qs[s][t]*z_storage[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)]*z_demand[l] for (l, conns) in bus_loads if t in conns) + sum(z_shunt[sh] * - ((-ref(pm, nw, :shunt, sh)["bs"][findfirst(isequal(t), conns), findfirst(isequal(t), conns)] * vm[t]^2) - -sum( (ref(pm, nw, :shunt, sh)["bs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * cos(va[t]-va[u])) - -(ref(pm, nw, :shunt, sh)["gs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * sin(va[t]-va[u])) + (-ref(pm, nw, :shunt, sh)["bs"][findfirst(isequal(t), conns), findfirst(isequal(t), conns)] * vm[t]^2 + -sum( ref(pm, nw, :shunt, sh)["bs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * cos(va[t]-va[u]) + -ref(pm, nw, :shunt, sh)["gs"][findfirst(isequal(t), conns), findfirst(isequal(u), conns)] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx, u) in ungrounded_terminals if idx != jdx ) ) for (sh, conns) in bus_shunts if t in conns ) == @@ -299,37 +304,37 @@ function constraint_mc_power_balance_simple(pm::AbstractUnbalancedACPModel, nw:: ungrounded_terminals = [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]] for (idx,t) in ungrounded_terminals - cp = JuMP.@constraint(pm.model, + cp = JuMP.@NLconstraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens) - + sum(ps[s][t] for (s, conns) in bus_storage) - + Pd[idx] - + ( # shunt - (Gt[idx,idx] * vm[t]^2) - +sum( (Gt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) - +(Bt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) + == + sum(pg[g][t] for (g, conns) in bus_gens) + - sum(ps[s][t] for (s, conns) in bus_storage) + - Pd[idx] + - ( # shunt + Gt[idx,idx] * vm[t]^2 + +sum( Gt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) + +Bt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx,u) in ungrounded_terminals if idx != jdx) ) - == 0.0 ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, + cq = JuMP.@NLconstraint(pm.model, sum(q[a][c] for a in bus_arcs) + sum(qsw[a_sw][c] for a_sw in bus_arcs_sw) + sum(qt[a_trans][c] for a_trans in bus_arcs_trans) - + sum(-qg[g][c] for g in bus_gens) - + sum(qs[s][c] for s in bus_storage) - + Qd[idx] - + ( # shunt - (-Bt[idx,idx] * vm[t]^2) - -sum( (Bt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) - -(Gt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) + == + sum(qg[g][c] for g in bus_gens) + - sum(qs[s][c] for s in bus_storage) + - Qd[idx] + - ( # shunt + -Bt[idx,idx] * vm[t]^2 + -sum( Bt[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) + -Gt[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx,u) in ungrounded_terminals if idx != jdx) ) - == 0.0 ) push!(cstr_q, cq) end @@ -369,17 +374,17 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: for (idx,t) in ungrounded_terminals if any(Bs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) || any(Gs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) - cp = JuMP.@constraint(pm.model, + cp = JuMP.@NLconstraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt - (Gs[idx,idx] * vm[t]^2) - +sum( (Gs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) - +(Bs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) + +Gs[idx,idx] * vm[t]^2 + +sum( Gs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) + +Bs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx,u) in ungrounded_terminals if idx != jdx) ) == @@ -387,17 +392,17 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, + cq = JuMP.@NLconstraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt - (-Bs[idx,idx] * vm[t]^2) - -sum( (Bs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) - -(Gs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) + -Bs[idx,idx] * vm[t]^2 + -sum( Bs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) + -Gs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx,u) in ungrounded_terminals if idx != jdx) ) == @@ -405,27 +410,27 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: ) push!(cstr_q, cq) else - cp = JuMP.@constraint(pm.model, + cp = @smart_constraint(pm.model, [p, pg, ps, psw, pt, pd, vm], sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) - + (Gs[idx,idx] * vm[t]^2) + + Gs[idx,idx] * vm[t]^2 == 0.0 ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, + cq = @smart_constraint(pm.model, [q, qg, qs, qsw, qt, qd, vm], sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) - - (Bs[idx,idx] * vm[t]^2) + - Bs[idx,idx] * vm[t]^2 == 0.0 ) @@ -481,7 +486,7 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In cap_state = 1.0 ncnds = length(terminals) Gs = fill(0.0, ncnds, ncnds) - Bs = convert(Matrix{JuMP.NonlinearExpr}, JuMP.@expression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) + Bs = convert(Matrix{JuMP.NonlinearExpression}, JuMP.@NLexpression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) for (val, connections) in bus_shunts shunt = ref(pm,nw,:shunt,val) for (idx,c) in enumerate(connections) @@ -490,7 +495,7 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In end for (jdx,d) in enumerate(connections) Gs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] += shunt["gs"][idx,jdx] - Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@expression(pm.model, Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + (shunt["bs"][idx,jdx]*cap_state)) + Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@NLexpression(pm.model, Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + shunt["bs"][idx,jdx]*cap_state) end end end @@ -501,17 +506,17 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In for (idx,t) in ungrounded_terminals if any(Bs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) || any(Gs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) - cp = JuMP.@constraint(pm.model, + cp = JuMP.@NLconstraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt - (Gs[idx,idx] * vm[t]^2) - +sum( (Gs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) - +(Bs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) + +Gs[idx,idx] * vm[t]^2 + +sum( Gs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) + +Bs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx,u) in ungrounded_terminals if idx != jdx) ) == @@ -519,17 +524,17 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, + cq = JuMP.@NLconstraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt - (-Bs[idx,idx] * vm[t]^2) - -sum( (Bs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u])) - -(Gs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u])) + -Bs[idx,idx] * vm[t]^2 + -sum( Bs[idx,jdx] * vm[t]*vm[u] * cos(va[t]-va[u]) + -Gs[idx,jdx] * vm[t]*vm[u] * sin(va[t]-va[u]) for (jdx,u) in ungrounded_terminals if idx != jdx) ) == @@ -537,27 +542,27 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_q, cq) else - cp = JuMP.@constraint(pm.model, + cp = @smart_constraint(pm.model, [p, pg, ps, psw, pt, pd, vm], sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) - + (Gs[idx,idx] * vm[t]^2) + + Gs[idx,idx] * vm[t]^2 == 0.0 ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, + cq = @smart_constraint(pm.model, [q, qg, qs, qsw, qt, qd, vm, Bs], sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) - - (Bs[idx,idx] * vm[t]^2) + - Bs[idx,idx] * vm[t]^2 == 0.0 ) @@ -665,22 +670,22 @@ function constraint_mc_ohms_yt_from(pm::AbstractUnbalancedACPModel, nw::Int, f_b ohms_yt_p = JuMP.ConstraintRef[] ohms_yt_q = JuMP.ConstraintRef[] for (idx, (fc,tc)) in enumerate(zip(f_connections,t_connections)) - push!(ohms_yt_p, JuMP.@constraint(pm.model, p_fr[fc] == ((G[idx,idx]+G_fr[idx,idx])*vm_fr[fc]^2) - +sum( ((G[idx,jdx]+G_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd])) - +((B[idx,jdx]+B_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd])) + push!(ohms_yt_p, JuMP.@NLconstraint(pm.model, p_fr[fc] == (G[idx,idx]+G_fr[idx,idx])*vm_fr[fc]^2 + +sum( (G[idx,jdx]+G_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd]) + +(B[idx,jdx]+B_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd]) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections)) if idx != jdx) - +sum( (-G[idx,jdx]*vm_fr[fc]*vm_to[td]*cos(va_fr[fc]-va_to[td])) - -(B[idx,jdx]*vm_fr[fc]*vm_to[td]*sin(va_fr[fc]-va_to[td])) + +sum( -G[idx,jdx]*vm_fr[fc]*vm_to[td]*cos(va_fr[fc]-va_to[td]) + -B[idx,jdx]*vm_fr[fc]*vm_to[td]*sin(va_fr[fc]-va_to[td]) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections))) ) ) - push!(ohms_yt_q, JuMP.@constraint(pm.model, q_fr[fc] == (-(B[idx,idx]+B_fr[idx,idx])*vm_fr[fc]^2) - -sum( ((B[idx,jdx]+B_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd])) - -((G[idx,jdx]+G_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd])) + push!(ohms_yt_q, JuMP.@NLconstraint(pm.model, q_fr[fc] == -(B[idx,idx]+B_fr[idx,idx])*vm_fr[fc]^2 + -sum( (B[idx,jdx]+B_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd]) + -(G[idx,jdx]+G_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd]) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections)) if idx != jdx) - -sum((-B[idx,jdx]*vm_fr[fc]*vm_to[td]*cos(va_fr[fc]-va_to[td])) - +(G[idx,jdx]*vm_fr[fc]*vm_to[td]*sin(va_fr[fc]-va_to[td])) + -sum(-B[idx,jdx]*vm_fr[fc]*vm_to[td]*cos(va_fr[fc]-va_to[td]) + +G[idx,jdx]*vm_fr[fc]*vm_to[td]*sin(va_fr[fc]-va_to[td]) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections))) ) ) @@ -734,16 +739,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractUnbalancedACPModel, nw:: x = transformer["controls"]["x"][idx] # (cr+jci) = (p-jq)/(vm⋅cos(va)-jvm⋅sin(va)) - cr = JuMP.@expression(pm.model, ( (p_to[idx]*vm_to[tc]*cos(va_to[tc])) + (q_to[idx]*vm_to[tc]*sin(va_to[tc])))/vm_to[tc]^2) - ci = JuMP.@expression(pm.model, ((-q_to[idx]*vm_to[tc]*cos(va_to[tc])) + (p_to[idx]*vm_to[tc]*sin(va_to[tc])))/vm_to[tc]^2) + cr = JuMP.@NLexpression(pm.model, ( p_to[idx]*vm_to[tc]*cos(va_to[tc]) + q_to[idx]*vm_to[tc]*sin(va_to[tc]))/vm_to[tc]^2) + ci = JuMP.@NLexpression(pm.model, (-q_to[idx]*vm_to[tc]*cos(va_to[tc]) + p_to[idx]*vm_to[tc]*sin(va_to[tc]))/vm_to[tc]^2) # v_drop = (cr+jci)⋅(r+jx) - vr_drop = JuMP.@expression(pm.model, (r*cr)-(x*ci)) - vi_drop = JuMP.@expression(pm.model, (r*ci)+(x*cr)) + vr_drop = JuMP.@NLexpression(pm.model, r*cr-x*ci) + vi_drop = JuMP.@NLexpression(pm.model, r*ci+x*cr) # v_ref-δ ≤ vm_fr-(cr+jci)⋅(r+jx)≤ v_ref+δ # vm_fr/1.1 ≤ vm_to ≤ vm_fr/0.9 - JuMP.@constraint(pm.model, ((vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2) + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≥ (v_ref - δ)^2) - JuMP.@constraint(pm.model, ((vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2) + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≤ (v_ref + δ)^2) + JuMP.@NLconstraint(pm.model, (vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2 + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≥ (v_ref - δ)^2) + JuMP.@NLconstraint(pm.model, (vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2 + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≤ (v_ref + δ)^2) JuMP.@constraint(pm.model, vm_fr[fc]/1.1 ≤ vm_to[tc]) JuMP.@constraint(pm.model, vm_fr[fc]/0.9 ≥ vm_to[tc]) end @@ -777,10 +782,10 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACPModel, nw:: # e.g., for nph=3: 1->3, 2->1, 3->2 jdx = (idx-1+1)%nph+1 fd = f_connections[jdx] - vd_re[idx] = JuMP.@expression(pm.model, (vm_fr[fc]*cos(va_fr[fc]))-(vm_fr[fd]*cos(va_fr[fd]))) - vd_im[idx] = JuMP.@expression(pm.model, (vm_fr[fc]*sin(va_fr[fc]))-(vm_fr[fd]*sin(va_fr[fd]))) - JuMP.@constraint(pm.model, vd_re[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*cos(va_to[tc])) - JuMP.@constraint(pm.model, vd_im[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*sin(va_to[tc])) + vd_re[idx] = JuMP.@NLexpression(pm.model, vm_fr[fc]*cos(va_fr[fc])-vm_fr[fd]*cos(va_fr[fd])) + vd_im[idx] = JuMP.@NLexpression(pm.model, vm_fr[fc]*sin(va_fr[fc])-vm_fr[fd]*sin(va_fr[fd])) + JuMP.@NLconstraint(pm.model, vd_re[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*cos(va_to[tc])) + JuMP.@NLconstraint(pm.model, vd_im[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*sin(va_to[tc])) end p_fr = var(pm, nw, :pt, f_idx) @@ -796,8 +801,8 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACPModel, nw:: # -Im(s/v) = -(q*cos(va)-p*sin(va))/|v| for (idx,(fc,tc)) in enumerate(zip(f_connections,t_connections)) # id = conj(s_to/v_to)./tm - id_re[idx] = JuMP.@expression(pm.model, ((p_to[tc]*cos(va_to[tc]))+(q_to[tc]*sin(va_to[tc])))/vm_to[tc]/(tm_scale*tm[idx])/pol) - id_im[idx] = JuMP.@expression(pm.model, -((q_to[tc]*cos(va_to[tc]))-(p_to[tc]*sin(va_to[tc])))/vm_to[tc]/(tm_scale*tm[idx])/pol) + id_re[idx] = JuMP.@NLexpression(pm.model, (p_to[tc]*cos(va_to[tc])+q_to[tc]*sin(va_to[tc]))/vm_to[tc]/(tm_scale*tm[idx])/pol) + id_im[idx] = JuMP.@NLexpression(pm.model, -(q_to[tc]*cos(va_to[tc])-p_to[tc]*sin(va_to[tc]))/vm_to[tc]/(tm_scale*tm[idx])/pol) end for (idx, (fc,tc)) in enumerate(zip(f_connections,t_connections)) # rotate by nph-1 to get 'previous' phase @@ -806,13 +811,13 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACPModel, nw:: # s_fr = v_fr*conj(i_fr) # = v_fr*conj(id[q]-id[p]) # = v_fr*(id_re[q]-j*id_im[q]-id_re[p]+j*id_im[p]) - JuMP.@constraint(pm.model, p_fr[fc] == - (vm_fr[fc]*cos(va_fr[fc])*( id_re[jdx]-id_re[idx])) - -(vm_fr[fc]*sin(va_fr[fc])*(-id_im[jdx]+id_im[idx])) + JuMP.@NLconstraint(pm.model, p_fr[fc] == + vm_fr[fc]*cos(va_fr[fc])*( id_re[jdx]-id_re[idx]) + -vm_fr[fc]*sin(va_fr[fc])*(-id_im[jdx]+id_im[idx]) ) - JuMP.@constraint(pm.model, q_fr[fc] == - (vm_fr[fc]*cos(va_fr[fc])*(-id_im[jdx]+id_im[idx])) - +(vm_fr[fc]*sin(va_fr[fc])*( id_re[jdx]-id_re[idx])) + JuMP.@NLconstraint(pm.model, q_fr[fc] == + vm_fr[fc]*cos(va_fr[fc])*(-id_im[jdx]+id_im[idx]) + +vm_fr[fc]*sin(va_fr[fc])*( id_re[jdx]-id_re[idx]) ) end end @@ -840,25 +845,25 @@ function constraint_mc_bus_voltage_magnitude_vuf(pm::AbstractUnbalancedACPModel, a2re = real(a^2) a2im = imag(a^2) # real and imaginary components of U+ - vrepos = JuMP.@expression(pm.model, - ((vm_a*cos(va_a)) + (are*vm_b*cos(va_b)) - (aim*vm_b*sin(va_b)) + (a2re*vm_c*cos(va_c)) - (a2im*vm_c*sin(va_c)))/3 + vrepos = JuMP.@NLexpression(pm.model, + (vm_a*cos(va_a) + are*vm_b*cos(va_b) - aim*vm_b*sin(va_b) + a2re*vm_c*cos(va_c) - a2im*vm_c*sin(va_c))/3 ) - vimpos = JuMP.@expression(pm.model, - ((vm_a*sin(va_a)) + (are*vm_b*sin(va_b)) + (aim*vm_b*cos(va_b)) + (a2re*vm_c*sin(va_c)) + (a2im*vm_c*cos(va_c)))/3 + vimpos = JuMP.@NLexpression(pm.model, + (vm_a*sin(va_a) + are*vm_b*sin(va_b) + aim*vm_b*cos(va_b) + a2re*vm_c*sin(va_c) + a2im*vm_c*cos(va_c))/3 ) # square of magnitude of U+, |U+|^2 - vmpossqr = JuMP.@expression(pm.model, vrepos^2+vimpos^2) + vmpossqr = JuMP.@NLexpression(pm.model, vrepos^2+vimpos^2) # real and imaginary components of U- - vreneg = JuMP.@expression(pm.model, - ((vm_a*cos(va_a)) + (a2re*vm_b*cos(va_b)) - (a2im*vm_b*sin(va_b)) + (are*vm_c*cos(va_c)) - (aim*vm_c*sin(va_c)))/3 + vreneg = JuMP.@NLexpression(pm.model, + (vm_a*cos(va_a) + a2re*vm_b*cos(va_b) - a2im*vm_b*sin(va_b) + are*vm_c*cos(va_c) - aim*vm_c*sin(va_c))/3 ) - vimneg = JuMP.@expression(pm.model, - ((vm_a*sin(va_a)) + (a2re*vm_b*sin(va_b)) + (a2im*vm_b*cos(va_b)) + (are*vm_c*sin(va_c)) + (aim*vm_c*cos(va_c)))/3 + vimneg = JuMP.@NLexpression(pm.model, + (vm_a*sin(va_a) + a2re*vm_b*sin(va_b) + a2im*vm_b*cos(va_b) + are*vm_c*sin(va_c) + aim*vm_c*cos(va_c))/3 ) # square of magnitude of U-, |U-|^2 - vmnegsqr = JuMP.@expression(pm.model, vreneg^2+vimneg^2) + vmnegsqr = JuMP.@NLexpression(pm.model, vreneg^2+vimneg^2) # finally, apply constraint - JuMP.@constraint(pm.model, vmnegsqr <= vufmax^2*vmpossqr) + JuMP.@NLconstraint(pm.model, vmnegsqr <= vufmax^2*vmpossqr) # DEBUGGING: save references for post check #var(pm, nw_id_default, :vmpossqr)[bus_id] = vmpossqr #var(pm, nw_id_default, :vmnegsqr)[bus_id] = vmnegsqr @@ -887,16 +892,16 @@ function constraint_mc_bus_voltage_magnitude_negative_sequence(pm::AbstractUnbal a2re = real(a^2) a2im = imag(a^2) # real and imaginary components of U- - vreneg = JuMP.@expression(pm.model, - ((vm_a*cos(va_a)) + (a2re*vm_b*cos(va_b)) - (a2im*vm_b*sin(va_b)) + (are*vm_c*cos(va_c)) - (aim*vm_c*sin(va_c)))/3 + vreneg = JuMP.@NLexpression(pm.model, + (vm_a*cos(va_a) + a2re*vm_b*cos(va_b) - a2im*vm_b*sin(va_b) + are*vm_c*cos(va_c) - aim*vm_c*sin(va_c))/3 ) - vimneg = JuMP.@expression(pm.model, - ((vm_a*sin(va_a)) + (a2re*vm_b*sin(va_b)) + (a2im*vm_b*cos(va_b)) + (are*vm_c*sin(va_c)) + (aim*vm_c*cos(va_c)))/3 + vimneg = JuMP.@NLexpression(pm.model, + (vm_a*sin(va_a) + a2re*vm_b*sin(va_b) + a2im*vm_b*cos(va_b) + are*vm_c*sin(va_c) + aim*vm_c*cos(va_c))/3 ) # square of magnitude of U-, |U-|^2 - vmnegsqr = JuMP.@expression(pm.model, vreneg^2+vimneg^2) + vmnegsqr = JuMP.@NLexpression(pm.model, vreneg^2+vimneg^2) # finally, apply constraint - JuMP.@constraint(pm.model, vmnegsqr <= vmnegmax^2) + JuMP.@NLconstraint(pm.model, vmnegsqr <= vmnegmax^2) end @@ -922,16 +927,16 @@ function constraint_mc_bus_voltage_magnitude_positive_sequence(pm::AbstractUnbal a2re = real(a^2) a2im = imag(a^2) # real and imaginary components of U+ - vrepos = JuMP.@expression(pm.model, - ((vm_a*cos(va_a)) + (are*vm_b*cos(va_b)) - (aim*vm_b*sin(va_b)) + (a2re*vm_c*cos(va_c)) - (a2im*vm_c*sin(va_c)))/3 + vrepos = JuMP.@NLexpression(pm.model, + (vm_a*cos(va_a) + are*vm_b*cos(va_b) - aim*vm_b*sin(va_b) + a2re*vm_c*cos(va_c) - a2im*vm_c*sin(va_c))/3 ) - vimpos = JuMP.@expression(pm.model, - ((vm_a*sin(va_a)) + (are*vm_b*sin(va_b)) + (aim*vm_b*cos(va_b)) + (a2re*vm_c*sin(va_c)) + (a2im*vm_c*cos(va_c)))/3 + vimpos = JuMP.@NLexpression(pm.model, + (vm_a*sin(va_a) + are*vm_b*sin(va_b) + aim*vm_b*cos(va_b) + a2re*vm_c*sin(va_c) + a2im*vm_c*cos(va_c))/3 ) # square of magnitude of U+, |U+|^2 - vmpossqr = JuMP.@expression(pm.model, vrepos^2+vimpos^2) + vmpossqr = JuMP.@NLexpression(pm.model, vrepos^2+vimpos^2) # finally, apply constraint - JuMP.@constraint(pm.model, vmpossqr <= vmposmax^2) + JuMP.@NLconstraint(pm.model, vmpossqr <= vmposmax^2) end @@ -951,16 +956,16 @@ function constraint_mc_bus_voltage_magnitude_zero_sequence(pm::AbstractUnbalance (vm_a, vm_b, vm_c) = [var(pm, nw, :vm, bus_id)[i] for i in 1:3] (va_a, va_b, va_c) = [var(pm, nw, :va, bus_id)[i] for i in 1:3] # real and imaginary components of U+ - vrezero = JuMP.@expression(pm.model, - ((vm_a*cos(va_a)) + (vm_b*cos(va_b)) + (vm_c*cos(va_c)))/3 + vrezero = JuMP.@NLexpression(pm.model, + (vm_a*cos(va_a) + vm_b*cos(va_b) + vm_c*cos(va_c))/3 ) - vimzero = JuMP.@expression(pm.model, - ((vm_a*sin(va_a)) + (vm_b*sin(va_b)) + (vm_c*sin(va_c)))/3 + vimzero = JuMP.@NLexpression(pm.model, + (vm_a*sin(va_a) + vm_b*sin(va_b) + vm_c*sin(va_c))/3 ) # square of magnitude of U+, |U+|^2 - vmzerosqr = JuMP.@expression(pm.model, vrezero^2+vimzero^2) + vmzerosqr = JuMP.@NLexpression(pm.model, vrezero^2+vimzero^2) # finally, apply constraint - JuMP.@constraint(pm.model, vmzerosqr <= vmzeromax^2) + JuMP.@NLconstraint(pm.model, vmzerosqr <= vmzeromax^2) end @@ -979,8 +984,8 @@ function constraint_mc_load_current_delta(pm::AbstractUnbalancedACPModel, nw::In vm_a, vm_b, vm_c = var(pm, nw, :vm, load_bus_id) va_a, va_b, va_c = var(pm, nw, :va, load_bus_id) # v_xy = v_x - v_y - vre_xy(vm_x, va_x, vm_y, va_y) = JuMP.@expression(pm.model, (vm_x*cos(va_x))-(vm_y*cos(va_y))) - vim_xy(vm_x, va_x, vm_y, va_y) = JuMP.@expression(pm.model, (vm_x*sin(va_x))-(vm_y*sin(va_y))) + vre_xy(vm_x, va_x, vm_y, va_y) = JuMP.@NLexpression(pm.model, vm_x*cos(va_x)-vm_y*cos(va_y)) + vim_xy(vm_x, va_x, vm_y, va_y) = JuMP.@NLexpression(pm.model, vm_x*sin(va_x)-vm_y*sin(va_y)) vre_ab = vre_xy(vm_a, va_a, vm_b, va_b) vim_ab = vim_xy(vm_a, va_a, vm_b, va_b) vre_bc = vre_xy(vm_b, va_b, vm_c, va_c) @@ -988,8 +993,8 @@ function constraint_mc_load_current_delta(pm::AbstractUnbalancedACPModel, nw::In vre_ca = vre_xy(vm_c, va_c, vm_a, va_a) vim_ca = vim_xy(vm_c, va_c, vm_a, va_a) # i_xy = conj(s_xy/v_xy) - ire_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@expression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*((cp_xy*vre_xy)+(cq_xy*vim_xy))) - iim_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@expression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*((cp_xy*vim_xy)-(cq_xy*vre_xy))) + ire_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@NLexpression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*(cp_xy*vre_xy+cq_xy*vim_xy)) + iim_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@NLexpression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*(cp_xy*vim_xy-cq_xy*vre_xy)) ire_ab = ire_xy(cp_ab, cq_ab, vre_ab, vim_ab) iim_ab = iim_xy(cp_ab, cq_ab, vre_ab, vim_ab) ire_bc = ire_xy(cp_bc, cq_bc, vre_bc, vim_bc) @@ -999,8 +1004,8 @@ function constraint_mc_load_current_delta(pm::AbstractUnbalancedACPModel, nw::In # s_x = v_x*conj(i_xy-i_zx) # p_x = vm_x*cos(va_x)*(ire_xy-ire_zx) + vm_x*sin(va_x)*(iim_xy-iim_zx) # q_x = vm_x*sin(va_x)*(ire_xy-ire_zx) - vm_x*cos(va_x)*(iim_xy-iim_zx) - p_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@expression(pm.model, (vm_x*cos(va_x)*(ire_xy-ire_zx)) + (vm_x*sin(va_x)*(iim_xy-iim_zx))) - q_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@expression(pm.model, (vm_x*sin(va_x)*(ire_xy-ire_zx)) - (vm_x*cos(va_x)*(iim_xy-iim_zx))) + p_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@NLexpression(pm.model, vm_x*cos(va_x)*(ire_xy-ire_zx) + vm_x*sin(va_x)*(iim_xy-iim_zx)) + q_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@NLexpression(pm.model, vm_x*sin(va_x)*(ire_xy-ire_zx) - vm_x*cos(va_x)*(iim_xy-iim_zx)) # s_x = s_x,ref var(pm, nw, :pd_bus)[load_id] = [ p_x(vm_a, va_a, ire_ab, iim_ab, ire_ca, iim_ca), @@ -1018,20 +1023,20 @@ function constraint_mc_bus_voltage_magnitude_ll(pm::AbstractUnbalancedACPModel, # 3 conductors asserted in template already vm_ln = [var(pm, nw, :vm, bus_id)[i] for i in 1:3] va_ln = [var(pm, nw, :va, bus_id)[i] for i in 1:3] - vr_ll = JuMP.@expression(pm.model, [i in 1:3], - (vm_ln[i]*cos(va_ln[i])) - (vm_ln[i%3+1]*cos(va_ln[i%3+1])) + vr_ll = JuMP.@NLexpression(pm.model, [i in 1:3], + vm_ln[i]*cos(va_ln[i]) - vm_ln[i%3+1]*cos(va_ln[i%3+1]) ) - vi_ll = JuMP.@expression(pm.model, [i in 1:3], - (vm_ln[i]*sin(va_ln[i])) - (vm_ln[i%3+1]*sin(va_ln[i%3+1])) + vi_ll = JuMP.@NLexpression(pm.model, [i in 1:3], + vm_ln[i]*sin(va_ln[i]) - vm_ln[i%3+1]*sin(va_ln[i%3+1]) ) for c in 1:3 # factor of 3 is needed because vm_ll bounds are with respect to the # LL base, not the LN base if vm_ll_min[c] > 0 - JuMP.@constraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 >= vm_ll_min[c]^2*3) + JuMP.@NLconstraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 >= vm_ll_min[c]^2*3) end if vm_ll_max[c] < Inf - JuMP.@constraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 <= vm_ll_max[c]^2*3) + JuMP.@NLconstraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 <= vm_ll_max[c]^2*3) end end end @@ -1078,21 +1083,21 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACPModel, nw::Int, i pd_bus = a qd_bus = b else - pd_bus = Vector{JuMP.NonlinearExpr}([]) - qd_bus = Vector{JuMP.NonlinearExpr}([]) + pd_bus = Vector{JuMP.NonlinearExpression}([]) + qd_bus = Vector{JuMP.NonlinearExpression}([]) for (idx, c) in enumerate(connections) - crd = JuMP.@expression(pm.model, - (a[idx]*vm[c]*cos(va[c])*(vm[c]^2)^(alpha[idx]/2-1)) - +(b[idx]*vm[c]*sin(va[c])*(vm[c]^2)^( beta[idx]/2-1)) + crd = JuMP.@NLexpression(pm.model, + a[idx]*vm[c]*cos(va[c])*(vm[c]^2)^(alpha[idx]/2-1) + +b[idx]*vm[c]*sin(va[c])*(vm[c]^2)^( beta[idx]/2-1) ) - cid = JuMP.@expression(pm.model, - (a[idx]*vm[c]*sin(va[c])*(vm[c]^2)^(alpha[idx]/2-1)) - -(b[idx]*vm[c]*cos(va[c])*(vm[c]^2)^( beta[idx]/2-1)) + cid = JuMP.@NLexpression(pm.model, + a[idx]*vm[c]*sin(va[c])*(vm[c]^2)^(alpha[idx]/2-1) + -b[idx]*vm[c]*cos(va[c])*(vm[c]^2)^( beta[idx]/2-1) ) - push!(pd_bus, JuMP.@expression(pm.model, -(vm[c]*cos(va[c])*(-crd))-(vm[c]*sin(va[c])*(-cid)))) - push!(qd_bus, JuMP.@expression(pm.model, (vm[c]*cos(va[c])*(-cid))-(vm[c]*sin(va[c])*(-crd)))) + push!(pd_bus, JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])*crd+vm[c]*sin(va[c])*cid)) + push!(qd_bus, JuMP.@NLexpression(pm.model, -vm[c]*cos(va[c])*cid+vm[c]*sin(va[c])*crd)) end end @@ -1106,12 +1111,12 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACPModel, nw::Int, i sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpr}([]) - qd = Vector{JuMP.NonlinearExpr}([]) + pd = Vector{JuMP.NonlinearExpression}([]) + qd = Vector{JuMP.NonlinearExpression}([]) for (idx,c) in enumerate(connections) - push!(pd, JuMP.@expression(pm.model, a[idx]*vm[c]^alpha[idx] )) - push!(qd, JuMP.@expression(pm.model, b[idx]*vm[c]^beta[idx] )) + push!(pd, JuMP.@NLexpression(pm.model, a[idx]*vm[c]^alpha[idx] )) + push!(qd, JuMP.@NLexpression(pm.model, b[idx]*vm[c]^beta[idx] )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -1134,20 +1139,20 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACPModel, nw::Int, vrd = Dict() vid = Dict() for (idx, c) in enumerate(connections) - vrd[c] = JuMP.@expression(pm.model, (vm[c]*cos(va[c]))-(vm[next[c]]*cos(va[next[c]]))) - vid[c] = JuMP.@expression(pm.model, (vm[c]*sin(va[c]))-(vm[next[c]]*sin(va[next[c]]))) + vrd[c] = JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])-vm[next[c]]*cos(va[next[c]])) + vid[c] = JuMP.@NLexpression(pm.model, vm[c]*sin(va[c])-vm[next[c]]*sin(va[next[c]])) end crd = Dict() cid = Dict() for (idx, c) in enumerate(connections) - crd[c] = JuMP.@expression(pm.model, - (a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)) - +(b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) + crd[c] = JuMP.@NLexpression(pm.model, + a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1) + +b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1) ) - cid[c] = JuMP.@expression(pm.model, - (a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)) - -(b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) + cid[c] = JuMP.@NLexpression(pm.model, + a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1) + -b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1) ) end @@ -1155,19 +1160,19 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACPModel, nw::Int, cid_bus = Dict() for (idx, c) in enumerate(conn_bus) if is_triplex - crd_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crd[1]) - cid_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cid[1]) + crd_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crd[1]) + cid_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cid[1]) else - crd_bus[c] = JuMP.@expression(pm.model, crd[c]-crd[prev[c]]) - cid_bus[c] = JuMP.@expression(pm.model, cid[c]-cid[prev[c]]) + crd_bus[c] = JuMP.@NLexpression(pm.model, crd[c]-crd[prev[c]]) + cid_bus[c] = JuMP.@NLexpression(pm.model, cid[c]-cid[prev[c]]) end end - pd_bus = Vector{JuMP.NonlinearExpr}([]) - qd_bus = Vector{JuMP.NonlinearExpr}([]) + pd_bus = Vector{JuMP.NonlinearExpression}([]) + qd_bus = Vector{JuMP.NonlinearExpression}([]) for (idx,c) in enumerate(conn_bus) - push!(pd_bus, JuMP.@expression(pm.model, -(vm[c]*cos(va[c])*(-crd_bus[c]))-(vm[c]*sin(va[c])*(-cid_bus[c])))) - push!(qd_bus, JuMP.@expression(pm.model, (vm[c]*cos(va[c])*(-cid_bus[c]))-(vm[c]*sin(va[c])*(-crd_bus[c])))) + push!(pd_bus, JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])*crd_bus[c]+vm[c]*sin(va[c])*cid_bus[c])) + push!(qd_bus, JuMP.@NLexpression(pm.model, -vm[c]*cos(va[c])*cid_bus[c]+vm[c]*sin(va[c])*crd_bus[c])) end pd_bus = JuMP.Containers.DenseAxisArray(pd_bus, conn_bus) @@ -1183,8 +1188,8 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACPModel, nw::Int, pd = [] qd = [] for (idx,c) in enumerate(connections) - push!(pd, JuMP.@expression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@expression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = pd sol(pm, nw, :load, id)[:qd] = qd @@ -1209,34 +1214,34 @@ function constraint_mc_generator_power_delta(pm::AbstractUnbalancedACPModel, nw: vrg = Dict() vig = Dict() for c in connections - vrg[c] = JuMP.@expression(pm.model, (vm[c]*cos(va[c]))-(vm[next[c]]*cos(va[next[c]]))) - vig[c] = JuMP.@expression(pm.model, (vm[c]*sin(va[c]))-(vm[next[c]]*sin(va[next[c]]))) + vrg[c] = JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])-vm[next[c]]*cos(va[next[c]])) + vig[c] = JuMP.@NLexpression(pm.model, vm[c]*sin(va[c])-vm[next[c]]*sin(va[next[c]])) end crg = Dict() cig = Dict() for c in connections - crg[c] = JuMP.@expression(pm.model, ((pg[c]*vrg[c])+(qg[c]*vig[c]))/(vrg[c]^2+vig[c]^2) ) - cig[c] = JuMP.@expression(pm.model, ((pg[c]*vig[c])-(qg[c]*vrg[c]))/(vrg[c]^2+vig[c]^2) ) + crg[c] = JuMP.@NLexpression(pm.model, (pg[c]*vrg[c]+qg[c]*vig[c])/(vrg[c]^2+vig[c]^2) ) + cig[c] = JuMP.@NLexpression(pm.model, (pg[c]*vig[c]-qg[c]*vrg[c])/(vrg[c]^2+vig[c]^2) ) end crg_bus = Dict() cig_bus = Dict() for c in conn_bus if is_triplex - crg_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1]) - cig_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1]) + crg_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crg[1]) + cig_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cig[1]) else - crg_bus[c] = JuMP.@expression(pm.model, crg[c]-crg[prev[c]]) - cig_bus[c] = JuMP.@expression(pm.model, cig[c]-cig[prev[c]]) + crg_bus[c] = JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]]) + cig_bus[c] = JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]]) end end - pg_bus = Vector{JuMP.NonlinearExpr}([]) - qg_bus = Vector{JuMP.NonlinearExpr}([]) + pg_bus = Vector{JuMP.NonlinearExpression}([]) + qg_bus = Vector{JuMP.NonlinearExpression}([]) for c in conn_bus - push!(pg_bus, JuMP.@expression(pm.model, -(vm[c]*cos(va[c])*(-crg_bus[c]))-(vm[c]*sin(va[c])*(-cig_bus[c])))) - push!(qg_bus, JuMP.@expression(pm.model, (vm[c]*cos(va[c])*(-cig_bus[c]))-(vm[c]*sin(va[c])*(-crg_bus[c])))) + push!(pg_bus, JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])*crg_bus[c]+vm[c]*sin(va[c])*cig_bus[c])) + push!(qg_bus, JuMP.@NLexpression(pm.model, -vm[c]*cos(va[c])*cig_bus[c]+vm[c]*sin(va[c])*crg_bus[c])) end pg_bus = JuMP.Containers.DenseAxisArray(pg_bus, conn_bus) qg_bus = JuMP.Containers.DenseAxisArray(qg_bus, conn_bus) @@ -1260,19 +1265,16 @@ function constraint_mc_storage_losses(pm::AbstractUnbalancedACPModel, n::Int, i: sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - JuMP.@constraint(pm.model, - -sum(-ps[c] for c in connections) + (sd - sc) - - p_loss - - (r * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections)) - == 0.0 + JuMP.@NLconstraint(pm.model, + sum(ps[c] for c in connections) + (sd - sc) + == + p_loss + r * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections) ) - JuMP.@constraint(pm.model, - -sum(-qs[c] for c in connections) - - qsc - - q_loss - - (x * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections)) - == 0.0 + JuMP.@NLconstraint(pm.model, + sum(qs[c] for c in connections) + == + qsc + q_loss + x * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections) ) end diff --git a/src/form/acr.jl b/src/form/acr.jl old mode 100755 new mode 100644 index eca287764..fccc68ebe --- a/src/form/acr.jl +++ b/src/form/acr.jl @@ -332,12 +332,12 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedACRModel, nw::I sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - + Pd[idx] - + (vr.*(Gt*vr-Bt*vi) + vi.*(Gt*vi+Bt*vr)) - - p_slack[t] - == 0.0 + == + sum(pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + - Pd[idx] + - (vr.*(Gt*vr-Bt*vi) + vi.*(Gt*vi+Bt*vr)) + + p_slack[t] ) push!(cstr_p, cp) @@ -345,12 +345,12 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedACRModel, nw::I sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + == + sum(qg[g][t] for (g, conns) in bus_gens if t in conns) + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - + Qd[idx] - - ( vr[t] * cish - vi[t] * crsh) - - q_slack[t] - == 0.0 + - Qd[idx] + + ( vr[t] * cish - vi[t] * crsh) + + q_slack[t] ) push!(cstr_q, cq) end @@ -404,12 +404,12 @@ function constraint_mc_power_balance_simple(pm::AbstractUnbalancedACRModel, nw:: sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - + Pd[idx] - - sum(-vr[t] * sum(Gt[idx,jdx]*vr[s]-Bt[idx,jdx]*vi[s] for (jdx,s) in ungrounded_terminals) + == + sum(pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + - Pd[idx] + + sum(-vr[t] * sum(Gt[idx,jdx]*vr[s]-Bt[idx,jdx]*vi[s] for (jdx,s) in ungrounded_terminals) -vi[t] * sum(Gt[idx,jdx]*vi[s]+Bt[idx,jdx]*vr[s] for (jdx,s) in ungrounded_terminals)) - == 0.0 ) push!(cstr_p, cp) @@ -417,12 +417,12 @@ function constraint_mc_power_balance_simple(pm::AbstractUnbalancedACRModel, nw:: sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - + Qd[idx] - - ( vr[t] * sum(Gt[idx,jdx]*vi[s]+Bt[idx,jdx]*vr[s] for (jdx,s) in ungrounded_terminals) + == + sum(qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + - Qd[idx] + + ( vr[t] * sum(Gt[idx,jdx]*vi[s]+Bt[idx,jdx]*vr[s] for (jdx,s) in ungrounded_terminals) -vi[t] * sum(Gt[idx,jdx]*vr[s]-Bt[idx,jdx]*vi[s] for (jdx,s) in ungrounded_terminals) ) - == 0.0 ) push!(cstr_q, cq) end @@ -463,31 +463,31 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACRModel, nw::Int, i: # pd/qd can be NLexpressions, so cannot be vectorized for (idx, t) in ungrounded_terminals - cp = JuMP.@constraint(pm.model, + cp = @smart_constraint(pm.model, [p, q, pg, qg, ps, qs, psw, qsw, pt, qt, pd, qd, vr, vi], sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - + sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) - + sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - + sum(pd[load][t] for (load, conns) in bus_loads if t in conns) - + ( (vr[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) - +(vi[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) + == + sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) + - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + + ( -vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) + -vi[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) ) - == 0.0 ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, + cq = @smart_constraint(pm.model, [p, q, pg, qg, ps, qs, psw, qsw, pt, qt, pd, qd, vr, vi], sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - + sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) - + sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - + sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) - - ( (vr[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) - -(vi[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) + == + sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) + - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + + ( vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) + -vi[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) ) - == 0.0 ) push!(cstr_q, cq) end @@ -538,14 +538,14 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACRModel, nw::In # calculate Gs, Bs ncnds = length(terminals) Gt = fill(0.0, ncnds, ncnds) - Bt = convert(Matrix{JuMP.NonlinearExpr}, JuMP.@expression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) + Bt = convert(Matrix{JuMP.NonlinearExpression}, JuMP.@NLexpression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) for (val, connections) in bus_shunts shunt = ref(pm,nw,:shunt,val) for (idx,c) in enumerate(connections) cap_state = haskey(shunt,"controls") ? var(pm, nw, :capacitor_state, val)[c] : 1.0 for (jdx,d) in enumerate(connections) Gt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] += shunt["gs"][idx,jdx] - Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@expression(pm.model, Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + (shunt["bs"][idx,jdx]*cap_state)) + Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@NLexpression(pm.model, Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + shunt["bs"][idx,jdx]*cap_state) end end end @@ -557,31 +557,31 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACRModel, nw::In # pd/qd can be NLexpressions, so cannot be vectorized for (idx, t) in ungrounded_terminals - cp = JuMP.@constraint(pm.model, + cp = JuMP.@NLconstraint(pm.model, sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - + sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) - + sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - + sum(pd[load][t] for (load, conns) in bus_loads if t in conns) - - ( -(vr[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) - -(vi[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) + == + sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) + - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + + ( -vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) + -vi[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) ) - == 0.0 ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, + cq = JuMP.@NLconstraint(pm.model, sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - + sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) - + sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - + sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) - - ( (vr[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) - -(vi[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) + == + sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) + - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + + ( vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) + -vi[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) ) - == 0.0 ) push!(cstr_q, cq) end @@ -684,29 +684,29 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACRModel, nw::In # pd/qd can be NLexpressions, so cannot be vectorized for (idx, t) in ungrounded_terminals - cp = JuMP.@constraint(pm.model, + cp = @smart_constraint(pm.model, [p, pg, ps, psw, pt], sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + - sum(pg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + sum(ps[s][t]*zs[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, d, "pd")[findfirst(isequal(t), conns)]*zd[d] for (d, conns) in bus_loads if t in conns) - + ( (vr[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals)) - +(vi[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals))) + + (+vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) + +vi[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals)) == 0.0 ) push!(cstr_p, cp) - cq = JuMP.@constraint(pm.model, + cq = @smart_constraint(pm.model, [q, qg, qs, qsw, qt], sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + - sum(qg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + sum(qs[s][t]*zs[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, d, "qd")[findfirst(isequal(t), conns)]*zd[d] for (d, conns) in bus_loads if t in conns) - + (-(vr[t] * sum((Gt[idx,jdx]*vi[u])+(Bt[idx,jdx]*vr[u]) for (jdx,u) in ungrounded_terminals)) - +(vi[t] * sum((Gt[idx,jdx]*vr[u])-(Bt[idx,jdx]*vi[u]) for (jdx,u) in ungrounded_terminals))) + + (-vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) + +vi[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals)) == 0.0 ) @@ -780,15 +780,15 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACRModel, nw::Int, i pd_bus = a qd_bus = b else - pd_bus = Vector{JuMP.NonlinearExpr}([]) - qd_bus = Vector{JuMP.NonlinearExpr}([]) + pd_bus = Vector{JuMP.NonlinearExpression}([]) + qd_bus = Vector{JuMP.NonlinearExpression}([]) for (idx,c) in enumerate(connections) - crd = JuMP.@expression(pm.model, (a[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1))+(b[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1))) - cid = JuMP.@expression(pm.model, (a[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1))-(b[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1))) + crd = JuMP.@NLexpression(pm.model, a[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1)+b[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1)) + cid = JuMP.@NLexpression(pm.model, a[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1)-b[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1)) - push!(pd_bus, JuMP.@expression(pm.model, -(vr[c]*(-crd))-(vi[c]*(-cid)))) - push!(qd_bus, JuMP.@expression(pm.model, (vr[c]*(-cid))-(vi[c]*(-crd)))) + push!(pd_bus, JuMP.@NLexpression(pm.model, vr[c]*crd+vi[c]*cid)) + push!(qd_bus, JuMP.@NLexpression(pm.model, -vr[c]*cid+vi[c]*crd)) end end @@ -802,12 +802,12 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACRModel, nw::Int, i sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpr}([]) - qd = Vector{JuMP.NonlinearExpr}([]) + pd = Vector{JuMP.NonlinearExpression}([]) + qd = Vector{JuMP.NonlinearExpression}([]) for (idx,c) in enumerate(connections) - push!(pd, JuMP.@expression(pm.model, a[idx]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@expression(pm.model, b[idx]*(vr[c]^2+vi[c]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vr[c]^2+vi[c]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -830,34 +830,34 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACRModel, nw::Int, vrd = Dict() vid = Dict() for (idx, c) in enumerate(connections) - vrd[c] = JuMP.@expression(pm.model, vr[c]-vr[next[c]]) - vid[c] = JuMP.@expression(pm.model, vi[c]-vi[next[c]]) + vrd[c] = JuMP.@NLexpression(pm.model, vr[c]-vr[next[c]]) + vid[c] = JuMP.@NLexpression(pm.model, vi[c]-vi[next[c]]) end crd = Dict() cid = Dict() for (idx, c) in enumerate(connections) - crd[c] = JuMP.@expression(pm.model, (a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1))+(b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1))) - cid[c] = JuMP.@expression(pm.model, (a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1))-(b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1))) + crd[c] = JuMP.@NLexpression(pm.model, a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)+b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) + cid[c] = JuMP.@NLexpression(pm.model, a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)-b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) end crd_bus = Dict() cid_bus = Dict() for (idx, c) in enumerate(conn_bus) if is_triplex - crd_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crd[1]) - cid_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cid[1]) + crd_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crd[1]) + cid_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cid[1]) else - crd_bus[c] = JuMP.@expression(pm.model, crd[c]-crd[prev[c]]) - cid_bus[c] = JuMP.@expression(pm.model, cid[c]-cid[prev[c]]) + crd_bus[c] = JuMP.@NLexpression(pm.model, crd[c]-crd[prev[c]]) + cid_bus[c] = JuMP.@NLexpression(pm.model, cid[c]-cid[prev[c]]) end end - pd_bus = Vector{JuMP.NonlinearExpr}([]) - qd_bus = Vector{JuMP.NonlinearExpr}([]) + pd_bus = Vector{JuMP.NonlinearExpression}([]) + qd_bus = Vector{JuMP.NonlinearExpression}([]) for (idx,c) in enumerate(conn_bus) - push!(pd_bus, JuMP.@expression(pm.model, -(vr[c]*(-crd_bus[c]))-(vi[c]*(-cid_bus[c])))) - push!(qd_bus, JuMP.@expression(pm.model, (vr[c]*(-cid_bus[c]))-(vi[c]*(-crd_bus[c])))) + push!(pd_bus, JuMP.@NLexpression(pm.model, vr[c]*crd_bus[c]+vi[c]*cid_bus[c])) + push!(qd_bus, JuMP.@NLexpression(pm.model, -vr[c]*cid_bus[c]+vi[c]*crd_bus[c])) end pd_bus = JuMP.Containers.DenseAxisArray(pd_bus, conn_bus) @@ -870,11 +870,11 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACRModel, nw::Int, sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpr}([]) - qd = Vector{JuMP.NonlinearExpr}([]) + pd = Vector{JuMP.NonlinearExpression}([]) + qd = Vector{JuMP.NonlinearExpression}([]) for (idx,c) in enumerate(connections) - push!(pd, JuMP.@expression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@expression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -908,34 +908,34 @@ function constraint_mc_generator_power_delta(pm::AbstractUnbalancedACRModel, nw: vrg = Dict() vig = Dict() for c in connections - vrg[c] = JuMP.@expression(pm.model, vr[c]-vr[next[c]]) - vig[c] = JuMP.@expression(pm.model, vi[c]-vi[next[c]]) + vrg[c] = JuMP.@NLexpression(pm.model, vr[c]-vr[next[c]]) + vig[c] = JuMP.@NLexpression(pm.model, vi[c]-vi[next[c]]) end crg = Dict() cig = Dict() for c in connections - crg[c] = JuMP.@expression(pm.model, ((pg[c]*vrg[c])+(qg[c]*vig[c]))/(vrg[c]^2+vig[c]^2) ) - cig[c] = JuMP.@expression(pm.model, ((pg[c]*vig[c])-(qg[c]*vrg[c]))/(vrg[c]^2+vig[c]^2) ) + crg[c] = JuMP.@NLexpression(pm.model, (pg[c]*vrg[c]+qg[c]*vig[c])/(vrg[c]^2+vig[c]^2) ) + cig[c] = JuMP.@NLexpression(pm.model, (pg[c]*vig[c]-qg[c]*vrg[c])/(vrg[c]^2+vig[c]^2) ) end crg_bus = Dict() cig_bus = Dict() for c in conn_bus if is_triplex - crg_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1]) - cig_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1]) + crg_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crg[1]) + cig_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cig[1]) else - crg_bus[c] = JuMP.@expression(pm.model, crg[c]-crg[prev[c]]) - cig_bus[c] = JuMP.@expression(pm.model, cig[c]-cig[prev[c]]) + crg_bus[c] = JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]]) + cig_bus[c] = JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]]) end end - pg_bus = Vector{JuMP.NonlinearExpr}([]) - qg_bus = Vector{JuMP.NonlinearExpr}([]) + pg_bus = Vector{JuMP.NonlinearExpression}([]) + qg_bus = Vector{JuMP.NonlinearExpression}([]) for (idx,c) in enumerate(conn_bus) - push!(pg_bus, JuMP.@expression(pm.model, -(vr[c]*(-crg_bus[c]))-(vi[c]*(-cig_bus[c])))) - push!(qg_bus, JuMP.@expression(pm.model, (vr[c]*(-cig_bus[c]))-(vi[c]*(-crg_bus[c])))) + push!(pg_bus, JuMP.@NLexpression(pm.model, vr[c]*crg_bus[c]+vi[c]*cig_bus[c])) + push!(qg_bus, JuMP.@NLexpression(pm.model, -vr[c]*cig_bus[c]+vi[c]*crg_bus[c])) end pg_bus = JuMP.Containers.DenseAxisArray(pg_bus, conn_bus) @@ -985,16 +985,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractUnbalancedACRModel, nw:: x = transformer["controls"]["x"][idx] # (cr+jci) = (p-jq)/(vr-j⋅vi) - cr = JuMP.@expression(pm.model, ( (p_to[idx]*vr_to[tc]) + (q_to[idx]*vi_to[tc]))/(vr_to[tc]^2+vi_to[tc]^2)) - ci = JuMP.@expression(pm.model, (-(q_to[idx]*vr_to[tc]) + (p_to[idx]*vi_to[tc]))/(vr_to[tc]^2+vi_to[tc]^2)) + cr = JuMP.@NLexpression(pm.model, ( p_to[idx]*vr_to[tc] + q_to[idx]*vi_to[tc])/(vr_to[tc]^2+vi_to[tc]^2)) + ci = JuMP.@NLexpression(pm.model, (-q_to[idx]*vr_to[tc] + p_to[idx]*vi_to[tc])/(vr_to[tc]^2+vi_to[tc]^2)) # v_drop = (cr+jci)⋅(r+jx) - vr_drop = JuMP.@expression(pm.model, (r*cr)-(x*ci)) - vi_drop = JuMP.@expression(pm.model, (r*ci)+(x*cr)) + vr_drop = JuMP.@NLexpression(pm.model, r*cr-x*ci) + vi_drop = JuMP.@NLexpression(pm.model, r*ci+x*cr) # (v_ref-δ)^2 ≤ (vr_fr-vr_drop)^2 + (vi_fr-vi_drop)^2 ≤ (v_ref+δ)^2 # (vr_fr^2 + vi_fr^2)/1.1^2 ≤ (vr_to^2 + vi_to^2) ≤ (vr_fr^2 + vi_fr^2)/0.9^2 - JuMP.@constraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≥ (v_ref - δ)^2) - JuMP.@constraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≤ (v_ref + δ)^2) + JuMP.@NLconstraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≥ (v_ref - δ)^2) + JuMP.@NLconstraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≤ (v_ref + δ)^2) JuMP.@constraint(pm.model, (vr_fr[fc]^2 + vi_fr[fc]^2)/1.1^2 ≤ vr_to[tc]^2 + vi_to[tc]^2) JuMP.@constraint(pm.model, (vr_fr[fc]^2 + vi_fr[fc]^2)/0.9^2 ≥ vr_to[tc]^2 + vi_to[tc]^2) end @@ -1041,21 +1041,21 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACRModel, nw:: # -Im(s/v) = -(q*cos(va)-p*sin(va))/|v| for (idx, (fc,tc)) in enumerate(zip(f_connections,t_connections)) # id = conj(s_to/v_to)./tm - id_re[idx] = JuMP.@expression(pm.model, ((p_to[tc]*vr_p_to[idx])+(q_to[tc]*vi_p_to[idx]))/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) - id_im[idx] = JuMP.@expression(pm.model, ((p_to[tc]*vi_p_to[idx])-(q_to[tc]*vr_p_to[idx]))/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) + id_re[idx] = JuMP.@NLexpression(pm.model, (p_to[tc]*vr_p_to[idx]+q_to[tc]*vi_p_to[idx])/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) + id_im[idx] = JuMP.@NLexpression(pm.model, (p_to[tc]*vi_p_to[idx]-q_to[tc]*vr_p_to[idx])/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) end for (idx,(fc,tc)) in enumerate(zip(f_connections, t_connections)) jdx = (idx-1+nph-1)%nph+1 # s_fr = v_fr*conj(i_fr) # = v_fr*conj(id[q]-id[p]) # = v_fr*(id_re[q]-j*id_im[q]-id_re[p]+j*id_im[p]) - JuMP.@constraint(pm.model, p_fr[fc] == - (vr_p_fr[idx]*( id_re[jdx]-id_re[idx])) - -(vi_p_fr[idx]*(-id_im[jdx]+id_im[idx])) + JuMP.@NLconstraint(pm.model, p_fr[fc] == + vr_p_fr[idx]*( id_re[jdx]-id_re[idx]) + -vi_p_fr[idx]*(-id_im[jdx]+id_im[idx]) ) - JuMP.@constraint(pm.model, q_fr[fc] == - (vr_p_fr[idx]*(-id_im[jdx]+id_im[idx])) - +(vi_p_fr[idx]*( id_re[jdx]-id_re[idx])) + JuMP.@NLconstraint(pm.model, q_fr[fc] == + vr_p_fr[idx]*(-id_im[jdx]+id_im[idx]) + +vi_p_fr[idx]*( id_re[jdx]-id_re[idx]) ) end end @@ -1078,16 +1078,16 @@ function constraint_mc_storage_losses(pm::AbstractUnbalancedACRModel, i::Int; nw r = storage["r"] x = storage["x"] - JuMP.@constraint(pm.model, + JuMP.@NLconstraint(pm.model, sum(ps[c] for c in storage["connections"]) + (sd - sc) == - p_loss + (r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"]))) + p_loss + r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"])) ) - JuMP.@constraint(pm.model, + JuMP.@NLconstraint(pm.model, sum(qs[c] for c in storage["connections"]) == - qsc + q_loss + (x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"]))) + qsc + q_loss + x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"])) ) end @@ -1102,16 +1102,16 @@ function constraint_mc_storage_losses(pm::AbstractUnbalancedACRModel, n::Int, i: sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - JuMP.@constraint(pm.model, + JuMP.@NLconstraint(pm.model, sum(ps[c] for c in connections) + (sd - sc) == - p_loss + (r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections)) + p_loss + r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections) ) - JuMP.@constraint(pm.model, + JuMP.@NLconstraint(pm.model, sum(qs[c] for c in connections) == - qsc + q_loss + (x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections)) + qsc + q_loss + x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections) ) end diff --git a/src/form/apo.jl b/src/form/apo.jl index 0e38efd06..018c4d980 100644 --- a/src/form/apo.jl +++ b/src/form/apo.jl @@ -126,11 +126,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedActivePowerModel, nw: sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - + sum(pd[d][t] for (d, conns) in bus_loads if t in conns) - + LinearAlgebra.diag(Gt)[idx] - == 0.0 + == + sum(pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + - sum(pd[d][t] for (d, conns) in bus_loads if t in conns) + - LinearAlgebra.diag(Gt)[idx] ) push!(cstr_p, cp) end diff --git a/src/form/bf_fbs.jl b/src/form/bf_fbs.jl old mode 100755 new mode 100644 index f923cb880..c0aa6ff58 --- a/src/form/bf_fbs.jl +++ b/src/form/bf_fbs.jl @@ -316,13 +316,13 @@ function constraint_mc_power_balance(pm::FBSUBFPowerModel, nw::Int, i::Int, term sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - + sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) - + sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - + sum(pd[load][t] for (load, conns) in bus_loads if t in conns) - - ( -vr0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) + == + sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) + - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + + ( -vr0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) -vi0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) ) - == 0.0 ) push!(cstr_p, cp) @@ -330,13 +330,13 @@ function constraint_mc_power_balance(pm::FBSUBFPowerModel, nw::Int, i::Int, term sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - + sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) - + sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - + sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) - - ( vr0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) + == + sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) + - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + + ( vr0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) -vi0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) ) - == 0.0 ) push!(cstr_q, cq) end @@ -402,13 +402,13 @@ function constraint_mc_power_balance_capc(pm::FBSUBFPowerModel, nw::Int, i::Int, sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - + sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) - + sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - + sum(pd[load][t] for (load, conns) in bus_loads if t in conns) - - ( -vr0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) + == + sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) + - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + + ( -vr0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) -vi0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) ) - == 0.0 ) push!(cstr_p, cp) @@ -416,13 +416,13 @@ function constraint_mc_power_balance_capc(pm::FBSUBFPowerModel, nw::Int, i::Int, sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) - + sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) - + sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - + sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) - - ( vr0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) + == + sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) + - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + + ( vr0[idx] * sum(Gt[idx,jdx]*vi0[jdx]+Bt[idx,jdx]*vr0[jdx] for (jdx,u) in ungrounded_terminals) -vi0[idx] * sum(Gt[idx,jdx]*vr0[jdx]-Bt[idx,jdx]*vi0[jdx] for (jdx,u) in ungrounded_terminals) ) - == 0.0 ) push!(cstr_q, cq) end @@ -827,8 +827,8 @@ function constraint_mc_generator_power_delta(pm::FBSUBFPowerModel, nw::Int, id:: crg_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1]) cig_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1]) else - crg_bus[c] = JuMP.@expression(pm.model, crg[c]-crg[prev[c]]) - cig_bus[c] = JuMP.@expression(pm.model, cig[c]-cig[prev[c]]) + crg_bus[c] = JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]]) + cig_bus[c] = JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]]) end end diff --git a/src/form/bf_mx.jl b/src/form/bf_mx.jl index c1e98b237..0954da408 100644 --- a/src/form/bf_mx.jl +++ b/src/form/bf_mx.jl @@ -1045,11 +1045,10 @@ function constraint_mc_power_balance(pm::KCLMXModels, nw::Int, i::Int, terminals sum( P[a][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a, conns) in bus_arcs if t in conns && u in conns) # + sum( Psw[a_sw][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a_sw, conns) in bus_arcs_sw if t in conns && u in conns) # + sum(Pt[a_trans][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a_trans, conns) in bus_arcs_trans if t in conns && u in conns) - - + sum( -Pg[g][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (g, conns) in bus_gens if t in conns && u in conns) - + sum( Pd[d][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (d, conns) in bus_loads if t in conns && u in conns) - + LinearAlgebra.diag(Wr*Gt'+Wi*Bt')[idx] - == 0.0 + == + sum( Pg[g][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (g, conns) in bus_gens if t in conns && u in conns) + - sum( Pd[d][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (d, conns) in bus_loads if t in conns && u in conns) + - LinearAlgebra.diag(Wr*Gt'+Wi*Bt')[idx] ) push!(cstr_p, cp) @@ -1057,10 +1056,10 @@ function constraint_mc_power_balance(pm::KCLMXModels, nw::Int, i::Int, terminals sum( Q[a][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a, conns) in bus_arcs if t in conns && u in conns) # + sum( Qsw[a_sw][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a_sw, conns) in bus_arcs_sw if t in conns && u in conns) # + sum(Qt[a_trans][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (a_trans, conns) in bus_arcs_trans if t in conns && u in conns) - + sum( -Qg[g][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (g, conns) in bus_gens if t in conns && u in conns) - + sum( Qd[d][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (d, conns) in bus_loads if t in conns && u in conns) - + LinearAlgebra.diag(-Wr*Bt'+Wi*Gt')[idx] - == 0.0 + == + sum( Qg[g][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (g, conns) in bus_gens if t in conns && u in conns) + - sum( Qd[d][findfirst(isequal(t), conns),findfirst(isequal(u), conns)] for (d, conns) in bus_loads if t in conns && u in conns) + - LinearAlgebra.diag(-Wr*Bt'+Wi*Gt')[idx] ) push!(cstr_q, cq) end diff --git a/src/form/bf_mx_lin.jl b/src/form/bf_mx_lin.jl index b0e40f1ed..6891e1e45 100644 --- a/src/form/bf_mx_lin.jl +++ b/src/form/bf_mx_lin.jl @@ -138,7 +138,7 @@ function constraint_mc_power_balance(pm::LPUBFDiagModel, nw::Int, i::Int, termin sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[d][t] for (d, conns) in bus_loads if t in conns) + sum(LinearAlgebra.diag(ref(pm, nw, :shunt, sh, "gs"))[findfirst(isequal(t), conns)]*w[t] for (sh, conns) in bus_shunts if t in conns) @@ -151,7 +151,7 @@ function constraint_mc_power_balance(pm::LPUBFDiagModel, nw::Int, i::Int, termin sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[d][t] for (d, conns) in bus_loads if t in conns) - sum(LinearAlgebra.diag(ref(pm, nw, :shunt, sh, "bs"))[findfirst(isequal(t), conns)]*w[t] for (sh, conns) in bus_shunts if t in conns) @@ -228,11 +228,11 @@ function constraint_mc_power_balance_capc(pm::LPUBFDiagModel, nw::Int, i::Int, t sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - + sum(pd[l][t] for (l, conns) in bus_loads if t in conns) - + sum((w[t] * LinearAlgebra.diag(Gt')[idx]) for (sh, conns) in bus_shunts if t in conns) - == 0.0 + == + sum(pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + - sum(pd[l][t] for (l, conns) in bus_loads if t in conns) + - sum((w[t] * LinearAlgebra.diag(Gt')[idx]) for (sh, conns) in bus_shunts if t in conns) ) push!(cstr_p, cp) @@ -257,12 +257,12 @@ function constraint_mc_power_balance_capc(pm::LPUBFDiagModel, nw::Int, i::Int, t sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - + sum(qd[l][t] for (l, conns) in bus_loads if t in conns) - + sum((-w[t] * LinearAlgebra.diag(Bt')[idx]) for (sh, conns) in uncontrolled_shunts if t in conns) - + sum(-var(pm, nw, :capacitor_reactive_power, sh)[t] for (sh, conns) in controlled_shunts if t in conns) - == 0.0 + == + sum(qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + - sum(qd[l][t] for (l, conns) in bus_loads if t in conns) + - sum((-w[t] * LinearAlgebra.diag(Bt')[idx]) for (sh, conns) in uncontrolled_shunts if t in conns) + - sum(-var(pm, nw, :capacitor_reactive_power, sh)[t] for (sh, conns) in controlled_shunts if t in conns) ) push!(cstr_q, cq) end diff --git a/src/form/en_acr.jl b/src/form/en_acr.jl old mode 100755 new mode 100644 index 4ab28882d..bd5e446d1 --- a/src/form/en_acr.jl +++ b/src/form/en_acr.jl @@ -57,19 +57,19 @@ function constraint_mc_generator_power_wye(pm::AbstractExplicitNeutralACRModel, vr_pn = [vr[p]-vr[n] for p in phases] vi_pn = [vi[p]-vi[n] for p in phases] - crg = JuMP.@expression(pm.model, [idx in 1:P], + crg = JuMP.@NLexpression(pm.model, [idx in 1:P], ( pg[idx]*vr_pn[idx] + qg[idx]*vi_pn[idx] )/( vr_pn[idx]^2 + vi_pn[idx]^2 ) ) - cig = JuMP.@expression(pm.model, [idx in 1:P], + cig = JuMP.@NLexpression(pm.model, [idx in 1:P], ( pg[idx]*vi_pn[idx] - qg[idx]*vr_pn[idx] )/( vr_pn[idx]^2 + vi_pn[idx]^2 ) ) pg_bus_unmerged = [ - [JuMP.@expression(pm.model, vr[p]*crg[idx]+vi[p]*cig[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@expression(pm.model, vr[n]*sum(-crg[idx] for idx in 1:P)+vi[n]*sum(-cig[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, vr[p]*crg[idx]+vi[p]*cig[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@NLexpression(pm.model, vr[n]*sum(-crg[idx] for idx in 1:P)+vi[n]*sum(-cig[idx] for idx in 1:P)) ] qg_bus_unmerged = [ - [JuMP.@expression(pm.model, -vr[p]*cig[idx]+vi[p]*crg[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@expression(pm.model, -vr[n]*sum(-cig[idx] for idx in 1:P)+vi[n]*sum(-crg[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, -vr[p]*cig[idx]+vi[p]*crg[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@NLexpression(pm.model, -vr[n]*sum(-cig[idx] for idx in 1:P)+vi[n]*sum(-crg[idx] for idx in 1:P)) ] end var(pm, nw, :pg_bus)[id] = pg_bus = _merge_bus_flows(pm, pg_bus_unmerged, connections) @@ -115,17 +115,17 @@ function constraint_mc_generator_power_delta(pm::AbstractExplicitNeutralACRModel vr_pp = [vr[c]-vr[d] for (c,d) in zip(ph,ph_next)] vi_pp = [vi[c]-vi[d] for (c,d) in zip(ph,ph_next)] - crg = JuMP.@expression(pm.model, [idx in 1:P], + crg = JuMP.@NLexpression(pm.model, [idx in 1:P], ( pg[idx]*vr_pp[idx] + qg[idx]*vi_pp[idx] )/( vr_pp[idx]^2 + vi_pp[idx]^2 ) ) - cig = JuMP.@expression(pm.model, [idx in 1:P], + cig = JuMP.@NLexpression(pm.model, [idx in 1:P], ( pg[idx]*vi_pp[idx] - qg[idx]*vr_pp[idx] )/( vr_pp[idx]^2 + vi_pp[idx]^2 ) ) - crg_bus = JuMP.@expression(pm.model, [idx in 1:P], crg[idx] - crg[idxs_prev[idx]]) - cig_bus = JuMP.@expression(pm.model, [idx in 1:P], cig[idx] - cig[idxs_prev[idx]]) + crg_bus = JuMP.@NLexpression(pm.model, [idx in 1:P], crg[idx] - crg[idxs_prev[idx]]) + cig_bus = JuMP.@NLexpression(pm.model, [idx in 1:P], cig[idx] - cig[idxs_prev[idx]]) - pg_bus_unmerged = [JuMP.@expression(pm.model, vr[p]*crg_bus[idx]+vi[p]*cig_bus[idx]) for (idx,p) in enumerate(ph)] - qg_bus_unmerged = [JuMP.@expression(pm.model, -vr[p]*cig_bus[idx]+vi[p]*crg_bus[idx]) for (idx,p) in enumerate(ph)] + pg_bus_unmerged = [JuMP.@NLexpression(pm.model, vr[p]*crg_bus[idx]+vi[p]*cig_bus[idx]) for (idx,p) in enumerate(ph)] + qg_bus_unmerged = [JuMP.@NLexpression(pm.model, -vr[p]*cig_bus[idx]+vi[p]*crg_bus[idx]) for (idx,p) in enumerate(ph)] var(pm, nw, :pg_bus)[id] = pg_bus = _merge_bus_flows(pm, pg_bus_unmerged, connections) var(pm, nw, :qg_bus)[id] = qg_bus = _merge_bus_flows(pm, qg_bus_unmerged, connections) @@ -190,8 +190,8 @@ function constraint_mc_load_power_wye(pm::AbstractExplicitNeutralACRModel, nw::I vr_pn = [vr[p]-vr[n] for p in phases] vi_pn = [vi[p]-vi[n] for p in phases] - crd = JuMP.@expression(pm.model, [idx in 1:P], a[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)+b[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) - cid = JuMP.@expression(pm.model, [idx in 1:P], a[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)-b[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) + crd = JuMP.@NLexpression(pm.model, [idx in 1:P], a[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)+b[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) + cid = JuMP.@NLexpression(pm.model, [idx in 1:P], a[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)-b[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) # if constant power load @@ -199,8 +199,8 @@ function constraint_mc_load_power_wye(pm::AbstractExplicitNeutralACRModel, nw::I pd = a qd = b else - pd = JuMP.@expression(pm.model, [idx in 1:P], vr_pn[idx]*crd[idx]+vi_pn[idx]*cid[idx]) - qd = JuMP.@expression(pm.model, [idx in 1:P], -vr_pn[idx]*cid[idx]+vi_pn[idx]*crd[idx]) + pd = JuMP.@NLexpression(pm.model, [idx in 1:P], vr_pn[idx]*crd[idx]+vi_pn[idx]*cid[idx]) + qd = JuMP.@NLexpression(pm.model, [idx in 1:P], -vr_pn[idx]*cid[idx]+vi_pn[idx]*crd[idx]) end if iszero(vr[n]) && iszero(vi[n]) @@ -208,12 +208,12 @@ function constraint_mc_load_power_wye(pm::AbstractExplicitNeutralACRModel, nw::I qd_bus_unmerged = [qd..., 0.0] else pd_bus_unmerged = [ - [JuMP.@expression(pm.model, vr[p]*crd[idx]+vi[p]*cid[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@expression(pm.model, vr[n]*sum(-crd[idx] for idx in 1:P)+vi[n]*sum(-cid[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, vr[p]*crd[idx]+vi[p]*cid[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@NLexpression(pm.model, vr[n]*sum(-crd[idx] for idx in 1:P)+vi[n]*sum(-cid[idx] for idx in 1:P)) ] qd_bus_unmerged = [ - [JuMP.@expression(pm.model, -vr[p]*cid[idx]+vi[p]*crd[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@expression(pm.model, -vr[n]*sum(-cid[idx] for idx in 1:P)+vi[n]*sum(-crd[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, -vr[p]*cid[idx]+vi[p]*crd[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@NLexpression(pm.model, -vr[n]*sum(-cid[idx] for idx in 1:P)+vi[n]*sum(-crd[idx] for idx in 1:P)) ] end var(pm, nw, :pd_bus)[id] = pd_bus = _merge_bus_flows(pm, pd_bus_unmerged, connections) @@ -258,14 +258,14 @@ function constraint_mc_load_power_delta(pm::AbstractExplicitNeutralACRModel, nw: vrd = [vr[t]-vr[connections[next(idx)]] for (idx,t) in enumerate(connections)] vid = [vi[t]-vi[connections[next(idx)]] for (idx,t) in enumerate(connections)] - crd = JuMP.@expression(pm.model, [idx in 1:nph], a[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)+b[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) - cid = JuMP.@expression(pm.model, [idx in 1:nph], a[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)-b[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) + crd = JuMP.@NLexpression(pm.model, [idx in 1:nph], a[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)+b[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) + cid = JuMP.@NLexpression(pm.model, [idx in 1:nph], a[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)-b[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) - crd_bus_unmerged = JuMP.@expression(pm.model, [idx in 1:nph], crd[idx]-crd[prev(idx)]) - cid_bus_unmerged = JuMP.@expression(pm.model, [idx in 1:nph], cid[idx]-cid[prev(idx)]) + crd_bus_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:nph], crd[idx]-crd[prev(idx)]) + cid_bus_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:nph], cid[idx]-cid[prev(idx)]) - pd_bus_unmerged = [JuMP.@expression(pm.model, vr[p]*crd_bus_unmerged[idx]+vi[p]*cid_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] - qd_bus_unmerged = [JuMP.@expression(pm.model, -vr[p]*cid_bus_unmerged[idx]+vi[p]*crd_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] + pd_bus_unmerged = [JuMP.@NLexpression(pm.model, vr[p]*crd_bus_unmerged[idx]+vi[p]*cid_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] + qd_bus_unmerged = [JuMP.@NLexpression(pm.model, -vr[p]*cid_bus_unmerged[idx]+vi[p]*crd_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] var(pm, nw, :pd_bus)[id] = pd_bus = _merge_bus_flows(pm, pd_bus_unmerged, connections) var(pm, nw, :qd_bus)[id] = qd_bus = _merge_bus_flows(pm, qd_bus_unmerged, connections) @@ -274,11 +274,11 @@ function constraint_mc_load_power_delta(pm::AbstractExplicitNeutralACRModel, nw: sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpr}([]) - qd = Vector{JuMP.NonlinearExpr}([]) + pd = Vector{JuMP.NonlinearExpression}([]) + qd = Vector{JuMP.NonlinearExpression}([]) for idx in 1:nph - push!(pd, JuMP.@expression(pm.model, a[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@expression(pm.model, b[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -357,16 +357,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractExplicitNeutralACRModel, vr_fr_pn = [vr_fr[p]-vr_fr[f_n] for p in f_phases] vi_fr_pn = [vi_fr[p]-vi_fr[f_n] for p in f_phases] - crt_fr = [JuMP.@expression(pm.model, ( pt_fr[idx]*vr_fr_pn[idx]+qt_fr[idx]*vi_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] - cit_fr = [JuMP.@expression(pm.model, (-pt_fr[idx]*vi_fr_pn[idx]+qt_fr[idx]*vr_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] + crt_fr = [JuMP.@NLexpression(pm.model, ( pt_fr[idx]*vr_fr_pn[idx]+qt_fr[idx]*vi_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] + cit_fr = [JuMP.@NLexpression(pm.model, (-pt_fr[idx]*vi_fr_pn[idx]+qt_fr[idx]*vr_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] pt_bus_fr_unmerged = [ - [JuMP.@expression(pm.model, vr_fr[p]*crt_fr[idx]+vi_fr[p]*cit_fr[idx]) for (idx,p) in enumerate(f_phases)]..., - JuMP.@expression(pm.model, vr_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, vr_fr[p]*crt_fr[idx]+vi_fr[p]*cit_fr[idx]) for (idx,p) in enumerate(f_phases)]..., + JuMP.@NLexpression(pm.model, vr_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)) ] qt_bus_fr_unmerged = [ - [JuMP.@expression(pm.model, -vr_fr[p]*cit_fr[idx]+vi_fr[p]*crt_fr[idx]) for (idx,p) in enumerate(f_phases)]..., - JuMP.@expression(pm.model, -vr_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, -vr_fr[p]*cit_fr[idx]+vi_fr[p]*crt_fr[idx]) for (idx,p) in enumerate(f_phases)]..., + JuMP.@NLexpression(pm.model, -vr_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)) ] end var(pm, nw, :pt_bus)[f_idx] = pt_bus_fr = _merge_bus_flows(pm, pt_bus_fr_unmerged, f_connections) @@ -380,16 +380,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractExplicitNeutralACRModel, vr_to_pn = [vr_to[p]-vr_to[t_n] for p in t_phases] vi_to_pn = [vi_to[p]-vi_to[t_n] for p in t_phases] - crt_to = [JuMP.@expression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] - cit_to = [JuMP.@expression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + crt_to = [JuMP.@NLexpression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + cit_to = [JuMP.@NLexpression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] pt_bus_to_unmerged = [ - [JuMP.@expression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(t_phases)]..., - JuMP.@expression(pm.model, vr_to[t_n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-cit_to[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(t_phases)]..., + JuMP.@NLexpression(pm.model, vr_to[t_n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-cit_to[idx] for idx in 1:P)) ] qt_bus_to_unmerged = [ - [JuMP.@expression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(t_phases)]..., - JuMP.@expression(pm.model, -vr_to[t_n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-crt_to[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(t_phases)]..., + JuMP.@NLexpression(pm.model, -vr_to[t_n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-crt_to[idx] for idx in 1:P)) ] end var(pm, nw, :pt_bus)[t_idx] = pt_bus_to = _merge_bus_flows(pm, pt_bus_to_unmerged, t_connections) @@ -440,14 +440,14 @@ function constraint_mc_transformer_power_dy(pm::AbstractExplicitNeutralACRModel, vrg_fr = [vr_fr[p]-vr_fr[f_connections[next(idx)]] for (idx,p) in enumerate(f_connections)] vig_fr = [vi_fr[p]-vi_fr[f_connections[next(idx)]] for (idx,p) in enumerate(f_connections)] - crt_fr = JuMP.@expression(pm.model, [idx in 1:P], (pt_fr[idx]*vrg_fr[idx]+qt_fr[idx]*vig_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) - cit_fr = JuMP.@expression(pm.model, [idx in 1:P], (pt_fr[idx]*vig_fr[idx]-qt_fr[idx]*vrg_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) + crt_fr = JuMP.@NLexpression(pm.model, [idx in 1:P], (pt_fr[idx]*vrg_fr[idx]+qt_fr[idx]*vig_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) + cit_fr = JuMP.@NLexpression(pm.model, [idx in 1:P], (pt_fr[idx]*vig_fr[idx]-qt_fr[idx]*vrg_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) - crt_bus_fr_unmerged = JuMP.@expression(pm.model, [idx in 1:P], crt_fr[idx]-crt_fr[prev(idx)]) - cit_bus_fr_unmerged = JuMP.@expression(pm.model, [idx in 1:P], cit_fr[idx]-cit_fr[prev(idx)]) + crt_bus_fr_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:P], crt_fr[idx]-crt_fr[prev(idx)]) + cit_bus_fr_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:P], cit_fr[idx]-cit_fr[prev(idx)]) - pt_bus_fr_unmerged = [JuMP.@expression(pm.model, vr_fr[p]*crt_bus_fr_unmerged[idx]+vi_fr[p]*cit_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] - qt_bus_fr_unmerged = [JuMP.@expression(pm.model, -vr_fr[p]*cit_bus_fr_unmerged[idx]+vi_fr[p]*crt_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] + pt_bus_fr_unmerged = [JuMP.@NLexpression(pm.model, vr_fr[p]*crt_bus_fr_unmerged[idx]+vi_fr[p]*cit_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] + qt_bus_fr_unmerged = [JuMP.@NLexpression(pm.model, -vr_fr[p]*cit_bus_fr_unmerged[idx]+vi_fr[p]*crt_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] var(pm, nw, :pt_bus)[f_idx] = pt_bus_fr = _merge_bus_flows(pm, pt_bus_fr_unmerged, f_connections) var(pm, nw, :qt_bus)[f_idx] = qt_bus_fr = _merge_bus_flows(pm, qt_bus_fr_unmerged, f_connections) @@ -460,16 +460,16 @@ function constraint_mc_transformer_power_dy(pm::AbstractExplicitNeutralACRModel, vr_to_pn = [vr_to[p]-vr_to[t_n] for p in t_phases] vi_to_pn = [vi_to[p]-vi_to[t_n] for p in t_phases] - crt_to = [JuMP.@expression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] - cit_to = [JuMP.@expression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + crt_to = [JuMP.@NLexpression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + cit_to = [JuMP.@NLexpression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] pt_bus_to_unmerged = [ - [JuMP.@expression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@expression(pm.model, vr_to[n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[n]*sum(-cit_to[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@NLexpression(pm.model, vr_to[n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[n]*sum(-cit_to[idx] for idx in 1:P)) ] qt_bus_to_unmerged = [ - [JuMP.@expression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@expression(pm.model, -vr_to[n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[n]*sum(-crt_to[idx] for idx in 1:P)) + [JuMP.@NLexpression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@NLexpression(pm.model, -vr_to[n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[n]*sum(-crt_to[idx] for idx in 1:P)) ] end var(pm, nw, :pt_bus)[t_idx] = pt_bus_to = _merge_bus_flows(pm, pt_bus_to_unmerged, t_connections) @@ -680,7 +680,7 @@ function constraint_mc_thermal_limit_from(pm::AbstractExplicitNeutralACRModel, n if rate_a[idx]= pg[i]) - JuMP.@constraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) - JuMP.@constraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) + JuMP.@NLconstraint(pm.model, [i in 1:nph], pmin[i] <= pg[i]) + JuMP.@NLconstraint(pm.model, [i in 1:nph], pmax[i] >= pg[i]) + JuMP.@NLconstraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) + JuMP.@NLconstraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) var(pm, nw, :pg)[id] = JuMP.Containers.DenseAxisArray(pg, connections) var(pm, nw, :qg)[id] = JuMP.Containers.DenseAxisArray(qg, connections) @@ -499,38 +499,38 @@ function constraint_mc_load_current_wye(pm::AbstractExplicitNeutralIVRModel, nw: vr = var(pm, nw, :vr, bus_id) vi = var(pm, nw, :vi, bus_id) - crd = Vector{JuMP.NonlinearExpr}([]) - cid = Vector{JuMP.NonlinearExpr}([]) + crd = Vector{JuMP.NonlinearExpression}([]) + cid = Vector{JuMP.NonlinearExpression}([]) phases = connections[1:end-1] n = connections[end] for (idx, p) in enumerate(phases) - push!(crd, JuMP.@expression(pm.model, - (a[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1)) - +(b[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1)) + push!(crd, JuMP.@NLexpression(pm.model, + a[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1) + +b[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1) )) - push!(cid, JuMP.@expression(pm.model, - (a[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1)) - -(b[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1)) + push!(cid, JuMP.@NLexpression(pm.model, + a[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1) + -b[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1) )) end var(pm, nw, :crd)[id] = crd var(pm, nw, :cid)[id] = cid - crd_bus_n = JuMP.@expression(pm.model, -sum(crd[i] for i in 1:length(phases))) - cid_bus_n = JuMP.@expression(pm.model, -sum(cid[i] for i in 1:length(phases))) + crd_bus_n = JuMP.@NLexpression(pm.model, -sum(crd[i] for i in 1:length(phases))) + cid_bus_n = JuMP.@NLexpression(pm.model, -sum(cid[i] for i in 1:length(phases))) var(pm, nw, :crd_bus)[id] = crd_bus = _merge_bus_flows(pm, [crd..., crd_bus_n], connections) var(pm, nw, :cid_bus)[id] = cid_bus = _merge_bus_flows(pm, [cid..., cid_bus_n], connections) if report - pd_bus = Vector{JuMP.NonlinearExpr}([]) - qd_bus = Vector{JuMP.NonlinearExpr}([]) + pd_bus = Vector{JuMP.NonlinearExpression}([]) + qd_bus = Vector{JuMP.NonlinearExpression}([]) for (idx,c) in enumerate(connections) - push!(pd_bus, JuMP.@expression(pm.model, (vr[c]*crd_bus[c])+(vi[c]*cid_bus[c]))) - push!(qd_bus, JuMP.@expression(pm.model, -(vr[c]*cid_bus[c])+(vi[c]*crd_bus[c]))) + push!(pd_bus, JuMP.@NLexpression(pm.model, vr[c]*crd_bus[c]+vi[c]*cid_bus[c])) + push!(qd_bus, JuMP.@NLexpression(pm.model, -vr[c]*cid_bus[c]+vi[c]*crd_bus[c])) end sol(pm, nw, :load, id)[:pd_bus] = JuMP.Containers.DenseAxisArray(pd_bus, connections) @@ -542,11 +542,11 @@ function constraint_mc_load_current_wye(pm::AbstractExplicitNeutralIVRModel, nw: sol(pm, nw, :load, id)[:crd_bus] = crd_bus sol(pm, nw, :load, id)[:cid_bus] = cid_bus - pd = Vector{JuMP.NonlinearExpr}([]) - qd = Vector{JuMP.NonlinearExpr}([]) + pd = Vector{JuMP.NonlinearExpression}([]) + qd = Vector{JuMP.NonlinearExpression}([]) for (idx, p) in enumerate(phases) - push!(pd, JuMP.@expression(pm.model, a[idx]*(vr[p]^2+vi[p]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@expression(pm.model, b[idx]*(vr[p]^2+vi[p]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vr[p]^2+vi[p]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vr[p]^2+vi[p]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -586,30 +586,30 @@ function constraint_mc_load_current_delta(pm::AbstractExplicitNeutralIVRModel, n vrd = [vr[c]-vr[d] for (c,d) in zip(ph,ph_next)] vid = [vi[c]-vi[d] for (c,d) in zip(ph,ph_next)] - crd = JuMP.@expression(pm.model, [i in 1:P], - (a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1)) - +(b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1)) + crd = JuMP.@NLexpression(pm.model, [i in 1:P], + a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) + +b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) ) - cid = JuMP.@expression(pm.model, [i in 1:P], - (a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1)) - -(b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1)) + cid = JuMP.@NLexpression(pm.model, [i in 1:P], + a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) + -b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) ) - crd_bus = JuMP.@expression(pm.model, [i in 1:P], crd[i]-crd[idxs_prev[i]]) - cid_bus = JuMP.@expression(pm.model, [i in 1:P], cid[i]-cid[idxs_prev[i]]) + crd_bus = JuMP.@NLexpression(pm.model, [i in 1:P], crd[i]-crd[idxs_prev[i]]) + cid_bus = JuMP.@NLexpression(pm.model, [i in 1:P], cid[i]-cid[idxs_prev[i]]) var(pm, nw, :crd_bus)[id] = _merge_bus_flows(pm, crd_bus, connections) var(pm, nw, :cid_bus)[id] = _merge_bus_flows(pm, cid_bus, connections) if report - pd_bus = JuMP.@expression(pm.model, [i in 1:P], (vr[i]*crd_bus[i])+(vi[i]*cid_bus[i])) - qd_bus = JuMP.@expression(pm.model, [i in 1:P], -(vr[i]*cid_bus[i])+(vi[i]*crd_bus[i])) + pd_bus = JuMP.@NLexpression(pm.model, [i in 1:P], vr[i]*crd_bus[i]+vi[i]*cid_bus[i]) + qd_bus = JuMP.@NLexpression(pm.model, [i in 1:P], -vr[i]*cid_bus[i]+vi[i]*crd_bus[i]) sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = JuMP.@expression(pm.model, [i in 1:P], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) - qd = JuMP.@expression(pm.model, [i in 1:P], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) + pd = JuMP.@NLexpression(pm.model, [i in 1:P], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) + qd = JuMP.@NLexpression(pm.model, [i in 1:P], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) sol(pm, nw, :load, id)[:pd] = pd sol(pm, nw, :load, id)[:qd] = qd end @@ -1101,14 +1101,14 @@ function constraint_mc_transformer_thermal_limit(pm::AbstractNLExplicitNeutralIV vit_to = [vi_to[p]-vi_to[n_to] for p in P_to] idxs = [1:length(vrt_fr)...] - pt_fr = JuMP.@expression(pm.model, [i in idxs], (vrt_fr[i]*crt_fr[i]) + (vit_fr[i]*cit_fr[i])) - qt_fr = JuMP.@expression(pm.model, [i in idxs], -(vrt_fr[i]*cit_fr[i]) + (vit_fr[i]*crt_fr[i])) - pt_to = JuMP.@expression(pm.model, [i in idxs], (vrt_to[i]*crt_to[i]) + (vit_to[i]*cit_to[i])) - qt_to = JuMP.@expression(pm.model, [i in idxs], -(vrt_to[i]*cit_to[i]) + (vit_to[i]*crt_to[i])) + pt_fr = JuMP.@NLexpression(pm.model, [i in idxs], vrt_fr[i]*crt_fr[i] + vit_fr[i]*cit_fr[i]) + qt_fr = JuMP.@NLexpression(pm.model, [i in idxs], -vrt_fr[i]*cit_fr[i] + vit_fr[i]*crt_fr[i]) + pt_to = JuMP.@NLexpression(pm.model, [i in idxs], vrt_to[i]*crt_to[i] + vit_to[i]*cit_to[i]) + qt_to = JuMP.@NLexpression(pm.model, [i in idxs], -vrt_to[i]*cit_to[i] + vit_to[i]*crt_to[i]) if sm_ub(i+nph-2)%nph+1 for i in 1:nph) next = is_triplex ? conn_bus[2] : Dict(i=>i%nph+1 for i in 1:nph) - vrd = JuMP.@expression(pm.model, [i in 1:nph], vr[i]-vr[next[i]]) - vid = JuMP.@expression(pm.model, [i in 1:nph], vi[i]-vi[next[i]]) + vrd = JuMP.@NLexpression(pm.model, [i in 1:nph], vr[i]-vr[next[i]]) + vid = JuMP.@NLexpression(pm.model, [i in 1:nph], vi[i]-vi[next[i]]) - crd = JuMP.@expression(pm.model, [i in 1:nph], - (a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1)) - +(b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1)) + crd = JuMP.@NLexpression(pm.model, [i in 1:nph], + a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) + +b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) ) - cid = JuMP.@expression(pm.model, [i in 1:nph], - (a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1)) - -(b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1)) + cid = JuMP.@NLexpression(pm.model, [i in 1:nph], + a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) + -b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) ) crd_bus = Dict() cid_bus = Dict() for (idx, c) in enumerate(conn_bus) if is_triplex - crd_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crd[1]) - cid_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cid[1]) + crd_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crd[1]) + cid_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cid[1]) else - crd_bus[c] = JuMP.@expression(pm.model, crd[c]-crd[prev[c]]) - cid_bus[c] = JuMP.@expression(pm.model, cid[c]-cid[prev[c]]) + crd_bus[c] = JuMP.@NLexpression(pm.model, crd[c]-crd[prev[c]]) + cid_bus[c] = JuMP.@NLexpression(pm.model, cid[c]-cid[prev[c]]) end end @@ -698,13 +698,13 @@ function constraint_mc_load_power_delta(pm::IVRUPowerModel, nw::Int, id::Int, bu var(pm, nw, :cid_bus)[id] = cid_bus if report - pd_bus = JuMP.@expression(pm.model, [c in conn_bus], -(vr[c]*(-crd_bus[c]))-(vi[c]*(-cid_bus[c]))) - qd_bus = JuMP.@expression(pm.model, [c in conn_bus], (vr[c]*(-cid_bus[c]))-(vi[c]*(-crd_bus[c]))) + pd_bus = JuMP.@NLexpression(pm.model, [c in conn_bus], vr[c]*crd_bus[c]+vi[c]*cid_bus[c]) + qd_bus = JuMP.@NLexpression(pm.model, [c in conn_bus], -vr[c]*cid_bus[c]+vi[c]*crd_bus[c]) sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = JuMP.@expression(pm.model, [i in 1:nph], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) - qd = JuMP.@expression(pm.model, [i in 1:nph], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) + pd = JuMP.@NLexpression(pm.model, [i in 1:nph], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) + qd = JuMP.@NLexpression(pm.model, [i in 1:nph], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) sol(pm, nw, :load, id)[:pd] = pd sol(pm, nw, :load, id)[:qd] = qd end @@ -718,12 +718,12 @@ function constraint_mc_generator_power_wye(pm::IVRUPowerModel, nw::Int, id::Int, crg = var(pm, nw, :crg, id) cig = var(pm, nw, :cig, id) - pg = Vector{JuMP.NonlinearExpr}([]) - qg = Vector{JuMP.NonlinearExpr}([]) + pg = Vector{JuMP.NonlinearExpression}([]) + qg = Vector{JuMP.NonlinearExpression}([]) for (idx, c) in enumerate(connections) - push!(pg, JuMP.@expression(pm.model, -(vr[c]*(-crg[c]))-(vi[c]*(-cig[c])))) - push!(qg, JuMP.@expression(pm.model, (vr[c]*(-cig[c]))-(vi[c]*(-crg[c])))) + push!(pg, JuMP.@NLexpression(pm.model, vr[c]*crg[c]+vi[c]*cig[c])) + push!(qg, JuMP.@NLexpression(pm.model, -vr[c]*cig[c]+vi[c]*crg[c])) end if bounded @@ -775,41 +775,41 @@ function constraint_mc_generator_power_delta(pm::IVRUPowerModel, nw::Int, id::In vrg = Dict() vig = Dict() for c in connections - vrg[c] = JuMP.@expression(pm.model, vr[c]-vr[next[c]]) - vig[c] = JuMP.@expression(pm.model, vi[c]-vi[next[c]]) + vrg[c] = JuMP.@NLexpression(pm.model, vr[c]-vr[next[c]]) + vig[c] = JuMP.@NLexpression(pm.model, vi[c]-vi[next[c]]) end - pg = Vector{JuMP.NonlinearExpr}([]) - qg = Vector{JuMP.NonlinearExpr}([]) + pg = Vector{JuMP.NonlinearExpression}([]) + qg = Vector{JuMP.NonlinearExpression}([]) for c in connections - push!(pg, JuMP.@expression(pm.model, -(vrg[c]*(-crg[c]))-(vig[c]*(-cig[c])))) - push!(qg, JuMP.@expression(pm.model, (vrg[c]*(-cig[c]))-(vig[c]*(-crg[c])))) + push!(pg, JuMP.@NLexpression(pm.model, vrg[c]*crg[c]+vig[c]*cig[c])) + push!(qg, JuMP.@NLexpression(pm.model, -vrg[c]*cig[c]+vig[c]*crg[c])) end if bounded - JuMP.@constraint(pm.model, [i in 1:nph], pmin[i] <= pg[i]) - JuMP.@constraint(pm.model, [i in 1:nph], pmax[i] >= pg[i]) - JuMP.@constraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) - JuMP.@constraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) + JuMP.@NLconstraint(pm.model, [i in 1:nph], pmin[i] <= pg[i]) + JuMP.@NLconstraint(pm.model, [i in 1:nph], pmax[i] >= pg[i]) + JuMP.@NLconstraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) + JuMP.@NLconstraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) end - crg_bus = Vector{JuMP.NonlinearExpr}([]) - cig_bus = Vector{JuMP.NonlinearExpr}([]) + crg_bus = Vector{JuMP.NonlinearExpression}([]) + cig_bus = Vector{JuMP.NonlinearExpression}([]) for c in conn_bus if is_triplex - push!(crg_bus, JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1])) - push!(cig_bus, JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1])) + push!(crg_bus, JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crg[1])) + push!(cig_bus, JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cig[1])) else - push!(crg_bus, JuMP.@expression(pm.model, crg[c]-crg[prev[c]])) - push!(cig_bus, JuMP.@expression(pm.model, cig[c]-cig[prev[c]])) + push!(crg_bus, JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]])) + push!(cig_bus, JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]])) end end - pg_bus = Vector{JuMP.NonlinearExpr}([]) - qg_bus = Vector{JuMP.NonlinearExpr}([]) + pg_bus = Vector{JuMP.NonlinearExpression}([]) + qg_bus = Vector{JuMP.NonlinearExpression}([]) for (idx,c) in enumerate(conn_bus) - push!(pg_bus, JuMP.@expression(pm.model, -(vr[c]*(-crg_bus[c]))-(vi[c]*(-cig_bus[c])))) - push!(qg_bus, JuMP.@expression(pm.model, (vr[c]*(-cig_bus[c]))-(vi[c]*(-crg_bus[c])))) + push!(pg_bus, JuMP.@NLexpression(pm.model, vr[c]*crg_bus[c]+vi[c]*cig_bus[c])) + push!(qg_bus, JuMP.@NLexpression(pm.model, -vr[c]*cig_bus[c]+vi[c]*crg_bus[c])) end var(pm, nw, :crg_bus)[id] = JuMP.Containers.DenseAxisArray(crg_bus, conn_bus) diff --git a/src/form/shared.jl b/src/form/shared.jl index 253b98f78..5a3e10c10 100644 --- a/src/form/shared.jl +++ b/src/form/shared.jl @@ -63,24 +63,24 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedWModels, nw::In sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - + sum(ref(pm, nw, :load, l, "pd")[findfirst(isequal(t), conns)] for (l, conns) in bus_loads if t in conns) - + sum(w[t] * LinearAlgebra.diag(Gt')[idx] for (sh, conns) in bus_shunts if t in conns) - - p_slack[t] - == 0.0 + == + sum(pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + - sum(ref(pm, nw, :load, l, "pd")[findfirst(isequal(t), conns)] for (l, conns) in bus_loads if t in conns) + - sum(w[t] * LinearAlgebra.diag(Gt')[idx] for (sh, conns) in bus_shunts if t in conns) + + p_slack[t] ) push!(cstr_p, cp) cq = JuMP.@constraint(pm.model, sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - + sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)] for (l, conns) in bus_loads if t in conns) - + sum(-w[t] * LinearAlgebra.diag(Bt')[idx] for (sh, conns) in bus_shunts if t in conns) - - q_slack[t] - == 0.0 + == + sum(qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + - sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)] for (l, conns) in bus_loads if t in conns) + - sum(-w[t] * LinearAlgebra.diag(Bt')[idx] for (sh, conns) in bus_shunts if t in conns) + + q_slack[t] ) push!(cstr_q, cq) end @@ -152,22 +152,22 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedWModels, nw::Int sum(p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(pt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - + sum(ref(pm, nw, :load, l, "pd")[findfirst(isequal(t), conns)] * z_demand[l] for (l, conns) in bus_loads if t in conns) - + sum(z_shunt[sh] *(w[t] * LinearAlgebra.diag(Gt')[idx]) for (sh, conns) in bus_shunts if t in conns) - == 0.0 + == + sum(pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + - sum(ref(pm, nw, :load, l, "pd")[findfirst(isequal(t), conns)] * z_demand[l] for (l, conns) in bus_loads if t in conns) + - sum(z_shunt[sh] *(w[t] * LinearAlgebra.diag(Gt')[idx]) for (sh, conns) in bus_shunts if t in conns) ) push!(cstr_p, cp) cq = JuMP.@constraint(pm.model, sum(q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(qt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - + sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)]*z_demand[l] for (l, conns) in bus_loads if t in conns) - + sum(z_shunt[sh] * (-w[t] * LinearAlgebra.diag(Bt')[idx]) for (sh, conns) in bus_shunts if t in conns) - == 0.0 + == + sum(qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + - sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)]*z_demand[l] for (l, conns) in bus_loads if t in conns) + - sum(z_shunt[sh] * (-w[t] * LinearAlgebra.diag(Bt')[idx]) for (sh, conns) in bus_shunts if t in conns) ) push!(cstr_q, cq) end @@ -212,11 +212,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedWModels, nw::Int, i:: sum(LinearAlgebra.diag(P[a])[findfirst(isequal(t), conns)] for (a, conns) in bus_arcs if t in conns) + sum(LinearAlgebra.diag(Psw[a_sw])[findfirst(isequal(t), conns)] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(LinearAlgebra.diag(Pt[a_trans])[findfirst(isequal(t), conns)] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - + sum(pd[d][t] for (d, conns) in bus_loads if t in conns) - + LinearAlgebra.diag(Wr*Gt'+Wi*Bt')[idx] - == 0.0 + == + sum(pg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) + - sum(pd[d][t] for (d, conns) in bus_loads if t in conns) + - LinearAlgebra.diag(Wr*Gt'+Wi*Bt')[idx] ) push!(cstr_p, cp) @@ -224,11 +224,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedWModels, nw::Int, i:: sum(LinearAlgebra.diag(Q[a])[findfirst(isequal(t), conns)] for (a, conns) in bus_arcs if t in conns) + sum(LinearAlgebra.diag(Qsw[a_sw])[findfirst(isequal(t), conns)] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(LinearAlgebra.diag(Qt[a_trans])[findfirst(isequal(t), conns)] for (a_trans, conns) in bus_arcs_trans if t in conns) - + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) - + sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - + sum(qd[d][t] for (d, conns) in bus_loads if t in conns) - + LinearAlgebra.diag(-Wr*Bt'+Wi*Gt')[idx] - == 0.0 + == + sum(qg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) + - sum(qd[d][t] for (d, conns) in bus_loads if t in conns) + - LinearAlgebra.diag(-Wr*Bt'+Wi*Gt')[idx] ) push!(cstr_q, cq) end diff --git a/src/form/utils.jl b/src/form/utils.jl old mode 100755 new mode 100644 index d90b83d53..e426060c6 --- a/src/form/utils.jl +++ b/src/form/utils.jl @@ -7,8 +7,8 @@ function _merge_bus_flows(pm::ExplicitNeutralModels, flows::Vector, connections: flows_t = flows[idxs] if length(flows_t)==1 flows_merged_t = flows_t[1] - elseif any(isa(a, JuMP.NonlinearExpr) for a in flows_t) - flows_merged_t = JuMP.@expression(pm.model, sum(flows_t[i] for i in 1:length(flows_t))) + elseif any(isa(a, JuMP.NonlinearExpression) for a in flows_t) + flows_merged_t = JuMP.@NLexpression(pm.model, sum(flows_t[i] for i in 1:length(flows_t))) else flows_merged_t = sum(flows_t) end From f4e6f0dee3e4d939497abb3707e44138a4097686 Mon Sep 17 00:00:00 2001 From: David M Fobes Date: Thu, 9 May 2024 09:38:21 -0600 Subject: [PATCH 5/6] REF: reduce number of changes --- Project.toml | 4 +- docs/src/reference/base.md | 1 - src/core/base.jl | 16 --- src/core/data.jl | 25 ---- src/core/objective.jl | 34 +++--- src/core/solution.jl | 18 +-- src/form/acp.jl | 226 ++++++++++++++++++------------------- src/form/acr.jl | 132 +++++++++++----------- src/form/bf_fbs.jl | 4 +- src/form/en_acr.jl | 112 +++++++++--------- src/form/en_ivr.jl | 106 ++++++++--------- src/form/en_shared.jl | 8 +- src/form/fotp.jl | 4 +- src/form/fotr.jl | 4 +- src/form/ivr.jl | 120 ++++++++++---------- src/form/utils.jl | 4 +- 16 files changed, 382 insertions(+), 436 deletions(-) diff --git a/Project.toml b/Project.toml index 5ea33a264..c941eb3fb 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "PowerModelsDistribution" uuid = "d7431456-977f-11e9-2de3-97ff7677985e" authors = ["David M Fobes ", "Carleton Coffrin"] repo = "https://github.com/lanl-ansi/PowerModelsDistribution.jl.git" -version = "0.15.2" +version = "0.16.0" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" @@ -29,7 +29,7 @@ Graphs = "1" InfrastructureModels = "0.7.3, 0.7.5" Ipopt = "0.9, 1.0.2, 1.1" JSON = "0.18, 0.19, 0.20, 0.21" -JuMP = "0.22, 0.23, 1" +JuMP = "1.15" LoggingExtras = "0.4.7, 1" PolyhedralRelaxations = "0.3.5" SCS = "0.9, 1.0, 1.1" diff --git a/docs/src/reference/base.md b/docs/src/reference/base.md index f443600a3..76f9d9645 100644 --- a/docs/src/reference/base.md +++ b/docs/src/reference/base.md @@ -13,7 +13,6 @@ nw_ids ## Helper functions ```@docs -@smart_constraint set_lower_bound set_upper_bound comp_start_value diff --git a/src/core/base.jl b/src/core/base.jl index 5f33c2a90..9d5c0f3d7 100644 --- a/src/core/base.jl +++ b/src/core/base.jl @@ -69,22 +69,6 @@ function _check_var_keys(vars, keys, var_name, comp_name) end -""" - @smart_constraint model::JuMP.Model vars::Vector expr::JuMP.Expression - -Detection of whether a constraint should be NL or not" -""" -macro smart_constraint(model, vars, expr) - esc(quote - if _has_nl_expression($vars) - JuMP.@NLconstraint($model, $expr) - else - JuMP.@constraint($model, $expr) - end - end) -end - - """ function set_lower_bound( x::JuMP.VariableRef, diff --git a/src/core/data.jl b/src/core/data.jl index 8309af410..3e568b516 100644 --- a/src/core/data.jl +++ b/src/core/data.jl @@ -811,31 +811,6 @@ function _make_full_matrix_variable(diag::Vector{T}, lowertriangle::Vector{T}, u return matrix end -# TODO refactor into several functions -"helper to determine if expession has any Nonlinear terms" -function _has_nl_expression(x)::Bool - if isa(x, JuMP.NonlinearExpression) - return true - elseif isa(x, Array) - if any(_has_nl_expression.(x)) - return true - end - elseif isa(x, Dict) - for i in values(x) - if _has_nl_expression(i) - return true - end - end - elseif isa(x, JuMP.Containers.DenseAxisArray) - for i in values(x.data) - if _has_nl_expression(i) - return true - end - end - end - return false -end - """ correct_mc_voltage_angle_differences!(data::Dict{String,<:Any}, default_pad::Real=deg2rad(10.0)) diff --git a/src/core/objective.jl b/src/core/objective.jl index 126299e52..a866624ea 100644 --- a/src/core/objective.jl +++ b/src/core/objective.jl @@ -247,7 +247,7 @@ end "gen connections adaptation of min fuel cost polynomial linquad objective" function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPowerModel; report::Bool=true) - pg_contains_nl_exp = any(x<:JuMP.NonlinearExpression for x in vcat([typeof.(isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg) for nw in nw_ids(pm) for (id,pg) in var(pm, nw, :pg)]...)) + pg_contains_nl_exp = any(x<:JuMP.NonlinearExpr for x in vcat([typeof.(isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg) for nw in nw_ids(pm) for (id,pg) in var(pm, nw, :pg)]...)) gen_cost = Dict() if !pg_contains_nl_exp @@ -285,16 +285,16 @@ function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPo if length(gen["cost"]) == 1 gen_cost[(n,i)] = gen["cost"][1] elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, gen["cost"][1]*sum(pg[i] for i in 1:int_dim) + gen["cost"][2]) + gen_cost[(n,i)] = JuMP.@expression(pm.model, -gen["cost"][1]*sum(-pg[i] for i in 1:int_dim) + gen["cost"][2]) elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, gen["cost"][1]*sum(pg[i] for i in 1:int_dim)^2 + gen["cost"][2]*sum(pg[i] for i in 1:int_dim) + gen["cost"][3]) + gen_cost[(n,i)] = JuMP.@expression(pm.model, gen["cost"][1]*sum(pg[i] for i in 1:int_dim)^2 + -gen["cost"][2]*sum(-pg[i] for i in 1:int_dim) + gen["cost"][3]) else gen_cost[(n,i)] = 0.0 end end end - return JuMP.@NLobjective(pm.model, Min, + return JuMP.@objective(pm.model, Min, sum( sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) for (n, nw_ref) in nws(pm)) @@ -375,21 +375,21 @@ function _objective_mc_min_fuel_cost_polynomial_nl(pm::AbstractUnbalancedPowerMo cost_rev = reverse(gen["cost"]) if length(cost_rev) == 1 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1]) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1]) elseif length(cost_rev) == 2 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] + -cost_rev[2]*-pg) elseif length(cost_rev) == 3 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] + -cost_rev[2]*-pg + cost_rev[3]*pg^2) elseif length(cost_rev) >= 4 cost_rev_nl = cost_rev[4:end] - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] + -cost_rev[2]*-pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) else - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0) + gen_cost[(n,i)] = JuMP.@expression(pm.model, 0.0) end end end - return JuMP.@NLobjective(pm.model, Min, + return JuMP.@objective(pm.model, Min, sum( sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) for (n, nw_ref) in nws(pm)) @@ -406,21 +406,21 @@ function _objective_mc_min_fuel_cost_polynomial_nl_switch(pm::AbstractUnbalanced cost_rev = reverse(gen["cost"]) if length(cost_rev) == 1 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1]) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1]) elseif length(cost_rev) == 2 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] + -cost_rev[2]*-pg) elseif length(cost_rev) == 3 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] + -cost_rev[2]*-pg + cost_rev[3]*pg^2) elseif length(cost_rev) >= 4 cost_rev_nl = cost_rev[4:end] - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) + gen_cost[(n,i)] = JuMP.@expression(pm.model, cost_rev[1] + -cost_rev[2]*-pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) else - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0) + gen_cost[(n,i)] = JuMP.@expression(pm.model, 0.0) end end end - return JuMP.@NLobjective(pm.model, Min, + return JuMP.@objective(pm.model, Min, sum( sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) + sum( var(pm, n, :switch_state, l) for l in ids(pm, n, :switch_dispatchable)) @@ -448,7 +448,7 @@ function objective_variable_pg_cost(pm::AbstractUnbalancedIVRModel; report::Bool for (i, gen) in nw_ref[:gen] pg = var(pm, n, :pg, i) for line in gen_lines[i] - JuMP.@NLconstraint(pm.model, pg_cost[i] >= line.slope*sum(pg[c] for c in gen["connections"]) + line.intercept) + JuMP.@constraint(pm.model, pg_cost[i] >= -line.slope*sum(-pg[c] for c in gen["connections"]) + line.intercept) end end end diff --git a/src/core/solution.jl b/src/core/solution.jl index de41154e2..d39b51661 100644 --- a/src/core/solution.jl +++ b/src/core/solution.jl @@ -11,21 +11,9 @@ function _IM.solution_preprocessor(pm::AbstractUnbalancedPowerModel, solution::D end -"custom `build_solution_values` for multiconductor (vector) variables" -function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.VariableRef,1}) - return JuMP.value.(var.data) -end - - -"custom `build_solution_values` for multiconductor (vector) nonlinear expressions" -function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.NonlinearExpression,1}) - return JuMP.value.(var.data) -end - - -"custom `build_solution_values` for multiconductor (vector) generic affine expressions" -function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.GenericAffExpr,1}) - return JuMP.value.(var.data) +"custom `build_solution_values` for multiconductor (vector) JuMP expressions" +function _IM.build_solution_values(var::JuMP.AbstractJuMPScalar) + return JuMP.value(var) end diff --git a/src/form/acp.jl b/src/form/acp.jl index b70d5aaef..7e9e2565a 100644 --- a/src/form/acp.jl +++ b/src/form/acp.jl @@ -149,12 +149,12 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedACPModel, nw::I ungrounded_terminals = [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]] for (idx,t) in ungrounded_terminals - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) == - sum(pg[g][t] for (g, conns) in bus_gens if t in conns) + -sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) - sum(ps[s][t] for (s, conns) in bus_storage if t in conns) - Pd[idx] - ( # shunt @@ -167,12 +167,12 @@ function constraint_mc_power_balance_slack(pm::AbstractUnbalancedACPModel, nw::I ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) == - sum(qg[g][t] for (g, conns) in bus_gens if t in conns) + -sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) - sum(qs[s][t] for (s, conns) in bus_storage if t in conns) - Qd[idx] - ( # shunt @@ -223,11 +223,11 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACPModel, nw::In ungrounded_terminals = [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]] for (idx,t) in ungrounded_terminals - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum( pt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) - - sum(pg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + sum(ps[s][t]*z_storage[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, d, "pd")[findfirst(isequal(t), conns)]*z_demand[d] for (d, conns) in bus_loads if t in conns) + sum(z_shunt[s] * @@ -241,11 +241,11 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum( qt[a_t][t] for (a_t, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + + sum( -qg[g][t]*z_gen[g] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t]*z_storage[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, l, "qd")[findfirst(isequal(t), conns)]*z_demand[l] for (l, conns) in bus_loads if t in conns) + sum(z_shunt[sh] * @@ -304,12 +304,12 @@ function constraint_mc_power_balance_simple(pm::AbstractUnbalancedACPModel, nw:: ungrounded_terminals = [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]] for (idx,t) in ungrounded_terminals - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) == - sum(pg[g][t] for (g, conns) in bus_gens) + -sum(-pg[g][t] for (g, conns) in bus_gens) - sum(ps[s][t] for (s, conns) in bus_storage) - Pd[idx] - ( # shunt @@ -321,12 +321,12 @@ function constraint_mc_power_balance_simple(pm::AbstractUnbalancedACPModel, nw:: ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum(q[a][c] for a in bus_arcs) + sum(qsw[a_sw][c] for a_sw in bus_arcs_sw) + sum(qt[a_trans][c] for a_trans in bus_arcs_trans) == - sum(qg[g][c] for g in bus_gens) + -sum(-qg[g][c] for g in bus_gens) - sum(qs[s][c] for s in bus_storage) - Qd[idx] - ( # shunt @@ -374,11 +374,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: for (idx,t) in ungrounded_terminals if any(Bs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) || any(Gs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt @@ -392,11 +392,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt @@ -410,11 +410,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: ) push!(cstr_q, cq) else - cp = @smart_constraint(pm.model, [p, pg, ps, psw, pt, pd, vm], + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) + Gs[idx,idx] * vm[t]^2 @@ -423,11 +423,11 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACPModel, nw::Int, i: ) push!(cstr_p, cp) - cq = @smart_constraint(pm.model, [q, qg, qs, qsw, qt, qd, vm], + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) - Bs[idx,idx] * vm[t]^2 @@ -486,7 +486,7 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In cap_state = 1.0 ncnds = length(terminals) Gs = fill(0.0, ncnds, ncnds) - Bs = convert(Matrix{JuMP.NonlinearExpression}, JuMP.@NLexpression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) + Bs = convert(Matrix{JuMP.NonlinearExpr}, JuMP.@expression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) for (val, connections) in bus_shunts shunt = ref(pm,nw,:shunt,val) for (idx,c) in enumerate(connections) @@ -495,7 +495,7 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In end for (jdx,d) in enumerate(connections) Gs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] += shunt["gs"][idx,jdx] - Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@NLexpression(pm.model, Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + shunt["bs"][idx,jdx]*cap_state) + Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@expression(pm.model, Bs[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + shunt["bs"][idx,jdx]*cap_state) end end end @@ -506,11 +506,11 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In for (idx,t) in ungrounded_terminals if any(Bs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) || any(Gs[idx,jdx] != 0 for (jdx, u) in ungrounded_terminals if idx != jdx) - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt @@ -524,11 +524,11 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) + ( # shunt @@ -542,11 +542,11 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_q, cq) else - cp = @smart_constraint(pm.model, [p, pg, ps, psw, pt, pd, vm], + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( pg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t] for (g, conns) in bus_gens if t in conns) + sum( ps[s][t] for (s, conns) in bus_storage if t in conns) + sum( pd[l][t] for (l, conns) in bus_loads if t in conns) + Gs[idx,idx] * vm[t]^2 @@ -555,11 +555,11 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACPModel, nw::In ) push!(cstr_p, cp) - cq = @smart_constraint(pm.model, [q, qg, qs, qsw, qt, qd, vm, Bs], + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum( qg[g][t] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t] for (g, conns) in bus_gens if t in conns) + sum( qs[s][t] for (s, conns) in bus_storage if t in conns) + sum( qd[l][t] for (l, conns) in bus_loads if t in conns) - Bs[idx,idx] * vm[t]^2 @@ -670,7 +670,7 @@ function constraint_mc_ohms_yt_from(pm::AbstractUnbalancedACPModel, nw::Int, f_b ohms_yt_p = JuMP.ConstraintRef[] ohms_yt_q = JuMP.ConstraintRef[] for (idx, (fc,tc)) in enumerate(zip(f_connections,t_connections)) - push!(ohms_yt_p, JuMP.@NLconstraint(pm.model, p_fr[fc] == (G[idx,idx]+G_fr[idx,idx])*vm_fr[fc]^2 + push!(ohms_yt_p, JuMP.@constraint(pm.model, p_fr[fc] == (G[idx,idx]+G_fr[idx,idx])*vm_fr[fc]^2 +sum( (G[idx,jdx]+G_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd]) +(B[idx,jdx]+B_fr[idx,jdx]) * vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd]) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections)) if idx != jdx) @@ -680,7 +680,7 @@ function constraint_mc_ohms_yt_from(pm::AbstractUnbalancedACPModel, nw::Int, f_b ) ) - push!(ohms_yt_q, JuMP.@NLconstraint(pm.model, q_fr[fc] == -(B[idx,idx]+B_fr[idx,idx])*vm_fr[fc]^2 + push!(ohms_yt_q, JuMP.@constraint(pm.model, q_fr[fc] == -(B[idx,idx]+B_fr[idx,idx])*vm_fr[fc]^2 -sum( (B[idx,jdx]+B_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*cos(va_fr[fc]-va_fr[fd]) -(G[idx,jdx]+G_fr[idx,jdx])*vm_fr[fc]*vm_fr[fd]*sin(va_fr[fc]-va_fr[fd]) for (jdx, (fd,td)) in enumerate(zip(f_connections,t_connections)) if idx != jdx) @@ -739,16 +739,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractUnbalancedACPModel, nw:: x = transformer["controls"]["x"][idx] # (cr+jci) = (p-jq)/(vm⋅cos(va)-jvm⋅sin(va)) - cr = JuMP.@NLexpression(pm.model, ( p_to[idx]*vm_to[tc]*cos(va_to[tc]) + q_to[idx]*vm_to[tc]*sin(va_to[tc]))/vm_to[tc]^2) - ci = JuMP.@NLexpression(pm.model, (-q_to[idx]*vm_to[tc]*cos(va_to[tc]) + p_to[idx]*vm_to[tc]*sin(va_to[tc]))/vm_to[tc]^2) + cr = JuMP.@expression(pm.model, ( p_to[idx]*vm_to[tc]*cos(va_to[tc]) + q_to[idx]*vm_to[tc]*sin(va_to[tc]))/vm_to[tc]^2) + ci = JuMP.@expression(pm.model, (-q_to[idx]*vm_to[tc]*cos(va_to[tc]) + p_to[idx]*vm_to[tc]*sin(va_to[tc]))/vm_to[tc]^2) # v_drop = (cr+jci)⋅(r+jx) - vr_drop = JuMP.@NLexpression(pm.model, r*cr-x*ci) - vi_drop = JuMP.@NLexpression(pm.model, r*ci+x*cr) + vr_drop = JuMP.@expression(pm.model, r*cr-x*ci) + vi_drop = JuMP.@expression(pm.model, r*ci+x*cr) # v_ref-δ ≤ vm_fr-(cr+jci)⋅(r+jx)≤ v_ref+δ # vm_fr/1.1 ≤ vm_to ≤ vm_fr/0.9 - JuMP.@NLconstraint(pm.model, (vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2 + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≥ (v_ref - δ)^2) - JuMP.@NLconstraint(pm.model, (vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2 + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≤ (v_ref + δ)^2) + JuMP.@constraint(pm.model, (vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2 + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≥ (v_ref - δ)^2) + JuMP.@constraint(pm.model, (vm_fr[fc]*cos(va_fr[fc])-vr_drop)^2 + (vm_fr[fc]*sin(va_fr[fc])-vi_drop)^2 ≤ (v_ref + δ)^2) JuMP.@constraint(pm.model, vm_fr[fc]/1.1 ≤ vm_to[tc]) JuMP.@constraint(pm.model, vm_fr[fc]/0.9 ≥ vm_to[tc]) end @@ -782,10 +782,10 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACPModel, nw:: # e.g., for nph=3: 1->3, 2->1, 3->2 jdx = (idx-1+1)%nph+1 fd = f_connections[jdx] - vd_re[idx] = JuMP.@NLexpression(pm.model, vm_fr[fc]*cos(va_fr[fc])-vm_fr[fd]*cos(va_fr[fd])) - vd_im[idx] = JuMP.@NLexpression(pm.model, vm_fr[fc]*sin(va_fr[fc])-vm_fr[fd]*sin(va_fr[fd])) - JuMP.@NLconstraint(pm.model, vd_re[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*cos(va_to[tc])) - JuMP.@NLconstraint(pm.model, vd_im[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*sin(va_to[tc])) + vd_re[idx] = JuMP.@expression(pm.model, vm_fr[fc]*cos(va_fr[fc])-vm_fr[fd]*cos(va_fr[fd])) + vd_im[idx] = JuMP.@expression(pm.model, vm_fr[fc]*sin(va_fr[fc])-vm_fr[fd]*sin(va_fr[fd])) + JuMP.@constraint(pm.model, vd_re[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*cos(va_to[tc])) + JuMP.@constraint(pm.model, vd_im[idx] == pol*tm_scale*tm[idx]*vm_to[tc]*sin(va_to[tc])) end p_fr = var(pm, nw, :pt, f_idx) @@ -801,8 +801,8 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACPModel, nw:: # -Im(s/v) = -(q*cos(va)-p*sin(va))/|v| for (idx,(fc,tc)) in enumerate(zip(f_connections,t_connections)) # id = conj(s_to/v_to)./tm - id_re[idx] = JuMP.@NLexpression(pm.model, (p_to[tc]*cos(va_to[tc])+q_to[tc]*sin(va_to[tc]))/vm_to[tc]/(tm_scale*tm[idx])/pol) - id_im[idx] = JuMP.@NLexpression(pm.model, -(q_to[tc]*cos(va_to[tc])-p_to[tc]*sin(va_to[tc]))/vm_to[tc]/(tm_scale*tm[idx])/pol) + id_re[idx] = JuMP.@expression(pm.model, (p_to[tc]*cos(va_to[tc])+q_to[tc]*sin(va_to[tc]))/vm_to[tc]/(tm_scale*tm[idx])/pol) + id_im[idx] = JuMP.@expression(pm.model, -(q_to[tc]*cos(va_to[tc])-p_to[tc]*sin(va_to[tc]))/vm_to[tc]/(tm_scale*tm[idx])/pol) end for (idx, (fc,tc)) in enumerate(zip(f_connections,t_connections)) # rotate by nph-1 to get 'previous' phase @@ -811,11 +811,11 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACPModel, nw:: # s_fr = v_fr*conj(i_fr) # = v_fr*conj(id[q]-id[p]) # = v_fr*(id_re[q]-j*id_im[q]-id_re[p]+j*id_im[p]) - JuMP.@NLconstraint(pm.model, p_fr[fc] == + JuMP.@constraint(pm.model, p_fr[fc] == vm_fr[fc]*cos(va_fr[fc])*( id_re[jdx]-id_re[idx]) -vm_fr[fc]*sin(va_fr[fc])*(-id_im[jdx]+id_im[idx]) ) - JuMP.@NLconstraint(pm.model, q_fr[fc] == + JuMP.@constraint(pm.model, q_fr[fc] == vm_fr[fc]*cos(va_fr[fc])*(-id_im[jdx]+id_im[idx]) +vm_fr[fc]*sin(va_fr[fc])*( id_re[jdx]-id_re[idx]) ) @@ -845,25 +845,25 @@ function constraint_mc_bus_voltage_magnitude_vuf(pm::AbstractUnbalancedACPModel, a2re = real(a^2) a2im = imag(a^2) # real and imaginary components of U+ - vrepos = JuMP.@NLexpression(pm.model, + vrepos = JuMP.@expression(pm.model, (vm_a*cos(va_a) + are*vm_b*cos(va_b) - aim*vm_b*sin(va_b) + a2re*vm_c*cos(va_c) - a2im*vm_c*sin(va_c))/3 ) - vimpos = JuMP.@NLexpression(pm.model, + vimpos = JuMP.@expression(pm.model, (vm_a*sin(va_a) + are*vm_b*sin(va_b) + aim*vm_b*cos(va_b) + a2re*vm_c*sin(va_c) + a2im*vm_c*cos(va_c))/3 ) # square of magnitude of U+, |U+|^2 - vmpossqr = JuMP.@NLexpression(pm.model, vrepos^2+vimpos^2) + vmpossqr = JuMP.@expression(pm.model, vrepos^2+vimpos^2) # real and imaginary components of U- - vreneg = JuMP.@NLexpression(pm.model, + vreneg = JuMP.@expression(pm.model, (vm_a*cos(va_a) + a2re*vm_b*cos(va_b) - a2im*vm_b*sin(va_b) + are*vm_c*cos(va_c) - aim*vm_c*sin(va_c))/3 ) - vimneg = JuMP.@NLexpression(pm.model, + vimneg = JuMP.@expression(pm.model, (vm_a*sin(va_a) + a2re*vm_b*sin(va_b) + a2im*vm_b*cos(va_b) + are*vm_c*sin(va_c) + aim*vm_c*cos(va_c))/3 ) # square of magnitude of U-, |U-|^2 - vmnegsqr = JuMP.@NLexpression(pm.model, vreneg^2+vimneg^2) + vmnegsqr = JuMP.@expression(pm.model, vreneg^2+vimneg^2) # finally, apply constraint - JuMP.@NLconstraint(pm.model, vmnegsqr <= vufmax^2*vmpossqr) + JuMP.@constraint(pm.model, vmnegsqr <= vufmax^2*vmpossqr) # DEBUGGING: save references for post check #var(pm, nw_id_default, :vmpossqr)[bus_id] = vmpossqr #var(pm, nw_id_default, :vmnegsqr)[bus_id] = vmnegsqr @@ -892,16 +892,16 @@ function constraint_mc_bus_voltage_magnitude_negative_sequence(pm::AbstractUnbal a2re = real(a^2) a2im = imag(a^2) # real and imaginary components of U- - vreneg = JuMP.@NLexpression(pm.model, + vreneg = JuMP.@expression(pm.model, (vm_a*cos(va_a) + a2re*vm_b*cos(va_b) - a2im*vm_b*sin(va_b) + are*vm_c*cos(va_c) - aim*vm_c*sin(va_c))/3 ) - vimneg = JuMP.@NLexpression(pm.model, + vimneg = JuMP.@expression(pm.model, (vm_a*sin(va_a) + a2re*vm_b*sin(va_b) + a2im*vm_b*cos(va_b) + are*vm_c*sin(va_c) + aim*vm_c*cos(va_c))/3 ) # square of magnitude of U-, |U-|^2 - vmnegsqr = JuMP.@NLexpression(pm.model, vreneg^2+vimneg^2) + vmnegsqr = JuMP.@expression(pm.model, vreneg^2+vimneg^2) # finally, apply constraint - JuMP.@NLconstraint(pm.model, vmnegsqr <= vmnegmax^2) + JuMP.@constraint(pm.model, vmnegsqr <= vmnegmax^2) end @@ -927,16 +927,16 @@ function constraint_mc_bus_voltage_magnitude_positive_sequence(pm::AbstractUnbal a2re = real(a^2) a2im = imag(a^2) # real and imaginary components of U+ - vrepos = JuMP.@NLexpression(pm.model, + vrepos = JuMP.@expression(pm.model, (vm_a*cos(va_a) + are*vm_b*cos(va_b) - aim*vm_b*sin(va_b) + a2re*vm_c*cos(va_c) - a2im*vm_c*sin(va_c))/3 ) - vimpos = JuMP.@NLexpression(pm.model, + vimpos = JuMP.@expression(pm.model, (vm_a*sin(va_a) + are*vm_b*sin(va_b) + aim*vm_b*cos(va_b) + a2re*vm_c*sin(va_c) + a2im*vm_c*cos(va_c))/3 ) # square of magnitude of U+, |U+|^2 - vmpossqr = JuMP.@NLexpression(pm.model, vrepos^2+vimpos^2) + vmpossqr = JuMP.@expression(pm.model, vrepos^2+vimpos^2) # finally, apply constraint - JuMP.@NLconstraint(pm.model, vmpossqr <= vmposmax^2) + JuMP.@constraint(pm.model, vmpossqr <= vmposmax^2) end @@ -956,16 +956,16 @@ function constraint_mc_bus_voltage_magnitude_zero_sequence(pm::AbstractUnbalance (vm_a, vm_b, vm_c) = [var(pm, nw, :vm, bus_id)[i] for i in 1:3] (va_a, va_b, va_c) = [var(pm, nw, :va, bus_id)[i] for i in 1:3] # real and imaginary components of U+ - vrezero = JuMP.@NLexpression(pm.model, + vrezero = JuMP.@expression(pm.model, (vm_a*cos(va_a) + vm_b*cos(va_b) + vm_c*cos(va_c))/3 ) - vimzero = JuMP.@NLexpression(pm.model, + vimzero = JuMP.@expression(pm.model, (vm_a*sin(va_a) + vm_b*sin(va_b) + vm_c*sin(va_c))/3 ) # square of magnitude of U+, |U+|^2 - vmzerosqr = JuMP.@NLexpression(pm.model, vrezero^2+vimzero^2) + vmzerosqr = JuMP.@expression(pm.model, vrezero^2+vimzero^2) # finally, apply constraint - JuMP.@NLconstraint(pm.model, vmzerosqr <= vmzeromax^2) + JuMP.@constraint(pm.model, vmzerosqr <= vmzeromax^2) end @@ -984,8 +984,8 @@ function constraint_mc_load_current_delta(pm::AbstractUnbalancedACPModel, nw::In vm_a, vm_b, vm_c = var(pm, nw, :vm, load_bus_id) va_a, va_b, va_c = var(pm, nw, :va, load_bus_id) # v_xy = v_x - v_y - vre_xy(vm_x, va_x, vm_y, va_y) = JuMP.@NLexpression(pm.model, vm_x*cos(va_x)-vm_y*cos(va_y)) - vim_xy(vm_x, va_x, vm_y, va_y) = JuMP.@NLexpression(pm.model, vm_x*sin(va_x)-vm_y*sin(va_y)) + vre_xy(vm_x, va_x, vm_y, va_y) = JuMP.@expression(pm.model, vm_x*cos(va_x)-vm_y*cos(va_y)) + vim_xy(vm_x, va_x, vm_y, va_y) = JuMP.@expression(pm.model, vm_x*sin(va_x)-vm_y*sin(va_y)) vre_ab = vre_xy(vm_a, va_a, vm_b, va_b) vim_ab = vim_xy(vm_a, va_a, vm_b, va_b) vre_bc = vre_xy(vm_b, va_b, vm_c, va_c) @@ -993,8 +993,8 @@ function constraint_mc_load_current_delta(pm::AbstractUnbalancedACPModel, nw::In vre_ca = vre_xy(vm_c, va_c, vm_a, va_a) vim_ca = vim_xy(vm_c, va_c, vm_a, va_a) # i_xy = conj(s_xy/v_xy) - ire_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@NLexpression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*(cp_xy*vre_xy+cq_xy*vim_xy)) - iim_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@NLexpression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*(cp_xy*vim_xy-cq_xy*vre_xy)) + ire_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@expression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*(cp_xy*vre_xy+cq_xy*vim_xy)) + iim_xy(cp_xy, cq_xy, vre_xy, vim_xy) = JuMP.@expression(pm.model, 1/sqrt(vre_xy^2+vim_xy^2)*(cp_xy*vim_xy-cq_xy*vre_xy)) ire_ab = ire_xy(cp_ab, cq_ab, vre_ab, vim_ab) iim_ab = iim_xy(cp_ab, cq_ab, vre_ab, vim_ab) ire_bc = ire_xy(cp_bc, cq_bc, vre_bc, vim_bc) @@ -1004,8 +1004,8 @@ function constraint_mc_load_current_delta(pm::AbstractUnbalancedACPModel, nw::In # s_x = v_x*conj(i_xy-i_zx) # p_x = vm_x*cos(va_x)*(ire_xy-ire_zx) + vm_x*sin(va_x)*(iim_xy-iim_zx) # q_x = vm_x*sin(va_x)*(ire_xy-ire_zx) - vm_x*cos(va_x)*(iim_xy-iim_zx) - p_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@NLexpression(pm.model, vm_x*cos(va_x)*(ire_xy-ire_zx) + vm_x*sin(va_x)*(iim_xy-iim_zx)) - q_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@NLexpression(pm.model, vm_x*sin(va_x)*(ire_xy-ire_zx) - vm_x*cos(va_x)*(iim_xy-iim_zx)) + p_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@expression(pm.model, vm_x*cos(va_x)*(ire_xy-ire_zx) + vm_x*sin(va_x)*(iim_xy-iim_zx)) + q_x(vm_x, va_x, ire_xy, iim_xy, ire_zx, iim_zx) = JuMP.@expression(pm.model, vm_x*sin(va_x)*(ire_xy-ire_zx) - vm_x*cos(va_x)*(iim_xy-iim_zx)) # s_x = s_x,ref var(pm, nw, :pd_bus)[load_id] = [ p_x(vm_a, va_a, ire_ab, iim_ab, ire_ca, iim_ca), @@ -1023,20 +1023,20 @@ function constraint_mc_bus_voltage_magnitude_ll(pm::AbstractUnbalancedACPModel, # 3 conductors asserted in template already vm_ln = [var(pm, nw, :vm, bus_id)[i] for i in 1:3] va_ln = [var(pm, nw, :va, bus_id)[i] for i in 1:3] - vr_ll = JuMP.@NLexpression(pm.model, [i in 1:3], + vr_ll = JuMP.@expression(pm.model, [i in 1:3], vm_ln[i]*cos(va_ln[i]) - vm_ln[i%3+1]*cos(va_ln[i%3+1]) ) - vi_ll = JuMP.@NLexpression(pm.model, [i in 1:3], + vi_ll = JuMP.@expression(pm.model, [i in 1:3], vm_ln[i]*sin(va_ln[i]) - vm_ln[i%3+1]*sin(va_ln[i%3+1]) ) for c in 1:3 # factor of 3 is needed because vm_ll bounds are with respect to the # LL base, not the LN base if vm_ll_min[c] > 0 - JuMP.@NLconstraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 >= vm_ll_min[c]^2*3) + JuMP.@constraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 >= vm_ll_min[c]^2*3) end if vm_ll_max[c] < Inf - JuMP.@NLconstraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 <= vm_ll_max[c]^2*3) + JuMP.@constraint(pm.model, vr_ll[c]^2+vi_ll[c]^2 <= vm_ll_max[c]^2*3) end end end @@ -1083,21 +1083,21 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACPModel, nw::Int, i pd_bus = a qd_bus = b else - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx, c) in enumerate(connections) - crd = JuMP.@NLexpression(pm.model, + crd = JuMP.@expression(pm.model, a[idx]*vm[c]*cos(va[c])*(vm[c]^2)^(alpha[idx]/2-1) +b[idx]*vm[c]*sin(va[c])*(vm[c]^2)^( beta[idx]/2-1) ) - cid = JuMP.@NLexpression(pm.model, + cid = JuMP.@expression(pm.model, a[idx]*vm[c]*sin(va[c])*(vm[c]^2)^(alpha[idx]/2-1) -b[idx]*vm[c]*cos(va[c])*(vm[c]^2)^( beta[idx]/2-1) ) - push!(pd_bus, JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])*crd+vm[c]*sin(va[c])*cid)) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vm[c]*cos(va[c])*cid+vm[c]*sin(va[c])*crd)) + push!(pd_bus, JuMP.@expression(pm.model, -vm[c]*cos(va[c])*-crd-vm[c]*sin(va[c])*-cid)) + push!(qd_bus, JuMP.@expression(pm.model, vm[c]*cos(va[c])*-cid-vm[c]*sin(va[c])*-crd)) end end @@ -1111,12 +1111,12 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACPModel, nw::Int, i sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*vm[c]^alpha[idx] )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*vm[c]^beta[idx] )) + push!(pd, JuMP.@expression(pm.model, a[idx]*vm[c]^alpha[idx] )) + push!(qd, JuMP.@expression(pm.model, b[idx]*vm[c]^beta[idx] )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -1139,18 +1139,18 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACPModel, nw::Int, vrd = Dict() vid = Dict() for (idx, c) in enumerate(connections) - vrd[c] = JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])-vm[next[c]]*cos(va[next[c]])) - vid[c] = JuMP.@NLexpression(pm.model, vm[c]*sin(va[c])-vm[next[c]]*sin(va[next[c]])) + vrd[c] = JuMP.@expression(pm.model, vm[c]*cos(va[c])-vm[next[c]]*cos(va[next[c]])) + vid[c] = JuMP.@expression(pm.model, vm[c]*sin(va[c])-vm[next[c]]*sin(va[next[c]])) end crd = Dict() cid = Dict() for (idx, c) in enumerate(connections) - crd[c] = JuMP.@NLexpression(pm.model, + crd[c] = JuMP.@expression(pm.model, a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1) +b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1) ) - cid[c] = JuMP.@NLexpression(pm.model, + cid[c] = JuMP.@expression(pm.model, a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1) -b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1) ) @@ -1160,19 +1160,19 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACPModel, nw::Int, cid_bus = Dict() for (idx, c) in enumerate(conn_bus) if is_triplex - crd_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crd[1]) - cid_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cid[1]) + crd_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crd[1]) + cid_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cid[1]) else - crd_bus[c] = JuMP.@NLexpression(pm.model, crd[c]-crd[prev[c]]) - cid_bus[c] = JuMP.@NLexpression(pm.model, cid[c]-cid[prev[c]]) + crd_bus[c] = JuMP.@expression(pm.model, crd[c]-crd[prev[c]]) + cid_bus[c] = JuMP.@expression(pm.model, cid[c]-cid[prev[c]]) end end - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(conn_bus) - push!(pd_bus, JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])*crd_bus[c]+vm[c]*sin(va[c])*cid_bus[c])) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vm[c]*cos(va[c])*cid_bus[c]+vm[c]*sin(va[c])*crd_bus[c])) + push!(pd_bus, JuMP.@expression(pm.model, -vm[c]*cos(va[c])*-crd_bus[c]-vm[c]*sin(va[c])*-cid_bus[c])) + push!(qd_bus, JuMP.@expression(pm.model, vm[c]*cos(va[c])*-cid_bus[c]-vm[c]*sin(va[c])*-crd_bus[c])) end pd_bus = JuMP.Containers.DenseAxisArray(pd_bus, conn_bus) @@ -1188,8 +1188,8 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACPModel, nw::Int, pd = [] qd = [] for (idx,c) in enumerate(connections) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = pd sol(pm, nw, :load, id)[:qd] = qd @@ -1214,34 +1214,34 @@ function constraint_mc_generator_power_delta(pm::AbstractUnbalancedACPModel, nw: vrg = Dict() vig = Dict() for c in connections - vrg[c] = JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])-vm[next[c]]*cos(va[next[c]])) - vig[c] = JuMP.@NLexpression(pm.model, vm[c]*sin(va[c])-vm[next[c]]*sin(va[next[c]])) + vrg[c] = JuMP.@expression(pm.model, vm[c]*cos(va[c])-vm[next[c]]*cos(va[next[c]])) + vig[c] = JuMP.@expression(pm.model, vm[c]*sin(va[c])-vm[next[c]]*sin(va[next[c]])) end crg = Dict() cig = Dict() for c in connections - crg[c] = JuMP.@NLexpression(pm.model, (pg[c]*vrg[c]+qg[c]*vig[c])/(vrg[c]^2+vig[c]^2) ) - cig[c] = JuMP.@NLexpression(pm.model, (pg[c]*vig[c]-qg[c]*vrg[c])/(vrg[c]^2+vig[c]^2) ) + crg[c] = JuMP.@expression(pm.model, (pg[c]*vrg[c]+qg[c]*vig[c])/(vrg[c]^2+vig[c]^2) ) + cig[c] = JuMP.@expression(pm.model, (pg[c]*vig[c]-qg[c]*vrg[c])/(vrg[c]^2+vig[c]^2) ) end crg_bus = Dict() cig_bus = Dict() for c in conn_bus if is_triplex - crg_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crg[1]) - cig_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cig[1]) + crg_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1]) + cig_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1]) else - crg_bus[c] = JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]]) - cig_bus[c] = JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]]) + crg_bus[c] = JuMP.@expression(pm.model, crg[c]-crg[prev[c]]) + cig_bus[c] = JuMP.@expression(pm.model, cig[c]-cig[prev[c]]) end end - pg_bus = Vector{JuMP.NonlinearExpression}([]) - qg_bus = Vector{JuMP.NonlinearExpression}([]) + pg_bus = Vector{JuMP.NonlinearExpr}([]) + qg_bus = Vector{JuMP.NonlinearExpr}([]) for c in conn_bus - push!(pg_bus, JuMP.@NLexpression(pm.model, vm[c]*cos(va[c])*crg_bus[c]+vm[c]*sin(va[c])*cig_bus[c])) - push!(qg_bus, JuMP.@NLexpression(pm.model, -vm[c]*cos(va[c])*cig_bus[c]+vm[c]*sin(va[c])*crg_bus[c])) + push!(pg_bus, JuMP.@expression(pm.model, vm[c]*cos(va[c])*crg_bus[c]+vm[c]*sin(va[c])*cig_bus[c])) + push!(qg_bus, JuMP.@expression(pm.model, -vm[c]*cos(va[c])*cig_bus[c]+vm[c]*sin(va[c])*crg_bus[c])) end pg_bus = JuMP.Containers.DenseAxisArray(pg_bus, conn_bus) qg_bus = JuMP.Containers.DenseAxisArray(qg_bus, conn_bus) @@ -1265,13 +1265,13 @@ function constraint_mc_storage_losses(pm::AbstractUnbalancedACPModel, n::Int, i: sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(ps[c] for c in connections) + (sd - sc) == p_loss + r * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections) ) - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(qs[c] for c in connections) == qsc + q_loss + x * sum((ps[c]^2 + qs[c]^2)/vm[c]^2 for c in connections) diff --git a/src/form/acr.jl b/src/form/acr.jl index fccc68ebe..9eeff16c7 100644 --- a/src/form/acr.jl +++ b/src/form/acr.jl @@ -463,12 +463,12 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACRModel, nw::Int, i: # pd/qd can be NLexpressions, so cannot be vectorized for (idx, t) in ungrounded_terminals - cp = @smart_constraint(pm.model, [p, q, pg, qg, ps, qs, psw, qsw, pt, qt, pd, qd, vr, vi], + cp = JuMP.@constraint(pm.model, sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) == - sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + ( -vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) @@ -477,12 +477,12 @@ function constraint_mc_power_balance(pm::AbstractUnbalancedACRModel, nw::Int, i: ) push!(cstr_p, cp) - cq = @smart_constraint(pm.model, [p, q, pg, qg, ps, qs, psw, qsw, pt, qt, pd, qd, vr, vi], + cq = JuMP.@constraint(pm.model, sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) == - sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + ( vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) @@ -538,14 +538,14 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACRModel, nw::In # calculate Gs, Bs ncnds = length(terminals) Gt = fill(0.0, ncnds, ncnds) - Bt = convert(Matrix{JuMP.NonlinearExpression}, JuMP.@NLexpression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) + Bt = convert(Matrix{JuMP.NonlinearExpr}, JuMP.@expression(pm.model, [idx=1:ncnds, jdx=1:ncnds], 0.0)) for (val, connections) in bus_shunts shunt = ref(pm,nw,:shunt,val) for (idx,c) in enumerate(connections) cap_state = haskey(shunt,"controls") ? var(pm, nw, :capacitor_state, val)[c] : 1.0 for (jdx,d) in enumerate(connections) Gt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] += shunt["gs"][idx,jdx] - Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@NLexpression(pm.model, Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + shunt["bs"][idx,jdx]*cap_state) + Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] = JuMP.@expression(pm.model, Bt[findfirst(isequal(c), terminals),findfirst(isequal(d), terminals)] + shunt["bs"][idx,jdx]*cap_state) end end end @@ -557,12 +557,12 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACRModel, nw::In # pd/qd can be NLexpressions, so cannot be vectorized for (idx, t) in ungrounded_terminals - cp = JuMP.@NLconstraint(pm.model, + cp = JuMP.@constraint(pm.model, sum( p[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) == - sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + ( -vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) @@ -571,12 +571,12 @@ function constraint_mc_power_balance_capc(pm::AbstractUnbalancedACRModel, nw::In ) push!(cstr_p, cp) - cq = JuMP.@NLconstraint(pm.model, + cq = JuMP.@constraint(pm.model, sum( q[arc][t] for (arc, conns) in bus_arcs if t in conns) + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) == - sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + ( vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) @@ -684,11 +684,11 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACRModel, nw::In # pd/qd can be NLexpressions, so cannot be vectorized for (idx, t) in ungrounded_terminals - cp = @smart_constraint(pm.model, [p, pg, ps, psw, pt], + cp = JuMP.@constraint(pm.model, sum( p[a][t] for (a, conns) in bus_arcs if t in conns) + sum(psw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( pt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum(pg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + + sum(-pg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + sum(ps[s][t]*zs[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, d, "pd")[findfirst(isequal(t), conns)]*zd[d] for (d, conns) in bus_loads if t in conns) + (+vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) @@ -698,11 +698,11 @@ function constraint_mc_power_balance_shed(pm::AbstractUnbalancedACRModel, nw::In ) push!(cstr_p, cp) - cq = @smart_constraint(pm.model, [q, qg, qs, qsw, qt], + cq = JuMP.@constraint(pm.model, sum( q[a][t] for (a, conns) in bus_arcs if t in conns) + sum(qsw[a][t] for (a, conns) in bus_arcs_sw if t in conns) + sum( qt[a][t] for (a, conns) in bus_arcs_trans if t in conns) - - sum(qg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + + sum(-qg[g][t]*zg[g] for (g, conns) in bus_gens if t in conns) + sum(qs[s][t]*zs[s] for (s, conns) in bus_storage if t in conns) + sum(ref(pm, nw, :load, d, "qd")[findfirst(isequal(t), conns)]*zd[d] for (d, conns) in bus_loads if t in conns) + (-vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) @@ -780,15 +780,15 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACRModel, nw::Int, i pd_bus = a qd_bus = b else - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - crd = JuMP.@NLexpression(pm.model, a[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1)+b[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1)) - cid = JuMP.@NLexpression(pm.model, a[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1)-b[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1)) + crd = JuMP.@expression(pm.model, a[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1)+b[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1)) + cid = JuMP.@expression(pm.model, a[idx]*vi[c]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2-1)-b[idx]*vr[c]*(vr[c]^2+vi[c]^2)^(beta[idx]/2 -1)) - push!(pd_bus, JuMP.@NLexpression(pm.model, vr[c]*crd+vi[c]*cid)) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vr[c]*cid+vi[c]*crd)) + push!(pd_bus, JuMP.@expression(pm.model, -vr[c]*-crd-vi[c]*-cid)) + push!(qd_bus, JuMP.@expression(pm.model, vr[c]*-cid-vi[c]*-crd)) end end @@ -802,12 +802,12 @@ function constraint_mc_load_power_wye(pm::AbstractUnbalancedACRModel, nw::Int, i sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vr[c]^2+vi[c]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vr[c]^2+vi[c]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vr[c]^2+vi[c]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -830,34 +830,34 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACRModel, nw::Int, vrd = Dict() vid = Dict() for (idx, c) in enumerate(connections) - vrd[c] = JuMP.@NLexpression(pm.model, vr[c]-vr[next[c]]) - vid[c] = JuMP.@NLexpression(pm.model, vi[c]-vi[next[c]]) + vrd[c] = JuMP.@expression(pm.model, vr[c]-vr[next[c]]) + vid[c] = JuMP.@expression(pm.model, vi[c]-vi[next[c]]) end crd = Dict() cid = Dict() for (idx, c) in enumerate(connections) - crd[c] = JuMP.@NLexpression(pm.model, a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)+b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) - cid[c] = JuMP.@NLexpression(pm.model, a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)-b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) + crd[c] = JuMP.@expression(pm.model, a[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)+b[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) + cid[c] = JuMP.@expression(pm.model, a[idx]*vid[c]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2-1)-b[idx]*vrd[c]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2 -1)) end crd_bus = Dict() cid_bus = Dict() for (idx, c) in enumerate(conn_bus) if is_triplex - crd_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crd[1]) - cid_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cid[1]) + crd_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crd[1]) + cid_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cid[1]) else - crd_bus[c] = JuMP.@NLexpression(pm.model, crd[c]-crd[prev[c]]) - cid_bus[c] = JuMP.@NLexpression(pm.model, cid[c]-cid[prev[c]]) + crd_bus[c] = JuMP.@expression(pm.model, crd[c]-crd[prev[c]]) + cid_bus[c] = JuMP.@expression(pm.model, cid[c]-cid[prev[c]]) end end - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(conn_bus) - push!(pd_bus, JuMP.@NLexpression(pm.model, vr[c]*crd_bus[c]+vi[c]*cid_bus[c])) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vr[c]*cid_bus[c]+vi[c]*crd_bus[c])) + push!(pd_bus, JuMP.@expression(pm.model, -vr[c]*-crd_bus[c]-vi[c]*-cid_bus[c])) + push!(qd_bus, JuMP.@expression(pm.model, vr[c]*-cid_bus[c]-vi[c]*-crd_bus[c])) end pd_bus = JuMP.Containers.DenseAxisArray(pd_bus, conn_bus) @@ -870,11 +870,11 @@ function constraint_mc_load_power_delta(pm::AbstractUnbalancedACRModel, nw::Int, sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vrd[c]^2+vid[c]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vrd[c]^2+vid[c]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -908,34 +908,34 @@ function constraint_mc_generator_power_delta(pm::AbstractUnbalancedACRModel, nw: vrg = Dict() vig = Dict() for c in connections - vrg[c] = JuMP.@NLexpression(pm.model, vr[c]-vr[next[c]]) - vig[c] = JuMP.@NLexpression(pm.model, vi[c]-vi[next[c]]) + vrg[c] = JuMP.@expression(pm.model, vr[c]-vr[next[c]]) + vig[c] = JuMP.@expression(pm.model, vi[c]-vi[next[c]]) end crg = Dict() cig = Dict() for c in connections - crg[c] = JuMP.@NLexpression(pm.model, (pg[c]*vrg[c]+qg[c]*vig[c])/(vrg[c]^2+vig[c]^2) ) - cig[c] = JuMP.@NLexpression(pm.model, (pg[c]*vig[c]-qg[c]*vrg[c])/(vrg[c]^2+vig[c]^2) ) + crg[c] = JuMP.@expression(pm.model, (pg[c]*vrg[c]+qg[c]*vig[c])/(vrg[c]^2+vig[c]^2) ) + cig[c] = JuMP.@expression(pm.model, (pg[c]*vig[c]-qg[c]*vrg[c])/(vrg[c]^2+vig[c]^2) ) end crg_bus = Dict() cig_bus = Dict() for c in conn_bus if is_triplex - crg_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crg[1]) - cig_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cig[1]) + crg_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1]) + cig_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1]) else - crg_bus[c] = JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]]) - cig_bus[c] = JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]]) + crg_bus[c] = JuMP.@expression(pm.model, crg[c]-crg[prev[c]]) + cig_bus[c] = JuMP.@expression(pm.model, cig[c]-cig[prev[c]]) end end - pg_bus = Vector{JuMP.NonlinearExpression}([]) - qg_bus = Vector{JuMP.NonlinearExpression}([]) + pg_bus = Vector{JuMP.NonlinearExpr}([]) + qg_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(conn_bus) - push!(pg_bus, JuMP.@NLexpression(pm.model, vr[c]*crg_bus[c]+vi[c]*cig_bus[c])) - push!(qg_bus, JuMP.@NLexpression(pm.model, -vr[c]*cig_bus[c]+vi[c]*crg_bus[c])) + push!(pg_bus, JuMP.@expression(pm.model, vr[c]*crg_bus[c]+vi[c]*cig_bus[c])) + push!(qg_bus, JuMP.@expression(pm.model, -vr[c]*cig_bus[c]+vi[c]*crg_bus[c])) end pg_bus = JuMP.Containers.DenseAxisArray(pg_bus, conn_bus) @@ -985,16 +985,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractUnbalancedACRModel, nw:: x = transformer["controls"]["x"][idx] # (cr+jci) = (p-jq)/(vr-j⋅vi) - cr = JuMP.@NLexpression(pm.model, ( p_to[idx]*vr_to[tc] + q_to[idx]*vi_to[tc])/(vr_to[tc]^2+vi_to[tc]^2)) - ci = JuMP.@NLexpression(pm.model, (-q_to[idx]*vr_to[tc] + p_to[idx]*vi_to[tc])/(vr_to[tc]^2+vi_to[tc]^2)) + cr = JuMP.@expression(pm.model, ( p_to[idx]*vr_to[tc] + q_to[idx]*vi_to[tc])/(vr_to[tc]^2+vi_to[tc]^2)) + ci = JuMP.@expression(pm.model, (-q_to[idx]*vr_to[tc] + p_to[idx]*vi_to[tc])/(vr_to[tc]^2+vi_to[tc]^2)) # v_drop = (cr+jci)⋅(r+jx) - vr_drop = JuMP.@NLexpression(pm.model, r*cr-x*ci) - vi_drop = JuMP.@NLexpression(pm.model, r*ci+x*cr) + vr_drop = JuMP.@expression(pm.model, r*cr-x*ci) + vi_drop = JuMP.@expression(pm.model, r*ci+x*cr) # (v_ref-δ)^2 ≤ (vr_fr-vr_drop)^2 + (vi_fr-vi_drop)^2 ≤ (v_ref+δ)^2 # (vr_fr^2 + vi_fr^2)/1.1^2 ≤ (vr_to^2 + vi_to^2) ≤ (vr_fr^2 + vi_fr^2)/0.9^2 - JuMP.@NLconstraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≥ (v_ref - δ)^2) - JuMP.@NLconstraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≤ (v_ref + δ)^2) + JuMP.@constraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≥ (v_ref - δ)^2) + JuMP.@constraint(pm.model, (vr_fr[fc]-vr_drop)^2 + (vi_fr[fc]-vi_drop)^2 ≤ (v_ref + δ)^2) JuMP.@constraint(pm.model, (vr_fr[fc]^2 + vi_fr[fc]^2)/1.1^2 ≤ vr_to[tc]^2 + vi_to[tc]^2) JuMP.@constraint(pm.model, (vr_fr[fc]^2 + vi_fr[fc]^2)/0.9^2 ≥ vr_to[tc]^2 + vi_to[tc]^2) end @@ -1041,19 +1041,19 @@ function constraint_mc_transformer_power_dy(pm::AbstractUnbalancedACRModel, nw:: # -Im(s/v) = -(q*cos(va)-p*sin(va))/|v| for (idx, (fc,tc)) in enumerate(zip(f_connections,t_connections)) # id = conj(s_to/v_to)./tm - id_re[idx] = JuMP.@NLexpression(pm.model, (p_to[tc]*vr_p_to[idx]+q_to[tc]*vi_p_to[idx])/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) - id_im[idx] = JuMP.@NLexpression(pm.model, (p_to[tc]*vi_p_to[idx]-q_to[tc]*vr_p_to[idx])/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) + id_re[idx] = JuMP.@expression(pm.model, (p_to[tc]*vr_p_to[idx]+q_to[tc]*vi_p_to[idx])/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) + id_im[idx] = JuMP.@expression(pm.model, (p_to[tc]*vi_p_to[idx]-q_to[tc]*vr_p_to[idx])/(tm_scale*tm[idx]*pol)/(vr_p_to[idx]^2+vi_p_to[idx]^2)) end for (idx,(fc,tc)) in enumerate(zip(f_connections, t_connections)) jdx = (idx-1+nph-1)%nph+1 # s_fr = v_fr*conj(i_fr) # = v_fr*conj(id[q]-id[p]) # = v_fr*(id_re[q]-j*id_im[q]-id_re[p]+j*id_im[p]) - JuMP.@NLconstraint(pm.model, p_fr[fc] == + JuMP.@constraint(pm.model, p_fr[fc] == vr_p_fr[idx]*( id_re[jdx]-id_re[idx]) -vi_p_fr[idx]*(-id_im[jdx]+id_im[idx]) ) - JuMP.@NLconstraint(pm.model, q_fr[fc] == + JuMP.@constraint(pm.model, q_fr[fc] == vr_p_fr[idx]*(-id_im[jdx]+id_im[idx]) +vi_p_fr[idx]*( id_re[jdx]-id_re[idx]) ) @@ -1078,13 +1078,13 @@ function constraint_mc_storage_losses(pm::AbstractUnbalancedACRModel, i::Int; nw r = storage["r"] x = storage["x"] - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(ps[c] for c in storage["connections"]) + (sd - sc) == p_loss + r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"])) ) - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(qs[c] for c in storage["connections"]) == qsc + q_loss + x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for (idx,c) in enumerate(storage["connections"])) @@ -1102,13 +1102,13 @@ function constraint_mc_storage_losses(pm::AbstractUnbalancedACRModel, n::Int, i: sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(ps[c] for c in connections) + (sd - sc) == p_loss + r * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections) ) - JuMP.@NLconstraint(pm.model, + JuMP.@constraint(pm.model, sum(qs[c] for c in connections) == qsc + q_loss + x * sum((ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in connections) diff --git a/src/form/bf_fbs.jl b/src/form/bf_fbs.jl index c0aa6ff58..0942717fc 100644 --- a/src/form/bf_fbs.jl +++ b/src/form/bf_fbs.jl @@ -827,8 +827,8 @@ function constraint_mc_generator_power_delta(pm::FBSUBFPowerModel, nw::Int, id:: crg_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1]) cig_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1]) else - crg_bus[c] = JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]]) - cig_bus[c] = JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]]) + crg_bus[c] = JuMP.@expression(pm.model, crg[c]-crg[prev[c]]) + cig_bus[c] = JuMP.@expression(pm.model, cig[c]-cig[prev[c]]) end end diff --git a/src/form/en_acr.jl b/src/form/en_acr.jl index bd5e446d1..4ab28882d 100644 --- a/src/form/en_acr.jl +++ b/src/form/en_acr.jl @@ -57,19 +57,19 @@ function constraint_mc_generator_power_wye(pm::AbstractExplicitNeutralACRModel, vr_pn = [vr[p]-vr[n] for p in phases] vi_pn = [vi[p]-vi[n] for p in phases] - crg = JuMP.@NLexpression(pm.model, [idx in 1:P], + crg = JuMP.@expression(pm.model, [idx in 1:P], ( pg[idx]*vr_pn[idx] + qg[idx]*vi_pn[idx] )/( vr_pn[idx]^2 + vi_pn[idx]^2 ) ) - cig = JuMP.@NLexpression(pm.model, [idx in 1:P], + cig = JuMP.@expression(pm.model, [idx in 1:P], ( pg[idx]*vi_pn[idx] - qg[idx]*vr_pn[idx] )/( vr_pn[idx]^2 + vi_pn[idx]^2 ) ) pg_bus_unmerged = [ - [JuMP.@NLexpression(pm.model, vr[p]*crg[idx]+vi[p]*cig[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, vr[n]*sum(-crg[idx] for idx in 1:P)+vi[n]*sum(-cig[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr[p]*crg[idx]+vi[p]*cig[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, vr[n]*sum(-crg[idx] for idx in 1:P)+vi[n]*sum(-cig[idx] for idx in 1:P)) ] qg_bus_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr[p]*cig[idx]+vi[p]*crg[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, -vr[n]*sum(-cig[idx] for idx in 1:P)+vi[n]*sum(-crg[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr[p]*cig[idx]+vi[p]*crg[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, -vr[n]*sum(-cig[idx] for idx in 1:P)+vi[n]*sum(-crg[idx] for idx in 1:P)) ] end var(pm, nw, :pg_bus)[id] = pg_bus = _merge_bus_flows(pm, pg_bus_unmerged, connections) @@ -115,17 +115,17 @@ function constraint_mc_generator_power_delta(pm::AbstractExplicitNeutralACRModel vr_pp = [vr[c]-vr[d] for (c,d) in zip(ph,ph_next)] vi_pp = [vi[c]-vi[d] for (c,d) in zip(ph,ph_next)] - crg = JuMP.@NLexpression(pm.model, [idx in 1:P], + crg = JuMP.@expression(pm.model, [idx in 1:P], ( pg[idx]*vr_pp[idx] + qg[idx]*vi_pp[idx] )/( vr_pp[idx]^2 + vi_pp[idx]^2 ) ) - cig = JuMP.@NLexpression(pm.model, [idx in 1:P], + cig = JuMP.@expression(pm.model, [idx in 1:P], ( pg[idx]*vi_pp[idx] - qg[idx]*vr_pp[idx] )/( vr_pp[idx]^2 + vi_pp[idx]^2 ) ) - crg_bus = JuMP.@NLexpression(pm.model, [idx in 1:P], crg[idx] - crg[idxs_prev[idx]]) - cig_bus = JuMP.@NLexpression(pm.model, [idx in 1:P], cig[idx] - cig[idxs_prev[idx]]) + crg_bus = JuMP.@expression(pm.model, [idx in 1:P], crg[idx] - crg[idxs_prev[idx]]) + cig_bus = JuMP.@expression(pm.model, [idx in 1:P], cig[idx] - cig[idxs_prev[idx]]) - pg_bus_unmerged = [JuMP.@NLexpression(pm.model, vr[p]*crg_bus[idx]+vi[p]*cig_bus[idx]) for (idx,p) in enumerate(ph)] - qg_bus_unmerged = [JuMP.@NLexpression(pm.model, -vr[p]*cig_bus[idx]+vi[p]*crg_bus[idx]) for (idx,p) in enumerate(ph)] + pg_bus_unmerged = [JuMP.@expression(pm.model, vr[p]*crg_bus[idx]+vi[p]*cig_bus[idx]) for (idx,p) in enumerate(ph)] + qg_bus_unmerged = [JuMP.@expression(pm.model, -vr[p]*cig_bus[idx]+vi[p]*crg_bus[idx]) for (idx,p) in enumerate(ph)] var(pm, nw, :pg_bus)[id] = pg_bus = _merge_bus_flows(pm, pg_bus_unmerged, connections) var(pm, nw, :qg_bus)[id] = qg_bus = _merge_bus_flows(pm, qg_bus_unmerged, connections) @@ -190,8 +190,8 @@ function constraint_mc_load_power_wye(pm::AbstractExplicitNeutralACRModel, nw::I vr_pn = [vr[p]-vr[n] for p in phases] vi_pn = [vi[p]-vi[n] for p in phases] - crd = JuMP.@NLexpression(pm.model, [idx in 1:P], a[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)+b[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) - cid = JuMP.@NLexpression(pm.model, [idx in 1:P], a[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)-b[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) + crd = JuMP.@expression(pm.model, [idx in 1:P], a[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)+b[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) + cid = JuMP.@expression(pm.model, [idx in 1:P], a[idx]*vi_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(alpha[idx]/2-1)-b[idx]*vr_pn[idx]*(vr_pn[idx]^2+vi_pn[idx]^2)^(beta[idx]/2 -1)) # if constant power load @@ -199,8 +199,8 @@ function constraint_mc_load_power_wye(pm::AbstractExplicitNeutralACRModel, nw::I pd = a qd = b else - pd = JuMP.@NLexpression(pm.model, [idx in 1:P], vr_pn[idx]*crd[idx]+vi_pn[idx]*cid[idx]) - qd = JuMP.@NLexpression(pm.model, [idx in 1:P], -vr_pn[idx]*cid[idx]+vi_pn[idx]*crd[idx]) + pd = JuMP.@expression(pm.model, [idx in 1:P], vr_pn[idx]*crd[idx]+vi_pn[idx]*cid[idx]) + qd = JuMP.@expression(pm.model, [idx in 1:P], -vr_pn[idx]*cid[idx]+vi_pn[idx]*crd[idx]) end if iszero(vr[n]) && iszero(vi[n]) @@ -208,12 +208,12 @@ function constraint_mc_load_power_wye(pm::AbstractExplicitNeutralACRModel, nw::I qd_bus_unmerged = [qd..., 0.0] else pd_bus_unmerged = [ - [JuMP.@NLexpression(pm.model, vr[p]*crd[idx]+vi[p]*cid[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, vr[n]*sum(-crd[idx] for idx in 1:P)+vi[n]*sum(-cid[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr[p]*crd[idx]+vi[p]*cid[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, vr[n]*sum(-crd[idx] for idx in 1:P)+vi[n]*sum(-cid[idx] for idx in 1:P)) ] qd_bus_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr[p]*cid[idx]+vi[p]*crd[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, -vr[n]*sum(-cid[idx] for idx in 1:P)+vi[n]*sum(-crd[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr[p]*cid[idx]+vi[p]*crd[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, -vr[n]*sum(-cid[idx] for idx in 1:P)+vi[n]*sum(-crd[idx] for idx in 1:P)) ] end var(pm, nw, :pd_bus)[id] = pd_bus = _merge_bus_flows(pm, pd_bus_unmerged, connections) @@ -258,14 +258,14 @@ function constraint_mc_load_power_delta(pm::AbstractExplicitNeutralACRModel, nw: vrd = [vr[t]-vr[connections[next(idx)]] for (idx,t) in enumerate(connections)] vid = [vi[t]-vi[connections[next(idx)]] for (idx,t) in enumerate(connections)] - crd = JuMP.@NLexpression(pm.model, [idx in 1:nph], a[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)+b[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) - cid = JuMP.@NLexpression(pm.model, [idx in 1:nph], a[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)-b[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) + crd = JuMP.@expression(pm.model, [idx in 1:nph], a[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)+b[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) + cid = JuMP.@expression(pm.model, [idx in 1:nph], a[idx]*vid[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2-1)-b[idx]*vrd[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2 -1)) - crd_bus_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:nph], crd[idx]-crd[prev(idx)]) - cid_bus_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:nph], cid[idx]-cid[prev(idx)]) + crd_bus_unmerged = JuMP.@expression(pm.model, [idx in 1:nph], crd[idx]-crd[prev(idx)]) + cid_bus_unmerged = JuMP.@expression(pm.model, [idx in 1:nph], cid[idx]-cid[prev(idx)]) - pd_bus_unmerged = [JuMP.@NLexpression(pm.model, vr[p]*crd_bus_unmerged[idx]+vi[p]*cid_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] - qd_bus_unmerged = [JuMP.@NLexpression(pm.model, -vr[p]*cid_bus_unmerged[idx]+vi[p]*crd_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] + pd_bus_unmerged = [JuMP.@expression(pm.model, vr[p]*crd_bus_unmerged[idx]+vi[p]*cid_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] + qd_bus_unmerged = [JuMP.@expression(pm.model, -vr[p]*cid_bus_unmerged[idx]+vi[p]*crd_bus_unmerged[idx]) for (idx,p) in enumerate(connections)] var(pm, nw, :pd_bus)[id] = pd_bus = _merge_bus_flows(pm, pd_bus_unmerged, connections) var(pm, nw, :qd_bus)[id] = qd_bus = _merge_bus_flows(pm, qd_bus_unmerged, connections) @@ -274,11 +274,11 @@ function constraint_mc_load_power_delta(pm::AbstractExplicitNeutralACRModel, nw: sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for idx in 1:nph - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vrd[idx]^2+vid[idx]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vrd[idx]^2+vid[idx]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -357,16 +357,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractExplicitNeutralACRModel, vr_fr_pn = [vr_fr[p]-vr_fr[f_n] for p in f_phases] vi_fr_pn = [vi_fr[p]-vi_fr[f_n] for p in f_phases] - crt_fr = [JuMP.@NLexpression(pm.model, ( pt_fr[idx]*vr_fr_pn[idx]+qt_fr[idx]*vi_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] - cit_fr = [JuMP.@NLexpression(pm.model, (-pt_fr[idx]*vi_fr_pn[idx]+qt_fr[idx]*vr_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] + crt_fr = [JuMP.@expression(pm.model, ( pt_fr[idx]*vr_fr_pn[idx]+qt_fr[idx]*vi_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] + cit_fr = [JuMP.@expression(pm.model, (-pt_fr[idx]*vi_fr_pn[idx]+qt_fr[idx]*vr_fr_pn[idx])/(vr_fr_pn[idx]^2+vi_fr_pn[idx]^2)) for idx in 1:P] pt_bus_fr_unmerged = [ - [JuMP.@NLexpression(pm.model, vr_fr[p]*crt_fr[idx]+vi_fr[p]*cit_fr[idx]) for (idx,p) in enumerate(f_phases)]..., - JuMP.@NLexpression(pm.model, vr_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr_fr[p]*crt_fr[idx]+vi_fr[p]*cit_fr[idx]) for (idx,p) in enumerate(f_phases)]..., + JuMP.@expression(pm.model, vr_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)) ] qt_bus_fr_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr_fr[p]*cit_fr[idx]+vi_fr[p]*crt_fr[idx]) for (idx,p) in enumerate(f_phases)]..., - JuMP.@NLexpression(pm.model, -vr_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr_fr[p]*cit_fr[idx]+vi_fr[p]*crt_fr[idx]) for (idx,p) in enumerate(f_phases)]..., + JuMP.@expression(pm.model, -vr_fr[f_n]*sum(-cit_fr[idx] for idx in 1:P)+vi_fr[f_n]*sum(-crt_fr[idx] for idx in 1:P)) ] end var(pm, nw, :pt_bus)[f_idx] = pt_bus_fr = _merge_bus_flows(pm, pt_bus_fr_unmerged, f_connections) @@ -380,16 +380,16 @@ function constraint_mc_transformer_power_yy(pm::AbstractExplicitNeutralACRModel, vr_to_pn = [vr_to[p]-vr_to[t_n] for p in t_phases] vi_to_pn = [vi_to[p]-vi_to[t_n] for p in t_phases] - crt_to = [JuMP.@NLexpression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] - cit_to = [JuMP.@NLexpression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + crt_to = [JuMP.@expression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + cit_to = [JuMP.@expression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] pt_bus_to_unmerged = [ - [JuMP.@NLexpression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(t_phases)]..., - JuMP.@NLexpression(pm.model, vr_to[t_n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-cit_to[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(t_phases)]..., + JuMP.@expression(pm.model, vr_to[t_n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-cit_to[idx] for idx in 1:P)) ] qt_bus_to_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(t_phases)]..., - JuMP.@NLexpression(pm.model, -vr_to[t_n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-crt_to[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(t_phases)]..., + JuMP.@expression(pm.model, -vr_to[t_n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[t_n]*sum(-crt_to[idx] for idx in 1:P)) ] end var(pm, nw, :pt_bus)[t_idx] = pt_bus_to = _merge_bus_flows(pm, pt_bus_to_unmerged, t_connections) @@ -440,14 +440,14 @@ function constraint_mc_transformer_power_dy(pm::AbstractExplicitNeutralACRModel, vrg_fr = [vr_fr[p]-vr_fr[f_connections[next(idx)]] for (idx,p) in enumerate(f_connections)] vig_fr = [vi_fr[p]-vi_fr[f_connections[next(idx)]] for (idx,p) in enumerate(f_connections)] - crt_fr = JuMP.@NLexpression(pm.model, [idx in 1:P], (pt_fr[idx]*vrg_fr[idx]+qt_fr[idx]*vig_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) - cit_fr = JuMP.@NLexpression(pm.model, [idx in 1:P], (pt_fr[idx]*vig_fr[idx]-qt_fr[idx]*vrg_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) + crt_fr = JuMP.@expression(pm.model, [idx in 1:P], (pt_fr[idx]*vrg_fr[idx]+qt_fr[idx]*vig_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) + cit_fr = JuMP.@expression(pm.model, [idx in 1:P], (pt_fr[idx]*vig_fr[idx]-qt_fr[idx]*vrg_fr[idx])/(vrg_fr[idx]^2+vig_fr[idx]^2)) - crt_bus_fr_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:P], crt_fr[idx]-crt_fr[prev(idx)]) - cit_bus_fr_unmerged = JuMP.@NLexpression(pm.model, [idx in 1:P], cit_fr[idx]-cit_fr[prev(idx)]) + crt_bus_fr_unmerged = JuMP.@expression(pm.model, [idx in 1:P], crt_fr[idx]-crt_fr[prev(idx)]) + cit_bus_fr_unmerged = JuMP.@expression(pm.model, [idx in 1:P], cit_fr[idx]-cit_fr[prev(idx)]) - pt_bus_fr_unmerged = [JuMP.@NLexpression(pm.model, vr_fr[p]*crt_bus_fr_unmerged[idx]+vi_fr[p]*cit_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] - qt_bus_fr_unmerged = [JuMP.@NLexpression(pm.model, -vr_fr[p]*cit_bus_fr_unmerged[idx]+vi_fr[p]*crt_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] + pt_bus_fr_unmerged = [JuMP.@expression(pm.model, vr_fr[p]*crt_bus_fr_unmerged[idx]+vi_fr[p]*cit_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] + qt_bus_fr_unmerged = [JuMP.@expression(pm.model, -vr_fr[p]*cit_bus_fr_unmerged[idx]+vi_fr[p]*crt_bus_fr_unmerged[idx]) for (idx,p) in enumerate(f_connections)] var(pm, nw, :pt_bus)[f_idx] = pt_bus_fr = _merge_bus_flows(pm, pt_bus_fr_unmerged, f_connections) var(pm, nw, :qt_bus)[f_idx] = qt_bus_fr = _merge_bus_flows(pm, qt_bus_fr_unmerged, f_connections) @@ -460,16 +460,16 @@ function constraint_mc_transformer_power_dy(pm::AbstractExplicitNeutralACRModel, vr_to_pn = [vr_to[p]-vr_to[t_n] for p in t_phases] vi_to_pn = [vi_to[p]-vi_to[t_n] for p in t_phases] - crt_to = [JuMP.@NLexpression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] - cit_to = [JuMP.@NLexpression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + crt_to = [JuMP.@expression(pm.model, ( pt_to[idx]*vr_to_pn[idx]+qt_to[idx]*vi_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] + cit_to = [JuMP.@expression(pm.model, (-pt_to[idx]*vi_to_pn[idx]+qt_to[idx]*vr_to_pn[idx])/(vr_to_pn[idx]^2+vi_to_pn[idx]^2)) for idx in 1:P] pt_bus_to_unmerged = [ - [JuMP.@NLexpression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, vr_to[n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[n]*sum(-cit_to[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, vr_to[p]*crt_to[idx]+vi_to[p]*cit_to[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, vr_to[n]*sum(-crt_to[idx] for idx in 1:P)+vi_to[n]*sum(-cit_to[idx] for idx in 1:P)) ] qt_bus_to_unmerged = [ - [JuMP.@NLexpression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(phases)]..., - JuMP.@NLexpression(pm.model, -vr_to[n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[n]*sum(-crt_to[idx] for idx in 1:P)) + [JuMP.@expression(pm.model, -vr_to[p]*cit_to[idx]+vi_to[p]*crt_to[idx]) for (idx,p) in enumerate(phases)]..., + JuMP.@expression(pm.model, -vr_to[n]*sum(-cit_to[idx] for idx in 1:P)+vi_to[n]*sum(-crt_to[idx] for idx in 1:P)) ] end var(pm, nw, :pt_bus)[t_idx] = pt_bus_to = _merge_bus_flows(pm, pt_bus_to_unmerged, t_connections) @@ -680,7 +680,7 @@ function constraint_mc_thermal_limit_from(pm::AbstractExplicitNeutralACRModel, n if rate_a[idx]= pg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], pmin[i] <= pg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], pmax[i] >= pg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) var(pm, nw, :pg)[id] = JuMP.Containers.DenseAxisArray(pg, connections) var(pm, nw, :qg)[id] = JuMP.Containers.DenseAxisArray(qg, connections) @@ -499,18 +499,18 @@ function constraint_mc_load_current_wye(pm::AbstractExplicitNeutralIVRModel, nw: vr = var(pm, nw, :vr, bus_id) vi = var(pm, nw, :vi, bus_id) - crd = Vector{JuMP.NonlinearExpression}([]) - cid = Vector{JuMP.NonlinearExpression}([]) + crd = Vector{JuMP.NonlinearExpr}([]) + cid = Vector{JuMP.NonlinearExpr}([]) phases = connections[1:end-1] n = connections[end] for (idx, p) in enumerate(phases) - push!(crd, JuMP.@NLexpression(pm.model, + push!(crd, JuMP.@expression(pm.model, a[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1) +b[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1) )) - push!(cid, JuMP.@NLexpression(pm.model, + push!(cid, JuMP.@expression(pm.model, a[idx]*(vi[p]-vi[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(alpha[idx]/2-1) -b[idx]*(vr[p]-vr[n])*((vr[p]-vr[n])^2+(vi[p]-vi[n])^2)^(beta[idx]/2 -1) )) @@ -519,18 +519,18 @@ function constraint_mc_load_current_wye(pm::AbstractExplicitNeutralIVRModel, nw: var(pm, nw, :crd)[id] = crd var(pm, nw, :cid)[id] = cid - crd_bus_n = JuMP.@NLexpression(pm.model, -sum(crd[i] for i in 1:length(phases))) - cid_bus_n = JuMP.@NLexpression(pm.model, -sum(cid[i] for i in 1:length(phases))) + crd_bus_n = JuMP.@expression(pm.model, -sum(crd[i] for i in 1:length(phases))) + cid_bus_n = JuMP.@expression(pm.model, -sum(cid[i] for i in 1:length(phases))) var(pm, nw, :crd_bus)[id] = crd_bus = _merge_bus_flows(pm, [crd..., crd_bus_n], connections) var(pm, nw, :cid_bus)[id] = cid_bus = _merge_bus_flows(pm, [cid..., cid_bus_n], connections) if report - pd_bus = Vector{JuMP.NonlinearExpression}([]) - qd_bus = Vector{JuMP.NonlinearExpression}([]) + pd_bus = Vector{JuMP.NonlinearExpr}([]) + qd_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(connections) - push!(pd_bus, JuMP.@NLexpression(pm.model, vr[c]*crd_bus[c]+vi[c]*cid_bus[c])) - push!(qd_bus, JuMP.@NLexpression(pm.model, -vr[c]*cid_bus[c]+vi[c]*crd_bus[c])) + push!(pd_bus, JuMP.@expression(pm.model, vr[c]*crd_bus[c]+vi[c]*cid_bus[c])) + push!(qd_bus, JuMP.@expression(pm.model, -vr[c]*cid_bus[c]+vi[c]*crd_bus[c])) end sol(pm, nw, :load, id)[:pd_bus] = JuMP.Containers.DenseAxisArray(pd_bus, connections) @@ -542,11 +542,11 @@ function constraint_mc_load_current_wye(pm::AbstractExplicitNeutralIVRModel, nw: sol(pm, nw, :load, id)[:crd_bus] = crd_bus sol(pm, nw, :load, id)[:cid_bus] = cid_bus - pd = Vector{JuMP.NonlinearExpression}([]) - qd = Vector{JuMP.NonlinearExpression}([]) + pd = Vector{JuMP.NonlinearExpr}([]) + qd = Vector{JuMP.NonlinearExpr}([]) for (idx, p) in enumerate(phases) - push!(pd, JuMP.@NLexpression(pm.model, a[idx]*(vr[p]^2+vi[p]^2)^(alpha[idx]/2) )) - push!(qd, JuMP.@NLexpression(pm.model, b[idx]*(vr[p]^2+vi[p]^2)^(beta[idx]/2) )) + push!(pd, JuMP.@expression(pm.model, a[idx]*(vr[p]^2+vi[p]^2)^(alpha[idx]/2) )) + push!(qd, JuMP.@expression(pm.model, b[idx]*(vr[p]^2+vi[p]^2)^(beta[idx]/2) )) end sol(pm, nw, :load, id)[:pd] = JuMP.Containers.DenseAxisArray(pd, connections) sol(pm, nw, :load, id)[:qd] = JuMP.Containers.DenseAxisArray(qd, connections) @@ -586,30 +586,30 @@ function constraint_mc_load_current_delta(pm::AbstractExplicitNeutralIVRModel, n vrd = [vr[c]-vr[d] for (c,d) in zip(ph,ph_next)] vid = [vi[c]-vi[d] for (c,d) in zip(ph,ph_next)] - crd = JuMP.@NLexpression(pm.model, [i in 1:P], + crd = JuMP.@expression(pm.model, [i in 1:P], a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) +b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) ) - cid = JuMP.@NLexpression(pm.model, [i in 1:P], + cid = JuMP.@expression(pm.model, [i in 1:P], a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) -b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) ) - crd_bus = JuMP.@NLexpression(pm.model, [i in 1:P], crd[i]-crd[idxs_prev[i]]) - cid_bus = JuMP.@NLexpression(pm.model, [i in 1:P], cid[i]-cid[idxs_prev[i]]) + crd_bus = JuMP.@expression(pm.model, [i in 1:P], crd[i]-crd[idxs_prev[i]]) + cid_bus = JuMP.@expression(pm.model, [i in 1:P], cid[i]-cid[idxs_prev[i]]) var(pm, nw, :crd_bus)[id] = _merge_bus_flows(pm, crd_bus, connections) var(pm, nw, :cid_bus)[id] = _merge_bus_flows(pm, cid_bus, connections) if report - pd_bus = JuMP.@NLexpression(pm.model, [i in 1:P], vr[i]*crd_bus[i]+vi[i]*cid_bus[i]) - qd_bus = JuMP.@NLexpression(pm.model, [i in 1:P], -vr[i]*cid_bus[i]+vi[i]*crd_bus[i]) + pd_bus = JuMP.@expression(pm.model, [i in 1:P], vr[i]*crd_bus[i]+vi[i]*cid_bus[i]) + qd_bus = JuMP.@expression(pm.model, [i in 1:P], -vr[i]*cid_bus[i]+vi[i]*crd_bus[i]) sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = JuMP.@NLexpression(pm.model, [i in 1:P], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) - qd = JuMP.@NLexpression(pm.model, [i in 1:P], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) + pd = JuMP.@expression(pm.model, [i in 1:P], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) + qd = JuMP.@expression(pm.model, [i in 1:P], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) sol(pm, nw, :load, id)[:pd] = pd sol(pm, nw, :load, id)[:qd] = qd end @@ -1101,14 +1101,14 @@ function constraint_mc_transformer_thermal_limit(pm::AbstractNLExplicitNeutralIV vit_to = [vi_to[p]-vi_to[n_to] for p in P_to] idxs = [1:length(vrt_fr)...] - pt_fr = JuMP.@NLexpression(pm.model, [i in idxs], vrt_fr[i]*crt_fr[i] + vit_fr[i]*cit_fr[i]) - qt_fr = JuMP.@NLexpression(pm.model, [i in idxs], -vrt_fr[i]*cit_fr[i] + vit_fr[i]*crt_fr[i]) - pt_to = JuMP.@NLexpression(pm.model, [i in idxs], vrt_to[i]*crt_to[i] + vit_to[i]*cit_to[i]) - qt_to = JuMP.@NLexpression(pm.model, [i in idxs], -vrt_to[i]*cit_to[i] + vit_to[i]*crt_to[i]) + pt_fr = JuMP.@expression(pm.model, [i in idxs], vrt_fr[i]*crt_fr[i] + vit_fr[i]*cit_fr[i]) + qt_fr = JuMP.@expression(pm.model, [i in idxs], -vrt_fr[i]*cit_fr[i] + vit_fr[i]*crt_fr[i]) + pt_to = JuMP.@expression(pm.model, [i in idxs], vrt_to[i]*crt_to[i] + vit_to[i]*cit_to[i]) + qt_to = JuMP.@expression(pm.model, [i in idxs], -vrt_to[i]*cit_to[i] + vit_to[i]*crt_to[i]) if sm_ub(i+nph-2)%nph+1 for i in 1:nph) next = is_triplex ? conn_bus[2] : Dict(i=>i%nph+1 for i in 1:nph) - vrd = JuMP.@NLexpression(pm.model, [i in 1:nph], vr[i]-vr[next[i]]) - vid = JuMP.@NLexpression(pm.model, [i in 1:nph], vi[i]-vi[next[i]]) + vrd = JuMP.@expression(pm.model, [i in 1:nph], vr[i]-vr[next[i]]) + vid = JuMP.@expression(pm.model, [i in 1:nph], vi[i]-vi[next[i]]) - crd = JuMP.@NLexpression(pm.model, [i in 1:nph], + crd = JuMP.@expression(pm.model, [i in 1:nph], a[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) +b[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) ) - cid = JuMP.@NLexpression(pm.model, [i in 1:nph], + cid = JuMP.@expression(pm.model, [i in 1:nph], a[i]*vid[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2-1) -b[i]*vrd[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2 -1) ) @@ -686,11 +686,11 @@ function constraint_mc_load_power_delta(pm::IVRUPowerModel, nw::Int, id::Int, bu cid_bus = Dict() for (idx, c) in enumerate(conn_bus) if is_triplex - crd_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crd[1]) - cid_bus[c] = JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cid[1]) + crd_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*crd[1]) + cid_bus[c] = JuMP.@expression(pm.model, (-1.0)^(c-1)*cid[1]) else - crd_bus[c] = JuMP.@NLexpression(pm.model, crd[c]-crd[prev[c]]) - cid_bus[c] = JuMP.@NLexpression(pm.model, cid[c]-cid[prev[c]]) + crd_bus[c] = JuMP.@expression(pm.model, crd[c]-crd[prev[c]]) + cid_bus[c] = JuMP.@expression(pm.model, cid[c]-cid[prev[c]]) end end @@ -698,13 +698,13 @@ function constraint_mc_load_power_delta(pm::IVRUPowerModel, nw::Int, id::Int, bu var(pm, nw, :cid_bus)[id] = cid_bus if report - pd_bus = JuMP.@NLexpression(pm.model, [c in conn_bus], vr[c]*crd_bus[c]+vi[c]*cid_bus[c]) - qd_bus = JuMP.@NLexpression(pm.model, [c in conn_bus], -vr[c]*cid_bus[c]+vi[c]*crd_bus[c]) + pd_bus = JuMP.@expression(pm.model, [c in conn_bus], vr[c]*crd_bus[c]+vi[c]*cid_bus[c]) + qd_bus = JuMP.@expression(pm.model, [c in conn_bus], -vr[c]*cid_bus[c]+vi[c]*crd_bus[c]) sol(pm, nw, :load, id)[:pd_bus] = pd_bus sol(pm, nw, :load, id)[:qd_bus] = qd_bus - pd = JuMP.@NLexpression(pm.model, [i in 1:nph], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) - qd = JuMP.@NLexpression(pm.model, [i in 1:nph], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) + pd = JuMP.@expression(pm.model, [i in 1:nph], a[i]*(vrd[i]^2+vid[i]^2)^(alpha[i]/2) ) + qd = JuMP.@expression(pm.model, [i in 1:nph], b[i]*(vrd[i]^2+vid[i]^2)^(beta[i]/2) ) sol(pm, nw, :load, id)[:pd] = pd sol(pm, nw, :load, id)[:qd] = qd end @@ -718,12 +718,12 @@ function constraint_mc_generator_power_wye(pm::IVRUPowerModel, nw::Int, id::Int, crg = var(pm, nw, :crg, id) cig = var(pm, nw, :cig, id) - pg = Vector{JuMP.NonlinearExpression}([]) - qg = Vector{JuMP.NonlinearExpression}([]) + pg = Vector{JuMP.NonlinearExpr}([]) + qg = Vector{JuMP.NonlinearExpr}([]) for (idx, c) in enumerate(connections) - push!(pg, JuMP.@NLexpression(pm.model, vr[c]*crg[c]+vi[c]*cig[c])) - push!(qg, JuMP.@NLexpression(pm.model, -vr[c]*cig[c]+vi[c]*crg[c])) + push!(pg, JuMP.@expression(pm.model, vr[c]*crg[c]+vi[c]*cig[c])) + push!(qg, JuMP.@expression(pm.model, -vr[c]*cig[c]+vi[c]*crg[c])) end if bounded @@ -775,41 +775,41 @@ function constraint_mc_generator_power_delta(pm::IVRUPowerModel, nw::Int, id::In vrg = Dict() vig = Dict() for c in connections - vrg[c] = JuMP.@NLexpression(pm.model, vr[c]-vr[next[c]]) - vig[c] = JuMP.@NLexpression(pm.model, vi[c]-vi[next[c]]) + vrg[c] = JuMP.@expression(pm.model, vr[c]-vr[next[c]]) + vig[c] = JuMP.@expression(pm.model, vi[c]-vi[next[c]]) end - pg = Vector{JuMP.NonlinearExpression}([]) - qg = Vector{JuMP.NonlinearExpression}([]) + pg = Vector{JuMP.NonlinearExpr}([]) + qg = Vector{JuMP.NonlinearExpr}([]) for c in connections - push!(pg, JuMP.@NLexpression(pm.model, vrg[c]*crg[c]+vig[c]*cig[c])) - push!(qg, JuMP.@NLexpression(pm.model, -vrg[c]*cig[c]+vig[c]*crg[c])) + push!(pg, JuMP.@expression(pm.model, vrg[c]*crg[c]+vig[c]*cig[c])) + push!(qg, JuMP.@expression(pm.model, -vrg[c]*cig[c]+vig[c]*crg[c])) end if bounded - JuMP.@NLconstraint(pm.model, [i in 1:nph], pmin[i] <= pg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], pmax[i] >= pg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) - JuMP.@NLconstraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], pmin[i] <= pg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], pmax[i] >= pg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], qmin[i] <= qg[i]) + JuMP.@constraint(pm.model, [i in 1:nph], qmax[i] >= qg[i]) end - crg_bus = Vector{JuMP.NonlinearExpression}([]) - cig_bus = Vector{JuMP.NonlinearExpression}([]) + crg_bus = Vector{JuMP.NonlinearExpr}([]) + cig_bus = Vector{JuMP.NonlinearExpr}([]) for c in conn_bus if is_triplex - push!(crg_bus, JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*crg[1])) - push!(cig_bus, JuMP.@NLexpression(pm.model, (-1.0)^(c-1)*cig[1])) + push!(crg_bus, JuMP.@expression(pm.model, (-1.0)^(c-1)*crg[1])) + push!(cig_bus, JuMP.@expression(pm.model, (-1.0)^(c-1)*cig[1])) else - push!(crg_bus, JuMP.@NLexpression(pm.model, crg[c]-crg[prev[c]])) - push!(cig_bus, JuMP.@NLexpression(pm.model, cig[c]-cig[prev[c]])) + push!(crg_bus, JuMP.@expression(pm.model, crg[c]-crg[prev[c]])) + push!(cig_bus, JuMP.@expression(pm.model, cig[c]-cig[prev[c]])) end end - pg_bus = Vector{JuMP.NonlinearExpression}([]) - qg_bus = Vector{JuMP.NonlinearExpression}([]) + pg_bus = Vector{JuMP.NonlinearExpr}([]) + qg_bus = Vector{JuMP.NonlinearExpr}([]) for (idx,c) in enumerate(conn_bus) - push!(pg_bus, JuMP.@NLexpression(pm.model, vr[c]*crg_bus[c]+vi[c]*cig_bus[c])) - push!(qg_bus, JuMP.@NLexpression(pm.model, -vr[c]*cig_bus[c]+vi[c]*crg_bus[c])) + push!(pg_bus, JuMP.@expression(pm.model, vr[c]*crg_bus[c]+vi[c]*cig_bus[c])) + push!(qg_bus, JuMP.@expression(pm.model, -vr[c]*cig_bus[c]+vi[c]*crg_bus[c])) end var(pm, nw, :crg_bus)[id] = JuMP.Containers.DenseAxisArray(crg_bus, conn_bus) diff --git a/src/form/utils.jl b/src/form/utils.jl index e426060c6..d90b83d53 100644 --- a/src/form/utils.jl +++ b/src/form/utils.jl @@ -7,8 +7,8 @@ function _merge_bus_flows(pm::ExplicitNeutralModels, flows::Vector, connections: flows_t = flows[idxs] if length(flows_t)==1 flows_merged_t = flows_t[1] - elseif any(isa(a, JuMP.NonlinearExpression) for a in flows_t) - flows_merged_t = JuMP.@NLexpression(pm.model, sum(flows_t[i] for i in 1:length(flows_t))) + elseif any(isa(a, JuMP.NonlinearExpr) for a in flows_t) + flows_merged_t = JuMP.@expression(pm.model, sum(flows_t[i] for i in 1:length(flows_t))) else flows_merged_t = sum(flows_t) end From 7d5c8972b3f35311846d1798817778eb133e3ff9 Mon Sep 17 00:00:00 2001 From: David M Fobes Date: Thu, 9 May 2024 11:01:01 -0600 Subject: [PATCH 6/6] FIX: branch power magnitude bound --- src/form/en_acr.jl | 8 ++++---- src/form/en_shared.jl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/form/en_acr.jl b/src/form/en_acr.jl index 4ab28882d..262249bb6 100644 --- a/src/form/en_acr.jl +++ b/src/form/en_acr.jl @@ -64,11 +64,11 @@ function constraint_mc_generator_power_wye(pm::AbstractExplicitNeutralACRModel, ( pg[idx]*vi_pn[idx] - qg[idx]*vr_pn[idx] )/( vr_pn[idx]^2 + vi_pn[idx]^2 ) ) pg_bus_unmerged = [ - [JuMP.@expression(pm.model, vr[p]*crg[idx]+vi[p]*cig[idx]) for (idx,p) in enumerate(phases)]..., + [JuMP.@expression(pm.model, -vr[p]*-crg[idx]-vi[p]*-cig[idx]) for (idx,p) in enumerate(phases)]..., JuMP.@expression(pm.model, vr[n]*sum(-crg[idx] for idx in 1:P)+vi[n]*sum(-cig[idx] for idx in 1:P)) ] qg_bus_unmerged = [ - [JuMP.@expression(pm.model, -vr[p]*cig[idx]+vi[p]*crg[idx]) for (idx,p) in enumerate(phases)]..., + [JuMP.@expression(pm.model, vr[p]*-cig[idx]-vi[p]*-crg[idx]) for (idx,p) in enumerate(phases)]..., JuMP.@expression(pm.model, -vr[n]*sum(-cig[idx] for idx in 1:P)+vi[n]*sum(-crg[idx] for idx in 1:P)) ] end @@ -124,8 +124,8 @@ function constraint_mc_generator_power_delta(pm::AbstractExplicitNeutralACRModel crg_bus = JuMP.@expression(pm.model, [idx in 1:P], crg[idx] - crg[idxs_prev[idx]]) cig_bus = JuMP.@expression(pm.model, [idx in 1:P], cig[idx] - cig[idxs_prev[idx]]) - pg_bus_unmerged = [JuMP.@expression(pm.model, vr[p]*crg_bus[idx]+vi[p]*cig_bus[idx]) for (idx,p) in enumerate(ph)] - qg_bus_unmerged = [JuMP.@expression(pm.model, -vr[p]*cig_bus[idx]+vi[p]*crg_bus[idx]) for (idx,p) in enumerate(ph)] + pg_bus_unmerged = [JuMP.@expression(pm.model, -vr[p]*-crg_bus[idx]-vi[p]*-cig_bus[idx]) for (idx,p) in enumerate(ph)] + qg_bus_unmerged = [JuMP.@expression(pm.model, vr[p]*-cig_bus[idx]-vi[p]*-crg_bus[idx]) for (idx,p) in enumerate(ph)] var(pm, nw, :pg_bus)[id] = pg_bus = _merge_bus_flows(pm, pg_bus_unmerged, connections) var(pm, nw, :qg_bus)[id] = qg_bus = _merge_bus_flows(pm, qg_bus_unmerged, connections) diff --git a/src/form/en_shared.jl b/src/form/en_shared.jl index 309ab7aea..dc087ba9a 100644 --- a/src/form/en_shared.jl +++ b/src/form/en_shared.jl @@ -138,7 +138,7 @@ function constraint_mc_current_balance(pm::RectangularVoltageExplicitNeutralMode + sum(crsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(crt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) == - sum(crg[g][t] for (g, conns) in bus_gens if t in conns) + - sum(-crg[g][t] for (g, conns) in bus_gens if t in conns) - sum(crs[s][t] for (s, conns) in bus_storage if t in conns) - sum(crd[d][t] for (d, conns) in bus_loads if t in conns) - sum( Gt[idx,jdx]*vr[u] -Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) # shunts @@ -148,7 +148,7 @@ function constraint_mc_current_balance(pm::RectangularVoltageExplicitNeutralMode + sum(cisw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(cit[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) == - sum(cig[g][t] for (g, conns) in bus_gens if t in conns) + - sum(-cig[g][t] for (g, conns) in bus_gens if t in conns) - sum(cis[s][t] for (s, conns) in bus_storage if t in conns) - sum(cid[d][t] for (d, conns) in bus_loads if t in conns) - sum( Gt[idx,jdx]*vi[u] +Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals) # shunts @@ -206,7 +206,7 @@ function constraint_mc_power_balance(pm::RectangularVoltageExplicitNeutralModels + sum(psw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( pt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) == - sum(pg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(-pg[gen][t] for (gen, conns) in bus_gens if t in conns) - sum(ps[strg][t] for (strg, conns) in bus_storage if t in conns) - sum(pd[load][t] for (load, conns) in bus_loads if t in conns) + ( -vr[t] * sum(Gt[idx,jdx]*vr[u]-Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) @@ -220,7 +220,7 @@ function constraint_mc_power_balance(pm::RectangularVoltageExplicitNeutralModels + sum(qsw[arc][t] for (arc, conns) in bus_arcs_sw if t in conns) + sum( qt[arc][t] for (arc, conns) in bus_arcs_trans if t in conns) == - sum(qg[gen][t] for (gen, conns) in bus_gens if t in conns) + - sum(-qg[gen][t] for (gen, conns) in bus_gens if t in conns) - sum(qd[load][t] for (load, conns) in bus_loads if t in conns) - sum(qs[strg][t] for (strg, conns) in bus_storage if t in conns) + ( vr[t] * sum(Gt[idx,jdx]*vi[u]+Bt[idx,jdx]*vr[u] for (jdx,u) in ungrounded_terminals)