-
Notifications
You must be signed in to change notification settings - Fork 1
Add HVDCTwoTerminalVSC two-terminal HVDC formulation #119
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
085eb77
Add HVDCTwoTerminalVSC two-terminal HVDC formulation
9d249b7
Address PR #119 review on HVDCTwoTerminalVSC
b5649b5
Address PR #119 Review 2 on HVDCTwoTerminalVSC
c6ca90a
Address PR #119 Review 3 on HVDCTwoTerminalVSC
c4b50e6
Address PR #119 Review 3 follow-up on HVDCTwoTerminalVSC
45eb412
formatting
d176fb0
Address PR #119 Review 4 on HVDCTwoTerminalVSC
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1670,3 +1670,161 @@ function construct_device!( | |
| add_feedforward_constraints!(container, device_model, devices) | ||
| return | ||
| end | ||
|
|
||
| ############################################################################ | ||
| ####################### Two-Terminal VSC HVDC Construct #################### | ||
| ############################################################################ | ||
|
|
||
| # Quadratic / bilinear approximation traits — same scheme used by the MT | ||
| # converter formulations. | ||
| _quad_config(::Type{HVDCTwoTerminalVSCNLP}) = IOM.NoQuadApproxConfig() | ||
| _quad_config(::Type{HVDCTwoTerminalVSCLP}) = | ||
| IOM.SolverSOS2QuadConfig(DEFAULT_INTERPOLATION_LENGTH) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @acostarelli Can you open an issue to figure out how the user can configure the interpolation and model option (BIN2 or other) for the approximation for the future? We don't need to solve this in this PR, but we need to be aware of that. |
||
| _bilinear_config(::Type{HVDCTwoTerminalVSCNLP}) = IOM.NoBilinearApproxConfig() | ||
| _bilinear_config(::Type{HVDCTwoTerminalVSCLP}) = | ||
| IOM.Bin2Config(IOM.SolverSOS2QuadConfig(DEFAULT_INTERPOLATION_LENGTH)) | ||
|
|
||
| function construct_device!( | ||
| container::OptimizationContainer, | ||
| sys::PSY.System, | ||
| ::ArgumentConstructStage, | ||
| device_model::DeviceModel{PSY.TwoTerminalVSCLine, F}, | ||
| network_model::NetworkModel{<:AbstractPowerModel}, | ||
| ) where {F <: AbstractTwoTerminalVSCFormulation} | ||
| devices = get_available_components(device_model, sys) | ||
|
|
||
| add_variables!(container, FlowActivePowerFromToVariable, devices, F) | ||
| add_variables!(container, FlowActivePowerToFromVariable, devices, F) | ||
| add_variables!(container, DCLineCurrentFlowVariable, devices, F) | ||
| add_variables!(container, HVDCFromDCVoltage, devices, F) | ||
| add_variables!(container, HVDCToDCVoltage, devices, F) | ||
|
|
||
| _maybe_add_reactive_power_variables!( | ||
| container, devices, device_model, network_model, | ||
| (HVDCReactivePowerFromVariable, HVDCReactivePowerToVariable), | ||
| ) | ||
|
|
||
| # use_linear_loss = true adds a binary direction variable (CurrentDirection). | ||
| # Both HVDCTwoTerminalVSCNLP and HVDCTwoTerminalVSCLP dispatch through here: | ||
| # on the NLP formulation this pushes the model from a smooth NLP to MINLP | ||
| # (caller must supply a MINLP-capable solver); on the LP formulation the | ||
| # SOS2 PWL approximations already make the model MILP, so the extra binary | ||
| # is free. | ||
| if get_attribute(device_model, "use_linear_loss") | ||
| _add_abs_value_decomposition_variables!( | ||
| container, devices, device_model, network_model, | ||
| ) | ||
| end | ||
|
|
||
| add_to_expression!( | ||
| container, ActivePowerBalance, FlowActivePowerFromToVariable, | ||
| devices, device_model, network_model, | ||
| ) | ||
| add_to_expression!( | ||
| container, ActivePowerBalance, FlowActivePowerToFromVariable, | ||
| devices, device_model, network_model, | ||
| ) | ||
|
|
||
| add_feedforward_arguments!(container, device_model, devices) | ||
| return | ||
| end | ||
|
|
||
| function construct_device!( | ||
| container::OptimizationContainer, | ||
| sys::PSY.System, | ||
| ::ModelConstructStage, | ||
| device_model::DeviceModel{PSY.TwoTerminalVSCLine, F}, | ||
| network_model::NetworkModel{<:AbstractPowerModel}, | ||
| ) where {F <: AbstractTwoTerminalVSCFormulation} | ||
| devices = get_available_components(device_model, sys) | ||
| time_steps = get_time_steps(container) | ||
| line_names = [PSY.get_name(d) for d in devices] | ||
|
|
||
| v_f_var = get_variable(container, HVDCFromDCVoltage, PSY.TwoTerminalVSCLine) | ||
| v_t_var = get_variable(container, HVDCToDCVoltage, PSY.TwoTerminalVSCLine) | ||
| i_var = get_variable(container, DCLineCurrentFlowVariable, PSY.TwoTerminalVSCLine) | ||
|
|
||
| v_f_bounds = PSY.get_voltage_limits_from.(devices) | ||
| v_t_bounds = PSY.get_voltage_limits_to.(devices) | ||
| i_bounds = [ | ||
| (min = -_linear_loss_i_max(d), max = _linear_loss_i_max(d)) for d in devices | ||
| ] | ||
|
|
||
| quad_cfg, bilin_cfg = _quad_config(F), _bilinear_config(F) | ||
|
|
||
| v_f_sq_expr = IOM._add_quadratic_approx!( | ||
| quad_cfg, container, PSY.TwoTerminalVSCLine, | ||
| line_names, time_steps, v_f_var, v_f_bounds, "v_f_sq", | ||
| ) | ||
| v_t_sq_expr = IOM._add_quadratic_approx!( | ||
| quad_cfg, container, PSY.TwoTerminalVSCLine, | ||
| line_names, time_steps, v_t_var, v_t_bounds, "v_t_sq", | ||
| ) | ||
| i_sq_expr = IOM._add_quadratic_approx!( | ||
| quad_cfg, container, PSY.TwoTerminalVSCLine, | ||
| line_names, time_steps, i_var, i_bounds, "i_sq", | ||
| ) | ||
|
|
||
| IOM._add_bilinear_approx!( | ||
| bilin_cfg, container, PSY.TwoTerminalVSCLine, | ||
| line_names, time_steps, | ||
| v_f_sq_expr, i_sq_expr, v_f_var, i_var, | ||
| v_f_bounds, i_bounds, "vi_ft", | ||
| ) | ||
| IOM._add_bilinear_approx!( | ||
| bilin_cfg, container, PSY.TwoTerminalVSCLine, | ||
| line_names, time_steps, | ||
| v_t_sq_expr, i_sq_expr, v_t_var, i_var, | ||
| v_t_bounds, i_bounds, "vi_tf", | ||
| ) | ||
|
|
||
| _register_pq_sq_expressions!( | ||
| container, devices, line_names, time_steps, device_model, | ||
| network_model, | ||
| ) | ||
|
|
||
| if get_attribute(device_model, "use_linear_loss") | ||
| _add_abs_value_decomposition_constraints!( | ||
| container, devices, device_model, network_model, | ||
| DCLineCurrentFlowVariable, | ||
| ) | ||
| end | ||
|
|
||
| add_constraints!( | ||
| container, HVDCCableOhmsLawConstraint, devices, device_model, network_model, | ||
| ) | ||
| add_constraints!( | ||
| container, HVDCVSCConverterPowerConstraint, devices, device_model, network_model, | ||
| ) | ||
| _maybe_add_reactive_power_constraints!( | ||
| container, devices, device_model, network_model, | ||
| HVDCVSCApparentPowerLimitConstraint, | ||
| ) | ||
|
|
||
| add_constraint_dual!(container, sys, device_model) | ||
| add_feedforward_constraints!(container, device_model, devices) | ||
| return | ||
| end | ||
|
|
||
| # AreaBalancePowerModel warning (consistent with other two-terminal formulations). | ||
| function construct_device!( | ||
| ::OptimizationContainer, | ||
| ::PSY.System, | ||
| ::ArgumentConstructStage, | ||
| ::DeviceModel{PSY.TwoTerminalVSCLine, <:AbstractTwoTerminalVSCFormulation}, | ||
| ::NetworkModel{AreaBalancePowerModel}, | ||
| ) | ||
| @warn "AreaBalancePowerModel doesn't model individual line flows for PSY.TwoTerminalVSCLine. Arguments not built" | ||
| return | ||
| end | ||
|
|
||
| function construct_device!( | ||
| ::OptimizationContainer, | ||
| ::PSY.System, | ||
| ::ModelConstructStage, | ||
| ::DeviceModel{PSY.TwoTerminalVSCLine, <:AbstractTwoTerminalVSCFormulation}, | ||
| ::NetworkModel{AreaBalancePowerModel}, | ||
| ) | ||
| @warn "AreaBalancePowerModel doesn't model individual line flows for PSY.TwoTerminalVSCLine. Model not built" | ||
| return | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Helpers for variables/constraints that should only appear when the network | ||
| # model actually represents the relevant physical quantity (e.g. reactive | ||
| # power on AC networks). Each helper has a no-op method that dispatches on | ||
| # `NetworkModel{<:AbstractActivePowerModel}`; Julia's method resolution picks | ||
| # the more specific no-op over the AC body for DC formulations. | ||
|
|
||
| """ | ||
| Add reactive-power variables for a device and register them in the system's | ||
| `ReactivePowerBalance` expression. `var_types` is a tuple/iterable of | ||
| `VariableType` subtypes; each is added via `add_variables!` and then linked | ||
| into `ReactivePowerBalance` via `add_to_expression!`. The caller's | ||
| device-specific `add_to_expression!` methods are responsible for the actual | ||
| bus mapping and sign convention. | ||
| """ | ||
| function _maybe_add_reactive_power_variables!( | ||
| container::OptimizationContainer, | ||
| devices, | ||
| model::DeviceModel{D, F}, | ||
| network_model::NetworkModel{<:AbstractPowerModel}, | ||
| var_types, | ||
| ) where {D <: PSY.Device, F} | ||
| for V in var_types | ||
| add_variables!(container, V, devices, F) | ||
| add_to_expression!( | ||
| container, ReactivePowerBalance, V, devices, model, network_model, | ||
| ) | ||
| end | ||
| return | ||
| end | ||
|
|
||
| _maybe_add_reactive_power_variables!( | ||
| ::OptimizationContainer, | ||
| _devices, | ||
| ::DeviceModel{D, F}, | ||
| ::NetworkModel{<:AbstractActivePowerModel}, | ||
| _var_types, | ||
| ) where {D <: PSY.Device, F} = nothing | ||
|
|
||
| """ | ||
| Add a reactive-power-related constraint for a device on AC networks. | ||
| """ | ||
| function _maybe_add_reactive_power_constraints!( | ||
| container::OptimizationContainer, | ||
| devices, | ||
| model::DeviceModel{D, F}, | ||
| network_model::NetworkModel{<:AbstractPowerModel}, | ||
| constraint_type::Type{<:ConstraintType}, | ||
| ) where {D <: PSY.Device, F} | ||
| add_constraints!(container, constraint_type, devices, model, network_model) | ||
| return | ||
| end | ||
|
|
||
| _maybe_add_reactive_power_constraints!( | ||
| ::OptimizationContainer, | ||
| _devices, | ||
| ::DeviceModel{D, F}, | ||
| ::NetworkModel{<:AbstractActivePowerModel}, | ||
| ::Type{<:ConstraintType}, | ||
| ) where {D <: PSY.Device, F} = nothing |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.