Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_components + get_available_components docstrings #1206

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pages = OrderedDict(
"Reference" =>
Any["Public API" => "api/public.md",
"Glossary and Acronyms" => "api/glossary.md",
"Type Hierarchy" => "api/type_tree.md",
"Type Tree" => "api/type_tree.md",
"`ValueCurve` Options" => "api/valuecurve_options.md",
"Specifying the category of..." => "api/enumerated_types.md",
"Citation" => "api/citation.md",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/type_tree.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Type Hierarchy
# Type Tree

Here is the complete `PowerSystems.jl` type hierarchy:

Expand Down
50 changes: 39 additions & 11 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1080,22 +1080,25 @@ function get_component(::Type{T}, sys::System, name::AbstractString) where {T <:
end

"""
Returns an iterator of components. T can be concrete or abstract.
Return an iterator of components of a given `Type` from a [`System`](@ref).

`T` can be a concrete or abstract [`Component`](@ref) type from the [Type Tree](@ref).
Call collect on the result if an array is desired.

# Examples
```julia
iter = PowerSystems.get_components(ThermalStandard, sys)
iter = PowerSystems.get_components(Generator, sys)
iter = PowerSystems.get_components(x -> PowerSystems.get_available(x), Generator, sys)
thermal_gens = get_components(ThermalStandard, sys) do gen
get_available(gen)
end
generators = collect(PowerSystems.get_components(Generator, sys))

iter = get_components(ThermalStandard, sys)
iter = get_components(Generator, sys)
generators = collect(get_components(Generator, sys))
```

See also: [`iterate_components`](@ref)
See also: [`iterate_components`](@ref), [`get_components` with a filter](@ref get_components(
filter_func::Function,
::Type{T},
sys::System;
subsystem_name = nothing,
) where {T <: Component}),
[`get_available_components`](@ref), [`get_buses`](@ref)
"""
function get_components(
::Type{T},
Expand All @@ -1105,6 +1108,27 @@ function get_components(
return IS.get_components(T, sys.data; subsystem_name = subsystem_name)
end

"""
Return an iterator of components of a given `Type` from a [`System`](@ref), using an
additional filter

`T` can be a concrete or abstract [`Component`](@ref) type from the [Type Tree](@ref).
Call collect on the result if an array is desired.

# Examples
```julia
iter_coal = get_components(x -> get_fuel(x) == ThermalFuels.COAL, Generator, sys)
pv_gens =
collect(get_components(x -> get_prime_mover_type(x) == PrimeMovers.PVe, Generator, sys))
```

See also: [`get_components`](@ref get_components(
::Type{T},
sys::System;
subsystem_name = nothing,
) where {T <: Component}), [`get_available_components`](@ref),
[`get_buses`](@ref)
"""
function get_components(
filter_func::Function,
::Type{T},
Expand Down Expand Up @@ -1161,7 +1185,11 @@ function get_components_by_name(
end

"""
Gets components availability. Requires type T to have the method get_available implemented.
Returns iterator of available components in a [`System`](@ref).

`T` can be a concrete or abstract [`Component`](@ref) type from the [Type Tree](@ref)
and must have the method `get_available` implemented.
Call collect on the result if an array is desired.
"""
function get_available_components(::Type{T}, sys::System) where {T <: Component}
return get_components(get_available, T, sys)
Expand Down
Loading