From f38f839c4d84dc2e999ebcd5d452469ffc59dae5 Mon Sep 17 00:00:00 2001 From: alefcastelli Date: Wed, 24 Jan 2024 15:28:41 -0700 Subject: [PATCH] afc/multiproblem template creation --- src/multiproblem_template.jl | 39 ++++++++++++++++++++++-------------- test/first_test.jl | 18 ++++++++--------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/multiproblem_template.jl b/src/multiproblem_template.jl index 9e4c6c3..222cf36 100644 --- a/src/multiproblem_template.jl +++ b/src/multiproblem_template.jl @@ -17,6 +17,9 @@ function MultiProblemTemplate( return MultiProblemTemplate(PSI.ProblemTemplate(network), problem_keys) end +function get_sub_templates(template::MultiProblemTemplate) + return values(template.sub_templates) +end """ Sets the network model in a template. @@ -26,7 +29,7 @@ function PSI.set_network_model!( model::PSI.NetworkModel{<:PM.AbstractPowerModel}, ) PSI.set_network_model!(template.base_template, model) - for sub_template in values(sub_templates) + for sub_template in get_sub_templates(template) PSI.set_network_model!(sub_template, model) end return @@ -42,7 +45,7 @@ function PSI.set_device_model!( formulation::Type{<:PSI.AbstractDeviceFormulation}, ) PSI.set_device_model!(template.base_template, PSI.DeviceModel(component_type, formulation)) - for sub_template in values(sub_templates) + for sub_template in get_sub_templates(template) PSI.set_device_model!(sub_template, PSI.DeviceModel(component_type, formulation)) end return @@ -56,7 +59,7 @@ function PSI.set_device_model!( model::PSI.DeviceModel{<:PSY.Device, <:PSI.AbstractDeviceFormulation}, ) PSI.set_device_model!(template.base_template, model) - for sub_template in values(sub_templates) + for sub_template in get_sub_templates(template) PSI.set_device_model!(sub_template, model) end return @@ -67,8 +70,8 @@ function PSI.set_device_model!( model::PSI.DeviceModel{<:PSY.Branch, <:PSI.AbstractDeviceFormulation}, ) PSI.set_device_model!(template.base_template, model) - for sub_template in values(sub_templates) - PSI.set_device_model!(sub_template, model) + for sub_template in get_sub_templates(template) + PSI.set_device_model!(sub_template, PSI.DeviceModel(component_type, formulation)) end return end @@ -88,12 +91,12 @@ function PSI.set_service_model!( service_name, ServiceModel(service_type, formulation; use_service_name = true), ) - for sub_template in values(sub_templates) + for sub_template in get_sub_templates(template) PSI.set_service_model!( - sub_template, - service_name, - ServiceModel(service_type, formulation; use_service_name = true), - ) + sub_template, + service_name, + ServiceModel(service_type, formulation; use_service_name = true), + ) end return end @@ -107,12 +110,12 @@ function PSI.set_service_model!( formulation::Type{<:PSI.AbstractServiceFormulation}, ) PSI.set_service_model!(template.base_template, PSI.ServiceModel(service_type, formulation)) - for sub_template in values(sub_templates) + for sub_template in get_sub_templates(template) PSI.set_service_model!( - sub_template, - service_name, - PSI.ServiceModel(service_type, formulation), - ) + sub_template, + service_name, + PSI.ServiceModel(service_type, formulation), + ) end return end @@ -123,6 +126,9 @@ function PSI.set_service_model!( model::PSI.ServiceModel{<:PSY.Service, <:PSI.AbstractServiceFormulation}, ) PSI.set_service_model!(template.base_template, service_name, model) + for sub_template in get_sub_templates(template) + PSI.set_service_model!(sub_template, service_name, model) + end return end @@ -131,5 +137,8 @@ function PSI.set_service_model!( model::PSI.ServiceModel{<:PSY.Service, <:PSI.AbstractServiceFormulation}, ) PSI.set_service_model!(template.base_template, model) + for sub_template in get_sub_templates(template) + PSI.set_service_model!(sub_template, model) + end return end diff --git a/test/first_test.jl b/test/first_test.jl index 35038a6..401bb77 100644 --- a/test/first_test.jl +++ b/test/first_test.jl @@ -33,7 +33,6 @@ sys_twin_rts_DA = PSY.System("GDO systems/saved_main_RTS_GMLC_DA_final_sys_" * n # ! check reserves - # modify the system -> add features in the "ext" field for d in PSY.get_components(PSY.Component, sys_twin_rts_DA) if typeof(d) <: PSY.Bus || :available in fieldnames(typeof(d)) @@ -82,9 +81,10 @@ storage_model = DeviceModel( # UC model template_uc = - ProblemTemplate( + MultiProblemTemplate( # NetworkModel(StandardPTDFModel; PTDF_matrix = PTDF(sys_twin_rts)), NetworkModel(DCPPowerModel; use_slacks=true), + ["1", "2"] ) set_device_model!(template_uc, ThermalStandard, ThermalStandardUnitCommitment) set_device_model!(template_uc, RenewableDispatch, RenewableFullDispatch) @@ -131,13 +131,13 @@ model = DecisionModel( calculate_conflict = true, ) -for b in get_components(ACBus, model.sys) - @show get_bustype(b) - @show get_bustype(b) == PSY.ACBusTypes.ISOLATED - # if get_bustype(b) == PSY.ACBusTypes.ISOLATED - # @show get_name(b) - # end -end +# for b in get_components(ACBus, model.sys) +# @show get_bustype(b) +# @show get_bustype(b) == PSY.ACBusTypes.ISOLATED +# # if get_bustype(b) == PSY.ACBusTypes.ISOLATED +# # @show get_name(b) +# # end +# end # b = get_component(ACBus, model.sys, "Caesar") # get_bustype(b) == ACBusTypes.ISOLATED