Skip to content

Commit

Permalink
other error found 5
Browse files Browse the repository at this point in the history
  • Loading branch information
alefcastelli committed Aug 1, 2023
1 parent 9a9255a commit c4dde3f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/ptdf_calculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function _calculate_PTDF_matrix_KLU(
# inizialize matrices for evaluation
valid_ix = setdiff(1:buscount, ref_bus_positions)
PTDFm_t = zeros(buscount, linecount)

if !isempty(dist_slack) && length(ref_bus_positions) != 1
error(
"Distibuted slack is not supported for systems with multiple reference buses.",
Expand Down Expand Up @@ -324,23 +325,23 @@ function _calculate_PTDF_matrix_MKLPardiso(
ps = Pardiso.MKLPardisoSolver()
Pardiso.set_iparm!(ps, 59, 2)
Pardiso.set_msglvl!(ps, Pardiso.MESSAGE_LEVEL_ON)

Pardiso.solve!(ps, ABA_inv, ABA, Ix)
# inizialize matrices for evaluation
valid_ix = setdiff(1:buscount, ref_bus_positions)
PTDFm_t = zeros(buscount, linecount)
row_idx = setdiff(1:size(PTDFm_t, 1), ref_bus_positions)

if !isempty(dist_slack) && length(ref_bus_positions) != 1
error(
"Distibuted slack is not supported for systems with multiple reference buses.",
)
elseif isempty(dist_slack) && length(ref_bus_positions) < buscount
PTDFm_t[row_idx, :] = ABA_inv * @view BA[row_idx, :]
elseif isempty(dist_slack) && length(ref_bus_positions) != buscount
PTDFm_t[valid_ix, :] = ABA_inv * @view BA[valid_ix, :]
return PTDFm_t
elseif length(dist_slack) == buscount
@info "Distributed bus"
PTDFm_t[row_idx, :] = ABA_inv * @view BA[row_idx, :]
PTDFm_t[valid_ix, :] = ABA_inv * @view BA[valid_ix, :]
slack_array = dist_slack / sum(dist_slack)
slack_array = reshape(slack_array, buscount, 1)
slack_array = reshape(slack_array, 1, buscount)
return PTDFm_t - ones(buscount, 1) * (slack_array * PTDFm_t)
else
error("Distributed bus specification doesn't match the number of buses.")
Expand Down

0 comments on commit c4dde3f

Please sign in to comment.