-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/nr_pf_solver #54
base: hrgks/psse_exporter_psy4
Are you sure you want to change the base?
Conversation
…CPowerFlow, introduce KLUACPowerFlow for the use in the new NR power flow function
…nction supports KLU PF; implement tests for KLUACPowerFlow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
JuliaFormatter
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 191 to 192 in 210937c
if isapprox(Psources, P_gen; atol=0.001) && | |
isapprox(Qsources, Q_gen; atol=0.001) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 207 in 210937c
sort(collect(devices_); by=x -> _get_limits_for_power_distribution(x).max) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 229 in 210937c
if !isapprox(p_residual, 0.0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 236 in 210937c
while !isapprox(p_residual, 0.0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 258 in 210937c
if isapprox(p_residual, 0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 266 in 210937c
if !isapprox(p_residual, 0.0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 301 in 210937c
if isapprox(Qsources, Q_gen; atol=0.001) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 314 in 210937c
devices = sort(collect(devices_); by=x -> PSY.get_max_reactive_power(x)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 321 in 210937c
if isapprox(total_active_power, 0.0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 336 to 337 in 210937c
if isapprox(q_limits.max, 0.0; atol=BOUNDS_TOLERANCE) && | |
isapprox(q_limits.min, 0.0; atol=BOUNDS_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 364 in 210937c
if isapprox(q_residual, 0.0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 369 in 210937c
if !isapprox(q_residual, 0.0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 371 in 210937c
while !isapprox(q_residual, 0.0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 410 in 210937c
if isapprox(q_residual, 0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 422 in 210937c
if !isapprox(q_residual, 0.0; atol=ISAPPROX_ZERO_TOLERANCE) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 439 in 210937c
atol=ISAPPROX_ZERO_TOLERANCE, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 454 in 210937c
sort!(collect(PSY.get_components(PSY.Bus, sys)); by=x -> PSY.get_number(x)), |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 459 to 460 in 210937c
P_gen = result[2*ix-1] | |
Q_gen = result[2*ix] |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 463 to 464 in 210937c
Q_gen = result[2*ix-1] | |
bus.angle = result[2*ix] |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 467 to 468 in 210937c
Vm = result[2*ix-1] | |
θ = result[2*ix] |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 484 in 210937c
function _get_branches_buses(data::Union{PTDFPowerFlowData,vPTDFPowerFlowData}) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 516 to 524 in 210937c
bus_number=buses, | |
Vm=bus_magnitude, | |
θ=bus_angles, | |
P_gen=P_gen_vect, | |
P_load=P_load_vect, | |
P_net=P_gen_vect - P_load_vect, | |
Q_gen=Q_gen_vect, | |
Q_load=Q_load_vect, | |
Q_net=Q_gen_vect - Q_load_vect, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 529 to 537 in 210937c
line_name=branches, | |
bus_from=from_bus, | |
bus_to=to_bus, | |
P_from_to=P_from_to_vect, | |
Q_from_to=Q_from_to_vect, | |
P_to_from=P_to_from_vect, | |
Q_to_from=Q_to_from_vect, | |
P_losses=zeros(length(branches)), | |
Q_losses=zeros(length(branches)), |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 556 in 210937c
data::Union{PTDFPowerFlowData,vPTDFPowerFlowData,ABAPowerFlowData}, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 575 in 210937c
result_dict = Dict{Union{String,Char},Dict{String,DataFrames.DataFrame}}() |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 617 in 210937c
buses = sort!(collect(PSY.get_components(PSY.Bus, sys)); by=x -> PSY.get_number(x)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 637 to 638 in 210937c
P_gen_vect[ix] = result[2*ix-1] * sys_basepower | |
Q_gen_vect[ix] = result[2*ix] * sys_basepower |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 641 in 210937c
θ_vect[ix] = result[2*ix] |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Line 643 in 210937c
Q_gen_vect[ix] = result[2*ix-1] * sys_basepower |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 645 to 646 in 210937c
Vm_vect[ix] = result[2*ix-1] | |
θ_vect[ix] = result[2*ix] |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 669 to 677 in 210937c
bus_number=PSY.get_number.(buses), | |
Vm=Vm_vect, | |
θ=θ_vect, | |
P_gen=P_gen_vect, | |
P_load=P_load_vect, | |
P_net=P_gen_vect - P_load_vect, | |
Q_gen=Q_gen_vect, | |
Q_load=Q_load_vect, | |
Q_net=Q_gen_vect - Q_load_vect, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/src/post_processing.jl
Lines 681 to 689 in 210937c
line_name=PSY.get_name.(branches), | |
bus_from=PSY.get_number.(PSY.get_from.(PSY.get_arc.(branches))), | |
bus_to=PSY.get_number.(PSY.get_to.(PSY.get_arc.(branches))), | |
P_from_to=P_from_to_vect, | |
Q_from_to=Q_from_to_vect, | |
P_to_from=P_to_from_vect, | |
Q_to_from=Q_to_from_vect, | |
P_losses=P_from_to_vect + P_to_from_vect, | |
Q_losses=Q_from_to_vect + Q_to_from_vect, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 33 to 34 in 210937c
sys = PSB.build_system(PSB.PSITestSystems, "c_sys14"; add_forecasts=false) | |
data = PowerFlows.PowerFlowData(ACPowerFlow(), sys; check_connectivity=true) |
[JuliaFormatter] reported by reviewdog 🐶
@test solve_ac_powerflow!(ACPowerFlow(), sys; method=:newton) |
[JuliaFormatter] reported by reviewdog 🐶
data = PowerFlows.PowerFlowData(ACPowerFlow(), sys; check_connectivity=true) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 48 to 49 in 210937c
@testset "AC Power Flow 14-Bus Line Configurations" for ACPowerFlow in (NLSolveACPowerFlow, KLUACPowerFlow) | |
sys = PSB.build_system(PSB.PSITestSystems, "c_sys14"; add_forecasts=false) |
[JuliaFormatter] reported by reviewdog 🐶
sys = PSB.build_system(PSB.PSITestSystems, "c_sys14"; add_forecasts=false) |
[JuliaFormatter] reported by reviewdog 🐶
@test isapprox(PSY.get_magnitude(test_bus), 1.002; atol=1e-3, rtol=0) |
[JuliaFormatter] reported by reviewdog 🐶
sys = PSB.build_system(PSB.PSITestSystems, "c_sys14"; add_forecasts=false) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 82 to 83 in 210937c
@test isapprox(df["bus_results"].P_gen, p_gen_matpower_3bus, atol=1e-4) | |
@test isapprox(df["bus_results"].Q_gen, q_gen_matpower_3bus, atol=1e-4) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 86 to 87 in 210937c
@testset "AC Power Flow convergence fail testing" for ACPowerFlow in (NLSolveACPowerFlow, KLUACPowerFlow) | |
pf_sys5_re = PSB.build_system(PSB.PSITestSystems, "c_sys5_re"; add_forecasts=false) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 110 to 111 in 210937c
bus_name_formatter=x -> strip(string(x["name"])) * "-" * string(x["index"]), | |
runchecks=false, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 138 to 144 in 210937c
number=1, | |
name="01", | |
bustype=ACBusTypes.REF, | |
angle=0.0, | |
magnitude=1.1, | |
voltage_limits=(0.0, 2.0), | |
base_voltage=230, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 150 to 156 in 210937c
name="source_1", | |
available=true, | |
bus=b, | |
active_power=0.5, | |
reactive_power=0.1, | |
R_th=1e-5, | |
X_th=1e-5, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 160 to 166 in 210937c
name="source_2", | |
available=true, | |
bus=b, | |
active_power=-0.5, | |
reactive_power=-0.1, | |
R_th=1e-5, | |
X_th=1e-5, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 179 to 185 in 210937c
number=1, | |
name="01", | |
bustype=ACBusTypes.REF, | |
angle=0.0, | |
magnitude=1.1, | |
voltage_limits=(0.0, 2.0), | |
base_voltage=230, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 189 to 195 in 210937c
number=2, | |
name="02", | |
bustype=ACBusTypes.PV, | |
angle=0.0, | |
magnitude=1.1, | |
voltage_limits=(0.0, 2.0), | |
base_voltage=230, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Line 198 in 210937c
a = Arc(; from=b1, to=b2) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 201 to 210 in 210937c
name="l1", | |
available=true, | |
active_power_flow=0.0, | |
reactive_power_flow=0.0, | |
arc=a, | |
r=1e-3, | |
x=1e-3, | |
b=(from=0.0, to=0.0), | |
rating=0.0, | |
angle_limits=(min=-pi / 2, max=pi / 2), |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 216 to 222 in 210937c
name="source_1", | |
available=true, | |
bus=b1, | |
active_power=0.5, | |
reactive_power=0.1, | |
R_th=1e-5, | |
X_th=1e-5, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 226 to 232 in 210937c
name="source_2", | |
available=true, | |
bus=b2, | |
active_power=0.5, | |
reactive_power=1.1, | |
R_th=1e-5, | |
X_th=1e-5, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 236 to 242 in 210937c
name="source_3", | |
available=true, | |
bus=b2, | |
active_power=-0.5, | |
reactive_power=-1.1, | |
R_th=1e-5, | |
X_th=1e-5, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 256 to 262 in 210937c
number=1, | |
name="01", | |
bustype=ACBusTypes.REF, | |
angle=0.0, | |
magnitude=1.1, | |
voltage_limits=(0.0, 2.0), | |
base_voltage=230, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 268 to 274 in 210937c
name="source_1", | |
available=true, | |
bus=b, | |
active_power=0.5, | |
reactive_power=0.1, | |
R_th=1e-5, | |
X_th=1e-5, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 278 to 295 in 210937c
name="init", | |
available=true, | |
status=false, | |
bus=b, | |
active_power=0.1, | |
reactive_power=0.1, | |
rating=0.0, | |
active_power_limits=(min=0.0, max=0.0), | |
reactive_power_limits=nothing, | |
ramp_limits=nothing, | |
operation_cost=ThermalGenerationCost(nothing), | |
base_power=100.0, | |
time_limits=nothing, | |
prime_mover_type=PrimeMovers.OT, | |
fuel=ThermalFuels.OTHER, | |
services=Device[], | |
dynamic_injector=nothing, | |
ext=Dict{String,Any}(), |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Line 303 in 210937c
atol=0.001, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Line 308 in 210937c
atol=0.001, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 315 to 321 in 210937c
number=1, | |
name="01", | |
bustype=ACBusTypes.REF, | |
angle=0.0, | |
magnitude=1.1, | |
voltage_limits=(0.0, 2.0), | |
base_voltage=230, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 325 to 331 in 210937c
number=2, | |
name="02", | |
bustype=ACBusTypes.PV, | |
angle=0.0, | |
magnitude=1.1, | |
voltage_limits=(0.0, 2.0), | |
base_voltage=230, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Line 334 in 210937c
a = Arc(; from=b1, to=b2) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 337 to 346 in 210937c
name="l1", | |
available=true, | |
active_power_flow=0.0, | |
reactive_power_flow=0.0, | |
arc=a, | |
r=1e-3, | |
x=1e-3, | |
b=(from=0.0, to=0.0), | |
rating=0.0, | |
angle_limits=(min=-pi / 2, max=pi / 2), |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 352 to 358 in 210937c
name="source_1", | |
available=true, | |
bus=b1, | |
active_power=0.5, | |
reactive_power=0.1, | |
R_th=1e-5, | |
X_th=1e-5, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 362 to 368 in 210937c
name="source_2", | |
available=true, | |
bus=b2, | |
active_power=0.5, | |
reactive_power=1.1, | |
R_th=1e-5, | |
X_th=1e-5, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Lines 372 to 389 in 210937c
name="init", | |
available=true, | |
status=false, | |
bus=b2, | |
active_power=0.1, | |
reactive_power=0.1, | |
rating=0.0, | |
active_power_limits=(min=0.0, max=0.0), | |
reactive_power_limits=nothing, | |
ramp_limits=nothing, | |
operation_cost=ThermalGenerationCost(nothing), | |
base_power=100.0, | |
time_limits=nothing, | |
prime_mover_type=PrimeMovers.OT, | |
fuel=ThermalFuels.OTHER, | |
services=Device[], | |
dynamic_injector=nothing, | |
ext=Dict{String,Any}(), |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Line 397 in 210937c
atol=0.001, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_nlsolve_powerflow.jl
Line 402 in 210937c
atol=0.001, |
[JuliaFormatter] reported by reviewdog 🐶
sys = PSB.build_system(PSB.PSITestSystems, "c_sys14"; add_forecasts=false) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_powerflow_data.jl
Line 10 in 210937c
sys = PSB.build_system(PSB.PSITestSystems, "c_sys14"; add_forecasts=false) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_powerflow_data.jl
Lines 13 to 14 in 210937c
@test PowerFlowData(DCPowerFlow(), sys; time_steps=time_steps) isa PF.ABAPowerFlowData | |
@test PowerFlowData(PTDFDCPowerFlow(), sys; time_steps=time_steps) isa |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_powerflow_data.jl
Line 16 in 210937c
@test PowerFlowData(vPTDFDCPowerFlow(), sys; time_steps=time_steps) isa |
[JuliaFormatter] reported by reviewdog 🐶
isdir(test_psse_export_dir) && rm(test_psse_export_dir; recursive=true) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 13 in 210937c
macro log_assert(ex, comparison_name=nothing) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 27 in 210937c
default_tol=SYSTEM_REIMPORT_COMPARISON_TOLERANCE; |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 41 in 210937c
all(isapprox.(col1, col2; atol=my_tol)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 55 in 210937c
default_tol=SYSTEM_REIMPORT_COMPARISON_TOLERANCE; |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 67 in 210937c
isapprox(a, b; atol=SYSTEM_REIMPORT_COMPARISON_TOLERANCE) || IS.isequivalent(a, b) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 71 in 210937c
bus_name_mapping=Dict{String,String}(), |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 73 in 210937c
include_types=[ |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 86 in 210937c
exclude_fields=Set([ |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 93 in 210937c
exclude_fields_for_type=Dict( |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 114 in 210937c
generator_comparison_fns=[ # TODO rating |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Lines 121 to 123 in 210937c
ignore_name_order=true, | |
ignore_extra_of_type=Union{PSY.ThermalStandard,PSY.StaticLoad}, | |
exclude_reactive_power=false) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 132 in 210937c
result &= IS.compare_values(sys1, sys2; exclude=[:data]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 181 in 210937c
exclude=my_excludes, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 192 in 210937c
GenSource = Union{Generator,Source} |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 208 in 210937c
any(Union{typeof(gen1),typeof(gen2)} .<: include_types) && continue |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 214 in 210937c
exclude=exclude_fields, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 225 in 210937c
function test_power_flow(sys1::System, sys2::System; exclude_reactive_flow=false) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Lines 235 to 236 in 210937c
POWERFLOW_COMPARISON_TOLERANCE; line_name=nothing, Q_to_from=reactive_power_tol, | |
Q_from_to=reactive_power_tol, Q_losses=reactive_power_tol) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Lines 253 to 254 in 210937c
do_power_flow_test=true, | |
exclude_reactive_flow=false, |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 268 in 210937c
test_power_flow(sys, sys2; exclude_reactive_flow=exclude_reactive_flow) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 277 in 210937c
exclude_metadata_keys=["case_name"], |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 332 in 210937c
exclude_reactive_flow=true) # TODO why is reactive flow not matching? |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 363 in 210937c
test_power_flow(sys2, reread_sys2; exclude_reactive_flow=true) # TODO why is reactive flow not matching? |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 377 in 210937c
exclude_reactive_flow=true) # TODO why is reactive flow not matching? |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 407 in 210937c
test_power_flow(sys2, reread_sys2; exclude_reactive_flow=true) # TODO why is reactive flow not matching? |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 420 in 210937c
exclude_reactive_power=true) # TODO why is reactive power not matching? |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 424 in 210937c
test_power_flow(sys2, reread_sys3; exclude_reactive_flow=true) # TODO why is reactive flow not matching? |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 427 in 210937c
exporter = PSSEExporter(sys, :v33, export_location; write_comments=true) |
[JuliaFormatter] reported by reviewdog 🐶
PowerFlows.jl/test/test_psse_export.jl
Line 429 in 210937c
exclude_reactive_flow=true) # TODO why is reactive flow not matching? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few initial comments. I'll dig into the math more later. Thanks!
@@ -4,7 +4,8 @@ export solve_powerflow | |||
export solve_ac_powerflow! | |||
export PowerFlowData | |||
export DCPowerFlow | |||
export ACPowerFlow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For backwards compatibility, we may want something like
const ACPowerFlow = NLSolveACPowerFlow
somewhere.
src/nlsolve_ac_powerflow.jl
Outdated
write_powerflow_solution!(system, res.zero, max_iterations) | ||
converged, x = _solve_powerflow!(pf, data, check_reactive_power_limits; kwargs...) | ||
if converged | ||
write_powerflow_solution!(system, x, max_iterations) | ||
@info("PowerFlow solve converged, the results have been stored in the system") | ||
#Restore original per unit base | ||
PSY.set_units_base_system!(system, settings_unit_cache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily your responsibility but just flagging that this is a good use case for
PowerFlows.jl/src/psse_export.jl
Line 47 in 465e92f
function with_units(f::Function, sys::System, units::Union{PSY.UnitSystem, String}) |
src/nlsolve_ac_powerflow.jl
Outdated
# Find indices for each bus type | ||
ref = findall(x -> x == PowerSystems.ACBusTypesModule.ACBusTypes.REF, data.bus_type) | ||
pv = findall(x -> x == PowerSystems.ACBusTypesModule.ACBusTypes.PV, data.bus_type) | ||
pq = findall(x -> x == PowerSystems.ACBusTypesModule.ACBusTypes.PQ, data.bus_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably no significant difference, but note that these three lines could be combined to only iterate over the bus types once
src/nlsolve_ac_powerflow.jl
Outdated
J = [j11 j12; j21 j22] | ||
|
||
factor_J = KLU.klu(J) | ||
dx = -(factor_J \ F) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment from José: do this and previous two lines in place using functor approach
src/newton_ac_powerflow.jl
Outdated
j12 = real(dSbus_dVm[[pv; pq], pq]) | ||
j21 = imag(dSbus_dVa[pq, [pv; pq]]) | ||
j22 = imag(dSbus_dVm[pq, pq]) | ||
J = [j11 j12; j21 j22] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave note that we shouldn't allocate J every time
src/newton_ac_powerflow.jl
Outdated
Va = angle.(V) | ||
|
||
mis = V .* conj(Ybus * V) - Sbus | ||
F = [real(mis[[pv; pq]]); imag(mis[pq])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be changed to not allocating
src/newton_ac_powerflow.jl
Outdated
diagV = LinearAlgebra.Diagonal(V) | ||
diagIbus = LinearAlgebra.Diagonal(Ybus * V) | ||
diagVnorm = LinearAlgebra.Diagonal(V ./ abs.(V)) | ||
dSbus_dVm = diagV * conj(Ybus * diagVnorm) + conj(diagIbus) * diagVnorm | ||
dSbus_dVa = 1im * diagV * conj(diagIbus - Ybus * diagV) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this code should be non allocating
src/newton_ac_powerflow.jl
Outdated
1im * (data.bus_reactivepower_injection[:] - data.bus_reactivepower_withdrawals[:]) | ||
|
||
mis = V .* conj(Ybus * V) - Sbus | ||
F = [real(mis[[pv; pq]]); imag(mis[pq])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be not allocating
@@ -406,3 +433,23 @@ end | |||
atol = 0.001, | |||
) | |||
end | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
pf_default = ACPowerFlow() | ||
pf_klu = ACPowerFlow(KLUACPowerFlow) | ||
pf_nlsolve = ACPowerFlow(NLSolveACPowerFlow) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
res_klu = solve_powerflow(pf_klu, sys) | ||
res_nlsolve = solve_powerflow(pf_nlsolve, sys) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
@test all( | |
isapprox.( | |
res_klu["bus_results"][!, :Vm], | |
res_default["bus_results"][!, :Vm], | |
rtol = 0, | |
atol = 1e-12, | |
), | |
) | |
@test all( | |
isapprox.( | |
res_klu["bus_results"][!, :θ], | |
res_default["bus_results"][!, :θ], | |
rtol = 0, | |
atol = 1e-12, | |
), | |
) | |
@test all(isapprox.(res_klu["bus_results"][!, :Vm], res_default["bus_results"][!, :Vm], rtol=0, atol=1e-12)) | ||
@test all(isapprox.(res_klu["bus_results"][!, :θ], res_default["bus_results"][!, :θ], rtol=0, atol=1e-12)) | ||
|
||
@test all(isapprox.(res_klu["bus_results"][!, :Vm], res_nlsolve["bus_results"][!, :Vm], rtol=0, atol=1e-8)) | ||
@test all(isapprox.(res_klu["bus_results"][!, :θ], res_nlsolve["bus_results"][!, :θ], rtol=0, atol=1e-8)) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
@test all(isapprox.(res_klu["bus_results"][!, :Vm], res_default["bus_results"][!, :Vm], rtol=0, atol=1e-12)) | |
@test all(isapprox.(res_klu["bus_results"][!, :θ], res_default["bus_results"][!, :θ], rtol=0, atol=1e-12)) | |
@test all(isapprox.(res_klu["bus_results"][!, :Vm], res_nlsolve["bus_results"][!, :Vm], rtol=0, atol=1e-8)) | |
@test all(isapprox.(res_klu["bus_results"][!, :θ], res_nlsolve["bus_results"][!, :θ], rtol=0, atol=1e-8)) | |
end | |
@test all( | |
isapprox.( | |
res_klu["bus_results"][!, :Vm], | |
res_nlsolve["bus_results"][!, :Vm], | |
rtol = 0, | |
atol = 1e-8, | |
), | |
) | |
@test all( | |
isapprox.( | |
res_klu["bus_results"][!, :θ], | |
res_nlsolve["bus_results"][!, :θ], | |
rtol = 0, | |
atol = 1e-8, | |
), | |
) | |
end |
|
||
F = zeros(Float64, npvpq + npq) | ||
F_real = view(F, 1:npvpq) | ||
F_imag = view(F, npvpq + 1:npvpq + npq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
F_imag = view(F, npvpq + 1:npvpq + npq) | |
F_imag = view(F, (npvpq + 1):(npvpq + npq)) |
rows = vcat(1:npvpq, 1:npvpq, npvpq+1:npvpq+npq, npvpq+1:npvpq+npq) | ||
cols = vcat(1:npvpq, npvpq+1:npvpq+npq, 1:npvpq, npvpq+1:npvpq+npq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
rows = vcat(1:npvpq, 1:npvpq, npvpq+1:npvpq+npq, npvpq+1:npvpq+npq) | |
cols = vcat(1:npvpq, npvpq+1:npvpq+npq, 1:npvpq, npvpq+1:npvpq+npq) | |
rows = vcat(1:npvpq, 1:npvpq, (npvpq + 1):(npvpq + npq), (npvpq + 1):(npvpq + npq)) | |
cols = vcat(1:npvpq, (npvpq + 1):(npvpq + npq), 1:npvpq, (npvpq + 1):(npvpq + npq)) |
Sbus = | ||
data.bus_activepower_injection[:] - data.bus_activepower_withdrawals[:] + | ||
1im * (data.bus_reactivepower_injection[:] - data.bus_reactivepower_withdrawals[:]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
j12 = view(J, pvpq_lookup[pvpq], npvpq .+ pq_lookup[pq]) | ||
j21 = view(J, npvpq .+ pq_lookup[pq], pvpq_lookup[pvpq]) | ||
j22 = view(J, npvpq .+ pq_lookup[pq], npvpq .+ pq_lookup[pq]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
|
||
while i < maxIter && !converged | ||
i += 1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
F_imag = view(F, npvpq + 1:npvpq + npq) | ||
|
||
mis .= V .* conj.(Ybus * V) .- Sbus | ||
@. F_real = real(mis_pvpq) # In-place assignment to the real part, using views |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rbolgaryn I think you are overwriting F_real here. You might want to try F_real[:] =
Integrate the implementation of the Newton-Raphson Power Flow calculation leveraging KLU factorization