Skip to content

Commit

Permalink
add constructor for variablemaxinterface
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigomha committed Jun 28, 2024
1 parent aeba709 commit 27926a5
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/devices_models/devices/common/add_to_expression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,8 @@ function add_to_expression!(
::Type{InterfaceTotalFlow},
::Type{FlowActivePowerVariable},
service::PSY.TransmissionInterface,
model::ServiceModel{PSY.TransmissionInterface, ConstantMaxInterfaceFlow},
)
model::ServiceModel{PSY.TransmissionInterface, V},
) where {V <: Union{ConstantMaxInterfaceFlow, VariableMaxInterfaceFlow}}
expression = get_expression(container, InterfaceTotalFlow(), PSY.TransmissionInterface)
service_name = get_service_name(model)
for (device_type, devices) in get_contributing_devices_map(model)
Expand Down
8 changes: 8 additions & 0 deletions src/operation/problem_template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ function _modify_device_model!(
return
end

function _modify_device_model!(
::Dict{Symbol, DeviceModel},
::ServiceModel{PSY.TransmissionInterface, VariableMaxInterfaceFlow},
::Vector,
)
return
end

function _add_services_to_device_model!(template::ProblemTemplate)
service_models = get_service_models(template)
devices_template = get_device_models(template)
Expand Down
4 changes: 2 additions & 2 deletions src/parameters/add_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function add_parameters!(
::Type{T},
service::U,
model::ServiceModel{U, V},
) where {T <: TimeSeriesParameter, U <: PSY.Service, V <: AbstractReservesFormulation}
) where {T <: TimeSeriesParameter, U <: PSY.Service, V <: AbstractServiceFormulation}
if get_rebuild_model(get_settings(container)) &&
has_container_key(container, T, U, PSY.get_name(service))
return
Expand Down Expand Up @@ -258,7 +258,7 @@ function _add_parameters!(
::T,
service::U,
model::ServiceModel{U, V},
) where {T <: TimeSeriesParameter, U <: PSY.Service, V <: AbstractReservesFormulation}
) where {T <: TimeSeriesParameter, U <: PSY.Service, V <: AbstractServiceFormulation}
ts_type = get_default_time_series_type(container)
if !(ts_type <: Union{PSY.AbstractDeterministic, PSY.StaticTimeSeries})
error("add_parameters! for TimeSeriesParameter is not compatible with $ts_type")
Expand Down
91 changes: 91 additions & 0 deletions src/services_models/services_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,94 @@ function construct_service!(
objective_function!(container, service, model)
return
end

function construct_service!(
container::OptimizationContainer,
sys::PSY.System,
::ArgumentConstructStage,
model::ServiceModel{T, 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))
@assert PSY.get_available(interface)
transmission_interface_slacks!(container, interface)
end
# Lazy container addition for the expressions.
lazy_container_addition!(
container,
InterfaceTotalFlow(),
T,
PSY.get_name.(interfaces),
get_time_steps(container),
)
has_ts = PSY.has_time_series.(interfaces)
if any(has_ts) && !all(has_ts)
error(
"Not all TransmissionInterfaces devices have time series. Check data to complete (or remove) time series.",
)
end
if all(has_ts)
for device in interfaces
name = PSY.get_name(device)
num_ts = length(unique(PSY.get_name.(PSY.get_time_series_keys(device))))
if num_ts < 2
error(
"TransmissionInterface $name has less than two time series. It is required to add both min_flow and max_flow time series.",
)
end
add_parameters!(container, MinInterfaceFlowLimitParameter, device, model)
add_parameters!(container, MaxInterfaceFlowLimitParameter, device, model)
end
end
#add_feedforward_arguments!(container, model, service)
return
end

function construct_service!(
container::OptimizationContainer,
sys::PSY.System,
::ModelConstructStage,
model::ServiceModel{T, VariableMaxInterfaceFlow},
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)

add_to_expression!(
container,
InterfaceTotalFlow,
FlowActivePowerVariable,
service,
model,
)

if get_use_slacks(model)
add_to_expression!(
container,
InterfaceTotalFlow,
InterfaceFlowSlackUp,
service,
model,
)
add_to_expression!(
container,
InterfaceTotalFlow,
InterfaceFlowSlackDown,
service,
model,
)
end

add_constraints!(container, InterfaceFlowLimit, service, model)
add_feedforward_constraints!(container, model, service)
add_constraint_dual!(container, sys, model)
objective_function!(container, service, model)
return
end
72 changes: 71 additions & 1 deletion src/services_models/transmission_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ get_variable_lower_bound(::InterfaceFlowSlackDown, ::PSY.TransmissionInterface,
get_variable_multiplier(::InterfaceFlowSlackUp, ::PSY.TransmissionInterface, ::ConstantMaxInterfaceFlow) = 1.0
get_variable_multiplier(::InterfaceFlowSlackDown, ::PSY.TransmissionInterface, ::ConstantMaxInterfaceFlow) = -1.0

get_multiplier_value(::MinInterfaceFlowLimitParameter, d::PSY.TransmissionInterface, ::VariableMaxInterfaceFlow) = PSY.get_min_active_power_flow_limit(d)
get_multiplier_value(::MaxInterfaceFlowLimitParameter, d::PSY.TransmissionInterface, ::VariableMaxInterfaceFlow) = PSY.get_max_active_power_flow_limit(d)

#! format: On
function get_default_time_series_names(
::Type{PSY.TransmissionInterface},
Expand All @@ -14,12 +17,28 @@ function get_default_time_series_names(
return Dict{Type{<:TimeSeriesParameter}, String}()
end

function get_default_time_series_names(
::Type{PSY.TransmissionInterface},
::Type{VariableMaxInterfaceFlow},
)
return Dict{Type{<:TimeSeriesParameter}, String}(
MinInterfaceFlowLimitParameter => "min_active_power_flow_limit",
MaxInterfaceFlowLimitParameter => "max_active_power_flow_limit",
)
end

function get_default_attributes(
::Type{<:PSY.TransmissionInterface},
::Type{ConstantMaxInterfaceFlow})
return Dict{String, Any}()
end

function get_default_attributes(
::Type{<:PSY.TransmissionInterface},
::Type{VariableMaxInterfaceFlow})
return Dict{String, Any}()
end

function get_initial_conditions_service_model(
::OperationModel,
::ServiceModel{T, D},
Expand Down Expand Up @@ -61,11 +80,62 @@ function add_constraints!(container::OptimizationContainer,
return
end

function add_constraints!(container::OptimizationContainer,
::Type{InterfaceFlowLimit},
interface::T,
model::ServiceModel{T, VariableMaxInterfaceFlow},
) where {T <: PSY.TransmissionInterface}
expr = get_expression(container, InterfaceTotalFlow(), T)
interfaces, timesteps = axes(expr)
constraint_container_ub = lazy_container_addition!(
container,
InterfaceFlowLimit(),
T,
interfaces,
timesteps;
meta = "ub",
)
constraint_container_lb = lazy_container_addition!(
container,
InterfaceFlowLimit(),
T,
interfaces,
timesteps;
meta = "lb",
)
int_name = PSY.get_name(interface)
param_container_min =
get_parameter(container, MinInterfaceFlowLimitParameter(), PSY.TransmissionInterface, int_name)
@show param_multiplier_min = get_parameter_multiplier_array(
container,
MinInterfaceFlowLimitParameter(),
PSY.TransmissionInterface,
int_name,
)
param_container_max =
get_parameter(container, MaxInterfaceFlowLimitParameter(), PSY.TransmissionInterface, int_name)
@show param_multiplier_max = get_parameter_multiplier_array(
container,
MaxInterfaceFlowLimitParameter(),
PSY.TransmissionInterface,
int_name,
)
@show param_min = get_parameter_column_refs(param_container_min, int_name)
@show param_max = get_parameter_column_refs(param_container_max, int_name)
for t in timesteps
constraint_container_ub[int_name, t] =
JuMP.@constraint(get_jump_model(container), expr[int_name, t] <= param_multiplier_max[int_name, t] * param_max[t])
constraint_container_lb[int_name, t] =
JuMP.@constraint(get_jump_model(container), expr[int_name, t] >= param_multiplier_min[int_name, t] * param_min[t])
end
return
end

function objective_function!(
container::OptimizationContainer,
service::T,
model::ServiceModel{T, U},
) where {T <: PSY.TransmissionInterface, U <: ConstantMaxInterfaceFlow}
) where {T <: PSY.TransmissionInterface, U <: Union{ConstantMaxInterfaceFlow, VariableMaxInterfaceFlow}}
# At the moment the interfaces have no costs associated with them
return
end

0 comments on commit 27926a5

Please sign in to comment.