Skip to content

Commit

Permalink
Create PowerFlowContainer type hierarchy, supporting infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Oct 15, 2024
1 parent be3b467 commit 1605f14
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
33 changes: 32 additions & 1 deletion src/PowerFlowData.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
abstract type PowerFlowContainer end

"A `PowerFlowContainer` that represents its data as a `PSY.System`"
abstract type SystemPowerFlowContainer <: PowerFlowContainer end

get_system(container::SystemPowerFlowContainer) = container.system

"""
Structure containing all the data required for the evaluation of the power
flows and angles, as well as these ones.
Expand Down Expand Up @@ -52,7 +59,7 @@ struct PowerFlowData{
M <: Union{PNM.PowerNetworkMatrix, Nothing},
N <: Union{PNM.PowerNetworkMatrix, Nothing},
E,
}
} <: PowerFlowContainer
bus_lookup::Dict{Int, Int}
branch_lookup::Dict{String, Int}
bus_activepower_injection::Matrix{Float64}
Expand Down Expand Up @@ -468,3 +475,27 @@ function PowerFlowData(
)
return data
end

"""
Create an appropriate `PowerFlowContainer` for the given `PowerFlowEvaluationModel` and initialize it from the given `PSY.System`.
# Arguments:
- `pfem::PowerFlowEvaluationModel`: power flow model to construct a container for (e.g., `DCPowerFlow()`)
- `sys::PSY.System`: the system from which to initialize the power flow container
- `time_steps::Int`: number of time periods to consider (default is `1`)
- `timestep_names::Vector{String}`: names of the time periods defines by the argument "time_steps". Default value is `String[]`.
- `check_connectivity::Bool`: Perform connectivity check on the network matrix. Default value is `true`.
"""
function make_power_flow_container end

make_power_flow_container(pfem::ACPowerFlow, sys::PSY.System; kwargs...) =
PowerFlowData(pfem, sys; kwargs...)

make_power_flow_container(pfem::DCPowerFlow, sys::PSY.System; kwargs...) =
PowerFlowData(pfem, sys; kwargs...)

make_power_flow_container(pfem::PTDFDCPowerFlow, sys::PSY.System; kwargs...) =
PowerFlowData(pfem, sys; kwargs...)

make_power_flow_container(pfem::vPTDFDCPowerFlow, sys::PSY.System; kwargs...) =
PowerFlowData(pfem, sys; kwargs...)
13 changes: 10 additions & 3 deletions src/psse_export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ using `update_exporter` with any new data as relevant, and perform the export wi
- `write_comments::Bool`: whether to add the customary-but-not-in-spec-annotations after a
slash on the first line and at group boundaries
"""
mutable struct PSSEExporter
# Internal fields are very much subject to change as I iterate on the best way to do
# this! For instance, the final version will almost certainly not store an entire System
mutable struct PSSEExporter <: SystemPowerFlowContainer
system::PSY.System
psse_version::Symbol
export_dir::AbstractString
Expand Down Expand Up @@ -1053,3 +1051,12 @@ function PSY.System(raw_path::AbstractString, md::Dict)
# TODO remap everything else! Should be reading all the keys in `md`
return sys
end

# TODO handle kwargs
make_power_flow_container(pfem::PSSEExportPowerFlow, sys::PSY.System; kwargs...) =
PSSEExporter(
sys,
pfem.psse_version,
pfem.export_dir;
write_comments = pfem.write_comments,
)

0 comments on commit 1605f14

Please sign in to comment.