From d688b5856c87a8457c27aec17e3dd6c3e37fc749 Mon Sep 17 00:00:00 2001 From: Roman Bolgaryn Date: Wed, 8 Jan 2025 15:41:33 -0700 Subject: [PATCH] vectorized update for dSbus_dV --- src/newton_ac_powerflow.jl | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/newton_ac_powerflow.jl b/src/newton_ac_powerflow.jl index b47472c..231e900 100644 --- a/src/newton_ac_powerflow.jl +++ b/src/newton_ac_powerflow.jl @@ -278,20 +278,21 @@ function _update_dSbus_dV!(rows::Vector{Int64}, cols::Vector{Int64}, #dSbus_dVa .*= 1im LinearAlgebra.mul!(dSbus_dVa, dSbus_dVa, 1im) - for c in cols - for r in rows - r_dSbus_dVa[r, c] = real(dSbus_dVa[r, c]) - i_dSbus_dVa[r, c] = imag(dSbus_dVa[r, c]) - r_dSbus_dVm[r, c] = real(dSbus_dVm[r, c]) - i_dSbus_dVm[r, c] = imag(dSbus_dVm[r, c]) - end - end + # this loop is slower so we should use vectorize assignments below + # for c in cols + # for r in rows + # r_dSbus_dVa[r, c] = real(dSbus_dVa[r, c]) + # i_dSbus_dVa[r, c] = imag(dSbus_dVa[r, c]) + # r_dSbus_dVm[r, c] = real(dSbus_dVm[r, c]) + # i_dSbus_dVm[r, c] = imag(dSbus_dVm[r, c]) + # end + # end # sometimes can allocate so we have to use the for loop above - # r_dSbus_dVa .= real.(dSbus_dVa) - # r_dSbus_dVm .= real.(dSbus_dVm) - # i_dSbus_dVa .= imag.(dSbus_dVa) - # i_dSbus_dVm .= imag.(dSbus_dVm) + r_dSbus_dVa .= real.(dSbus_dVa) + r_dSbus_dVm .= real.(dSbus_dVm) + i_dSbus_dVa .= imag.(dSbus_dVa) + i_dSbus_dVm .= imag.(dSbus_dVm) return end