Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ PowerFlows = "94fada2c-fd9a-4e89-8d82-81405f5cb4f6"
[sources]
InfrastructureSystems = {rev = "IS4", url = "https://github.com/Sienna-Platform/InfrastructureSystems.jl"}
PowerSystems = {rev = "psy6", url = "https://github.com/Sienna-Platform/PowerSystems.jl"}
InfrastructureOptimizationModels = {rev = "main", url = "https://github.com/Sienna-Platform/InfrastructureOptimizationModels.jl"}
InfrastructureOptimizationModels = {rev = "jd/network-sources", url = "https://github.com/Sienna-Platform/InfrastructureOptimizationModels.jl"}
PowerNetworkMatrices = {rev = "psy6", url = "https://github.com/Sienna-Platform/PowerNetworkMatrices.jl"}

[extensions]
Expand Down
17 changes: 17 additions & 0 deletions src/PowerOperationsModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import Logging
import PowerNetworkMatrices
# Brought into namespace so the `export PTDF` / `export VirtualPTDF` below resolve (re-export to POM users)
import PowerNetworkMatrices: PTDF, VirtualPTDF
# Brought into namespace so `NetworkReductionSpec(RadialReduction())` resolves unqualified
# after `using PowerOperationsModels` (re-export to POM users)
import PowerNetworkMatrices:
RadialReduction, DegreeTwoReduction, WardReduction, ZeroImpedanceBranchReduction
import PowerSystems
import PowerSystems: get_component
import PrettyTables
Expand Down Expand Up @@ -307,6 +311,9 @@ include("ac_transmission_models/branch_constructor.jl")

# Network Models
include("network_models/network_reductions.jl")
include("network_models/reduction_exceptions.jl")
include("network_models/network_sources.jl")
include("network_models/network_data.jl")
include("network_models/instantiate_network_model.jl")
include("network_models/network_slack_variables.jl")
include("network_models/copperplate_model.jl")
Expand Down Expand Up @@ -960,9 +967,19 @@ export AbstractReactivePowerNetworkModel
export NFANetworkModel
export DCPLLNetworkModel

# Network source declarations (network_models/network_sources.jl); the derived
# network-data containers stay unexported — they are build outputs, not user inputs.
export NetworkReductionSpec
export PrebuiltMatrixSource
export PrebuiltCoreSource

# PowerNetworkMatrices
export PTDF
export VirtualPTDF
export RadialReduction
export DegreeTwoReduction
export WardReduction
export ZeroImpedanceBranchReduction

# Other utilities
export get_name
Expand Down
12 changes: 6 additions & 6 deletions src/ac_transmission_models/AC_branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function add_variables!(
U <: PSY.ACTransmission,
F <: AbstractBranchFormulation}
time_steps = get_time_steps(container)
net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
branch_names = get_branch_argument_variable_axis(net_reduction_data, devices)
reduced_branch_tracker = get_reduced_branch_tracker(network_model)
all_branch_maps_by_type = PNM.get_all_branch_maps_by_type(net_reduction_data)
Expand Down Expand Up @@ -513,7 +513,7 @@ function add_constraints!(
V <: AbstractActivePowerModel,
}
time_steps = get_time_steps(container)
net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
reduced_branch_tracker = get_reduced_branch_tracker(network_model)
branch_names = get_branch_argument_constraint_axis(
net_reduction_data,
Expand Down Expand Up @@ -574,7 +574,7 @@ function add_constraints!(
V <: AbstractPTDFNetworkModel,
}
time_steps = get_time_steps(container)
net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
reduced_branch_tracker = get_reduced_branch_tracker(network_model)
branch_names = get_branch_argument_constraint_axis(
net_reduction_data,
Expand Down Expand Up @@ -665,7 +665,7 @@ function add_flow_rate_constraint_with_parameters!(
V <: AbstractPTDFNetworkModel,
}
time_steps = get_time_steps(container)
net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
reduced_branch_tracker = get_reduced_branch_tracker(network_model)

# POM's `get_branch_argument_constraint_axis` already performs per-arc claim
Expand Down Expand Up @@ -821,7 +821,7 @@ function add_expressions!(
) where {B <: PSY.ACTransmission}
time_steps = get_time_steps(container)
ptdf = get_network_matrix(network_model)
net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
branch_names = get_branch_argument_variable_axis(net_reduction_data, devices)
# `collect` to a Vector so the spawn loop below can index it for multi-threading.
name_to_arc_map = collect(PNM.get_name_to_arc_map(net_reduction_data, B))
Expand Down Expand Up @@ -877,7 +877,7 @@ function add_constraints!(
time_steps = get_time_steps(container)
branch_flow_expr = get_expression(container, PTDFBranchFlow, T)
flow_variables = get_variable(container, FlowActivePowerVariable, T)
net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
reduced_branch_tracker = get_reduced_branch_tracker(network_model)
branches = get_branch_argument_constraint_axis(
net_reduction_data,
Expand Down
4 changes: 2 additions & 2 deletions src/ac_transmission_models/security_constrained_branch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ function add_constraints!(
}
time_steps = get_time_steps(container)

net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
all_branch_maps_by_type = PNM.get_all_branch_maps_by_type(net_reduction_data)

resolved = _resolve_monitored_arcs(device_model, net_reduction_data)
Expand Down Expand Up @@ -611,7 +611,7 @@ function _add_modf_post_contingency_flow_expressions!(
modf_matrix = get_contingency_matrix(network_model)
registered_contingencies = PNM.get_registered_contingencies(modf_matrix)

net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
resolved = _resolve_monitored_arcs(model, net_reduction_data)

expression_container = _add_post_contingency_sparse_expression!(
Expand Down
2 changes: 1 addition & 1 deletion src/area_interchange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function add_constraints!(
)

area_ex_var = get_variable(container, FlowActivePowerVariable, PSY.AreaInterchange)
net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
# Memoize the PTDF orientation sign per (type, name): a degree-two series
# member whose native from→to is `:ToFrom` relative to the merged arc
# contributes with a flipped sign to the area sum.
Expand Down
2 changes: 1 addition & 1 deletion src/common_models/add_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function _add_time_series_parameters!(
end
time_steps = get_time_steps(container)

net_reduction_data = network_model.network_reduction
net_reduction_data = get_network_reduction(network_model)
reduced_branch_tracker = get_reduced_branch_tracker(network_model)
all_branch_maps_by_type = PNM.get_all_branch_maps_by_type(net_reduction_data)

Expand Down
7 changes: 4 additions & 3 deletions src/common_models/make_system_expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ end
#################################################################################

function _verify_area_subnetwork_topology(sys::PSY.System, subnetworks::Dict{Int, Set{Int}})
if length(subnetworks) < 1
if length(subnetworks) <= 1
@debug "Only one subnetwork detected in the system. Area - Subnetwork topology check is valid."
return
end

@warn "More than one subnetwork detected in AreaBalanceNetworkModel. Topology consistency checks must be conducted."

area_map = PSY.get_aggregation_topology_mapping(PSY.Area, sys)
for (area, buses) in area_map
# Keyed by area name, not by the Area component.
for (area_name, buses) in area_map
bus_numbers =
[
PSY.get_number(b) for
Expand All @@ -169,7 +170,7 @@ function _verify_area_subnetwork_topology(sys::PSY.System, subnetworks::Dict{Int
end
end
if length(subnets) > 1
@error "Area $(PSY.get_name(area)) is connected to multiple subnetworks $(subnets)."
@error "Area $(area_name) is connected to multiple subnetworks $(subnets)."
throw(
IS.ConflictingInputsError(
"AreaBalanceNetworkModel doesn't support systems with Areas distributed across multiple asynchronous areas",
Expand Down
7 changes: 7 additions & 0 deletions src/core/network_formulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ requires_all_branch_models(::Type{AreaBalanceNetworkModel}) = false
branches_modeled(::Type{CopperPlateNetworkModel}) = false
branches_modeled(::Type{AreaBalanceNetworkModel}) = false

# Aggregated formulations resolve injections by area name or subnetwork reference bus, never
# through the reduction's bus map, so a reduction handed to one is computed and then ignored.
# `_validate_network_source` rejects a non-default source rather than discarding it silently.
honors_network_reduction(::Type{<:AbstractNetworkModel}) = true
honors_network_reduction(::Type{CopperPlateNetworkModel}) = false
honors_network_reduction(::Type{AreaBalanceNetworkModel}) = false

# AC network models allocate a ReactivePowerBalance expression; active-power-only models do not
# (see common_models/make_system_expressions.jl). Used to drop reactive-only device models.
network_has_reactive_power(::Type{<:AbstractNetworkModel}) = true
Expand Down
25 changes: 12 additions & 13 deletions src/initial_conditions/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ function get_initial_conditions_template(
# This is done to avoid passing the duals but also not re-allocating the PTDF when it
# exists

main_network_model = get_network_model(model.template)
network_model = NetworkModel(
get_network_formulation(model.template);
use_slacks = get_use_slacks(get_network_model(model.template)),
network_matrix = get_network_matrix(get_network_model(model.template)),
# Carry the contingency matrix forward so security-constrained branch models
# (which read the registered contingencies off the network model's contingency matrix)
# can build inside the initial-conditions sub-model. Without this the IC
# build hits `get_registered_contingencies(nothing)`.
contingency_matrix = get_contingency_matrix(get_network_model(model.template)),
reduce_radial_branches = get_reduce_radial_branches(
get_network_model(model.template),
),
use_slacks = get_use_slacks(main_network_model),
network_source = get_network_source(main_network_model),
reduction_exceptions = get_reduction_exceptions(main_network_model),
)
set_hvdc_network_model!(
network_model,
deepcopy(get_hvdc_network_model(model.template)),
)
network_model.network_reduction =
deepcopy(get_network_reduction(get_network_model(model.template)))
network_model.subnetworks = get_subnetworks(get_network_model(model.template))
# The IC sub-model never runs `instantiate_network_model!`: it reads the main
# model's derived matrices and reduction rather than deriving its own, so the
# contingency matrix's registered contingencies are available to the
# security-constrained branch models. Sharing the source and the derived data by
# reference is what makes an IC/main network divergence structurally impossible —
# the IC build reads the reduction, it does not extend it.
IOM.set_network_data!(network_model, get_network_data(main_network_model))
network_model.subnetworks = get_subnetworks(main_network_model)
# Initialization builds a fresh, empty EvaluationContainer: no power-flow (or other)
# evaluations are run during initialization.
network_model.evaluations = IOM.EvaluationContainer()
Expand Down
Loading
Loading