Skip to content

Commit 6100ee7

Browse files
committed
remove repeated computation of va expressions in branch flow expressions
1 parent bbf1c8d commit 6100ee7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/core/expression_template.jl

+12-4
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ function expression_branch_flow_from(pm::AbstractPowerModel, i::Int; nw::Int=pm.
9595
if haskey(branch, "rate_a")
9696
#sm_inv = ref(pm, nw, :sm_inv)
9797
sm = ref(pm, nw, :sm)
98-
expression_voltage(pm, nw, cnd, f_bus, sm)
99-
expression_voltage(pm, nw, cnd, t_bus, sm)
98+
if !haskey(var(pm, nw, cnd, :va), f_bus)
99+
expression_voltage(pm, nw, cnd, f_bus, sm)
100+
end
101+
if !haskey(var(pm, nw, cnd, :va), t_bus)
102+
expression_voltage(pm, nw, cnd, t_bus, sm)
103+
end
100104

101105
expression_branch_flow_from(pm, nw, cnd, f_bus, t_bus, f_idx, t_idx, g[cnd,cnd], b[cnd,cnd], g_fr, b_fr, tr[cnd], ti[cnd], tm)
102106
end
@@ -134,8 +138,12 @@ function expression_branch_flow_to(pm::AbstractPowerModel, i::Int; nw::Int=pm.cn
134138
if haskey(branch, "rate_a")
135139
#sm_inv = ref(pm, nw, :sm_inv)
136140
sm = ref(pm, nw, :sm)
137-
expression_voltage(pm, nw, cnd, f_bus, sm)
138-
expression_voltage(pm, nw, cnd, t_bus, sm)
141+
if !haskey(var(pm, nw, cnd, :va), f_bus)
142+
expression_voltage(pm, nw, cnd, f_bus, sm)
143+
end
144+
if !haskey(var(pm, nw, cnd, :va), t_bus)
145+
expression_voltage(pm, nw, cnd, t_bus, sm)
146+
end
139147

140148
expression_branch_flow_to(pm, nw, cnd, f_bus, t_bus, f_idx, t_idx, g[cnd,cnd], b[cnd,cnd], g_to, b_to, tr[cnd], ti[cnd], tm)
141149
end

0 commit comments

Comments
 (0)