Skip to content

Update compat to PowerFlows.jl v0.9.0 #400

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ ForwardDiff = "~v0.10"
InfrastructureSystems = "2"
NLsolve = "4"
PowerSystems = "4"
PowerFlows = "^0.7"
PowerNetworkMatrices = "^0.11"
PowerFlows = "^0.9"
PowerNetworkMatrices = "^0.12.1"
PrettyTables = "1, 2"
SciMLBase = "2"
TimerOutputs = "~0.5"
Expand Down
6 changes: 4 additions & 2 deletions docs/src/tutorials/tutorial_continuation_pf.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ for p in P_range
q_power = power * tan(acos(load_pf))
set_reactive_power!(load, q_power)
# Run Power Flow
status = solve_ac_powerflow!(sys_static)
pf = ACPowerFlow()
status = solve_powerflow!(pf, sys_static)
if !status
# Finish the loop if the power flow fails
print("Power Flow failed at p = $(power)")
Expand Down Expand Up @@ -143,7 +144,8 @@ for p in P_range
q_power = power * tan(acos(load_pf))
set_reactive_power!(load, q_power)
# Run Power Flow
status = solve_ac_powerflow!(sys_static)
pf = ACPowerFlow()
status = solve_powerflow!(pf, sys_static)
if !status
# Finish the loop if the power flow fails
print("Power Flow failed at p = $(power)")
Expand Down
1 change: 1 addition & 0 deletions src/base/nlsolve_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function _check_residual(
Generator = $gen_name, state = $state.
Residual error is too large to continue")
else
bus_count = get_bus_count(inputs)
bus_no = ix > bus_count ? ix - bus_count : ix
component = ix > bus_count ? "imag" : "real"
error("The initial residual in the state located at $ix has a value of $val.
Expand Down
3 changes: 2 additions & 1 deletion src/base/simulation_initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function power_flow_solution!(
sys::PSY.System,
inputs::SimulationInputs,
)
res = PF.solve_ac_powerflow!(sys)
pf = PF.ACPowerFlow()
res = PF.solve_powerflow!(pf, sys)
if !res
@error("PowerFlow failed to solve")
return BUILD_FAILED
Expand Down
13 changes: 10 additions & 3 deletions src/base/simulation_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ function post_proc_state_series(
)
global_state_index = get_global_index(res)
if !haskey(global_state_index, ref[1])
@error "$(keys(global_state_index))"
error("State $(ref[2]) device $(ref[1]) not found in the system. ")
available_devices = join(keys(global_state_index), ", ")
error("Device $(ref[1]) not found. Available devices: $available_devices")
end
ix = get(global_state_index[ref[1]], ref[2], 0)

state_dict = global_state_index[ref[1]]
if !haskey(state_dict, ref[2])
available_states = join(keys(state_dict), ", ")
error("State $(ref[2]) not found in device $(ref[1]). Available states: $available_states")
end

ix = state_dict[ref[2]]
return _post_proc_state_series(get_solution(res), ix, dt, unique_timestamps)
end

Expand Down
27 changes: 15 additions & 12 deletions src/post_processing/post_proc_generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# TODO: This will not plot correctly when changing P_ref in a callback
ts, _ = _post_proc_state_series(res.solution, 1, dt, unique_timestamps)
Expand All @@ -1038,7 +1038,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# Get params
Tc = PSY.get_Tc(tg)
Expand Down Expand Up @@ -1067,7 +1067,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# TODO: This will not plot correctly when changing P_ref in a callback
# Get params
Expand Down Expand Up @@ -1097,7 +1097,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# TODO: This will not plot correctly when changing P_ref in a callback
# Get params
Expand Down Expand Up @@ -1133,7 +1133,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# Get params
D_turb = PSY.get_D_turb(tg)
Expand All @@ -1154,6 +1154,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64},
unique_timestamps::Bool = true,
)
ts, x_a3 = post_proc_state_series(res, (name, :x_a3), dt, unique_timestamps)
return ts, x_a3
Expand All @@ -1167,7 +1168,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool,
unique_timestamps::Bool = true,
)
# Get params
q_nl = PSY.get_q_nl(tg)
Expand All @@ -1194,6 +1195,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool = true,
)
# Get params
D_turb = PSY.get_D_turb(tg)
Expand All @@ -1204,9 +1206,9 @@ function _mechanical_torque(
setpoints = get_setpoints(res)
ω_ref = setpoints[name]["ω_ref"]
# Get state results
ts, x_g7 = post_proc_state_series(res, (name, :x_g7), dt)
_, x_g6 = post_proc_state_series(res, (name, :x_g6), dt)
_, ω = post_proc_state_series(res, (name, :ω), dt)
ts, x_g7 = post_proc_state_series(res, (name, :x_g7), dt, unique_timestamps)
_, x_g6 = post_proc_state_series(res, (name, :x_g6), dt, unique_timestamps)
_, ω = post_proc_state_series(res, (name, :ω), dt, unique_timestamps)
Pe = similar(x_g7)
for (ix, x7) in enumerate(x_g7)
x6 = x_g6[ix]
Expand All @@ -1225,6 +1227,7 @@ function _mechanical_torque(
name::String,
res::SimulationResults,
dt::Union{Nothing, Float64, Vector{Float64}},
unique_timestamps::Bool = true,
)
# Get params
D = PSY.get_D(tg)
Expand All @@ -1235,9 +1238,9 @@ function _mechanical_torque(
ω_ref = setpoints[name]["ω_ref"]

# Get state results
ts, x_g7 = post_proc_state_series(res, (name, :x_g7), dt)
_, x_g6 = post_proc_state_series(res, (name, :x_g6), dt)
_, ω = post_proc_state_series(res, (name, :ω), dt)
ts, x_g7 = post_proc_state_series(res, (name, :x_g7), dt, unique_timestamps)
_, x_g6 = post_proc_state_series(res, (name, :x_g6), dt, unique_timestamps)
_, ω = post_proc_state_series(res, (name, :ω), dt, unique_timestamps)
Pm = similar(x_g7)

for (ix, x7) in enumerate(x_g7)
Expand Down
3 changes: 2 additions & 1 deletion test/test_case_5shaft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ The fault disconnects a circuit between buses 1 and 2, doubling its impedance.
##################################################

threebus_sys = build_system(PSIDTestSystems, "psid_test_threebus_5shaft")
solve_ac_powerflow!(threebus_sys)
pf = ACPowerFlow()
solve_powerflow!(pf, threebus_sys)
Ybus_fault = get_ybus_fault_threebus_sys(threebus_sys)

##################################################
Expand Down
3 changes: 2 additions & 1 deletion test/test_case_anderson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ and the generator located in bus 3.
##################################################

threebus_sys = build_system(PSIDTestSystems, "psid_test_threebus_anderson")
solve_ac_powerflow!(threebus_sys)
pf = ACPowerFlow()
solve_powerflow!(pf, threebus_sys)
Ybus_fault = get_ybus_fault_threebus_sys(threebus_sys)

##################################################
Expand Down
3 changes: 2 additions & 1 deletion test/test_case_marconato.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ and the generator located in bus 3.
##################################################

threebus_sys = build_system(PSIDTestSystems, "psid_test_threebus_marconato")
solve_ac_powerflow!(threebus_sys)
pf = ACPowerFlow()
solve_powerflow!(pf, threebus_sys)
Ybus_fault = get_ybus_fault_threebus_sys(threebus_sys)

##################################################
Expand Down
3 changes: 2 additions & 1 deletion test/test_case_oneDoneQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ and the generator located in bus 3.
##################################################

threebus_sys = build_system(PSIDTestSystems, "psid_test_threebus_oneDoneQ")
solve_ac_powerflow!(threebus_sys)
pf = ACPowerFlow()
solve_powerflow!(pf, threebus_sys)
Ybus_fault = get_ybus_fault_threebus_sys(threebus_sys)

##################################################
Expand Down
3 changes: 2 additions & 1 deletion test/test_case_simple_anderson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ and the generator located in bus 3.
##################################################

threebus_sys = build_system(PSIDTestSystems, "psid_test_threebus_simple_anderson")
solve_ac_powerflow!(threebus_sys)
pf = ACPowerFlow()
solve_powerflow!(pf, threebus_sys)
Ybus_fault = get_ybus_fault_threebus_sys(threebus_sys)

##################################################
Expand Down
3 changes: 2 additions & 1 deletion test/test_case_simple_marconato.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ and the generator located in bus 3.
##################################################

threebus_sys = build_system(PSIDTestSystems, "psid_test_threebus_simple_marconato")
solve_ac_powerflow!(threebus_sys)
pf = ACPowerFlow()
solve_powerflow!(pf, threebus_sys)
Ybus_fault = get_ybus_fault_threebus_sys(threebus_sys)

##################################################
Expand Down
Loading