Skip to content

Commit

Permalink
update name of variable to DC send
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigomha committed Nov 5, 2024
1 parent 84b8aa0 commit 5dc59d1
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 30 deletions.
20 changes: 14 additions & 6 deletions src/core/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,6 @@ Docs abbreviation: ``\\nu_c^``
"""
struct ConverterCurrentDirection <: VariableType end

"""
Struct to dispatch the creation of DC Converter Binary for Absolute Value Current Variables for DC formulations
Docs abbreviation: `\\nu_c``
"""
struct ConverterBinaryAbsoluteValueCurrent <: VariableType end

"""
Struct to dispatch the creation of Binary Variable for Converter Power Direction
Docs abbreviation: ``\\kappa_c^{dc}``
Expand Down Expand Up @@ -338,6 +332,20 @@ Docs abbreviation: ``z_c^{\\gamma}``
"""
struct InterpolationBinarySquaredBilinearVariableTo <: SparseVariableType end

"""
Struct to dispatch the creation of HVDC Received Flow at From Bus Variables for PWL formulations
Docs abbreviation: ``x``
"""
struct HVDCActiveDCPowerSentFromVariable <: VariableType end

"""
Struct to dispatch the creation of HVDC Received Flow at To Bus Variables for PWL formulations
Docs abbreviation: ``y``
"""
struct HVDCActiveDCPowerSentToVariable <: VariableType end

"""
Struct to dispatch the creation of bidirectional Active Power Flow Variables
Expand Down
15 changes: 4 additions & 11 deletions src/devices_models/device_constructors/branch_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,8 @@ function construct_device!(
#####################
V = HVDCTwoTerminalVSCLoss
# Add Power Variable
add_variables!(container, HVDCActivePowerReceivedFromVariable, devices, V()) # p_c^{ac,from}
add_variables!(container, HVDCActivePowerReceivedToVariable, devices, V()) # p_c^{ac,from}
add_variables!(container, HVDCActiveDCPowerSentFromVariable, devices, V()) # p_c^{ac,from}
add_variables!(container, HVDCActiveDCPowerSentToVariable, devices, V()) # p_c^{ac,from}
add_variables!(container, ConverterPowerDirection, devices, V()) #κ
# Add Voltage Variables: v_dc, v^sq, δ^v, z^v
add_variables!(container, DCVoltageFrom, devices, V()) # v_dc^{from}
Expand All @@ -931,13 +931,6 @@ function construct_device!(
add_variables!(container, ConverterCurrentDirection, devices, V())
add_variables!(container, HVDCLosses, devices, V())

add_variables!(
container,
ConverterBinaryAbsoluteValueCurrent,
devices,
V(),
) # ν

# Add Bilinear Variables: γ, γ^{sq}
add_variables!(
container,
Expand Down Expand Up @@ -973,7 +966,7 @@ function construct_device!(
add_to_expression!(
container,
ActivePowerBalance,
HVDCActivePowerReceivedFromVariable,
HVDCActiveDCPowerSentFromVariable,
devices,
model,
network_model,
Expand All @@ -982,7 +975,7 @@ function construct_device!(
add_to_expression!(
container,
ActivePowerBalance,
HVDCActivePowerReceivedToVariable,
HVDCActiveDCPowerSentToVariable,
devices,
model,
network_model,
Expand Down
50 changes: 39 additions & 11 deletions src/devices_models/devices/TwoTerminalDC_branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,28 @@ get_variable_binary(
) = true

get_variable_binary(
_,
::Union{
HVDCActiveDCPowerSentFromVariable,
HVDCActiveDCPowerSentToVariable,
DCVoltageFrom,
DCVoltageTo,
SquaredDCVoltageFrom,
SquaredDCVoltageTo,
ConverterCurrent,
SquaredConverterCurrent,
ConverterPositiveCurrent,
ConverterNegativeCurrent,
HVDCLosses,
AuxBilinearConverterVariableFrom,
AuxBilinearSquaredConverterVariableFrom,
AuxBilinearConverterVariableTo,
AuxBilinearSquaredConverterVariableTo,
InterpolationSquaredVoltageVariableFrom,
InterpolationSquaredVoltageVariableTo,
InterpolationSquaredCurrentVariable,
InterpolationSquaredBilinearVariableFrom,
InterpolationSquaredBilinearVariableTo,
},
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::HVDCTwoTerminalVSCLoss,
) = false
Expand All @@ -32,6 +53,11 @@ get_variable_binary(
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::HVDCTwoTerminalVSCLoss,
) = true
get_variable_binary(
::InterpolationBinarySquaredCurrentVariable,
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
::HVDCTwoTerminalVSCLoss,
) = true
get_variable_binary(
::InterpolationBinarySquaredBilinearVariableFrom,
::Type{<:PSY.TwoTerminalHVDCDetailedLine},
Expand Down Expand Up @@ -149,25 +175,25 @@ get_variable_lower_bound(
) = PSY.get_active_power_limits_to(d).min

get_variable_upper_bound(
::HVDCActivePowerReceivedFromVariable,
::Union{HVDCActivePowerReceivedFromVariable, HVDCActiveDCPowerSentFromVariable},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine},
::AbstractTwoTerminalDCLineFormulation,
) = PSY.get_active_power_limits_from(d).max

get_variable_lower_bound(
::HVDCActivePowerReceivedFromVariable,
::Union{HVDCActivePowerReceivedFromVariable, HVDCActiveDCPowerSentFromVariable},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine},
::AbstractTwoTerminalDCLineFormulation,
) = PSY.get_active_power_limits_from(d).min

get_variable_upper_bound(
::HVDCActivePowerReceivedToVariable,
::Union{HVDCActivePowerReceivedToVariable, HVDCActiveDCPowerSentToVariable},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine},
::AbstractTwoTerminalDCLineFormulation,
) = PSY.get_active_power_limits_to(d).max

get_variable_lower_bound(
::HVDCActivePowerReceivedToVariable,
::Union{HVDCActivePowerReceivedToVariable, HVDCActiveDCPowerSentToVariable},
d::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalHVDCDetailedLine},
::AbstractTwoTerminalDCLineFormulation,
) = PSY.get_active_power_limits_to(d).min
Expand Down Expand Up @@ -613,6 +639,8 @@ function _add_hvdc_flow_constraints!(
FlowActivePowerToFromVariable,
HVDCActivePowerReceivedFromVariable,
HVDCActivePowerReceivedToVariable,
HVDCActiveDCPowerSentFromVariable,
HVDCActiveDCPowerSentToVariable,
},
constraint::Union{FlowRateConstraintFromTo, FlowRateConstraintToFrom},
) where {T <: PSY.TwoTerminalHVDCLine}
Expand Down Expand Up @@ -896,8 +924,8 @@ function add_constraints!(
time_steps = get_time_steps(container)
names = [PSY.get_name(d) for d in devices]
# power vars #
from_power_var = get_variable(container, HVDCActivePowerReceivedFromVariable(), U)
to_power_var = get_variable(container, HVDCActivePowerReceivedToVariable(), U)
from_power_var = get_variable(container, HVDCActiveDCPowerSentFromVariable(), U)
to_power_var = get_variable(container, HVDCActiveDCPowerSentToVariable(), U)
# voltage vars #
from_voltage_var = get_variable(container, DCVoltageFrom(), U)
to_voltage_var = get_variable(container, DCVoltageTo(), U)
Expand Down Expand Up @@ -994,8 +1022,8 @@ function add_constraints!(
names = [PSY.get_name(d) for d in devices]
JuMPmodel = get_jump_model(container)
# power vars #
from_power_var = get_variable(container, HVDCActivePowerReceivedFromVariable(), U)
to_power_var = get_variable(container, HVDCActivePowerReceivedToVariable(), U)
from_power_var = get_variable(container, HVDCActiveDCPowerSentFromVariable(), U)
to_power_var = get_variable(container, HVDCActiveDCPowerSentToVariable(), U)
# current vars #
current_var = get_variable(container, ConverterCurrent(), U) # From direction
direction_var = get_variable(container, ConverterPowerDirection(), U)
Expand Down Expand Up @@ -1099,8 +1127,8 @@ function add_constraints!(
names = [PSY.get_name(d) for d in devices]
JuMPmodel = get_jump_model(container)
# power vars #
from_power_var = get_variable(container, HVDCActivePowerReceivedFromVariable(), U)
to_power_var = get_variable(container, HVDCActivePowerReceivedToVariable(), U)
from_power_var = get_variable(container, HVDCActiveDCPowerSentFromVariable(), U)
to_power_var = get_variable(container, HVDCActiveDCPowerSentToVariable(), U)
# current vars #
current_var = get_variable(container, ConverterCurrent(), U) # From direction
# voltage vars #
Expand Down
78 changes: 76 additions & 2 deletions src/devices_models/devices/common/add_to_expression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function add_to_expression!(
T <: ActivePowerBalance,
U <: HVDCActivePowerReceivedFromVariable,
V <: TwoTerminalHVDCTypes,
W <: Union{HVDCTwoTerminalPiecewiseLoss, HVDCTwoTerminalVSCLoss},
W <: HVDCTwoTerminalPiecewiseLoss,
X <: AbstractPTDFModel,
}
var = get_variable(container, U(), V)
Expand Down Expand Up @@ -430,7 +430,7 @@ function add_to_expression!(
T <: ActivePowerBalance,
U <: HVDCActivePowerReceivedToVariable,
V <: TwoTerminalHVDCTypes,
W <: Union{HVDCTwoTerminalPiecewiseLoss, HVDCTwoTerminalVSCLoss},
W <: HVDCTwoTerminalPiecewiseLoss,
X <: AbstractPTDFModel,
}
var = get_variable(container, U(), V)
Expand All @@ -453,6 +453,80 @@ function add_to_expression!(
return
end

"""
PWL implementation to add FromTo branch variables to SystemBalanceExpressions
"""
function add_to_expression!(
container::OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
::DeviceModel{V, W},
network_model::NetworkModel{X},
) where {
T <: ActivePowerBalance,
U <: HVDCActiveDCPowerSentFromVariable,
V <: TwoTerminalHVDCTypes,
W <: HVDCTwoTerminalVSCLoss,
X <: AbstractPTDFModel,
}
var = get_variable(container, U(), V)
nodal_expr = get_expression(container, T(), PSY.ACBus)
sys_expr = get_expression(container, T(), _system_expression_type(X))
radial_network_reduction = get_radial_network_reduction(network_model)
for d in devices
bus_no_from =
PNM.get_mapped_bus_number(radial_network_reduction, PSY.get_arc(d).from)
ref_bus_to = get_reference_bus(network_model, PSY.get_arc(d).to)
ref_bus_from = get_reference_bus(network_model, PSY.get_arc(d).from)
for t in get_time_steps(container)
flow_variable = var[PSY.get_name(d), t]
_add_to_jump_expression!(nodal_expr[bus_no_from, t], flow_variable, -1.0)
if ref_bus_from != ref_bus_to
_add_to_jump_expression!(sys_expr[ref_bus_from, t], flow_variable, -1.0)
end
end
end
return
end

"""
PWL implementation to add FromTo branch variables to SystemBalanceExpressions
"""
function add_to_expression!(
container::OptimizationContainer,
::Type{T},
::Type{U},
devices::IS.FlattenIteratorWrapper{V},
::DeviceModel{V, W},
network_model::NetworkModel{X},
) where {
T <: ActivePowerBalance,
U <: HVDCActiveDCPowerSentToVariable,
V <: TwoTerminalHVDCTypes,
W <: HVDCTwoTerminalVSCLoss,
X <: AbstractPTDFModel,
}
var = get_variable(container, U(), V)
nodal_expr = get_expression(container, T(), PSY.ACBus)
sys_expr = get_expression(container, T(), _system_expression_type(X))
radial_network_reduction = get_radial_network_reduction(network_model)
for d in devices
bus_no_to =
PNM.get_mapped_bus_number(radial_network_reduction, PSY.get_arc(d).to)
ref_bus_to = get_reference_bus(network_model, PSY.get_arc(d).to)
ref_bus_from = get_reference_bus(network_model, PSY.get_arc(d).from)
for t in get_time_steps(container)
flow_variable = var[PSY.get_name(d), t]
_add_to_jump_expression!(nodal_expr[bus_no_to, t], flow_variable, -1.0)
if ref_bus_from != ref_bus_to
_add_to_jump_expression!(sys_expr[ref_bus_to, t], flow_variable, -1.0)
end
end
end
return
end

"""
Default implementation to add branch variables to SystemBalanceExpressions
"""
Expand Down

0 comments on commit 5dc59d1

Please sign in to comment.