Skip to content

Commit

Permalink
Merge pull request #1012 from NREL-Sienna/psy3
Browse files Browse the repository at this point in the history
Psy3
  • Loading branch information
jd-lara committed Sep 12, 2023
2 parents 4f19d56 + 4e1d886 commit 1454cf0
Show file tree
Hide file tree
Showing 70 changed files with 1,579 additions and 835 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PowerSystems"
uuid = "bcd98974-b02a-5e2f-9ee0-a103f5c450dd"
authors = ["Jose Daniel Lara", "Daniel Thom", "Dheepak Krishnamurthy", "Clayton Barrows", "Sourabh Dalvi"]
version = "2.6.1"
version = "3.0.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
6 changes: 3 additions & 3 deletions docs/src/modeler_guide/enumerated_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ are intended to reflect the options denoted by
| `PS` | Energy Storage, Reversible Hydraulic Turbine (Pumped Storage) |
| `OT` | Other |
| `ST` | Steam Turbine (including nuclear, geothermal and solar steam; does not include combined-cycle turbine) |
| `PV` | Photovoltaic *renaming from EIA PV to PVe to avoid conflict with BusType.PV |
| `PV` | Photovoltaic *renaming from EIA PV to PVe to avoid conflict with ACBusType.PV |
| `WT` | Wind Turbine, Onshore |
| `WS` | Wind Turbine, Offshore |

## `BusTypes`
## `ACBusTypes`

`BusTypes` is used to denote which quantities are specified for load flow calculations and
`ACBusTypes` is used to denote which quantities are specified for load flow calculations and
to otherwise categorize buses for modeling activities.

| EnumName | Description |
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modeler_guide/market_bid_cost.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The code below shows an example how we can create a thermal device with MarketBi

```@repl market_bid_cost
using PowerSystems, Dates
bus = Bus(1, "nodeE", "REF", 0, 1.0, (min = 0.9, max = 1.05), 230, nothing, nothing)
bus = ACBus(1, "nodeE", "REF", 0, 1.0, (min = 0.9, max = 1.05), 230, nothing, nothing)
generator = ThermalStandard(
name = "Brighton",
Expand All @@ -25,7 +25,7 @@ generator = ThermalStandard(
active_power = 6.0,
reactive_power = 1.50,
rating = 0.75,
prime_mover = PrimeMovers.ST,
prime_mover_type = PrimeMovers.ST,
fuel = ThermalFuels.COAL,
active_power_limits = (min = 0.0, max = 6.0),
reactive_power_limits = (min = -4.50, max = 4.50),
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modeler_guide/type_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ types and create generic code to support modeling technologies that are not yet
implemented in the package.

`PowerSystems.jl` has a category [`Topology`](@ref) of topological components
(e.g., [`Bus`](@ref), [`Arc`](@ref)), separate from the physical components.
(e.g., [`ACBus`](@ref), [`Arc`](@ref)), separate from the physical components.

The hierarchy also includes components absent in standard data models, such as services.
The services category includes reserves, transfers and [`AGC`](@ref). The power of `PowerSystems.jl`
Expand Down
4 changes: 2 additions & 2 deletions docs/src/quick_start_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ system = System(joinpath(file_dir, "case5.m"))
new_renewable = RenewableDispatch(
name = "WindPowerNew",
available = true,
bus = get_component(Bus, system, "3"),
bus = get_component(ACBus, system, "3"),
active_power = 2.0,
reactive_power = 1.0,
rating = 1.2,
prime_mover = PrimeMovers.WT,
prime_mover_type = PrimeMovers.WT,
reactive_power_limits = (min = 0.0, max = 0.0),
base_power = 100.0,
operation_cost = TwoPartCost(22.0, 0.0),
Expand Down
10 changes: 7 additions & 3 deletions src/PowerSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module PowerSystems
export System
export Topology
export Bus
export ACBus
export DCBus
export Arc
export AggregationTopology
export Area
Expand All @@ -28,8 +30,9 @@ export ACBranch
export Line
export MonitoredLine
export DCBranch
export HVDCLine
export VSCDCLine
export TwoTerminalHVDCLine
export TwoTerminalVSCDCLine
export TModelHVDCLine
export Transformer2W
export TapTransformer
export PhaseShiftingTransformer
Expand All @@ -48,6 +51,7 @@ export HydroGen
export HydroDispatch
export HydroEnergyReservoir
export HydroPumpedStorage
export InterconnectingConverter

export RenewableGen
export RenewableFix
Expand Down Expand Up @@ -213,7 +217,7 @@ export VariableReserveNonSpinning
export TransmissionInterface

export AngleUnits
export BusTypes
export ACBusTypes
export PrimeMovers
export ThermalFuels
export StateTypes
Expand Down
40 changes: 20 additions & 20 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const SYSTEM_KWARGS = Set((
))

# This will be used in the future to handle serialization changes.
const DATA_FORMAT_VERSION = "2.0.0"
const DATA_FORMAT_VERSION = "3.0.0"

mutable struct SystemMetadata <: IS.InfrastructureSystemsType
name::Union{Nothing, String}
Expand All @@ -51,7 +51,7 @@ System(; kwargs...)
# Arguments
- `base_power::Float64`: the base power value for the system
- `buses::Vector{Bus}`: an array of buses
- `buses::Vector{ACBus}`: an array of buses
- `components...`: Each element must be an iterable containing subtypes of Component.
# Keyword arguments
Expand Down Expand Up @@ -136,7 +136,7 @@ end
"""
System constructor when components are constructed externally.
"""
function System(base_power::Float64, buses::Vector{Bus}, components...; kwargs...)
function System(base_power::Float64, buses::Vector{ACBus}, components...; kwargs...)
data = _create_system_data_from_kwargs(; kwargs...)
sys = System(data, base_power; kwargs...)

Expand All @@ -159,10 +159,10 @@ end
function System(
::Nothing;
buses = [
Bus(;
ACBus(;
number = 0,
name = "init",
bustype = BusTypes.REF,
bustype = ACBusTypes.REF,
angle = 0.0,
magnitude = 0.0,
voltage_limits = (min = 0.0, max = 0.0),
Expand Down Expand Up @@ -486,7 +486,7 @@ function add_component!(
# occurred when the original addition ran and do not apply to that scenario.
handle_component_addition!(sys, component; kwargs...)
# Special condition required to populate the bus numbers in the system after
elseif component isa Bus
elseif component isa ACBus
handle_component_addition!(sys, component; kwargs...)
end

Expand Down Expand Up @@ -1050,14 +1050,14 @@ function get_aggregation_topology_mapping(
::Type{T},
sys::System,
) where {T <: AggregationTopology}
mapping = Dict{String, Vector{Bus}}()
mapping = Dict{String, Vector{ACBus}}()
accessor_func = get_aggregation_topology_accessor(T)
for bus in get_components(Bus, sys)
for bus in get_components(ACBus, sys)
aggregator = accessor_func(bus)
name = get_name(aggregator)
buses = get(mapping, name, nothing)
if isnothing(buses)
mapping[name] = Vector{Bus}([bus])
mapping[name] = Vector{ACBus}([bus])
else
push!(buses, bus)
end
Expand All @@ -1075,8 +1075,8 @@ end

function _get_buses(data::IS.SystemData, aggregator::T) where {T <: AggregationTopology}
accessor_func = get_aggregation_topology_accessor(T)
buses = Vector{Bus}()
for bus in IS.get_components(Bus, data)
buses = Vector{ACBus}()
for bus in IS.get_components(ACBus, data)
_aggregator = accessor_func(bus)
if IS.get_uuid(_aggregator) == IS.get_uuid(aggregator)
push!(buses, bus)
Expand Down Expand Up @@ -1292,7 +1292,7 @@ IS.validate_struct(component::Component) = validate_component(component)
Check system consistency and validity.
"""
function check(sys::System)
buses = get_components(Bus, sys)
buses = get_components(ACBus, sys)
slack_bus_check(buses)
buscheck(buses)
critical_components_check(sys)
Expand Down Expand Up @@ -1535,14 +1535,14 @@ end
Return bus with name.
"""
function get_bus(sys::System, name::AbstractString)
return get_component(Bus, sys, name)
return get_component(ACBus, sys, name)
end

"""
Return bus with bus_number.
"""
function get_bus(sys::System, bus_number::Int)
for bus in get_components(Bus, sys)
for bus in get_components(ACBus, sys)
if bus.number == bus_number
return bus
end
Expand All @@ -1555,8 +1555,8 @@ end
Return all buses values with bus_numbers.
"""
function get_buses(sys::System, bus_numbers::Set{Int})
buses = Vector{Bus}()
for bus in get_components(Bus, sys)
buses = Vector{ACBus}()
for bus in get_components(ACBus, sys)
if bus.number in bus_numbers
push!(buses, bus)
end
Expand Down Expand Up @@ -1703,7 +1703,7 @@ function check_component_addition(sys::System, dyn_injector::DynamicInjection; k
return
end

function check_component_addition(sys::System, bus::Bus; kwargs...)
function check_component_addition(sys::System, bus::ACBus; kwargs...)
number = get_number(bus)
if number in sys.bus_numbers
throw(ArgumentError("bus number $number is already stored in the system"))
Expand All @@ -1720,7 +1720,7 @@ function check_component_addition(sys::System, bus::Bus; kwargs...)
end
end

function handle_component_addition!(sys::System, bus::Bus; kwargs...)
function handle_component_addition!(sys::System, bus::ACBus; kwargs...)
number = get_number(bus)
@assert !(number in sys.bus_numbers) "bus number $number is already stored"
push!(sys.bus_numbers, number)
Expand Down Expand Up @@ -1787,7 +1787,7 @@ end
"""
Throws ArgumentError if the bus number is not stored in the system.
"""
function handle_component_removal!(sys::System, bus::Bus)
function handle_component_removal!(sys::System, bus::ACBus)
_handle_component_removal_common!(bus)
number = get_number(bus)
@assert number in sys.bus_numbers "bus number $number is not stored"
Expand All @@ -1812,7 +1812,7 @@ end

function handle_component_removal!(sys::System, value::T) where {T <: AggregationTopology}
_handle_component_removal_common!(value)
for device in get_components(Bus, sys)
for device in get_components(ACBus, sys)
if get_aggregation_topology_accessor(T)(device) == value
_remove_aggregration_topology!(device, value)
end
Expand Down
98 changes: 74 additions & 24 deletions src/data_format_conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,82 @@
# Deserialization needs to add this field and value.
#

function pre_deserialize_conversion!(raw, sys::System)
old = raw["data_format_version"]
if old == "1.0.0"
for component in raw["data"]["components"]
for ts_metadata in get(component, "time_series_container", [])
if ts_metadata["__metadata__"]["type"] == "DeterministicMetadata" &&
!haskey(ts_metadata, "time_series_type")
# This will allow deserialization to work.
# post_deserialize_conversion will fix the type.
ts_metadata["time_series_type"] = Dict(
"__metadata__" => Dict(
"module" => "InfrastructureSystems",
"type" => "AbstractDeterministic",
),
)
end
function _convert_data!(
raw::Dict{String, Any},
::Val{Symbol("1.0.0")},
::Val{Symbol("2.0.0")},
)
for component in raw["data"]["components"]
for ts_metadata in get(component, "time_series_container", [])
if ts_metadata["__metadata__"]["type"] == "DeterministicMetadata" &&
!haskey(ts_metadata, "time_series_type")
# This will allow deserialization to work.
# post_deserialize_conversion will fix the type.
ts_metadata["time_series_type"] = Dict(
"__metadata__" => Dict(
"module" => "InfrastructureSystems",
"type" => "AbstractDeterministic",
),
)
end
end
elseif old == "1.0.1"
# Version 1.0.1 can be converted
@warn(
"System is saved in the data format version 1.0.1 will be automatically upgraded to 2.0.0 upon saving"
)
end
return
end

function _convert_data!(
raw::Dict{String, Any},
::Val{Symbol("2.0.0")},
::Val{Symbol("3.0.0")},
)
for component in raw["data"]["components"]
if component["__metadata__"]["type"] == "Bus"
component["__metadata__"]["type"] = "ACBus"
continue
end
if component["__metadata__"]["type"] == "HVDCLine"
component["__metadata__"]["type"] = "TwoTerminalHVDCLine"
continue
end
if component["__metadata__"]["type"] == "VSCDCLine"
component["__metadata__"]["type"] = "TwoTerminalVSCDCLine"
continue
end
if haskey(component, "prime_mover") && haskey(component, "dynamic_injector")
component["prime_mover_type"] = pop!(component, "prime_mover")
end
end
return
end

function _convert_data!(
raw::Dict{String, Any},
::Val{Symbol("1.0.0")},
::Val{Symbol("3.0.0")},
)
_convert_data!(raw, Val{Symbol("1.0.0")}(), Val{Symbol("2.0.0")}())
_convert_data!(raw, Val{Symbol("2.0.0")}(), Val{Symbol("3.0.0")}())
return
end

function _convert_data!(
raw::Dict{String, Any},
::Val{Symbol("1.0.1")},
::Val{Symbol("3.0.0")},
)
_convert_data!(raw, Val{Symbol("2.0.0")}(), Val{Symbol("3.0.0")}())
return
end

function pre_deserialize_conversion!(raw, sys::System)
old = raw["data_format_version"]
if old == DATA_FORMAT_VERSION
return
else
error("conversion of data from $old to $DATA_FORMAT_VERSION is not supported")
_convert_data!(raw, Val{Symbol(old)}(), Val{Symbol(DATA_FORMAT_VERSION)}())
@warn(
"System is saved in the data format version $old will be automatically upgraded to $DATA_FORMAT_VERSION upon saving"
)
end
end

Expand All @@ -54,11 +104,11 @@ function post_deserialize_conversion!(sys::System, raw)
end
end
end
elseif old == "1.0.1"
elseif old == "1.0.1" || old == "2.0.0"
# Version 1.0.1 can be converted
raw["data_format_version"] = DATA_FORMAT_VERSION
@warn(
"System is saved in the data format version 1.0.1 will be automatically upgraded to 2.0.0 upon saving"
"System is saved in the data format version $old will be automatically upgraded to $DATA_FORMAT_VERSION upon saving"
)
return
else
Expand Down
2 changes: 1 addition & 1 deletion src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ IS.@scoped_enum(GeneratorCostModels, PIECEWISE_LINEAR = 1, POLYNOMIAL = 2,)
IS.@scoped_enum(AngleUnits, DEGREES = 1, RADIANS = 2,)

# "From http://www.pserc.cornell.edu/matpower/MATPOWER-manual.pdf Table B-1"
IS.@scoped_enum(BusTypes, PQ = 1, PV = 2, REF = 3, ISOLATED = 4, SLACK = 5,)
IS.@scoped_enum(ACBusTypes, PQ = 1, PV = 2, REF = 3, ISOLATED = 4, SLACK = 5,)

"From https://www.eia.gov/survey/form/eia_923/instructions.pdf"

Expand Down
6 changes: 3 additions & 3 deletions src/descriptors/power_system_inputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@
{
"name": "dc_line_category",
"value_options": [
"VSCDCLine",
"HVDCLine"
"TwoTerminalVSCDCLine",
"TwoTerminalHVDCLine"
],
"description": "Type of Struct",
"default_value": "HVDCLine"
"default_value": "TwoTerminalHVDCLine"
}
],
"branch": [
Expand Down
Loading

0 comments on commit 1454cf0

Please sign in to comment.