Skip to content
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
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: local
hooks:
- id: julia-formatter
name: Run Julia formatter
entry: julia scripts/formatter/formatter_code.jl
language: system
types: [file]
pass_filenames: false
3 changes: 3 additions & 0 deletions src/PowerSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export HVDCPowerBalance
export HVDCLosses
export HVDCFlowDirectionVariable
export InputActivePowerVariableLimitsConstraint
export InterfaceFlowLimit
export NetworkFlowConstraint
export NodalBalanceActiveConstraint
export NodalBalanceReactiveConstraint
Expand Down Expand Up @@ -319,6 +320,8 @@ export PieceWiseLinearBlockDecrementalOfferConstraint
export ActivePowerTimeSeriesParameter
export ReactivePowerTimeSeriesParameter
export RequirementTimeSeriesParameter
export FromToFlowLimitParameter
export ToFromFlowLimitParameter

# Cost Parameters
export CostFunctionParameter
Expand Down
20 changes: 14 additions & 6 deletions src/core/network_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mutable struct NetworkModel{T <: PM.AbstractPowerModel}
subnetworks::Dict{Int, Set{Int}}
bus_area_map::Dict{PSY.ACBus, Int}
duals::Vector{DataType}
network_reduction::PNM.NetworkReduction
network_reduction::PNM.NetworkReductionData
reduce_radial_branches::Bool
power_flow_evaluation::Vector{PFS.PowerFlowEvaluationModel}
subsystem::Union{Nothing, String}
Expand All @@ -61,7 +61,7 @@ mutable struct NetworkModel{T <: PM.AbstractPowerModel}
subnetworks,
Dict{PSY.ACBus, Int}(),
duals,
PNM.NetworkReduction(),
PNM.NetworkReductionData(),
reduce_radial_branches,
_maybe_flatten_pfem(power_flow_evaluation),
nothing,
Expand Down Expand Up @@ -115,6 +115,13 @@ function instantiate_network_model(
return
end

function instantiate_network_model(
model::NetworkModel{AreaBalancePowerModel},
sys::PSY.System,
)
return
end

function instantiate_network_model(
model::NetworkModel{CopperPlatePowerModel},
sys::PSY.System,
Expand All @@ -139,15 +146,15 @@ function instantiate_network_model(
if model.reduce_radial_branches
network_reduction = PNM.get_radial_reduction(sys)
else
network_reduction = PNM.NetworkReduction()
network_reduction = PNM.NetworkReductionData()
end
model.PTDF_matrix =
PNM.VirtualPTDF(sys; network_reduction = network_reduction)
end

if !model.reduce_radial_branches &&
model.PTDF_matrix.network_reduction.reduction_type ==
PNM.NetworkReductionTypes.RADIAL
PNM.NetworkReductionDataTypes.RADIAL ∈
model.PTDF_matrix.network_reduction_data.reductions
throw(
IS.ConflictingInputsError(
"The provided PTDF Matrix has reduced radial branches and mismatches the network \\
Expand All @@ -157,7 +164,8 @@ function instantiate_network_model(
end

if model.reduce_radial_branches &&
model.PTDF_matrix.network_reduction.reduction_type == PNM.NetworkReductionTypes.WARD
PNM.NetworkReductionDataTypes.WARD ∈
model.PTDF_matrix.network_reduction_data.reductions
throw(
IS.ConflictingInputsError(
"The provided PTDF Matrix has a ward reduction specified and the keyword argument \\
Expand Down
13 changes: 10 additions & 3 deletions src/core/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ function add_component_name!(attr::TimeSeriesAttributes, name::String, uuid::Str
end

get_component_names(attr::TimeSeriesAttributes) = keys(attr.component_name_to_ts_uuid)
function _get_ts_uuid(attr::TimeSeriesAttributes, name)
function _get_ts_uuid(attr::TimeSeriesAttributes, name::String)
if !haskey(attr.component_name_to_ts_uuid, name)
throw(
ArgumentError(
"No time series UUID found for in attributes for component $name: available names are $(keys(attr.component_name_to_ts_uuid))",
),
)
end
return attr.component_name_to_ts_uuid[name]
end

Expand Down Expand Up @@ -325,12 +332,12 @@ Parameter to define component availability status updated from the system state
struct AvailableStatusParameter <: EventParameter end

"""
Parameter to define active power offset during an event.
Parameter to define active power offset during an event.
"""
struct ActivePowerOffsetParameter <: EventParameter end

"""
Parameter to define reactive power offset during an event.
Parameter to define reactive power offset during an event.
"""
struct ReactivePowerOffsetParameter <: EventParameter end

Expand Down
5 changes: 3 additions & 2 deletions src/devices_models/device_constructors/branch_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1524,12 +1524,13 @@ function construct_device!(
end

function construct_device!(
::OptimizationContainer,
::PSY.System,
container::OptimizationContainer,
sys::PSY.System,
::ModelConstructStage,
model::DeviceModel{PSY.AreaInterchange, StaticBranchUnbounded},
network_model::NetworkModel{AreaBalancePowerModel},
)
devices = get_available_components(model, sys)
add_feedforward_constraints!(container, model, devices)
return
end
Expand Down
1 change: 1 addition & 0 deletions src/devices_models/devices/area_interchange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function add_variables!(
@warn(
"CopperPlatePowerModel ignores AreaInterchanges. Instead use AreaBalancePowerModel."
)
return
end

"""
Expand Down
11 changes: 10 additions & 1 deletion src/devices_models/devices/common/add_to_expression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1454,11 +1454,20 @@ function add_to_expression!(
) where {V <: Union{ConstantMaxInterfaceFlow, VariableMaxInterfaceFlow}}
expression = get_expression(container, InterfaceTotalFlow(), PSY.TransmissionInterface)
service_name = get_service_name(model)
direction_map = PSY.get_direction_mapping(service)
specified_direction_mapping = isempty(direction_map)
for (device_type, devices) in get_contributing_devices_map(model)
variable = get_variable(container, FlowActivePowerVariable(), device_type)
for d in devices
name = PSY.get_name(d)
direction = get(PSY.get_direction_mapping(service), name, 1.0)
direction = 1.0
if specified_direction_mapping
if !haskey(direction_map, name)
@warn "Direction not found for $(summary(d)). Will use the default from -> to direction"
else
direction = direction_map[name]
end
end
for t in get_time_steps(container)
_add_to_jump_expression!(
expression[service_name, t],
Expand Down
5 changes: 5 additions & 0 deletions src/operation/problem_template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ function _populate_contributing_devices!(template::ProblemTemplate, sys::PSY.Sys
union!(modeled_devices, Set(get_component_type(m) for m in values(branch_models)))
incompatible_device_types = get_incompatible_devices(device_models)
services_mapping = PSY.get_contributing_device_mapping(sys)
if isempty(services_mapping)
error(
"No contributing devices mapping found in the system, consider adding contributing devices to the services",
)
end
for (service_key, service_model) in service_models
@debug "Populating service $(service_key)"
empty!(get_contributing_devices_map(service_model))
Expand Down
8 changes: 7 additions & 1 deletion src/parameters/add_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function _add_time_series_parameters!(
initial_values = Dict{String, AbstractArray}()
for device in devices
if !PSY.has_time_series(device, ts_type, ts_name)
@debug "skipped time series for $D, $(PSY.get_name(device))"
@info "Time series $(ts_type):$(ts_name) for $D, $(PSY.get_name(device)) not found skipping parameter addition."
continue
end
push!(device_names, PSY.get_name(device))
Expand All @@ -246,6 +246,12 @@ function _add_time_series_parameters!(
end
end

if isempty(device_names)
error(
"No devices with time series $ts_name found for $D devices. Check DeviceModel time_series_names field.",
)
end

param_container = add_param_container!(
container,
param,
Expand Down
61 changes: 28 additions & 33 deletions src/services_models/services_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -553,52 +553,46 @@ function construct_service!(
return
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dispatch on PSY.TransmissionInterface and not T in line 531?


# Repeated Methods to avoid ambiguity between ConstantMaxInterfaceFlow and VariableMaxInterfaceFlow
function construct_service!(
container::OptimizationContainer,
sys::PSY.System,
::ModelConstructStage,
model::ServiceModel{T, ConstantMaxInterfaceFlow},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
network_model::NetworkModel{AreaBalancePowerModel},
) where {T <: PSY.TransmissionInterface}
throw(
IS.ConflictingInputsError(
"AreaBalancePowerModel doesn't model individual line flows and it is not compatible with the addition of TransmissionInterface models",
),
)
return
end

function construct_service!(
container::OptimizationContainer,
sys::PSY.System,
::ModelConstructStage,
model::ServiceModel{T, VariableMaxInterfaceFlow},
::ArgumentConstructStage,
model::ServiceModel{PSY.TransmissionInterface, ConstantMaxInterfaceFlow},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
network_model::NetworkModel{AreaBalancePowerModel},
) where {T <: PSY.TransmissionInterface}
throw(
IS.ConflictingInputsError(
"AreaBalancePowerModel doesn't model individual line flows and it is not compatible with the addition of TransmissionInterface models",
),
)
interfaces = get_available_components(model, sys)
interface = PSY.get_component(PSY.TransmissionInterface, sys, get_service_name(model))
if get_use_slacks(model)
# Adding the slacks can be done in a cleaner fashion
@assert PSY.get_available(interface)
transmission_interface_slacks!(container, interface)
end
# Lazy container addition for the expressions.
lazy_container_addition!(
container,
InterfaceTotalFlow(),
PSY.TransmissionInterface,
PSY.get_name.(interfaces),
get_time_steps(container),
)
@warn "AreaBalancePowerModel doesn't model individual line flows and it ignores the flows on AC Transmission Devices"
add_feedforward_arguments!(container, model, interface)
return
end

function construct_service!(
container::OptimizationContainer,
sys::PSY.System,
::ModelConstructStage,
model::ServiceModel{T, ConstantMaxInterfaceFlow},
model::ServiceModel{PSY.TransmissionInterface, ConstantMaxInterfaceFlow},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
network_model::NetworkModel{<:PM.AbstractActivePowerModel},
) where {T <: PSY.TransmissionInterface}
)
name = get_service_name(model)
service = PSY.get_component(T, sys, name)
service = PSY.get_component(PSY.TransmissionInterface, sys, name)
!PSY.get_available(service) && return

add_to_expression!(
Expand Down Expand Up @@ -637,23 +631,24 @@ function construct_service!(
container::OptimizationContainer,
sys::PSY.System,
::ArgumentConstructStage,
model::ServiceModel{T, VariableMaxInterfaceFlow},
model::ServiceModel{PSY.TransmissionInterface, VariableMaxInterfaceFlow},
devices_template::Dict{Symbol, DeviceModel},
incompatible_device_types::Set{<:DataType},
network_model::NetworkModel{<:PM.AbstractPowerModel},
) where {T <: PSY.TransmissionInterface}
)
interfaces = get_available_components(model, sys)
if get_use_slacks(model)
# Adding the slacks can be done in a cleaner fashion
interface = PSY.get_component(T, sys, get_service_name(model))
interface =
PSY.get_component(PSY.TransmissionInterface, sys, get_service_name(model))
@assert PSY.get_available(interface)
transmission_interface_slacks!(container, interface)
end
# Lazy container addition for the expressions.
lazy_container_addition!(
container,
InterfaceTotalFlow(),
T,
PSY.TransmissionInterface,
PSY.get_name.(interfaces),
get_time_steps(container),
)
Expand All @@ -676,7 +671,7 @@ function construct_service!(
add_parameters!(container, MaxInterfaceFlowLimitParameter, device, model)
end
end
interface = PSY.get_component(T, sys, get_service_name(model))
interface = PSY.get_component(PSY.TransmissionInterface, sys, get_service_name(model))
add_feedforward_arguments!(container, model, interface)
return
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dispatch on PSY.TransmissionInterface and not T in line 688?

Expand Down
Loading
Loading