Skip to content
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

PSSE Exporter Part 2: Integrate with PowerSimulations #48

Merged
merged 24 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fed60b7
add abstract type
jd-lara Jan 9, 2024
e800a44
add branch types for the PowerFlowData
jd-lara Jan 9, 2024
ff4f38b
time_step clean up
jd-lara Jan 9, 2024
c6403f6
add methods and types
jd-lara Jan 23, 2024
501cc1b
add clear method
jd-lara Jan 25, 2024
0d6dd66
Do not copy time series when `deepcopy`ing for PSS/E export
GabrielKS Aug 26, 2024
73520f3
Reduce arguments to `write_export`
GabrielKS Sep 4, 2024
ced32c2
Add optional extra data to `PowerFlowData`
GabrielKS Sep 4, 2024
7fcc58c
Factor out egregious `PowerFlowData` constructor code duplication
GabrielKS Sep 4, 2024
1a5713d
Add overwrite option to PSS/E export
GabrielKS Oct 15, 2024
e1ac7fb
Create a `PSSEExportPowerFlow` `PowerFlowData` using `extra_data`
GabrielKS Oct 15, 2024
410b4c0
Fix `clear_injection_data!` bug, other minor code cleanup
GabrielKS Oct 15, 2024
abcc444
Create `PowerFlowContainer` type hierarchy, supporting infrastructure
GabrielKS Oct 15, 2024
c505394
Remove `extra_data` from `PowerFlowData`
GabrielKS Oct 15, 2024
d19fe48
Make `PowerFlowData` tests actually test something
GabrielKS Oct 15, 2024
95225a2
`PSSEExporter`: Add `name`, `step`, and `overwrite` fields
GabrielKS Oct 17, 2024
d4f1a91
Better accommodate multi period in PSS/E export
GabrielKS Oct 28, 2024
57ebcf5
Misc code cleanup following self-review
GabrielKS Oct 28, 2024
d42a9eb
Minor test fixes
GabrielKS Nov 1, 2024
700c104
Implement `get_total_p`, `q` for `InterruptiblePowerLoad`
GabrielKS Nov 4, 2024
31f5156
Exporter: allow for null area, load zone
GabrielKS Nov 4, 2024
147a94d
Strictly specify `vPTDFPowerFlowData`, fix bug 50
GabrielKS Nov 5, 2024
cdcabee
Add detail to `deepcopy_system_no_time_series`
GabrielKS Nov 5, 2024
8b8af1f
Gracefully skip tests when file is missing
GabrielKS Nov 5, 2024
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
448 changes: 150 additions & 298 deletions src/PowerFlowData.jl

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/PowerFlows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export DCPowerFlow
export ACPowerFlow
export PTDFDCPowerFlow
export vPTDFDCPowerFlow
export PSSEExportPowerFlow
export write_results
export PSSEExporter
export update_exporter!
Expand All @@ -33,12 +34,12 @@ include("common.jl")
include("definitions.jl")
include("powerflow_types.jl")
include("PowerFlowData.jl")
include("psse_export.jl")
include("solve_dc_powerflow.jl")
include("ac_power_flow.jl")
include("ac_power_flow_jacobian.jl")
include("nlsolve_ac_powerflow.jl")
include("post_processing.jl")
include("psse_export.jl")

# Old PSSE Exporter
import DataFrames: DataFrame
Expand Down
148 changes: 133 additions & 15 deletions src/common.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
function get_total_p(l::PSY.PowerLoad)
return PSY.get_active_power(l)
end

function get_total_q(l::PSY.PowerLoad)
return PSY.get_reactive_power(l)
end
_SingleComponentLoad = Union{PSY.PowerLoad, PSY.ExponentialLoad, PSY.InterruptiblePowerLoad}
get_total_p(l::_SingleComponentLoad) = PSY.get_active_power(l)
get_total_q(l::_SingleComponentLoad) = PSY.get_reactive_power(l)

function get_total_p(l::PSY.StandardLoad)
return PSY.get_constant_active_power(l) +
Expand All @@ -18,14 +14,6 @@ function get_total_q(l::PSY.StandardLoad)
PSY.get_impedance_reactive_power(l)
end

function get_total_p(l::PSY.ExponentialLoad)
return PSY.get_active_power(l)
end

function get_total_q(l::PSY.ExponentialLoad)
return PSY.get_reactive_power(l)
end

function _get_injections!(
bus_activepower_injection::Vector{Float64},
bus_reactivepower_injection::Vector{Float64},
Expand Down Expand Up @@ -116,3 +104,133 @@ function my_mul_mt(
end
return y
end

function make_dc_powerflowdata(
sys,
time_steps,
timestep_names,
power_network_matrix,
aux_network_matrix,
n_buses,
n_branches,
bus_lookup,
branch_lookup,
temp_bus_map,
valid_ix,
)
branch_types = Vector{DataType}(undef, length(branch_lookup))
for (ix, b) in enumerate(PNM.get_ac_branches(sys))
branch_types[ix] = typeof(b)
end
bus_reactivepower_bounds = Vector{Vector{Float64}}()
timestep_map = Dict(zip([i for i in 1:time_steps], timestep_names))
neighbors = Vector{Set{Int}}()
return make_powerflowdata(
sys,
time_steps,
power_network_matrix,
aux_network_matrix,
n_buses,
n_branches,
bus_lookup,
branch_lookup,
temp_bus_map,
branch_types,
bus_reactivepower_bounds,
timestep_map,
valid_ix,
neighbors,
)
end

function make_powerflowdata(
sys,
time_steps,
power_network_matrix,
aux_network_matrix,
n_buses,
n_branches,
bus_lookup,
branch_lookup,
temp_bus_map,
branch_types,
bus_reactivepower_bounds,
timestep_map,
valid_ix,
neighbors,
)
# TODO: bus_type might need to also be a Matrix since the type can change for a particular scenario
bus_type = Vector{PSY.ACBusTypes}(undef, n_buses)
GabrielKS marked this conversation as resolved.
Show resolved Hide resolved
bus_angles = zeros(Float64, n_buses)
bus_magnitude = zeros(Float64, n_buses)

_initialize_bus_data!(
bus_type,
bus_angles,
bus_magnitude,
temp_bus_map,
bus_lookup,
sys,
)

# define injection vectors related to the first timestep
bus_activepower_injection = zeros(Float64, n_buses)
bus_reactivepower_injection = zeros(Float64, n_buses)
_get_injections!(
bus_activepower_injection,
bus_reactivepower_injection,
bus_lookup,
sys,
)

bus_activepower_withdrawals = zeros(Float64, n_buses)
bus_reactivepower_withdrawals = zeros(Float64, n_buses)
_get_withdrawals!(
bus_activepower_withdrawals,
bus_reactivepower_withdrawals,
bus_lookup,
sys,
)

# initialize data
init_1 = zeros(n_buses, time_steps)
init_2 = zeros(n_branches, time_steps)

# define fields as matrices whose number of columns is eqault to the number of time_steps
bus_activepower_injection_1 = deepcopy(init_1)
bus_reactivepower_injection_1 = deepcopy(init_1)
bus_activepower_withdrawals_1 = deepcopy(init_1)
bus_reactivepower_withdrawals_1 = deepcopy(init_1)
bus_magnitude_1 = deepcopy(init_1)
bus_angles_1 = deepcopy(init_1)
branch_flow_values_1 = deepcopy(init_2)

# initial values related to first timestep allocated in the first column
bus_activepower_injection_1[:, 1] .= bus_activepower_injection
bus_reactivepower_injection_1[:, 1] .= bus_reactivepower_injection
bus_activepower_withdrawals_1[:, 1] .= bus_activepower_withdrawals
bus_reactivepower_withdrawals_1[:, 1] .= bus_reactivepower_withdrawals
bus_magnitude_1[:, 1] .= bus_magnitude
bus_angles_1[:, 1] .= bus_angles
branch_flow_values_1[:, 1] .= zeros(n_branches)

return PowerFlowData(
bus_lookup,
branch_lookup,
bus_activepower_injection_1,
bus_reactivepower_injection_1,
bus_activepower_withdrawals_1,
bus_reactivepower_withdrawals_1,
bus_reactivepower_bounds,
bus_type,
branch_types,
bus_magnitude_1,
bus_angles_1,
branch_flow_values_1,
timestep_map,
valid_ix,
power_network_matrix,
aux_network_matrix,
neighbors,
)
end
4 changes: 2 additions & 2 deletions src/post_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ end
"""
Modify the values in the given `System` to correspond to the given `PowerFlowData` such that
if a new `PowerFlowData` is constructed from the resulting system it is the same as `data`.
See also `write_powerflow_solution!`.
See also `write_powerflow_solution!`. NOTE that this assumes that `data` was initialized
from `sys` and then solved with no further modifications.
"""
function update_system!(sys::PSY.System, data::PowerFlowData)
for bus in PSY.get_components(PSY.Bus, sys)
Expand All @@ -719,5 +720,4 @@ function update_system!(sys::PSY.System, data::PowerFlowData)
PSY.set_angle!(bus, data.bus_angles[data.bus_lookup[PSY.get_number(bus)]])
end
end
# TODO
end
16 changes: 12 additions & 4 deletions src/powerflow_types.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
Base.@kwdef struct ACPowerFlow
abstract type PowerFlowEvaluationModel end

Base.@kwdef struct ACPowerFlow <: PowerFlowEvaluationModel
check_reactive_power_limits::Bool = false
end

struct DCPowerFlow end
struct PTDFDCPowerFlow end
struct vPTDFDCPowerFlow end
struct DCPowerFlow <: PowerFlowEvaluationModel end
struct PTDFDCPowerFlow <: PowerFlowEvaluationModel end
struct vPTDFDCPowerFlow <: PowerFlowEvaluationModel end

Base.@kwdef struct PSSEExportPowerFlow <: PowerFlowEvaluationModel
psse_version::Symbol
export_dir::AbstractString
write_comments::Bool = false
end
Loading
Loading