Skip to content

Commit

Permalink
Use PSY's fast_deepcopy_system
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Dec 26, 2024
1 parent 7b50501 commit f7e5fce
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions src/psse_export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,6 @@ const PSSE_DEFAULT_EXPORT_NAME = "export"
const PSSE_RAW_BUFFER_SIZEHINT = 1024
const PSSE_MD_BUFFER_SIZEHINT = 1024

"""
Make a `deepcopy` of the `System` except replace the time series manager and supplemental
attribute manager with blank versions so these are not copied.
"""
function deepcopy_system_no_time_series_no_supplementals(sys::System)
old_time_series_manager = sys.data.time_series_manager
old_supplemental_attribute_manager = sys.data.supplemental_attribute_manager

new_time_series_manager = IS.TimeSeriesManager(
IS.InMemoryTimeSeriesStorage(),
IS.TimeSeriesMetadataStore(),
true,
)
new_supplemental_attribute_manager = IS.SupplementalAttributeManager()

sys.data.time_series_manager = new_time_series_manager
sys.data.supplemental_attribute_manager = new_supplemental_attribute_manager

old_refs = Dict{Tuple{DataType, String}, IS.SharedSystemReferences}()
for comp in PSY.iterate_components(sys)
old_refs[(typeof(comp), PSY.get_name(comp))] =
comp.internal.shared_system_references
new_refs = IS.SharedSystemReferences(;
time_series_manager = new_time_series_manager,
supplemental_attribute_manager = new_supplemental_attribute_manager,
)
IS.set_shared_system_references!(comp, new_refs)
end

new_sys = try
deepcopy(sys)
finally
sys.data.time_series_manager = old_time_series_manager
sys.data.supplemental_attribute_manager = old_supplemental_attribute_manager

for comp in PSY.iterate_components(sys)
IS.set_shared_system_references!(comp,
old_refs[(typeof(comp), PSY.get_name(comp))])
end
end
return new_sys
end

"""
Structure to perform an export from a Sienna System, plus optional updates from
`PowerFlowData`, to the PSS/E format. Construct from a `System` and a PSS/E version, update
Expand Down Expand Up @@ -130,7 +87,7 @@ mutable struct PSSEExporter <: SystemPowerFlowContainer
"PSS/E version $psse_version is not supported, must be one of $PSSE_EXPORT_SUPPORTED_VERSIONS",
),
)
system = deepcopy_system_no_time_series_no_supplementals(base_system)
system = PSY.fast_deepcopy_system(base_system)
mkpath(export_dir)
new(
system,
Expand Down Expand Up @@ -191,7 +148,7 @@ function update_exporter!(exporter::PSSEExporter, data::PSY.System)
"System passed to update_exporter must be the same system as the one with which the exporter was constructed, just with different values",
),
)
exporter.system = deepcopy_system_no_time_series_no_supplementals(data)
exporter.system = PSY.fast_deepcopy_system(data)
reset_caches(exporter)
return
end
Expand Down

0 comments on commit f7e5fce

Please sign in to comment.