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 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 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
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/power_flow_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/power_flow_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
power_flow_evaluation::Union{Nothing, PFS.PowerFlowEvaluationModel}

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}(),
power_flow_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,
power_flow_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_power_flow_evaluation(m::NetworkModel) = m.power_flow_evaluation
has_subnetworks(m::NetworkModel) = !isempty(m.bus_area_map)

function add_dual!(model::NetworkModel, dual)
Expand Down
17 changes: 13 additions & 4 deletions 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_power_flow_evaluation(transmission_model), sys)
check_optimization_container(container)

return
end

Expand Down Expand Up @@ -684,8 +688,8 @@ function solve_impl!(container::OptimizationContainer, system::PSY.System)
return RunStatus.FAILED
end

status = RunStatus.SUCCESSFUL

# Order is important because if a dual is needed then it could move the results to the
# temporary primal container
_, optimizer_stats.timed_calculate_aux_variables =
@timed calculate_aux_variables!(container, system)

Expand All @@ -694,7 +698,8 @@ function solve_impl!(container::OptimizationContainer, system::PSY.System)

_, optimizer_stats.timed_calculate_dual_variables =
@timed calculate_dual_variables!(container, system, is_milp(container))
return status

return RunStatus.SUCCESSFUL
end

function compute_conflict!(container::OptimizationContainer)
Expand Down Expand Up @@ -1503,6 +1508,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_power_flow!(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
14 changes: 14 additions & 0 deletions src/core/power_flow_data_wrapper.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mutable struct PowerFlowEvaluationData{T <: PFS.PowerFlowData}
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
get_injection_key_map(ped::PowerFlowEvaluationData) = ped.injection_key_map
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.power_flow_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