Skip to content
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

Jd/hvdc model #1003

Merged
merged 76 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
13996a3
many renames
jd-lara Feb 5, 2023
d819b96
more rename
jd-lara Feb 5, 2023
77a0f7b
add new formulations
jd-lara Feb 5, 2023
aa31db8
WIP add test
jd-lara Feb 5, 2023
148b606
add methods and renames
jd-lara Feb 5, 2023
cead4c3
implement additional expressions
jd-lara Feb 5, 2023
1b122df
methods converter dc balance
jd-lara Feb 5, 2023
ca151fd
add line argument stage
jd-lara Feb 5, 2023
1311675
setup model construct stage
jd-lara Feb 5, 2023
f438eae
add hint
jd-lara Feb 5, 2023
1d60fdc
many renames
jd-lara Feb 5, 2023
cc3347b
more rename
jd-lara Feb 5, 2023
e35133c
add new formulations
jd-lara Feb 5, 2023
0fd9d5a
WIP add test
jd-lara Feb 5, 2023
0516fe6
add methods and renames
jd-lara Feb 5, 2023
8765fc3
implement additional expressions
jd-lara Feb 5, 2023
aa747e6
methods converter dc balance
jd-lara Feb 5, 2023
5f27c2a
add line argument stage
jd-lara Feb 5, 2023
6053b26
setup model construct stage
jd-lara Feb 5, 2023
64bce1c
add hint
jd-lara Feb 5, 2023
85a03be
Merge branch 'jd/hvdc_model' of https://github.com/NREL-SIIP/PowerSim…
jd-lara Feb 5, 2023
31f836d
add model for lossless HVDC system
jd-lara Feb 14, 2023
791d9cb
updates to expression types
jd-lara Feb 23, 2023
3be8a91
remove duplicate
jd-lara Feb 23, 2023
6c21b00
fix tests
jd-lara Feb 23, 2023
a196345
add missing function calls
jd-lara Feb 23, 2023
8109c5f
remove unused arguments
jd-lara Feb 23, 2023
8b8de2c
fix expression additions
jd-lara Jun 30, 2023
ceeb00e
fix duplicate call
jd-lara Jun 30, 2023
9dbc558
many renames
jd-lara Jul 3, 2023
d31c910
more rename
jd-lara Jul 3, 2023
6f80708
add new formulations
jd-lara Feb 5, 2023
c3df064
WIP add test
jd-lara Feb 5, 2023
8eef0b3
add methods and renames
jd-lara Jul 3, 2023
6a45362
implement additional expressions
jd-lara Jul 3, 2023
aa0acac
methods converter dc balance
jd-lara Feb 5, 2023
42dc8f2
add line argument stage
jd-lara Feb 5, 2023
34b8e0d
setup model construct stage
jd-lara Feb 5, 2023
303781f
add hint
jd-lara Feb 5, 2023
90fc7f5
many renames
jd-lara Feb 5, 2023
5351802
add new formulations
jd-lara Jul 3, 2023
ef0d640
add methods and renames
jd-lara Jul 3, 2023
a9ed97e
add line argument stage
jd-lara Feb 5, 2023
af96ad1
setup model construct stage
jd-lara Feb 5, 2023
f5f0224
add model for lossless HVDC system
jd-lara Jul 3, 2023
28098bf
updates to expression types
jd-lara Jul 3, 2023
ffcc583
remove duplicate
jd-lara Feb 23, 2023
ab17ae6
fix tests
jd-lara Jul 3, 2023
349a682
add missing function calls
jd-lara Feb 23, 2023
17c5dc0
remove unused arguments
jd-lara Feb 23, 2023
257cef6
fix expression additions
jd-lara Jun 30, 2023
3d664cc
fix duplicate call
jd-lara Jun 30, 2023
d4a37b2
Merge branch 'jd/hvdc_model' of https://github.com/NREL-SIIP/PowerSim…
jd-lara Jul 3, 2023
c7226a8
update code
jd-lara Jul 3, 2023
aa2c8d2
update bustypes
jd-lara Jul 3, 2023
a096566
fix some types
jd-lara Jul 5, 2023
01bad33
correct PTDF model
jd-lara Jul 7, 2023
0f7539d
bump project toml
jd-lara Jul 7, 2023
728dcb6
Merge branch 'main' into jd/hvdc_model
jd-lara Sep 6, 2023
38930dc
bump deps
jd-lara Sep 6, 2023
a7527bf
remove bad reference file
jd-lara Sep 6, 2023
698d0d5
add HPS to tests
jd-lara Sep 6, 2023
39aa50a
many fixes
jd-lara Sep 7, 2023
9ac586c
fix test
jd-lara Sep 7, 2023
5c944b1
fix some tests
jd-lara Sep 7, 2023
07c6294
fixes to reserves
jd-lara Sep 8, 2023
f4ebc64
address Dan's comment
jd-lara Sep 11, 2023
3e4ef49
use getters
jd-lara Sep 11, 2023
35ae6c7
bump hdf5
jd-lara Sep 13, 2023
e18c78b
fix bad merge
jd-lara Sep 13, 2023
cbf552f
add additional test
jd-lara Sep 13, 2023
40fed26
formatter
jd-lara Sep 13, 2023
894238f
fix undefined variable
jd-lara Sep 13, 2023
59a22a4
fix feedforwards
jd-lara Sep 13, 2023
81a6652
fix call to update parameter values
jd-lara Sep 13, 2023
370cdbc
formatter
jd-lara Sep 13, 2023
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
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PowerSimulations"
uuid = "e690365d-45e2-57bb-ac84-44ba829e73c4"
authors = ["Jose Daniel Lara", "Clayton Barrows", "Daniel Thom", "Dheepak Krishnamurthy", "Sourabh Dalvi"]
version = "0.22.0"
version = "0.23.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down Expand Up @@ -35,15 +35,15 @@ CSV = "~0.10"
DataFrames = "1"
DataStructures = "~0.18"
DocStringExtensions = "~v0.9"
HDF5 = "~0.16"
HDF5 = "~0.17"
InfrastructureSystems = "^1.21"
JSON = "0.21"
JSON3 = "1"
JuMP = "1"
MathOptInterface = "1"
PowerModels = "~0.19"
PowerNetworkMatrices = "^0.8"
PowerSystems = "^2.6"
PowerNetworkMatrices = "^0.9"
PowerSystems = "^3"
PrettyTables = "^1.3, 2"
ProgressMeter = "^1.5"
TimeSeries = "~0.23"
Expand Down
12 changes: 6 additions & 6 deletions docs/src/formulation_library/Branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ StaticBranchUnbounded

---

## `HVDCP2PLossless`
## `HVDCTwoTerminalLossless`

```@docs
HVDCP2PLossless
HVDCTwoTerminalLossless
```

---

## `HVDCP2PDispatch`
## `HVDCTwoTerminalDispatch`

```@docs
HVDCP2PDispatch
HVDCTwoTerminalDispatch
```

---

## `HVDCP2PUnbounded`
## `HVDCTwoTerminalUnbounded`

```@docs
HVDCP2PUnbounded
HVDCTwoTerminalUnbounded
```
15 changes: 11 additions & 4 deletions src/PowerSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ export ConstantMaxInterfaceFlow
export StaticBranch
export StaticBranchBounds
export StaticBranchUnbounded
export HVDCP2PLossless
export HVDCP2PDispatch
export HVDCP2PUnbounded
export HVDCTwoTerminalLossless
export HVDCTwoTerminalDispatch
export HVDCTwoTerminalUnbounded
export PhaseAngleControl
# export VoltageSourceDC

######## HVDC models ########
export LossLessConverter
export LossLessLine
######## Load Models ########
export StaticPowerLoad
export PowerLoadInterruption
Expand Down Expand Up @@ -511,7 +515,8 @@ include("devices_models/devices/renewable_generation.jl")
include("devices_models/devices/thermal_generation.jl")
include("devices_models/devices/electric_loads.jl")
include("devices_models/devices/AC_branches.jl")
include("devices_models/devices/DC_branches.jl")
include("devices_models/devices/TwoTerminalDC_branches.jl")
include("devices_models/devices/HVDCsystems.jl")
include("devices_models/devices/regulation_device.jl")

# Services Models
Expand All @@ -528,12 +533,14 @@ include("network_models/powermodels_interface.jl")
include("network_models/pm_translator.jl")
include("network_models/network_slack_variables.jl")
include("network_models/area_balance_model.jl")
include("network_models/hvdc_networks.jl")

include("initial_conditions/initialization.jl")

# Device constructors
include("devices_models/device_constructors/constructor_validations.jl")
include("devices_models/device_constructors/thermalgeneration_constructor.jl")
include("devices_models/device_constructors/hvdcsystems_constructor.jl")
include("devices_models/device_constructors/branch_constructor.jl")
include("devices_models/device_constructors/renewablegeneration_constructor.jl")
include("devices_models/device_constructors/load_constructor.jl")
Expand Down
1 change: 1 addition & 0 deletions src/core/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const JuMPVariableMatrix = DenseAxisArray{
const JuMPFloatArray = DenseAxisArray{Float64}
const JuMPVariableArray = DenseAxisArray{JuMP.VariableRef}

const TwoTerminalHVDCTypes = Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalVSCDCLine}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be an abstract type?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think there is much value in an additional abstraction in PSY for this.

# Settings constants
const UNSET_HORIZON = 0
const UNSET_INI_TIME = Dates.DateTime(0)
Expand Down
23 changes: 17 additions & 6 deletions src/core/formulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct MyCustomBranchFormulation <: PSI.AbstractDeviceFormulation
# Generic Branch Models
abstract type AbstractBranchFormulation <: AbstractDeviceFormulation end

############################### AC Branch Formulations #####################################
############################### AC/DC Branch Formulations #####################################
"""
Branch type to add unbounded flow variables and use flow constraints
"""
Expand All @@ -121,21 +121,32 @@ Branch formulation for PhaseShiftingTransformer flow control
struct PhaseAngleControl <: AbstractBranchFormulation end

############################### DC Branch Formulations #####################################
abstract type AbstractDCLineFormulation <: AbstractBranchFormulation end
abstract type AbstractTwoTerminalDCLineFormulation <: AbstractBranchFormulation end
"""
Branch type to avoid flow constraints
"""
struct HVDCP2PUnbounded <: AbstractDCLineFormulation end
struct HVDCTwoTerminalUnbounded <: AbstractTwoTerminalDCLineFormulation end
"""
Branch type to represent lossless power flow on DC lines
"""
struct HVDCP2PLossless <: AbstractDCLineFormulation end
struct HVDCTwoTerminalLossless <: AbstractTwoTerminalDCLineFormulation end
"""
Branch type to represent lossy power flow on DC lines
"""
struct HVDCP2PDispatch <: AbstractDCLineFormulation end
struct HVDCTwoTerminalDispatch <: AbstractTwoTerminalDCLineFormulation end
# Not Implemented
# struct VoltageSourceDC <: AbstractDCLineFormulation end
# struct VoltageSourceDC <: AbstractTwoTerminalDCLineFormulation end

############################### AC/DC Converter Formulations #####################################
abstract type AbstractConverterFormulation <: AbstractDeviceFormulation end

"""
LossLess InterconnectingConverter Model
"""
struct LossLessConverter <: AbstractConverterFormulation end

# TODO: Think if this an ok abstraction for future use cases
jd-lara marked this conversation as resolved.
Show resolved Hide resolved
struct LossLessLine <: AbstractBranchFormulation end

############################## Network Model Formulations ##################################
# These formulations are taken directly from PowerModels
Expand Down
8 changes: 4 additions & 4 deletions src/core/network_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mutable struct NetworkModel{T <: PM.AbstractPowerModel}
use_slacks::Bool
PTDF_matrix::Union{Nothing, PNM.PowerNetworkMatrix}
subnetworks::Dict{Int, Set{Int}}
bus_area_map::Dict{PSY.Bus, Int}
bus_area_map::Dict{PSY.ACBus, Int}
duals::Vector{DataType}

function NetworkModel(
Expand All @@ -41,7 +41,7 @@ mutable struct NetworkModel{T <: PM.AbstractPowerModel}
duals = Vector{DataType}(),
) where {T <: PM.AbstractPowerModel}
_check_pm_formulation(T)
new{T}(use_slacks, PTDF_matrix, subnetworks, Dict{PSY.Bus, Int}(), duals)
new{T}(use_slacks, PTDF_matrix, subnetworks, Dict{PSY.ACBus, Int}(), duals)
end
end

Expand Down Expand Up @@ -107,7 +107,7 @@ function _assign_subnetworks_to_buses(
) where {T <: Union{CopperPlatePowerModel, StandardPTDFModel}}
subnetworks = model.subnetworks
temp_bus_map = Dict{Int, Int}()
for bus in get_available_components(PSY.Bus, sys)
for bus in get_available_components(PSY.ACBus, sys)
bus_no = PSY.get_number(bus)
if haskey(temp_bus_map, bus_no)
model.bus_area_map[bus] = temp_bus_map[bus_no]
Expand All @@ -131,7 +131,7 @@ _assign_subnetworks_to_buses(

function get_reference_bus(
model::NetworkModel{T},
b::PSY.Bus,
b::PSY.ACBus,
)::Int where {T <: PM.AbstractPowerModel}
if isempty(model.bus_area_map)
return first(keys(model.subnetworks))
Expand Down
59 changes: 40 additions & 19 deletions src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ end
function is_milp(container::OptimizationContainer)::Bool
!supports_milp(container) && return false
if !isempty(
JuMP.all_constraints(container.JuMPmodel, JuMP.VariableRef, JuMP.MOI.ZeroOne),
JuMP.all_constraints(
PSI.get_jump_model(container),
JuMP.VariableRef,
JuMP.MOI.ZeroOne,
),
)
return true
end
Expand Down Expand Up @@ -307,10 +311,10 @@ function _finalize_jump_model!(container::OptimizationContainer, settings::Setti
@debug "The optimization model has no optimizer attached" _group =
LOG_GROUP_OPTIMIZATION_CONTAINER
else
JuMP.set_optimizer(container.JuMPmodel, get_optimizer(settings))
JuMP.set_optimizer(PSI.get_jump_model(container), get_optimizer(settings))
end

JuMPmodel = container.JuMPmodel
JuMPmodel = PSI.get_jump_model(container)
warm_start_enabled = get_warm_start(settings)
solver_supports_warm_start = _validate_warm_start_support(JuMPmodel, warm_start_enabled)
set_warm_start!(settings, solver_supports_warm_start)
Expand Down Expand Up @@ -386,7 +390,7 @@ function reset_optimization_model!(container::OptimizationContainer)
container.initial_conditions_data = InitialConditionsData()
container.objective_function = ObjectiveFunction()
container.primal_values_cache = PrimalValuesCache()
JuMP.empty!(container.JuMPmodel)
JuMP.empty!(PSI.get_jump_model(container))
return
end

Expand Down Expand Up @@ -425,36 +429,43 @@ end
function _make_system_expressions!(
container::OptimizationContainer,
subnetworks::Dict{Int, Set{Int}},
dc_bus_numbers::Vector{Int},
::Type{<:PM.AbstractPowerModel},
)
time_steps = get_time_steps(container)
bus_numbers = collect(Iterators.flatten(values(subnetworks)))
ac_bus_numbers = collect(Iterators.flatten(values(subnetworks)))
container.expressions = Dict(
ExpressionKey(ActivePowerBalance, PSY.Bus) =>
_make_container_array(bus_numbers, time_steps),
ExpressionKey(ReactivePowerBalance, PSY.Bus) =>
_make_container_array(bus_numbers, time_steps),
ExpressionKey(ActivePowerBalance, PSY.ACBus) =>
_make_container_array(ac_bus_numbers, time_steps),
ExpressionKey(ActivePowerBalance, PSY.DCBus) =>
_make_container_array(dc_bus_numbers, time_steps),
ExpressionKey(ReactivePowerBalance, PSY.ACBus) =>
_make_container_array(ac_bus_numbers, time_steps),
)
return
end

function _make_system_expressions!(
container::OptimizationContainer,
subnetworks::Dict{Int, Set{Int}},
dc_bus_numbers::Vector{Int},
::Type{<:PM.AbstractActivePowerModel},
)
time_steps = get_time_steps(container)
bus_numbers = collect(Iterators.flatten(values(subnetworks)))
ac_bus_numbers = collect(Iterators.flatten(values(subnetworks)))
container.expressions = Dict(
ExpressionKey(ActivePowerBalance, PSY.Bus) =>
_make_container_array(bus_numbers, time_steps),
ExpressionKey(ActivePowerBalance, PSY.ACBus) =>
_make_container_array(ac_bus_numbers, time_steps),
ExpressionKey(ActivePowerBalance, PSY.DCBus) =>
_make_container_array(dc_bus_numbers, time_steps),
)
return
end

function _make_system_expressions!(
container::OptimizationContainer,
subnetworks::Dict{Int, Set{Int}},
::Vector{Int},
::Type{CopperPlatePowerModel},
)
time_steps = get_time_steps(container)
Expand All @@ -469,16 +480,19 @@ end
function _make_system_expressions!(
container::OptimizationContainer,
subnetworks::Dict{Int, Set{Int}},
dc_bus_numbers::Vector{Int},
::Type{T},
) where {T <: Union{PTDFPowerModel, StandardPTDFModel}}
time_steps = get_time_steps(container)
bus_numbers = sort!(collect(Iterators.flatten(values(subnetworks))))
ac_bus_numbers = sort!(collect(Iterators.flatten(values(subnetworks))))
subnetworks = collect(keys(subnetworks))
container.expressions = Dict(
ExpressionKey(ActivePowerBalance, PSY.System) =>
_make_container_array(subnetworks, time_steps),
ExpressionKey(ActivePowerBalance, PSY.Bus) =>
_make_container_array(bus_numbers, time_steps),
ExpressionKey(ActivePowerBalance, PSY.DCBus) =>
_make_container_array(dc_bus_numbers, time_steps),
ExpressionKey(ActivePowerBalance, PSY.ACBus) =>
_make_container_array(ac_bus_numbers, time_steps),
)
return
end
Expand All @@ -487,8 +501,10 @@ function initialize_system_expressions!(
container::OptimizationContainer,
::Type{T},
subnetworks::Dict{Int, Set{Int}},
system::PSY.System,
) where {T <: PM.AbstractPowerModel}
_make_system_expressions!(container, subnetworks, T)
dc_bus_numbers = [PSY.get_number(b) for b in PSY.get_components(PSY.DCBus, system)]
_make_system_expressions!(container, subnetworks, dc_bus_numbers, T)
return
end

Expand All @@ -499,7 +515,12 @@ function build_impl!(
)
transmission = get_network_formulation(template)
transmission_model = get_network_model(template)
initialize_system_expressions!(container, transmission, transmission_model.subnetworks)
initialize_system_expressions!(
container,
transmission,
transmission_model.subnetworks,
sys,
)

# Order is required
for device_model in values(template.devices)
Expand Down Expand Up @@ -607,7 +628,7 @@ function build_impl!(
@debug "Building Objective" _group = LOG_GROUP_OPTIMIZATION_CONTAINER
update_objective_function!(container)
end
@debug "Total operation count $(container.JuMPmodel.operator_counter)" _group =
@debug "Total operation count $(PSI.get_jump_model(container).operator_counter)" _group =
LOG_GROUP_OPTIMIZATION_CONTAINER

check_optimization_container(container)
Expand Down Expand Up @@ -1325,7 +1346,7 @@ function get_expression(
::Type{U},
meta = CONTAINER_KEY_EMPTY_META,
) where {T <: SystemBalanceExpressions, U <: PM.AbstractPowerModel}
return get_expression(container, ExpressionKey(T, PSY.Bus, meta))
return get_expression(container, ExpressionKey(T, PSY.ACBus, meta))
end

function get_expression(
Expand Down
2 changes: 1 addition & 1 deletion src/core/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct FlowReactivePowerToFromVariable <: VariableType end

struct PhaseShifterAngle <: VariableType end

# Necessary as a work around for HVDCP2P models with losses
# Necessary as a work around for HVDCTwoTerminal models with losses
struct HVDCLosses <: VariableType end
struct HVDCFlowDirectionVariable <: VariableType end

Expand Down
Loading
Loading