From ca2f2521f2fc2305de4931e2ea4e0dbfe16ead56 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 13 Dec 2023 14:31:25 -0600 Subject: [PATCH] fix uses of default attributes --- src/core/device_model.jl | 9 +++++++-- src/core/service_model.jl | 20 +++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/core/device_model.jl b/src/core/device_model.jl index 1e73d2a560..02d854e4d4 100644 --- a/src/core/device_model.jl +++ b/src/core/device_model.jl @@ -59,8 +59,13 @@ mutable struct DeviceModel{D <: PSY.Device, B <: AbstractDeviceFormulation} use_slacks = false, duals = Vector{DataType}(), time_series_names = get_default_time_series_names(D, B), - attributes = get_default_attributes(D, B), + attributes = Dict{String, Any}(), ) where {D <: PSY.Device, B <: AbstractDeviceFormulation} + attributes_ = get_default_attributes(D, B) + for (k, v) in attributes + attributes_[k] = v + end + _check_device_formulation(D) _check_device_formulation(B) new{D, B}( @@ -69,7 +74,7 @@ mutable struct DeviceModel{D <: PSY.Device, B <: AbstractDeviceFormulation} duals, Vector{ServiceModel}(), time_series_names, - attributes, + attributes_, ) end end diff --git a/src/core/service_model.jl b/src/core/service_model.jl index 6ea786fa81..576946990b 100644 --- a/src/core/service_model.jl +++ b/src/core/service_model.jl @@ -46,9 +46,15 @@ mutable struct ServiceModel{D <: PSY.Service, B <: AbstractServiceFormulation} feedforwards = Vector{AbstractAffectFeedforward}(), duals = Vector{DataType}(), time_series_names = get_default_time_series_names(D, B), - attributes = get_default_attributes(D, B), + attributes = Dict{String, Any}(), contributing_devices_map = Dict{Type{<:PSY.Component}, Vector{<:PSY.Component}}(), ) where {D <: PSY.Service, B <: AbstractServiceFormulation} + + attributes_ = get_default_attributes(D, B) + for (k, v) in attributes + attributes_[k] = v + end + _check_service_formulation(D) _check_service_formulation(B) new{D, B}( @@ -57,7 +63,7 @@ mutable struct ServiceModel{D <: PSY.Service, B <: AbstractServiceFormulation} use_slacks, duals, time_series_names, - attributes, + attributes_, contributing_devices_map, ) end @@ -93,8 +99,12 @@ function ServiceModel( ) where {D <: PSY.Service, B <: AbstractServiceFormulation} # If more attributes are used later, move free form string to const and organize # attributes - if !haskey(attributes, "aggregated_service_model") - push!(attributes, "aggregated_service_model" => true) + attributes_ = get_default_attributes(D, B) + for (k, v) in attributes + attributes_[k] = v + end + if !haskey(attributes_, "aggregated_service_model") + push!(attributes_, "aggregated_service_model" => true) end return ServiceModel( service_type, @@ -104,7 +114,7 @@ function ServiceModel( feedforwards, duals, time_series_names, - attributes, + attributes_, ) end