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

wip: loss factor variable #1238

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/PowerSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export PowerFlowVoltageAngle
export PowerFlowVoltageMagnitude
export PowerFlowLineReactivePowerFromTo, PowerFlowLineReactivePowerToFrom
export PowerFlowLineActivePowerFromTo, PowerFlowLineActivePowerToFrom
export PowerFlowLossFactors

# Constraints
export AbsoluteValueConstraint
Expand Down
5 changes: 5 additions & 0 deletions src/core/auxiliary_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Auxiliary Variable for the line active flow in the to -> from direction from pow
"""
struct PowerFlowLineActivePowerToFrom <: PowerFlowAuxVariableType end

"""
Auxiliary Variable for the loss factors from AC power flow evaluation that are calculated using the Jacobian matrix
"""
struct PowerFlowLossFactors <: PowerFlowAuxVariableType end

convert_result_to_natural_units(::Type{PowerOutput}) = true
convert_result_to_natural_units(
::Type{
Expand Down
4 changes: 3 additions & 1 deletion src/network_models/power_flow_evaluation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ branch_aux_vars(::PFS.vPTDFPowerFlowData) =
branch_aux_vars(::PFS.PSSEExporter) = DataType[]

# Same for bus aux vars
bus_aux_vars(::PFS.ACPowerFlowData) = [PowerFlowVoltageAngle, PowerFlowVoltageMagnitude]
bus_aux_vars(::PFS.ACPowerFlowData) = [PowerFlowVoltageAngle, PowerFlowVoltageMagnitude, PowerFlowLossFactors]
bus_aux_vars(::PFS.ABAPowerFlowData) = [PowerFlowVoltageAngle]
bus_aux_vars(::PFS.PTDFPowerFlowData) = DataType[]
bus_aux_vars(::PFS.vPTDFPowerFlowData) = DataType[]
Expand Down Expand Up @@ -385,6 +385,8 @@ _get_pf_result(::Type{PowerFlowLineActivePowerFromTo}, pf_data::PFS.PowerFlowDat
PFS.get_branch_activepower_flow_from_to(pf_data)
_get_pf_result(::Type{PowerFlowLineActivePowerToFrom}, pf_data::PFS.PowerFlowData) =
PFS.get_branch_activepower_flow_to_from(pf_data)
_get_pf_result(::Type{PowerFlowLossFactors}, pf_data::PFS.PowerFlowData) =
[PFS.penalty_factors(aux_vars) for aux_vars in pf_data.aux_variables]
Copy link
Contributor

Choose a reason for hiding this comment

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

First, a bit of syntactic sugar:

Suggested change
[PFS.penalty_factors(aux_vars) for aux_vars in pf_data.aux_variables]
PFS.penalty_factors.(pf_data.aux_variables)

Copy link
Contributor

Choose a reason for hiding this comment

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

Second, maybe the issue you're having here is that this is a vector of vectors rather than a matrix? Might need to do some reshaping (see hcat, vcat, etc.).

Copy link
Contributor

Choose a reason for hiding this comment

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

Third, it looks like we now have two different types of things called aux variables. That's going to get confusing.


_get_pf_lookup(::Type{<:PSY.Bus}, pf_data::PFS.PowerFlowData) = PFS.get_bus_lookup(pf_data)
_get_pf_lookup(::Type{<:PSY.Branch}, pf_data::PFS.PowerFlowData) =
Expand Down
7 changes: 7 additions & 0 deletions test/test_simulation_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ function test_simulation_results(
ThermalStandard,
)],
)
@test !isempty(
sim.internal.store.dm_data[:ED].variables[PowerFlowLossFactors],
)
@test !isempty(sim.internal.store.dm_data[:ED].optimizer_stats)
empty!(sim.internal.store)
@test isempty(sim.internal.store.dm_data[:ED].variables)
Expand Down Expand Up @@ -349,6 +352,10 @@ function test_decision_problem_results_values(
@test size(v) == (12, 6)
end

loss_factors = read_variable(results_ed, PowerFlowLossFactors)
rbolgaryn marked this conversation as resolved.
Show resolved Hide resolved
@test length(keys(loss_factors)) == 48
println("loss factors: $loss_factors")

ren_dispatch_params =
read_parameter(results_ed, ActivePowerTimeSeriesParameter, RenewableDispatch)
@test length(keys(ren_dispatch_params)) == 48
Expand Down
Loading