Skip to content

Commit

Permalink
Better accommodate multi period in PSS/E export
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Oct 28, 2024
1 parent efa2d8a commit 61125ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/PowerFlowData.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
abstract type PowerFlowContainer end

"""
Trait signifying whether the `PowerFlowContainer` can represent multi-period data. Must be
implemented for all concrete subtypes.
"""
supports_multi_period(x::PowerFlowContainer) =
throw(
IS.NotImplementedError(
"supports_multi_period must be implemented for $(typeof(x))"),
)

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

Expand Down Expand Up @@ -95,6 +105,7 @@ get_valid_ix(pfd::PowerFlowData) = pfd.valid_ix
get_power_network_matrix(pfd::PowerFlowData) = pfd.power_network_matrix
get_aux_network_matrix(pfd::PowerFlowData) = pfd.aux_network_matrix
get_neighbor(pfd::PowerFlowData) = pfd.neighbors
supports_multi_period(::PowerFlowData) = true

function clear_injection_data!(pfd::PowerFlowData)
pfd.bus_activepower_injection .= 0.0
Expand Down
24 changes: 18 additions & 6 deletions src/psse_export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,22 @@ using `update_exporter` with any new data as relevant, and perform the export wi
flow-related values but may not fundamentally alter the system
- `psse_version::Symbol`: the version of PSS/E to target, must be one of
`PSSE_EXPORT_SUPPORTED_VERSIONS`
- `write_comments::Bool`: whether to add the customary-but-not-in-spec-annotations after a
slash on the first line and at group boundaries
- `write_comments::Bool` = false: whether to add the customary-but-not-in-spec-annotations
after a slash on the first line and at group boundaries
- `name::AbstractString = "export"`: the base name of the export
- `step::Union{Nothing, Integer, Tuple{Vararg{Integer}}} = nothing`: optional step number
or tuple of step numbers (e.g., step and timestamp within step) to append to the base
export name. User is responsible for updating the step.
- `overwrite::Bool = false`: `true` to silently overwrite existing exports, `false` to
throw an error if existing results are encountered
"""
mutable struct PSSEExporter <: SystemPowerFlowContainer
system::PSY.System
psse_version::Symbol
export_dir::AbstractString
write_comments::Bool
name::AbstractString
step::Union{Nothing, Int}
step::Union{Nothing, Integer, Tuple{Vararg{Integer}}}
overwrite::Bool

function PSSEExporter(
Expand All @@ -112,7 +118,7 @@ mutable struct PSSEExporter <: SystemPowerFlowContainer
export_dir::AbstractString;
write_comments::Bool = false,
name::AbstractString = PSSE_DEFAULT_EXPORT_NAME,
step::Union{Nothing, Int} = nothing,
step::Union{Nothing, Integer, Tuple{Vararg{Integer}}} = nothing,
overwrite::Bool = false,
)
(psse_version in PSSE_EXPORT_SUPPORTED_VERSIONS) ||
Expand All @@ -127,6 +133,8 @@ mutable struct PSSEExporter <: SystemPowerFlowContainer
end
end

supports_multi_period(::PSSEExporter) = false

function _validate_same_system(sys1::PSY.System, sys2::PSY.System)
return IS.get_uuid(PSY.get_internal(sys1)) == IS.get_uuid(PSY.get_internal(sys2))
end
Expand Down Expand Up @@ -873,13 +881,17 @@ function _write_raw(::Val{T}, io::IO, md::AbstractDict, exporter::PSSEExporter)
_write_skip_group(io, md, exporter, group_name)
end

_step_to_string(::Nothing) = ""
_step_to_string(step::Integer) = "_$step"
_step_to_string(step::Tuple{Vararg{Integer}}) = "_" * join(step, "_")

"Peform an export from the data contained in a `PSSEExporter` to the PSS/E file format."
function write_export(
exporter::PSSEExporter,
name::AbstractString;
overwrite = false,
)
isnothing(exporter.step) || (name *= "_$(exporter.step)")
name *= _step_to_string(exporter.step)
# Construct paths
export_subdir = joinpath(exporter.export_dir, name)
dir_exists = isdir(export_subdir)
Expand Down Expand Up @@ -1070,7 +1082,7 @@ make_power_flow_container(pfem::PSSEExportPowerFlow, sys::PSY.System; kwargs...)
pfem.psse_version,
pfem.export_dir;
write_comments = pfem.write_comments,
step = 0,
step = (0, 0),
)

solve_powerflow!(exporter::PSSEExporter) = write_export(exporter)

0 comments on commit 61125ef

Please sign in to comment.