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

[DNMY] Support in the loop PowerFlow evaluation #1040

Draft
wants to merge 43 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1c30601
add PFS deps
jd-lara Jan 9, 2024
0bcb68e
make time_steps consistent
jd-lara Jan 9, 2024
cac31f2
add PowerFlows
jd-lara Jan 9, 2024
1b7d415
add new aux variables for power flow
jd-lara Jan 9, 2024
02c52ed
make time steps consistent
jd-lara Jan 9, 2024
1e71c06
fix failing test
jd-lara Jan 9, 2024
a94defb
add power flow evaluator to model and container
jd-lara Jan 9, 2024
d1336c0
add evaluation in initialization
jd-lara Jan 9, 2024
7d1b0d2
add code for evaluation
jd-lara Jan 9, 2024
c4071f4
add missing kwarg
jd-lara Jan 9, 2024
61ee4b5
fix incorrect var type
jd-lara Jan 9, 2024
3b31d02
fix old bug
jd-lara Jan 9, 2024
347b67c
update aux vars for power flow evaluation
jd-lara Jan 9, 2024
5606f65
WIP: function for the power flow evaluation
jd-lara Jan 9, 2024
e8caaca
whitespace
jd-lara Jan 9, 2024
198e7b4
Merge branch 'main' into jd/pf_integration
jd-lara Jan 23, 2024
bf872ca
bump deps
jd-lara Jan 23, 2024
4e0f8ee
change to varnames
jd-lara Jan 23, 2024
7a2555a
add auxiliary variables
jd-lara Jan 23, 2024
d95ef9e
add wrapper for power flow data
jd-lara Jan 24, 2024
d2b26ac
use wrapper
jd-lara Jan 24, 2024
ddb92e3
add powerflow wrapper
jd-lara Jan 24, 2024
33bd977
power flow rename
jd-lara Jan 24, 2024
2645ced
file rename
jd-lara Jan 24, 2024
c997e2f
add evaluation to the container
jd-lara Jan 25, 2024
1ba76cb
WIP: add functions to map results to pf
jd-lara Jan 25, 2024
c11f4cf
Merge branch 'psy4' into jd/pf_integration
jd-lara Mar 6, 2024
4fcfa16
Merge branch 'main' into jd/pf_integration
GabrielKS Aug 19, 2024
b26e2b0
Remove redundant code
GabrielKS Oct 15, 2024
54e4859
Rewrite power flow evaluation to support more types of power flow
GabrielKS Oct 15, 2024
1e714ac
Support evaluation of multiple power flows in the loop
GabrielKS Oct 15, 2024
508db25
Better accommodate `PSSEExporter` in the loop, reduce duplication
GabrielKS Oct 16, 2024
b6fc453
Trait-based special behavior for power flow aux vars
GabrielKS Oct 17, 2024
eb51cfb
Scaffold subtype-based updating of power flow aux vars
GabrielKS Oct 17, 2024
dfd7405
Update power flow aux vars from `PowerFlowData`
GabrielKS Oct 17, 2024
c0ac0be
Complete prototype power flow in the loop -> export implementation
GabrielKS Oct 17, 2024
9e1f30a
Power flow in the loop: handle load special cases
GabrielKS Oct 28, 2024
1507b14
Power flow in the loop: support multi period export
GabrielKS Oct 28, 2024
9ec1356
Misc code cleanup following self-review
GabrielKS Oct 28, 2024
ad25918
Add basic tests of power flow in the loop
GabrielKS Nov 4, 2024
958e68d
Update `DISABLED_TEST_FILES`
GabrielKS Nov 4, 2024
187f473
Merge branch 'main' into jd/pf_integration
GabrielKS Nov 4, 2024
e016521
PERF: don't use `get_bus(sys, number)`, it's O(n)
GabrielKS Nov 19, 2024
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
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
PowerFlows = "94fada2c-fd9a-4e89-8d82-81405f5cb4f6"
PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"
PowerNetworkMatrices = "bed98974-b02a-5e2f-9fe0-a103f5c450dd"
PowerSystems = "bcd98974-b02a-5e2f-9ee0-a103f5c450dd"
Expand All @@ -45,8 +46,9 @@ JuMP = "1"
LinearAlgebra = "1"
Logging = "1"
MathOptInterface = "1"
PowerModels = "^0.20"
PowerModels = "^0.21"
PowerNetworkMatrices = "^0.10"
PowerFlows = "0.7"
PowerSystems = "^3"
PrettyTables = "2"
ProgressMeter = "^1.5"
Expand Down
8 changes: 8 additions & 0 deletions src/PowerSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ export LowerBoundFeedForwardSlack
export TimeDurationOn
export TimeDurationOff
export PowerOutput
export PowerFlowVoltageAngle
export PowerFlowVoltageMagnitude
export PowerFlowLineReactivePower
export PowerFlowLineActivePower

# Constraints
export AbsoluteValueConstraint
Expand Down Expand Up @@ -339,6 +343,7 @@ import LinearAlgebra
import JSON3
import PowerSystems
import InfrastructureSystems
import PowerFlows
import PowerNetworkMatrices
import PowerNetworkMatrices: PTDF, VirtualPTDF
export PTDF
Expand Down Expand Up @@ -399,6 +404,7 @@ const MOI = MathOptInterface
const MOIU = MathOptInterface.Utilities
const MOPFM = MOI.FileFormats.Model
const PNM = PowerNetworkMatrices
const PFS = PowerFlows
const TS = TimeSeries

################################################################################
Expand Down Expand Up @@ -444,6 +450,7 @@ include("core/results_by_time.jl")

# Order Required
include("operation/problem_template.jl")
include("core/powerflow_data_wrapper.jl")
include("core/optimization_container.jl")
include("core/store_common.jl")
include("initial_conditions/initial_condition_chronologies.jl")
Expand Down Expand Up @@ -530,6 +537,7 @@ 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("network_models/powerflow_evaluation.jl")

include("initial_conditions/initialization.jl")

Expand Down
22 changes: 22 additions & 0 deletions src/core/auxiliary_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,29 @@ Auxiliary Variable for Thermal Generation Models that solve for power above min
"""
struct PowerOutput <: AuxVariableType end

"""
Auxiliary Variable for the bus angle results from power flow evaluation
"""
struct PowerFlowVoltageAngle <: AuxVariableType end

"""
Auxiliary Variable for the bus voltage magnitued results from power flow evaluation
"""
struct PowerFlowVoltageMagnitude <: AuxVariableType end

"""
Auxiliary Variable for the line reactive flow from power flow evaluation
"""
struct PowerFlowLineReactivePower <: AuxVariableType end

"""
Auxiliary Variable for the line active flow from power flow evaluation
"""
struct PowerFlowLineActivePower <: AuxVariableType end

should_write_resulting_value(::Type{<:AuxVariableType}) = true

convert_result_to_natural_units(::Type{<:AuxVariableType}) = false
convert_result_to_natural_units(::Type{PowerOutput}) = true
convert_result_to_natural_units(::Type{PowerFlowLineReactivePower}) = true
convert_result_to_natural_units(::Type{PowerFlowLineActivePower}) = true
4 changes: 4 additions & 0 deletions src/core/network_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mutable struct NetworkModel{T <: PM.AbstractPowerModel}
duals::Vector{DataType}
radial_network_reduction::PNM.RadialNetworkReduction
reduce_radial_branches::Bool
powerflow_evaluation::Union{Nothing, PFS.PowerFlowEvaluationModel}
jd-lara marked this conversation as resolved.
Show resolved Hide resolved

function NetworkModel(
::Type{T};
Expand All @@ -42,6 +43,7 @@ mutable struct NetworkModel{T <: PM.AbstractPowerModel}
reduce_radial_branches = false,
subnetworks = Dict{Int, Set{Int}}(),
duals = Vector{DataType}(),
powerflow_evaluation = nothing,
) where {T <: PM.AbstractPowerModel}
_check_pm_formulation(T)
new{T}(
Expand All @@ -52,6 +54,7 @@ mutable struct NetworkModel{T <: PM.AbstractPowerModel}
duals,
PNM.RadialNetworkReduction(),
reduce_radial_branches,
powerflow_evaluation,
)
end
end
Expand All @@ -66,6 +69,7 @@ get_reference_buses(m::NetworkModel{T}) where {T <: PM.AbstractPowerModel} =
collect(keys(m.subnetworks))
get_subnetworks(m::NetworkModel) = m.subnetworks
get_bus_area_map(m::NetworkModel) = m.bus_area_map
get_powerflow_evaluation(m::NetworkModel) = m.powerflow_evaluation
has_subnetworks(m::NetworkModel) = !isempty(m.bus_area_map)

function add_dual!(model::NetworkModel, dual)
Expand Down
10 changes: 9 additions & 1 deletion src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ mutable struct OptimizationContainer <: AbstractModelContainer
built_for_recurrent_solves::Bool
metadata::OptimizationContainerMetadata
default_time_series_type::Type{<:PSY.TimeSeriesData}
power_flow_evaluation_data::Union{<:PowerFlowEvaluationData, Nothing}
end

function OptimizationContainer(
Expand Down Expand Up @@ -154,6 +155,7 @@ function OptimizationContainer(
false,
OptimizationContainerMetadata(),
T,
nothing,
)
end

Expand Down Expand Up @@ -191,6 +193,8 @@ get_jump_model(container::OptimizationContainer) = container.JuMPmodel
get_metadata(container::OptimizationContainer) = container.metadata
get_optimizer_stats(container::OptimizationContainer) = container.optimizer_stats
get_parameters(container::OptimizationContainer) = container.parameters
get_power_flow_evaluation_data(container::OptimizationContainer) =
container.power_flow_evaluation_data
get_resolution(container::OptimizationContainer) = container.resolution
get_settings(container::OptimizationContainer) = container.settings
get_time_steps(container::OptimizationContainer) = container.time_steps
Expand Down Expand Up @@ -650,8 +654,8 @@ function build_impl!(
@debug "Total operation count $(PSI.get_jump_model(container).operator_counter)" _group =
LOG_GROUP_OPTIMIZATION_CONTAINER

add_power_flow_data!(container, get_powerflow_evaluation(transmission_model), sys)
check_optimization_container(container)

return
end

Expand Down Expand Up @@ -1503,6 +1507,10 @@ function deserialize_key(container::OptimizationContainer, name::AbstractString)
end

function calculate_aux_variables!(container::OptimizationContainer, system::PSY.System)
if !isnothing(get_power_flow_data(container))
solve_powerflow!(container, system)
end

aux_vars = get_aux_variables(container)
for key in keys(aux_vars)
calculate_aux_variable_value!(container, key, system)
Expand Down
1 change: 1 addition & 0 deletions src/core/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function add_component_name!(attr::TimeSeriesAttributes, name::String, uuid::Str
return
end

get_component_names(attr::TimeSeriesAttributes) = keys(attr.component_name_to_ts_uuid)
_get_ts_uuid(attr::TimeSeriesAttributes, name) = attr.component_name_to_ts_uuid[name]

struct VariableValueAttributes{T <: OptimizationContainerKey} <: ParameterAttributes
Expand Down
13 changes: 13 additions & 0 deletions src/core/powerflow_data_wrapper.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mutable struct PowerFlowEvaluationData{T <: PFS.PowerFlowData}
jd-lara marked this conversation as resolved.
Show resolved Hide resolved
power_flow_data::T
injection_key_map::Dict{<:OptimizationContainerKey, Dict{String, Int}}
end

function PowerFlowEvaluationData(power_flow_data::T) where {T <: PFS.PowerFlowData}
return PowerFlowEvaluationData{T}(
power_flow_data,
Dict{OptimizationContainerKey, Dict{String, Int}}(),
)
end

get_power_flow_data(ped::PowerFlowEvaluationData) = ped.power_flow_data
2 changes: 2 additions & 0 deletions src/initial_conditions/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function get_initial_conditions_template(model::OperationModel)
network_model.radial_network_reduction =
get_radial_network_reduction(get_network_model(model.template))
network_model.subnetworks = get_subnetworks(get_network_model(model.template))
# Initialization does not support PowerFlow evaluation
network_model.powerflow_evaluation = nothing
bus_area_map = get_bus_area_map(get_network_model(model.template))
if !isempty(bus_area_map)
network_model.bus_area_map = get_bus_area_map(get_network_model(model.template))
Expand Down
Loading
Loading