Skip to content

Commit

Permalink
Prototype ComponentSelector grouping (tests not updated)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Sep 20, 2024
1 parent 2daeaec commit 419d510
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 59 deletions.
6 changes: 4 additions & 2 deletions src/PowerSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export subtype_to_string
export component_to_qualified_string
export select_components
export get_components
export get_subselectors
export get_groups
#################################################################################
# Imports

Expand Down Expand Up @@ -610,13 +610,15 @@ import InfrastructureSystems:
ComponentSelector,
ComponentSelectorElement,
ComponentSelectorSet,
DynamicallyGroupedComponentSelectorSet,
SingleComponentSelector,
ListComponentSelector,
SubtypeComponentSelector,
FilterComponentSelector,
component_to_qualified_string,
subtype_to_string,
NAME_DELIMETER
NAME_DELIMETER,
select_components
import InfrastructureSystems:
ValueCurve,
InputOutputCurve,
Expand Down
63 changes: 6 additions & 57 deletions src/component_selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,16 @@ get_components(e::ComponentSelector, sys::System; filterby = nothing) =
"""
Get the sub-selectors that make up the ComponentSelectorSet.
"""
get_subselectors(e::ComponentSelectorSet, sys::System; filterby = nothing) =
IS.get_subselectors(e, sys.data; filterby = filterby)

# SingleComponentSelector
# Construction
"""
Make a ComponentSelector pointing to a Component with the given subtype and name. Optionally
provide a name for the ComponentSelector.
"""
select_components(
component_subtype::Type{<:Component},
component_name::AbstractString,
name::Union{String, Nothing} = nothing,
) = IS.select_components(component_subtype, component_name, name)

"""
Construct a ComponentSelector from a Component reference, pointing to Components in any
System with the given Component's subtype and name.
"""
select_components(component_ref::Component, name::Union{String, Nothing} = nothing) =
IS.select_components(component_ref, name)

# ListComponentSelector
# Construction
select_components(content::ComponentSelector...; name::Union{String, Nothing} = nothing) =
IS.select_components(content...; name)

# SubtypeComponentSelector
# Construction
"""
Make a ComponentSelector from a subtype of Component. Optionally provide a name for the
ComponentSelectorSet.
"""
# name needs to be a kwarg to disambiguate from SingleComponentSelector's select_components
select_components(
component_subtype::Type{<:Component};
name::Union{String, Nothing} = nothing,
) = IS.select_components(component_subtype; name)

# FilterComponentSelector
# Construction
"""
Make a ComponentSelector from a filter function and a subtype of Component. Optionally
provide a name for the ComponentSelector. The filter function must accept instances of
component_subtype as a sole argument and return a Bool.
"""
function select_components(
filter_fn::Function,
component_subtype::Type{<:Component},
name::Union{String, Nothing} = nothing,
)
return IS.select_components(filter_fn, component_subtype, name)
end
get_groups(e::ComponentSelectorSet, sys::System; filterby = nothing) =
IS.get_groups(e, sys.data; filterby = filterby)

# TopologyComponentSelector
# This one is wholly implemented in PowerSystems rather than in IS because it depends on AggregationTopology
"ComponentSelectorSet represented by an AggregationTopology and a subtype of Component."
struct TopologyComponentSelector <: ComponentSelectorSet
struct TopologyComponentSelector <: DynamicallyGroupedComponentSelectorSet
component_subtype::Type{<:Component}
topology_subtype::Type{<:AggregationTopology}
topology_name::AbstractString
component_subtype::Type{<:Component}
name::Union{String, Nothing}
end

Expand All @@ -80,14 +29,14 @@ Make a ComponentSelector from an AggregationTopology and a subtype of Component.
provide a name for the ComponentSelector.
"""
select_components(
component_subtype::Type{<:Component},
topology_subtype::Type{<:AggregationTopology},
topology_name::AbstractString,
component_subtype::Type{<:Component},
name::Union{String, Nothing} = nothing,
) = TopologyComponentSelector(
component_subtype,
topology_subtype,
topology_name,
component_subtype,
name,
)

Expand Down

0 comments on commit 419d510

Please sign in to comment.