-
Notifications
You must be signed in to change notification settings - Fork 1
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/implement state estimator #5
base: main
Are you sure you want to change the base?
Conversation
…L-Sienna/PowerSimulationsDecomposition.jl into jd/implement_state_estimator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
JuliaFormatter
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
selected_line=["CA-1", "CB-1", "AB1"] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 44 to 45 in 2b67507
monitoredlined_line=["A28"] | |
limit=0.2 |
[JuliaFormatter] reported by reviewdog 🐶
function read_bus_df(results_rt,se=0) |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 al = read_realized_variable(results_rt, "StateEstimationInjections__ACBus") end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 66 to 69 in 2b67507
bus_ActivePowerVariable__ThermalStandard=Dict() | |
bus_ActivePowerTimeSeriesParameter__PowerLoad=Dict() | |
bus_ActivePowerBalance__ACBus=Dict() | |
bus_StateEstimationInjections__ACBus=Dict() |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 72 to 74 in 2b67507
bus_df=DataFrames.DataFrame(; | |
t =Int64[], bus=[], area = [], ThermalStandard=[], PowerLoad=[], ActivePowerBalance__ACBus=[], | |
StateEstimationInjections__ACBus=[], ptdf=[], flowcontribution=[], loopflowcontribution=[] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 77 to 80 in 2b67507
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); bus_ActivePowerVariable__ThermalStandard[t,bn]=0 | |
bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn]=0; bus_ActivePowerBalance__ACBus[t,bn]=0 | |
bus_StateEstimationInjections__ACBus[t,bn]=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 85 to 87 in 2b67507
try b=parse(Int,i) | |
for t=1:NT bus_ActivePowerBalance__ACBus[t,b]=ab[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 91 to 93 in 2b67507
try b=parse(Int,i) | |
for t=1:NT bus_StateEstimationInjections__ACBus[t,b]=al[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 98 to 100 in 2b67507
try b=get_number(get_bus(get_component(PowerLoad, sys, i))) | |
for t=1:NT bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]=bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]+ald[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 104 to 106 in 2b67507
try b=get_number(get_bus(get_component(ThermalStandard, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__ThermalStandard[t,b]=bus_ActivePowerVariable__ThermalStandard[t,b]+ac[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 110 to 114 in 2b67507
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); area=get_name(get_area(b)); | |
push!(bus_df,(t,bn,area, bus_ActivePowerVariable__ThermalStandard[t,bn], bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn], | |
bus_ActivePowerBalance__ACBus[t,bn], bus_StateEstimationInjections__ACBus[t,bn], ptdf[line,bn], | |
bus_ActivePowerBalance__ACBus[t,bn]*ptdf[line,bn],bus_StateEstimationInjections__ACBus[t,bn]*ptdf[line,bn])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 118 to 119 in 2b67507
bus_df[!,"buscheck"]=bus_df[!,"ActivePowerBalance__ACBus"]-bus_df[!,"ThermalStandard"]/100-bus_df[!,"PowerLoad"]/100 | |
println("bus check ActivePowerBalance__ACBus<>ThermalStandard/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 121 to 122 in 2b67507
return(bus_df) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 124 to 127 in 2b67507
function check_models(uc0,uc2a) | |
sol0=Dict() | |
v0=uc0.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol0=Dict(zip(name.(v0),value.(v0))) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 129 to 130 in 2b67507
fix(v,value.(v),force=true) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
v01=uc0.variables[InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, AreaInterchange}("")] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 134 to 146 in 2b67507
fix(v,value.(v),force=true) | |
end | |
v2a=uc2a.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol2a=Dict(zip(name.(v2a),value.(v2a))) | |
for (k,v) in sol2a | |
if abs(sol2a[k]-sol0[k])>0.00001 | |
println("k,",k,",",sol2a[k],",",sol0[k]) | |
var0=variable_by_name(uc0.JuMPmodel,k) | |
fix(var0,sol2a[k],force=true) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 150 to 153 in 2b67507
function objterms(uc0,ff) | |
objd0=Dict(); sol0=Dict(); objv0=0 | |
obj0=objective_function(uc0.JuMPmodel); objd0=Dict(zip(name.(keys(obj0.terms)),values(obj0.terms))); | |
av0 = JuMP.all_variables(uc0.JuMPmodel); sol0=Dict(zip(name.(av0), value.(av0))) |
[JuliaFormatter] reported by reviewdog 🐶
open(ff,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 157 to 159 in 2b67507
for (k,v) in objd0 | |
objv0=objv0+sol0[k]*objd0[k] | |
println("name;value;objcoef;obj_contribution;",k,";",sol0[k],";",objd0[k],";", sol0[k]*objd0[k]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 162 to 164 in 2b67507
end | |
return(objd0,sol0, objv0) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "2"), |
[JuliaFormatter] reported by reviewdog 🐶
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "3"), |
[JuliaFormatter] reported by reviewdog 🐶
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "2"), to_area=get_component(Area, sys, "3"), |
[JuliaFormatter] reported by reviewdog 🐶
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "2"), |
[JuliaFormatter] reported by reviewdog 🐶
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "3"), |
[JuliaFormatter] reported by reviewdog 🐶
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "2"), to_area=get_component(Area, sys2, "3"), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 210 to 212 in 2b67507
set_device_model!(template_uc, | |
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
set_device_model!(template_uc, DeviceModel(MonitoredLine, StaticBranchUnbounded, use_slacks = true)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 224 to 225 in 2b67507
set_device_model!(template_uc2, | |
DeviceModel(Line, StaticBranchUnbounded; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) |
[JuliaFormatter] reported by reviewdog 🐶
set_device_model!(template_uc2, DeviceModel(MonitoredLine, StaticBranch, use_slacks = true)) |
[JuliaFormatter] reported by reviewdog 🐶
set_flow_limits!(l,(from_to=limit,to_from=limit)) |
[JuliaFormatter] reported by reviewdog 🐶
# MultiRegionProblem, |
[JuliaFormatter] reported by reviewdog 🐶
FVFF_area_interchange = FixValueFeedforward(;component_type=AreaInterchange,source=FlowActivePowerVariable,affected_values=[FlowActivePowerVariable],) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 283 to 285 in 2b67507
feedforwards=Dict( | |
"UC_Subsystem" => uc_simulation_ff, | |
), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 301 to 304 in 2b67507
uc0=models.decision_models[1].internal.container | |
uc2=models.decision_models[2].internal.container | |
println("obj uc0,uc2,",objective_value(uc0.JuMPmodel),",",objective_value(uc2.JuMPmodel),",",objective_value(uc2b.JuMPmodel),",diff,",objective_value(uc0.JuMPmodel)-objective_value(uc2.JuMPmodel)) |
[JuliaFormatter] reported by reviewdog 🐶
open("mod_uc0.txt","w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 310 to 312 in 2b67507
for k in all_constraints(uc0.JuMPmodel,; include_variable_in_set_constraints = true) | |
println(name(k),",",k) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
open("mod_uc2.txt","w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 318 to 320 in 2b67507
for k in all_constraints(uc2.JuMPmodel,; include_variable_in_set_constraints = true) | |
println(name(k),",",k) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 324 to 331 in 2b67507
for (k,v) in uc0.constraints println(k) end | |
uc0.constraints[InfrastructureSystems.Optimization.ConstraintKey{CopperPlateBalanceConstraint, Area}("")][:,1] | |
for (k,v) in uc2.constraints println(k) end | |
uc2.constraints[InfrastructureSystems.Optimization.ConstraintKey{CopperPlateBalanceConstraint, Area}("")][:,1] | |
value.(uc0.variables[InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, AreaInterchange}("")][:,1]) | |
fix_value.(uc2.variables[InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, AreaInterchange}("")][:,1]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 338 to 344 in 2b67507
bus_df_uc0=read_bus_df(results_uc0,0) | |
bus_df_uc2=read_bus_df(results_uc1,0) | |
bus_df_uc0[!,"buscheck"]=bus_df_uc0[!,"ActivePowerBalance__ACBus"]-bus_df_uc0[!,"ThermalStandard"]/100-bus_df_uc0[!,"PowerLoad"]/100 | |
println("UC0 bus check ActivePowerBalance__ACBus<>ThermalStandard/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df_uc0)) | |
bus_df_uc2[!,"buscheck"]=bus_df_uc2[!,"ActivePowerBalance__ACBus"]-bus_df_uc2[!,"ThermalStandard"]/100-bus_df_uc2[!,"PowerLoad"]/100 | |
println("UC2 bus check ActivePowerBalance__ACBus<>ThermalStandard/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df_uc2)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 348 to 366 in 2b67507
area_df0=combine(groupby(bus_df_uc0, [:t, :area]), [:ThermalStandard, :PowerLoad, :ActivePowerBalance__ACBus, :StateEstimationInjections__ACBus] .=> sum) | |
area_df0[!,"areacheck"]=area_df0[!,"ActivePowerBalance__ACBus_sum"]-area_df0[!,"ThermalStandard_sum"]/100-area_df0[!,"PowerLoad_sum"]/100 | |
sum(area_df0[!,"areacheck"]) | |
area1_df0=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), area_df0) | |
area2_df0=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), area_df0) | |
area3_df0=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), area_df0) | |
area_df2=combine(groupby(bus_df_uc2, [:t, :area]), [:ThermalStandard, :PowerLoad, :ActivePowerBalance__ACBus, :StateEstimationInjections__ACBus] .=> sum) | |
area_df2[!,"areacheck"]=area_df2[!,"ActivePowerBalance__ACBus_sum"]-area_df2[!,"ThermalStandard_sum"]/100-area_df2[!,"PowerLoad_sum"]/100 | |
sum(area_df2[!,"areacheck"]) | |
area1_df2=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), area_df2) | |
area2_df2=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), area_df2) | |
area3_df2=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), area_df2) | |
println("area1 check uc0-uc2,", sum(area1_df2[!,"ActivePowerBalance__ACBus_sum"]-area1_df0[!,"ActivePowerBalance__ACBus_sum"])) | |
println("area2 check uc0-uc2,", sum(area2_df2[!,"ActivePowerBalance__ACBus_sum"]-area2_df0[!,"ActivePowerBalance__ACBus_sum"])) | |
println("area3 check uc0-uc2,", sum(area3_df2[!,"ActivePowerBalance__ACBus_sum"]-area3_df0[!,"ActivePowerBalance__ACBus_sum"])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 369 to 377 in 2b67507
areaflow_df0=combine(groupby(bus_df_uc0, [:t, :area]), [:flowcontribution, :loopflowcontribution] .=> sum) | |
areaflow1_df0=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), areaflow_df0) | |
areaflow2_df0=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), areaflow_df0) | |
areaflow3_df0=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), areaflow_df0) | |
areaflow_df2=combine(groupby(bus_df_uc2, [:t, :area]), [:flowcontribution, :loopflowcontribution] .=> sum) | |
areaflow1_df2=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), areaflow_df2) | |
areaflow2_df2=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), areaflow_df2) | |
areaflow3_df2=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), areaflow_df2) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 379 to 381 in 2b67507
println("areaflow1 check sum(uc0 flowcontribution_sum - uc2 flowcontribution_sum,",sum(areaflow1_df0[!,"flowcontribution_sum"]-areaflow1_df2[!,"flowcontribution_sum"])) | |
println("areaflow2 check sum(uc0 flowcontribution_sum - uc2 flowcontribution_sum,",sum(areaflow2_df0[!,"flowcontribution_sum"]-areaflow2_df2[!,"flowcontribution_sum"])) | |
println("areaflow3 check sum(uc0 flowcontribution_sum - uc2 flowcontribution_sum,",sum(areaflow3_df0[!,"flowcontribution_sum"]-areaflow3_df2[!,"flowcontribution_sum"])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 383 to 384 in 2b67507
areaflow1_df0[!,"seflow"]=areaflow1_df0[!,"flowcontribution_sum"]+areaflow2_df0[!,"flowcontribution_sum"]+areaflow3_df0[!,"flowcontribution_sum"] | |
areaflow1_df2[!,"seflow"]=areaflow1_df2[!,"flowcontribution_sum"]+areaflow2_df2[!,"flowcontribution_sum"]+areaflow3_df2[!,"flowcontribution_sum"] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_2stage.jl
Lines 387 to 391 in 2b67507
println("varflow_uc0,",value.(uc0.variables[InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, MonitoredLine}("")]["A28",:]) ) | |
println("varflow_uc2,",value.(uc2.variables[InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, MonitoredLine}("")]["A28",:]) ) | |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 40 to 73 in 2b67507
NT=24 | |
selected_line=["CA-1", "CB-1", "AB1"] | |
monitoredlined_line=["A28"] | |
limit=0.2 | |
use_monitoredline=1 | |
sys = build_system(PSISystems, "modified_RTS_GMLC_DA_sys") | |
sys2 = build_system(PSISystems, "modified_RTS_GMLC_DA_sys") | |
transform_single_time_series!(sys, Hour(NT), Hour(NT)) | |
transform_single_time_series!(sys2, Hour(1), Hour(1)) | |
#transform_single_time_series!(sys, Hour(1), Hour(1)) | |
#transform_single_time_series!(sys2, Hour(1), Hour(1)) | |
#enforced_region = ["1", "2", "3"] # first one is MRTO, second one is M2M coordinator, third one in RT is loopflow under M2M | |
enforced_region=["1","3","2"] | |
#enforced_region=["2","3","1"] | |
ptdf=PTDF(sys) | |
buildsubsystem(sys2, enforced_region, union(selected_line,monitoredlined_line)) | |
exchange_1_2 = AreaInterchange(; | |
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "2"), | |
flow_limits=(from_to=99999, to_from=99999), | |
) | |
add_component!(sys, exchange_1_2) | |
exchange_1_3 = AreaInterchange(; | |
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "3"), | |
flow_limits=(from_to=99999, to_from=99999), | |
) | |
add_component!(sys, exchange_1_3) | |
exchange_2_3 = AreaInterchange(; | |
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "2"), to_area=get_component(Area, sys, "3"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 75 to 79 in 2b67507
add_component!(sys, exchange_2_3) | |
exchange_1_2 = AreaInterchange(; | |
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "2"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 81 to 83 in 2b67507
add_component!(sys2, exchange_1_2) | |
add_component_to_subsystem!(sys2, "a", exchange_1_2) | |
add_component_to_subsystem!(sys2, "b", exchange_1_2) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 85 to 87 in 2b67507
exchange_1_3 = AreaInterchange(; | |
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "3"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 89 to 95 in 2b67507
add_component!(sys2, exchange_1_3) | |
add_component_to_subsystem!(sys2, "a", exchange_1_3) | |
add_component_to_subsystem!(sys2, "b", exchange_1_3) | |
exchange_2_3 = AreaInterchange(; | |
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "2"), to_area=get_component(Area, sys2, "3"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 97 to 121 in 2b67507
add_component!(sys2, exchange_2_3) | |
add_component_to_subsystem!(sys2, "a", exchange_2_3) | |
add_component_to_subsystem!(sys2, "b", exchange_2_3) | |
template_uc = ProblemTemplate(NetworkModel(AreaPTDFPowerModel; use_slacks=true)) | |
set_device_model!(template_uc, ThermalStandard, ThermalBasicUnitCommitment) | |
set_device_model!(template_uc, PowerLoad, StaticPowerLoad) | |
set_device_model!(template_uc, AreaInterchange, StaticBranch) | |
if use_monitoredline==0 | |
set_device_model!(template_uc, | |
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)), | |
#DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in selected_line), | |
#DeviceModel(Line, StaticBranch; attributes=Dict("filter_function" => x -> get_name(x) in selected_line), | |
)) | |
else | |
set_device_model!(template_uc, | |
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
set_device_model!(template_uc, MonitoredLine, StaticBranch) | |
for b in monitoredlined_line | |
line = PSY.get_component(Line, sys, b) | |
PSY.convert_component!(sys, line, MonitoredLine) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 123 to 143 in 2b67507
template_uc2 = MultiProblemTemplate(NetworkModel(SplitAreaPTDFPowerModel; use_slacks=true), ["a", "b"]) | |
set_device_model!(template_uc2, AreaInterchange, StaticBranch) | |
set_device_model!(template_uc2, ThermalStandard, ThermalBasicUnitCommitment) | |
set_device_model!(template_uc2, PowerLoad, StaticPowerLoad) | |
if use_monitoredline==0 | |
set_device_model!(template_uc2, | |
DeviceModel(Line, StaticBranch; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
l = PSY.get_component(ACBranch, sys2, "A28") | |
set_rating!(l,limit) | |
else | |
set_device_model!(template_uc2, | |
DeviceModel(Line, StaticBranchUnbounded; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
set_device_model!(template_uc2, MonitoredLine, StaticBranch) | |
for b in monitoredlined_line | |
line = PSY.get_component(Line, sys2, b) | |
PSY.convert_component!(sys2, line, MonitoredLine) | |
end | |
l = PSY.get_component(MonitoredLine, sys2, "A28") | |
set_flow_limits!(l,(from_to=limit,to_from=limit)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 145 to 152 in 2b67507
models = SimulationModels(; | |
decision_models=[ | |
DecisionModel( | |
template_uc, | |
sys; | |
name="UC0", | |
optimizer=optimizer_with_attributes( | |
HiGHS.Optimizer, |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 156 to 161 in 2b67507
), | |
system_to_file=false, | |
optimizer_solve_log_print=false, | |
direct_mode_optimizer=true, | |
store_variable_names=true, | |
calculate_conflict=true, |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 163 to 180 in 2b67507
DecisionModel( | |
MultiRegionProblem, | |
template_uc2, | |
sys2; | |
name="UC_Subsystem", | |
optimizer=optimizer_with_attributes( | |
HiGHS.Optimizer, | |
#Xpress.Optimizer, | |
#"MIPRELSTOP" => 0.00, # Set the relative mip gap tolerance | |
#"MAXMEMORYSOFT" => 600000, # Set the maximum amount of memory the solver can use (in MB) | |
), | |
system_to_file=false, | |
initialize_model=true, | |
optimizer_solve_log_print=false, | |
direct_mode_optimizer=true, | |
rebuild_model=false, | |
store_variable_names=true, | |
calculate_conflict=true, |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 182 to 188 in 2b67507
], | |
) | |
uc_simulation_ff = Vector{PowerSimulations.AbstractAffectFeedforward}() | |
#FVFF_area_interchange = FixValueFeedforward(;component_type=AreaInterchange,source=FlowActivePowerVariable,affected_values=[FlowActivePowerVariable],) | |
#push!(uc_simulation_ff, FVFF_area_interchange) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 190 to 195 in 2b67507
#LBFF = FixValueFeedforward(; | |
# component_type=ThermalStandard, | |
# source=OnVariable, | |
# affected_values=[OnVariable], | |
#) | |
#push!(uc_simulation_ff, LBFF) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 197 to 234 in 2b67507
sequence = SimulationSequence(; | |
models=models, | |
feedforwards=Dict( | |
"UC_Subsystem" => uc_simulation_ff, | |
), | |
ini_cond_chronology=InterProblemChronology(), | |
); | |
# use different names for saving the solution | |
sim = Simulation(; | |
name="sim", | |
steps=1, | |
models=models, | |
sequence=sequence, | |
initial_time=DateTime("2020-01-01T00:00:00"), | |
simulation_folder=mktempdir(), | |
); | |
build_out = build!(sim; console_level=Logging.Info, serialize=false) | |
execute_status = execute!(sim; enable_progress_bar=true); | |
uc0=models.decision_models[1].internal.container | |
uc2b=models.decision_models[2].internal.container.subproblems["b"] | |
uc2a=models.decision_models[2].internal.container.subproblems["a"] | |
println("obj uc0,uc2a,uc2b,",objective_value(uc0.JuMPmodel),",",objective_value(uc2a.JuMPmodel),",",objective_value(uc2b.JuMPmodel),",diff,",objective_value(uc0.JuMPmodel)-objective_value(uc2a.JuMPmodel)-objective_value(uc2b.JuMPmodel)) | |
results = SimulationResults(sim) | |
# #results = SimulationResults(sim) | |
results_uc = get_decision_problem_results(results, "UC0") | |
results_ha = get_decision_problem_results(results, "UC_Subsystem") | |
aa = read_realized_variable(results_uc, "FlowActivePowerVariable__MonitoredLine") | |
ac = read_realized_variable(results_ha, "FlowActivePowerVariable__MonitoredLine") | |
area_df=DataFrames.DataFrame(; | |
t =Int64[], uc=[], area1_gen = [], area1_load = [], area2_gen = [], area2_load = [], | |
area3_gen = [], area3_load = [], |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Line 240 in 2b67507
bus_df=read_bus_df(results_rt,"A28",1) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 244 to 257 in 2b67507
area_df=combine(groupby(bus_df, [:t, :area]), [:ThermalStandard, :PowerLoad, :ActivePowerBalance__ACBus, :StateEstimationInjections__ACBus] .=> sum) | |
area_df[!,"areacheck"]=area_df[!,"ActivePowerBalance__ACBus_sum"]-area_df[!,"ThermalStandard_sum"]/100-area_df[!,"PowerLoad_sum"]/100 | |
area1_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), area_df) | |
area2_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), area_df) | |
area3_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), area_df) | |
area1_df[!,"secheck"]=lag(area1_df[!,"ActivePowerBalance__ACBus_sum"])-area1_df[!,"StateEstimationInjections__ACBus_sum"] | |
area2_df[!,"secheck"]=lag(area2_df[!,"ActivePowerBalance__ACBus_sum"])-area2_df[!,"StateEstimationInjections__ACBus_sum"] | |
area3_df[!,"secheck"]=lag(area3_df[!,"ActivePowerBalance__ACBus_sum"])-area3_df[!,"StateEstimationInjections__ACBus_sum"] | |
println("area1 check max diff lag(ActivePowerBalance__ACBus_sum)-StateEstimationInjections__ACBus_sum,", maximum(area1_df[!,"secheck"][2,:])) | |
println("area2 check max diff lag(ActivePowerBalance__ACBus_sum)-StateEstimationInjections__ACBus_sum,", maximum(area2_df[!,"secheck"][2,:])) | |
println("area3 check max diff lag(ActivePowerBalance__ACBus_sum)-StateEstimationInjections__ACBus_sum,", maximum(area3_df[!,"secheck"][2,:])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Line 261 in 2b67507
areaflow_df=combine(groupby(bus_df, [:t, :area]), [:flowcontribution, :loopflowcontribution] .=> sum) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 264 to 274 in 2b67507
areaflow1_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), areaflow_df) | |
areaflow2_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), areaflow_df) | |
areaflow3_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), areaflow_df) | |
areaflow1_df[!,"secheck"]=lag(areaflow1_df[!,"flowcontribution_sum"])-areaflow1_df[!,"loopflowcontribution_sum"] | |
areaflow2_df[!,"secheck"]=lag(areaflow2_df[!,"flowcontribution_sum"])-areaflow2_df[!,"loopflowcontribution_sum"] | |
areaflow3_df[!,"secheck"]=lag(areaflow3_df[!,"flowcontribution_sum"])-areaflow3_df[!,"loopflowcontribution_sum"] | |
println("areaflow1 check max diff lag(flowcontribution_sum)-loopflowcontribution_sum,", maximum(area1_df[!,"secheck"][2,:])) | |
println("areaflow2 check max diff lag(flowcontribution_sum)-loopflowcontribution_sum,", maximum(area2_df[!,"secheck"][2,:])) | |
println("areaflow3 check max diff lag(flowcontribution_sum)-loopflowcontribution_sum,", maximum(area3_df[!,"secheck"][2,:])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 277 to 285 in 2b67507
areaflow13_df=innerjoin(areaflow1_df, areaflow3_df, on=:t,renamecols = "_1" => "_3") | |
areaflow132_df=innerjoin(areaflow13_df, areaflow2_df, on=:t,renamecols = "" => "_2") | |
areaflow132_df[!,"flow_subsystem_a"]=areaflow132_df[!,"flowcontribution_sum_1"]+areaflow132_df[!,"flowcontribution_sum_3"]+areaflow132_df[!,"loopflowcontribution_sum_2"] | |
areaflow132_df[!,"flow_subsystem_b"]=areaflow132_df[!,"loopflowcontribution_sum_1"]+areaflow132_df[!,"loopflowcontribution_sum_3"]+areaflow132_df[!,"flowcontribution_sum_2"] | |
areaflow132_df[!,"seflow"]=areaflow132_df[!,"flowcontribution_sum_1"]+areaflow132_df[!,"flowcontribution_sum_3"]+areaflow132_df[!,"flowcontribution_sum_2"] | |
StatsPlots.@df(areaflow132_df,Plots.plot(:t,[:flow_subsystem_a :flow_subsystem_b :seflow])) | |
[JuliaFormatter] reported by reviewdog 🐶
function read_bus_df(results_rt,line,se=0) |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 al = read_realized_variable(results_rt, "StateEstimationInjections__ACBus") end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 45 to 48 in 2b67507
bus_ActivePowerVariable__ThermalStandard=Dict() | |
bus_ActivePowerTimeSeriesParameter__PowerLoad=Dict() | |
bus_ActivePowerBalance__ACBus=Dict() | |
bus_StateEstimationInjections__ACBus=Dict() |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 50 to 52 in 2b67507
bus_df=DataFrames.DataFrame(; | |
t =Int64[], bus=[], area = [], ThermalStandard=[], PowerLoad=[], ActivePowerBalance__ACBus=[], | |
StateEstimationInjections__ACBus=[], ptdf=[], flowcontribution=[], loopflowcontribution=[] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 55 to 58 in 2b67507
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); bus_ActivePowerVariable__ThermalStandard[t,bn]=0 | |
bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn]=0; bus_ActivePowerBalance__ACBus[t,bn]=0 | |
bus_StateEstimationInjections__ACBus[t,bn]=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 63 to 65 in 2b67507
try b=parse(Int,i) | |
for t=1:NT bus_ActivePowerBalance__ACBus[t,b]=ab[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 69 to 71 in 2b67507
try b=parse(Int,i) | |
for t=1:NT bus_StateEstimationInjections__ACBus[t,b]=al[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 76 to 78 in 2b67507
try b=get_number(get_bus(get_component(PowerLoad, sys, i))) | |
for t=1:NT bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]=bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]+ald[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 82 to 84 in 2b67507
try b=get_number(get_bus(get_component(ThermalStandard, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__ThermalStandard[t,b]=bus_ActivePowerVariable__ThermalStandard[t,b]+ac[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 88 to 92 in 2b67507
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); area=get_name(get_area(b)); | |
push!(bus_df,(t,bn,area, bus_ActivePowerVariable__ThermalStandard[t,bn], bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn], | |
bus_ActivePowerBalance__ACBus[t,bn], bus_StateEstimationInjections__ACBus[t,bn], ptdf[line,bn], | |
bus_ActivePowerBalance__ACBus[t,bn]*ptdf[line,bn],bus_StateEstimationInjections__ACBus[t,bn]*ptdf[line,bn])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 96 to 97 in 2b67507
bus_df[!,"buscheck"]=bus_df[!,"ActivePowerBalance__ACBus"]-bus_df[!,"ThermalStandard"]/100-bus_df[!,"PowerLoad"]/100 | |
println("bus check ActivePowerBalance__ACBus<>ThermalStandard/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 99 to 100 in 2b67507
return(bus_df) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 102 to 105 in 2b67507
function check_models(uc0,uc2a) | |
sol0=Dict() | |
v0=uc0.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol0=Dict(zip(name.(v0),value.(v0))) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 107 to 108 in 2b67507
fix(v,value.(v),force=true) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
v01=uc0.variables[InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, AreaInterchange}("")] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 112 to 116 in 2b67507
fix(v,value.(v),force=true) | |
end | |
v2a=uc2a.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol2a=Dict(zip(name.(v2a),value.(v2a))) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 118 to 124 in 2b67507
for (k,v) in sol2a | |
if abs(sol2a[k]-sol0[k])>0.00001 | |
println("k,",k,",",sol2a[k],",",sol0[k]) | |
var0=variable_by_name(uc0.JuMPmodel,k) | |
fix(var0,sol2a[k],force=true) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 128 to 131 in 2b67507
function objterms(uc0,ff) | |
objd0=Dict(); sol0=Dict(); objv0=0 | |
obj0=objective_function(uc0.JuMPmodel); objd0=Dict(zip(name.(keys(obj0.terms)),values(obj0.terms))); | |
av0 = JuMP.all_variables(uc0.JuMPmodel); sol0=Dict(zip(name.(av0), value.(av0))) |
[JuliaFormatter] reported by reviewdog 🐶
open(ff,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 135 to 137 in 2b67507
for (k,v) in objd0 | |
objv0=objv0+sol0[k]*objd0[k] | |
println("name;value;objcoef;obj_contribution;",k,";",sol0[k],";",objd0[k],";", sol0[k]*objd0[k]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 140 to 142 in 2b67507
end | |
return(objd0,sol0, objv0) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 144 to 146 in 2b67507
function write_param_acbus(name,uc2a,line) | |
parameter_ACBus_2a=uc2a.parameters[InfrastructureSystems.Optimization.ParameterKey{PowerSimulationsDecomposition.StateEstimationInjections, ACBus}("")] | |
i=axes(parameter_ACBus_2a.parameter_array) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 148 to 154 in 2b67507
for j1 in i[1] | |
con=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][line,j2] | |
param=parameter_ACBus_2a.parameter_array[j1,j2] | |
println(name,",j1,j2,",j1,",",j2,",value,",value(parameter_ACBus_2a.parameter_array[j1,j2]),",coeff,",normalized_coefficient(con,param)) | |
end | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 158 to 161 in 2b67507
function write_coeff(uc2a,linename,t,fnm,use_monitoredline) | |
fixedmw=0; fixedflow=0; areamw=Dict(); areaflow=Dict(); areaload=Dict(); arealoadflow=Dict() | |
for j=1:3 areamw[j]=0; areaflow[j]=0 end | |
c=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{CopperPlateBalanceConstraint, Area}("")][:,t] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 163 to 164 in 2b67507
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(c[i], k)!=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 166 to 168 in 2b67507
if name(k)=="param" | |
areaload[i]=-normalized_coefficient(c[i], k) | |
println("area,",i,",",areaload[i]) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 174 to 179 in 2b67507
if use_monitoredline==1 | |
con2a=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][linename,t] | |
else | |
con2a=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, Line}("")][linename,t] | |
end | |
open(fnm,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 181 to 186 in 2b67507
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(con2a, k)!=0 | |
println("coef;",name(k),";",normalized_coefficient(con2a, k), ";is_fixed;",is_fixed(k),";value;",value(k)) | |
if name(k)=="param" | |
fixedmw=fixedmw+value(k); | |
fixedflow=fixedflow+value(k)*normalized_coefficient(con2a, k) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 188 to 193 in 2b67507
str=split(name(k),"{"); | |
println("name,",name(k),",str,",str) | |
if first(str[1],1)=="A" | |
a= parse(Int64,first(str[2],1));# tt=firstindex(split(str[2],", ")) | |
areamw[a]=areamw[a]+value(k) | |
areaflow[a]=areaflow[a]+value(k)*normalized_coefficient(con2a, k) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 197 to 198 in 2b67507
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
return(fixedmw,areamw,fixedflow,areaflow) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 204 to 206 in 2b67507
function write_param_internalload(name,uc0,line) | |
parameter_load_0=uc0.parameters[InfrastructureSystems.Optimization.ParameterKey{ActivePowerTimeSeriesParameter, PowerLoad}("")] | |
i=axes(parameter_load_0.parameter_array) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 208 to 228 in 2b67507
for j1 in i[1] | |
con=uc0.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][line,j2] | |
param=parameter_load_0.parameter_array[j1,j2] | |
println(name,",load,j1,j2,",j1,",",j2,",value,",value(parameter_load_0.parameter_array[j1,j2]),",coeff,",normalized_coefficient(con,param)) | |
end | |
end | |
end | |
function write_acbus(ucname,uc0,ax,t, debug=0) | |
area_param=Dict(); area_gen=Dict() | |
area_param[1]=0;area_param[2]=0;area_param[3]=0 | |
area_gen[1]=0;area_gen[2]=0;area_gen[3]=0 | |
for bus in ax[1] | |
for k in keys(PSI.get_expression(uc0, ActivePowerBalance(), PSY.ACBus)[bus,t].terms) | |
coef=PSI.get_expression(uc0, ActivePowerBalance(),PSY.ACBus)[bus,t].terms[k] | |
v=value(k); | |
if debug==1 | |
println(ucname,";bus;t;",bus,";",t,";",k,";coefficient;", coef,";solution;",v,";coef*v;",coef*v) | |
end | |
n=Int64(floor(bus/100)) | |
if name(k)=="param" area_param[n]=area_param[n]+coef*v else area_gen[n]=area_gen[n]+coef*v end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 230 to 231 in 2b67507
end | |
return(area_gen,area_param) |
[JuliaFormatter] reported by reviewdog 🐶
if get_name(get_area(get_bus(b))) == enforced_region[1] || get_name(get_area(get_bus(b))) == enforced_region[2] |
[JuliaFormatter] reported by reviewdog 🐶
if get_name(get_area(b)) == enforced_region[1] || get_name(get_area(b)) == enforced_region[2] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 265 to 266 in 2b67507
for b in selected_line | |
l=PSY.get_component(ACBranch, sys,b) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 270 to 272 in 2b67507
add_component_to_subsystem!(sys, "b", l) | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
JuliaFormatter
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 75 to 79 in 18035e6
add_component!(sys, exchange_2_3) | |
exchange_1_2 = AreaInterchange(; | |
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "2"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 81 to 83 in 18035e6
add_component!(sys2, exchange_1_2) | |
add_component_to_subsystem!(sys2, "a", exchange_1_2) | |
add_component_to_subsystem!(sys2, "b", exchange_1_2) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 85 to 87 in 18035e6
exchange_1_3 = AreaInterchange(; | |
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "3"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 89 to 95 in 18035e6
add_component!(sys2, exchange_1_3) | |
add_component_to_subsystem!(sys2, "a", exchange_1_3) | |
add_component_to_subsystem!(sys2, "b", exchange_1_3) | |
exchange_2_3 = AreaInterchange(; | |
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "2"), to_area=get_component(Area, sys2, "3"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 97 to 121 in 18035e6
add_component!(sys2, exchange_2_3) | |
add_component_to_subsystem!(sys2, "a", exchange_2_3) | |
add_component_to_subsystem!(sys2, "b", exchange_2_3) | |
template_uc = ProblemTemplate(NetworkModel(AreaPTDFPowerModel; use_slacks=true)) | |
set_device_model!(template_uc, ThermalStandard, ThermalBasicUnitCommitment) | |
set_device_model!(template_uc, PowerLoad, StaticPowerLoad) | |
set_device_model!(template_uc, AreaInterchange, StaticBranch) | |
if use_monitoredline==0 | |
set_device_model!(template_uc, | |
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)), | |
#DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in selected_line), | |
#DeviceModel(Line, StaticBranch; attributes=Dict("filter_function" => x -> get_name(x) in selected_line), | |
)) | |
else | |
set_device_model!(template_uc, | |
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
set_device_model!(template_uc, MonitoredLine, StaticBranch) | |
for b in monitoredlined_line | |
line = PSY.get_component(Line, sys, b) | |
PSY.convert_component!(sys, line, MonitoredLine) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 123 to 143 in 18035e6
template_uc2 = MultiProblemTemplate(NetworkModel(SplitAreaPTDFPowerModel; use_slacks=true), ["a", "b"]) | |
set_device_model!(template_uc2, AreaInterchange, StaticBranch) | |
set_device_model!(template_uc2, ThermalStandard, ThermalBasicUnitCommitment) | |
set_device_model!(template_uc2, PowerLoad, StaticPowerLoad) | |
if use_monitoredline==0 | |
set_device_model!(template_uc2, | |
DeviceModel(Line, StaticBranch; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
l = PSY.get_component(ACBranch, sys2, "A28") | |
set_rating!(l,limit) | |
else | |
set_device_model!(template_uc2, | |
DeviceModel(Line, StaticBranchUnbounded; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
set_device_model!(template_uc2, MonitoredLine, StaticBranch) | |
for b in monitoredlined_line | |
line = PSY.get_component(Line, sys2, b) | |
PSY.convert_component!(sys2, line, MonitoredLine) | |
end | |
l = PSY.get_component(MonitoredLine, sys2, "A28") | |
set_flow_limits!(l,(from_to=limit,to_from=limit)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 145 to 152 in 18035e6
models = SimulationModels(; | |
decision_models=[ | |
DecisionModel( | |
template_uc, | |
sys; | |
name="UC0", | |
optimizer=optimizer_with_attributes( | |
HiGHS.Optimizer, |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 156 to 161 in 18035e6
), | |
system_to_file=false, | |
optimizer_solve_log_print=false, | |
direct_mode_optimizer=true, | |
store_variable_names=true, | |
calculate_conflict=true, |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 163 to 180 in 18035e6
DecisionModel( | |
MultiRegionProblem, | |
template_uc2, | |
sys2; | |
name="UC_Subsystem", | |
optimizer=optimizer_with_attributes( | |
HiGHS.Optimizer, | |
#Xpress.Optimizer, | |
#"MIPRELSTOP" => 0.00, # Set the relative mip gap tolerance | |
#"MAXMEMORYSOFT" => 600000, # Set the maximum amount of memory the solver can use (in MB) | |
), | |
system_to_file=false, | |
initialize_model=true, | |
optimizer_solve_log_print=false, | |
direct_mode_optimizer=true, | |
rebuild_model=false, | |
store_variable_names=true, | |
calculate_conflict=true, |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 182 to 188 in 18035e6
], | |
) | |
uc_simulation_ff = Vector{PowerSimulations.AbstractAffectFeedforward}() | |
#FVFF_area_interchange = FixValueFeedforward(;component_type=AreaInterchange,source=FlowActivePowerVariable,affected_values=[FlowActivePowerVariable],) | |
#push!(uc_simulation_ff, FVFF_area_interchange) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 190 to 195 in 18035e6
#LBFF = FixValueFeedforward(; | |
# component_type=ThermalStandard, | |
# source=OnVariable, | |
# affected_values=[OnVariable], | |
#) | |
#push!(uc_simulation_ff, LBFF) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 197 to 234 in 18035e6
sequence = SimulationSequence(; | |
models=models, | |
feedforwards=Dict( | |
"UC_Subsystem" => uc_simulation_ff, | |
), | |
ini_cond_chronology=InterProblemChronology(), | |
); | |
# use different names for saving the solution | |
sim = Simulation(; | |
name="sim", | |
steps=1, | |
models=models, | |
sequence=sequence, | |
initial_time=DateTime("2020-01-01T00:00:00"), | |
simulation_folder=mktempdir(), | |
); | |
build_out = build!(sim; console_level=Logging.Info, serialize=false) | |
execute_status = execute!(sim; enable_progress_bar=true); | |
uc0=models.decision_models[1].internal.container | |
uc2b=models.decision_models[2].internal.container.subproblems["b"] | |
uc2a=models.decision_models[2].internal.container.subproblems["a"] | |
println("obj uc0,uc2a,uc2b,",objective_value(uc0.JuMPmodel),",",objective_value(uc2a.JuMPmodel),",",objective_value(uc2b.JuMPmodel),",diff,",objective_value(uc0.JuMPmodel)-objective_value(uc2a.JuMPmodel)-objective_value(uc2b.JuMPmodel)) | |
results = SimulationResults(sim) | |
# #results = SimulationResults(sim) | |
results_uc = get_decision_problem_results(results, "UC0") | |
results_ha = get_decision_problem_results(results, "UC_Subsystem") | |
aa = read_realized_variable(results_uc, "FlowActivePowerVariable__MonitoredLine") | |
ac = read_realized_variable(results_ha, "FlowActivePowerVariable__MonitoredLine") | |
area_df=DataFrames.DataFrame(; | |
t =Int64[], uc=[], area1_gen = [], area1_load = [], area2_gen = [], area2_load = [], | |
area3_gen = [], area3_load = [], |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Line 240 in 18035e6
bus_df=read_bus_df(results_rt,"A28",1) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 244 to 257 in 18035e6
area_df=combine(groupby(bus_df, [:t, :area]), [:ThermalStandard, :PowerLoad, :ActivePowerBalance__ACBus, :StateEstimationInjections__ACBus] .=> sum) | |
area_df[!,"areacheck"]=area_df[!,"ActivePowerBalance__ACBus_sum"]-area_df[!,"ThermalStandard_sum"]/100-area_df[!,"PowerLoad_sum"]/100 | |
area1_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), area_df) | |
area2_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), area_df) | |
area3_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), area_df) | |
area1_df[!,"secheck"]=lag(area1_df[!,"ActivePowerBalance__ACBus_sum"])-area1_df[!,"StateEstimationInjections__ACBus_sum"] | |
area2_df[!,"secheck"]=lag(area2_df[!,"ActivePowerBalance__ACBus_sum"])-area2_df[!,"StateEstimationInjections__ACBus_sum"] | |
area3_df[!,"secheck"]=lag(area3_df[!,"ActivePowerBalance__ACBus_sum"])-area3_df[!,"StateEstimationInjections__ACBus_sum"] | |
println("area1 check max diff lag(ActivePowerBalance__ACBus_sum)-StateEstimationInjections__ACBus_sum,", maximum(area1_df[!,"secheck"][2,:])) | |
println("area2 check max diff lag(ActivePowerBalance__ACBus_sum)-StateEstimationInjections__ACBus_sum,", maximum(area2_df[!,"secheck"][2,:])) | |
println("area3 check max diff lag(ActivePowerBalance__ACBus_sum)-StateEstimationInjections__ACBus_sum,", maximum(area3_df[!,"secheck"][2,:])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Line 261 in 18035e6
areaflow_df=combine(groupby(bus_df, [:t, :area]), [:flowcontribution, :loopflowcontribution] .=> sum) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 264 to 274 in 18035e6
areaflow1_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), areaflow_df) | |
areaflow2_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), areaflow_df) | |
areaflow3_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), areaflow_df) | |
areaflow1_df[!,"secheck"]=lag(areaflow1_df[!,"flowcontribution_sum"])-areaflow1_df[!,"loopflowcontribution_sum"] | |
areaflow2_df[!,"secheck"]=lag(areaflow2_df[!,"flowcontribution_sum"])-areaflow2_df[!,"loopflowcontribution_sum"] | |
areaflow3_df[!,"secheck"]=lag(areaflow3_df[!,"flowcontribution_sum"])-areaflow3_df[!,"loopflowcontribution_sum"] | |
println("areaflow1 check max diff lag(flowcontribution_sum)-loopflowcontribution_sum,", maximum(area1_df[!,"secheck"][2,:])) | |
println("areaflow2 check max diff lag(flowcontribution_sum)-loopflowcontribution_sum,", maximum(area2_df[!,"secheck"][2,:])) | |
println("areaflow3 check max diff lag(flowcontribution_sum)-loopflowcontribution_sum,", maximum(area3_df[!,"secheck"][2,:])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 277 to 285 in 18035e6
areaflow13_df=innerjoin(areaflow1_df, areaflow3_df, on=:t,renamecols = "_1" => "_3") | |
areaflow132_df=innerjoin(areaflow13_df, areaflow2_df, on=:t,renamecols = "" => "_2") | |
areaflow132_df[!,"flow_subsystem_a"]=areaflow132_df[!,"flowcontribution_sum_1"]+areaflow132_df[!,"flowcontribution_sum_3"]+areaflow132_df[!,"loopflowcontribution_sum_2"] | |
areaflow132_df[!,"flow_subsystem_b"]=areaflow132_df[!,"loopflowcontribution_sum_1"]+areaflow132_df[!,"loopflowcontribution_sum_3"]+areaflow132_df[!,"flowcontribution_sum_2"] | |
areaflow132_df[!,"seflow"]=areaflow132_df[!,"flowcontribution_sum_1"]+areaflow132_df[!,"flowcontribution_sum_3"]+areaflow132_df[!,"flowcontribution_sum_2"] | |
StatsPlots.@df(areaflow132_df,Plots.plot(:t,[:flow_subsystem_a :flow_subsystem_b :seflow])) | |
[JuliaFormatter] reported by reviewdog 🐶
function read_bus_df(results_rt,line,se=0) |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 al = read_realized_variable(results_rt, "StateEstimationInjections__ACBus") end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 45 to 48 in 18035e6
bus_ActivePowerVariable__ThermalStandard=Dict() | |
bus_ActivePowerTimeSeriesParameter__PowerLoad=Dict() | |
bus_ActivePowerBalance__ACBus=Dict() | |
bus_StateEstimationInjections__ACBus=Dict() |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 50 to 52 in 18035e6
bus_df=DataFrames.DataFrame(; | |
t =Int64[], bus=[], area = [], ThermalStandard=[], PowerLoad=[], ActivePowerBalance__ACBus=[], | |
StateEstimationInjections__ACBus=[], ptdf=[], flowcontribution=[], loopflowcontribution=[] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 55 to 58 in 18035e6
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); bus_ActivePowerVariable__ThermalStandard[t,bn]=0 | |
bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn]=0; bus_ActivePowerBalance__ACBus[t,bn]=0 | |
bus_StateEstimationInjections__ACBus[t,bn]=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 63 to 65 in 18035e6
try b=parse(Int,i) | |
for t=1:NT bus_ActivePowerBalance__ACBus[t,b]=ab[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 69 to 71 in 18035e6
try b=parse(Int,i) | |
for t=1:NT bus_StateEstimationInjections__ACBus[t,b]=al[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 76 to 78 in 18035e6
try b=get_number(get_bus(get_component(PowerLoad, sys, i))) | |
for t=1:NT bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]=bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]+ald[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 82 to 84 in 18035e6
try b=get_number(get_bus(get_component(ThermalStandard, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__ThermalStandard[t,b]=bus_ActivePowerVariable__ThermalStandard[t,b]+ac[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 88 to 92 in 18035e6
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); area=get_name(get_area(b)); | |
push!(bus_df,(t,bn,area, bus_ActivePowerVariable__ThermalStandard[t,bn], bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn], | |
bus_ActivePowerBalance__ACBus[t,bn], bus_StateEstimationInjections__ACBus[t,bn], ptdf[line,bn], | |
bus_ActivePowerBalance__ACBus[t,bn]*ptdf[line,bn],bus_StateEstimationInjections__ACBus[t,bn]*ptdf[line,bn])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 96 to 97 in 18035e6
bus_df[!,"buscheck"]=bus_df[!,"ActivePowerBalance__ACBus"]-bus_df[!,"ThermalStandard"]/100-bus_df[!,"PowerLoad"]/100 | |
println("bus check ActivePowerBalance__ACBus<>ThermalStandard/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 99 to 100 in 18035e6
return(bus_df) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 102 to 105 in 18035e6
function check_models(uc0,uc2a) | |
sol0=Dict() | |
v0=uc0.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol0=Dict(zip(name.(v0),value.(v0))) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 107 to 108 in 18035e6
fix(v,value.(v),force=true) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
v01=uc0.variables[InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, AreaInterchange}("")] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 112 to 116 in 18035e6
fix(v,value.(v),force=true) | |
end | |
v2a=uc2a.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol2a=Dict(zip(name.(v2a),value.(v2a))) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 118 to 124 in 18035e6
for (k,v) in sol2a | |
if abs(sol2a[k]-sol0[k])>0.00001 | |
println("k,",k,",",sol2a[k],",",sol0[k]) | |
var0=variable_by_name(uc0.JuMPmodel,k) | |
fix(var0,sol2a[k],force=true) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 128 to 131 in 18035e6
function objterms(uc0,ff) | |
objd0=Dict(); sol0=Dict(); objv0=0 | |
obj0=objective_function(uc0.JuMPmodel); objd0=Dict(zip(name.(keys(obj0.terms)),values(obj0.terms))); | |
av0 = JuMP.all_variables(uc0.JuMPmodel); sol0=Dict(zip(name.(av0), value.(av0))) |
[JuliaFormatter] reported by reviewdog 🐶
open(ff,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 135 to 137 in 18035e6
for (k,v) in objd0 | |
objv0=objv0+sol0[k]*objd0[k] | |
println("name;value;objcoef;obj_contribution;",k,";",sol0[k],";",objd0[k],";", sol0[k]*objd0[k]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 140 to 142 in 18035e6
end | |
return(objd0,sol0, objv0) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 144 to 146 in 18035e6
function write_param_acbus(name,uc2a,line) | |
parameter_ACBus_2a=uc2a.parameters[InfrastructureSystems.Optimization.ParameterKey{PowerSimulationsDecomposition.StateEstimationInjections, ACBus}("")] | |
i=axes(parameter_ACBus_2a.parameter_array) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 148 to 154 in 18035e6
for j1 in i[1] | |
con=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][line,j2] | |
param=parameter_ACBus_2a.parameter_array[j1,j2] | |
println(name,",j1,j2,",j1,",",j2,",value,",value(parameter_ACBus_2a.parameter_array[j1,j2]),",coeff,",normalized_coefficient(con,param)) | |
end | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 158 to 161 in 18035e6
function write_coeff(uc2a,linename,t,fnm,use_monitoredline) | |
fixedmw=0; fixedflow=0; areamw=Dict(); areaflow=Dict(); areaload=Dict(); arealoadflow=Dict() | |
for j=1:3 areamw[j]=0; areaflow[j]=0 end | |
c=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{CopperPlateBalanceConstraint, Area}("")][:,t] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 163 to 164 in 18035e6
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(c[i], k)!=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 166 to 168 in 18035e6
if name(k)=="param" | |
areaload[i]=-normalized_coefficient(c[i], k) | |
println("area,",i,",",areaload[i]) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 174 to 179 in 18035e6
if use_monitoredline==1 | |
con2a=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][linename,t] | |
else | |
con2a=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, Line}("")][linename,t] | |
end | |
open(fnm,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 181 to 186 in 18035e6
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(con2a, k)!=0 | |
println("coef;",name(k),";",normalized_coefficient(con2a, k), ";is_fixed;",is_fixed(k),";value;",value(k)) | |
if name(k)=="param" | |
fixedmw=fixedmw+value(k); | |
fixedflow=fixedflow+value(k)*normalized_coefficient(con2a, k) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 188 to 193 in 18035e6
str=split(name(k),"{"); | |
println("name,",name(k),",str,",str) | |
if first(str[1],1)=="A" | |
a= parse(Int64,first(str[2],1));# tt=firstindex(split(str[2],", ")) | |
areamw[a]=areamw[a]+value(k) | |
areaflow[a]=areaflow[a]+value(k)*normalized_coefficient(con2a, k) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 197 to 198 in 18035e6
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
return(fixedmw,areamw,fixedflow,areaflow) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 204 to 206 in 18035e6
function write_param_internalload(name,uc0,line) | |
parameter_load_0=uc0.parameters[InfrastructureSystems.Optimization.ParameterKey{ActivePowerTimeSeriesParameter, PowerLoad}("")] | |
i=axes(parameter_load_0.parameter_array) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 208 to 228 in 18035e6
for j1 in i[1] | |
con=uc0.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][line,j2] | |
param=parameter_load_0.parameter_array[j1,j2] | |
println(name,",load,j1,j2,",j1,",",j2,",value,",value(parameter_load_0.parameter_array[j1,j2]),",coeff,",normalized_coefficient(con,param)) | |
end | |
end | |
end | |
function write_acbus(ucname,uc0,ax,t, debug=0) | |
area_param=Dict(); area_gen=Dict() | |
area_param[1]=0;area_param[2]=0;area_param[3]=0 | |
area_gen[1]=0;area_gen[2]=0;area_gen[3]=0 | |
for bus in ax[1] | |
for k in keys(PSI.get_expression(uc0, ActivePowerBalance(), PSY.ACBus)[bus,t].terms) | |
coef=PSI.get_expression(uc0, ActivePowerBalance(),PSY.ACBus)[bus,t].terms[k] | |
v=value(k); | |
if debug==1 | |
println(ucname,";bus;t;",bus,";",t,";",k,";coefficient;", coef,";solution;",v,";coef*v;",coef*v) | |
end | |
n=Int64(floor(bus/100)) | |
if name(k)=="param" area_param[n]=area_param[n]+coef*v else area_gen[n]=area_gen[n]+coef*v end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 230 to 231 in 18035e6
end | |
return(area_gen,area_param) |
[JuliaFormatter] reported by reviewdog 🐶
if get_name(get_area(get_bus(b))) == enforced_region[1] || get_name(get_area(get_bus(b))) == enforced_region[2] |
[JuliaFormatter] reported by reviewdog 🐶
if get_name(get_area(b)) == enforced_region[1] || get_name(get_area(b)) == enforced_region[2] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 265 to 266 in 18035e6
for b in selected_line | |
l=PSY.get_component(ACBranch, sys,b) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 270 to 272 in 18035e6
add_component_to_subsystem!(sys, "b", l) | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
JuliaFormatter
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 75 to 79 in 0075692
add_component!(sys, exchange_2_3) | |
exchange_1_2 = AreaInterchange(; | |
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "2"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 81 to 83 in 0075692
add_component!(sys2, exchange_1_2) | |
add_component_to_subsystem!(sys2, "a", exchange_1_2) | |
add_component_to_subsystem!(sys2, "b", exchange_1_2) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 85 to 87 in 0075692
exchange_1_3 = AreaInterchange(; | |
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "1"), to_area=get_component(Area, sys2, "3"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 89 to 95 in 0075692
add_component!(sys2, exchange_1_3) | |
add_component_to_subsystem!(sys2, "a", exchange_1_3) | |
add_component_to_subsystem!(sys2, "b", exchange_1_3) | |
exchange_2_3 = AreaInterchange(; | |
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys2, "2"), to_area=get_component(Area, sys2, "3"), | |
flow_limits=(from_to=99999, to_from=99999), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 97 to 121 in 0075692
add_component!(sys2, exchange_2_3) | |
add_component_to_subsystem!(sys2, "a", exchange_2_3) | |
add_component_to_subsystem!(sys2, "b", exchange_2_3) | |
template_uc = ProblemTemplate(NetworkModel(AreaPTDFPowerModel; use_slacks=true)) | |
set_device_model!(template_uc, ThermalStandard, ThermalBasicUnitCommitment) | |
set_device_model!(template_uc, PowerLoad, StaticPowerLoad) | |
set_device_model!(template_uc, AreaInterchange, StaticBranch) | |
if use_monitoredline==0 | |
set_device_model!(template_uc, | |
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)), | |
#DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in selected_line), | |
#DeviceModel(Line, StaticBranch; attributes=Dict("filter_function" => x -> get_name(x) in selected_line), | |
)) | |
else | |
set_device_model!(template_uc, | |
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
set_device_model!(template_uc, MonitoredLine, StaticBranch) | |
for b in monitoredlined_line | |
line = PSY.get_component(Line, sys, b) | |
PSY.convert_component!(sys, line, MonitoredLine) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 123 to 143 in 0075692
template_uc2 = MultiProblemTemplate(NetworkModel(SplitAreaPTDFPowerModel; use_slacks=true), ["a", "b"]) | |
set_device_model!(template_uc2, AreaInterchange, StaticBranch) | |
set_device_model!(template_uc2, ThermalStandard, ThermalBasicUnitCommitment) | |
set_device_model!(template_uc2, PowerLoad, StaticPowerLoad) | |
if use_monitoredline==0 | |
set_device_model!(template_uc2, | |
DeviceModel(Line, StaticBranch; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
l = PSY.get_component(ACBranch, sys2, "A28") | |
set_rating!(l,limit) | |
else | |
set_device_model!(template_uc2, | |
DeviceModel(Line, StaticBranchUnbounded; use_slacks=true, attributes=Dict("filter_function" => x -> get_name(x) in union(selected_line,monitoredlined_line)),)) | |
set_device_model!(template_uc2, MonitoredLine, StaticBranch) | |
for b in monitoredlined_line | |
line = PSY.get_component(Line, sys2, b) | |
PSY.convert_component!(sys2, line, MonitoredLine) | |
end | |
l = PSY.get_component(MonitoredLine, sys2, "A28") | |
set_flow_limits!(l,(from_to=limit,to_from=limit)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 145 to 152 in 0075692
models = SimulationModels(; | |
decision_models=[ | |
DecisionModel( | |
template_uc, | |
sys; | |
name="UC0", | |
optimizer=optimizer_with_attributes( | |
HiGHS.Optimizer, |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 156 to 161 in 0075692
), | |
system_to_file=false, | |
optimizer_solve_log_print=false, | |
direct_mode_optimizer=true, | |
store_variable_names=true, | |
calculate_conflict=true, |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 163 to 180 in 0075692
DecisionModel( | |
MultiRegionProblem, | |
template_uc2, | |
sys2; | |
name="UC_Subsystem", | |
optimizer=optimizer_with_attributes( | |
HiGHS.Optimizer, | |
#Xpress.Optimizer, | |
#"MIPRELSTOP" => 0.00, # Set the relative mip gap tolerance | |
#"MAXMEMORYSOFT" => 600000, # Set the maximum amount of memory the solver can use (in MB) | |
), | |
system_to_file=false, | |
initialize_model=true, | |
optimizer_solve_log_print=false, | |
direct_mode_optimizer=true, | |
rebuild_model=false, | |
store_variable_names=true, | |
calculate_conflict=true, |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 182 to 188 in 0075692
], | |
) | |
uc_simulation_ff = Vector{PowerSimulations.AbstractAffectFeedforward}() | |
#FVFF_area_interchange = FixValueFeedforward(;component_type=AreaInterchange,source=FlowActivePowerVariable,affected_values=[FlowActivePowerVariable],) | |
#push!(uc_simulation_ff, FVFF_area_interchange) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 190 to 195 in 0075692
#LBFF = FixValueFeedforward(; | |
# component_type=ThermalStandard, | |
# source=OnVariable, | |
# affected_values=[OnVariable], | |
#) | |
#push!(uc_simulation_ff, LBFF) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 197 to 234 in 0075692
sequence = SimulationSequence(; | |
models=models, | |
feedforwards=Dict( | |
"UC_Subsystem" => uc_simulation_ff, | |
), | |
ini_cond_chronology=InterProblemChronology(), | |
); | |
# use different names for saving the solution | |
sim = Simulation(; | |
name="sim", | |
steps=1, | |
models=models, | |
sequence=sequence, | |
initial_time=DateTime("2020-01-01T00:00:00"), | |
simulation_folder=mktempdir(), | |
); | |
build_out = build!(sim; console_level=Logging.Info, serialize=false) | |
execute_status = execute!(sim; enable_progress_bar=true); | |
uc0=models.decision_models[1].internal.container | |
uc2b=models.decision_models[2].internal.container.subproblems["b"] | |
uc2a=models.decision_models[2].internal.container.subproblems["a"] | |
println("obj uc0,uc2a,uc2b,",objective_value(uc0.JuMPmodel),",",objective_value(uc2a.JuMPmodel),",",objective_value(uc2b.JuMPmodel),",diff,",objective_value(uc0.JuMPmodel)-objective_value(uc2a.JuMPmodel)-objective_value(uc2b.JuMPmodel)) | |
results = SimulationResults(sim) | |
# #results = SimulationResults(sim) | |
results_uc = get_decision_problem_results(results, "UC0") | |
results_ha = get_decision_problem_results(results, "UC_Subsystem") | |
aa = read_realized_variable(results_uc, "FlowActivePowerVariable__MonitoredLine") | |
ac = read_realized_variable(results_ha, "FlowActivePowerVariable__MonitoredLine") | |
area_df=DataFrames.DataFrame(; | |
t =Int64[], uc=[], area1_gen = [], area1_load = [], area2_gen = [], area2_load = [], | |
area3_gen = [], area3_load = [], |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Line 240 in 0075692
bus_df=read_bus_df(results_rt,"A28",1) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 244 to 257 in 0075692
area_df=combine(groupby(bus_df, [:t, :area]), [:ThermalStandard, :PowerLoad, :ActivePowerBalance__ACBus, :StateEstimationInjections__ACBus] .=> sum) | |
area_df[!,"areacheck"]=area_df[!,"ActivePowerBalance__ACBus_sum"]-area_df[!,"ThermalStandard_sum"]/100-area_df[!,"PowerLoad_sum"]/100 | |
area1_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), area_df) | |
area2_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), area_df) | |
area3_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), area_df) | |
area1_df[!,"secheck"]=lag(area1_df[!,"ActivePowerBalance__ACBus_sum"])-area1_df[!,"StateEstimationInjections__ACBus_sum"] | |
area2_df[!,"secheck"]=lag(area2_df[!,"ActivePowerBalance__ACBus_sum"])-area2_df[!,"StateEstimationInjections__ACBus_sum"] | |
area3_df[!,"secheck"]=lag(area3_df[!,"ActivePowerBalance__ACBus_sum"])-area3_df[!,"StateEstimationInjections__ACBus_sum"] | |
println("area1 check max diff lag(ActivePowerBalance__ACBus_sum)-StateEstimationInjections__ACBus_sum,", maximum(area1_df[!,"secheck"][2,:])) | |
println("area2 check max diff lag(ActivePowerBalance__ACBus_sum)-StateEstimationInjections__ACBus_sum,", maximum(area2_df[!,"secheck"][2,:])) | |
println("area3 check max diff lag(ActivePowerBalance__ACBus_sum)-StateEstimationInjections__ACBus_sum,", maximum(area3_df[!,"secheck"][2,:])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Line 261 in 0075692
areaflow_df=combine(groupby(bus_df, [:t, :area]), [:flowcontribution, :loopflowcontribution] .=> sum) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 264 to 274 in 0075692
areaflow1_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="1"), areaflow_df) | |
areaflow2_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="2"), areaflow_df) | |
areaflow3_df=filter([:t,:area] => (t,area)-> (t>=1) && (area=="3"), areaflow_df) | |
areaflow1_df[!,"secheck"]=lag(areaflow1_df[!,"flowcontribution_sum"])-areaflow1_df[!,"loopflowcontribution_sum"] | |
areaflow2_df[!,"secheck"]=lag(areaflow2_df[!,"flowcontribution_sum"])-areaflow2_df[!,"loopflowcontribution_sum"] | |
areaflow3_df[!,"secheck"]=lag(areaflow3_df[!,"flowcontribution_sum"])-areaflow3_df[!,"loopflowcontribution_sum"] | |
println("areaflow1 check max diff lag(flowcontribution_sum)-loopflowcontribution_sum,", maximum(area1_df[!,"secheck"][2,:])) | |
println("areaflow2 check max diff lag(flowcontribution_sum)-loopflowcontribution_sum,", maximum(area2_df[!,"secheck"][2,:])) | |
println("areaflow3 check max diff lag(flowcontribution_sum)-loopflowcontribution_sum,", maximum(area3_df[!,"secheck"][2,:])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_areaptdf_DA_areasplitptdf_RT1rolling.jl
Lines 277 to 285 in 0075692
areaflow13_df=innerjoin(areaflow1_df, areaflow3_df, on=:t,renamecols = "_1" => "_3") | |
areaflow132_df=innerjoin(areaflow13_df, areaflow2_df, on=:t,renamecols = "" => "_2") | |
areaflow132_df[!,"flow_subsystem_a"]=areaflow132_df[!,"flowcontribution_sum_1"]+areaflow132_df[!,"flowcontribution_sum_3"]+areaflow132_df[!,"loopflowcontribution_sum_2"] | |
areaflow132_df[!,"flow_subsystem_b"]=areaflow132_df[!,"loopflowcontribution_sum_1"]+areaflow132_df[!,"loopflowcontribution_sum_3"]+areaflow132_df[!,"flowcontribution_sum_2"] | |
areaflow132_df[!,"seflow"]=areaflow132_df[!,"flowcontribution_sum_1"]+areaflow132_df[!,"flowcontribution_sum_3"]+areaflow132_df[!,"flowcontribution_sum_2"] | |
StatsPlots.@df(areaflow132_df,Plots.plot(:t,[:flow_subsystem_a :flow_subsystem_b :seflow])) | |
[JuliaFormatter] reported by reviewdog 🐶
function read_bus_df(results_rt,line,se=0) |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 al = read_realized_variable(results_rt, "StateEstimationInjections__ACBus") end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 45 to 48 in 0075692
bus_ActivePowerVariable__ThermalStandard=Dict() | |
bus_ActivePowerTimeSeriesParameter__PowerLoad=Dict() | |
bus_ActivePowerBalance__ACBus=Dict() | |
bus_StateEstimationInjections__ACBus=Dict() |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 50 to 52 in 0075692
bus_df=DataFrames.DataFrame(; | |
t =Int64[], bus=[], area = [], ThermalStandard=[], PowerLoad=[], ActivePowerBalance__ACBus=[], | |
StateEstimationInjections__ACBus=[], ptdf=[], flowcontribution=[], loopflowcontribution=[] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 55 to 58 in 0075692
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); bus_ActivePowerVariable__ThermalStandard[t,bn]=0 | |
bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn]=0; bus_ActivePowerBalance__ACBus[t,bn]=0 | |
bus_StateEstimationInjections__ACBus[t,bn]=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 63 to 65 in 0075692
try b=parse(Int,i) | |
for t=1:NT bus_ActivePowerBalance__ACBus[t,b]=ab[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 69 to 71 in 0075692
try b=parse(Int,i) | |
for t=1:NT bus_StateEstimationInjections__ACBus[t,b]=al[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 76 to 78 in 0075692
try b=get_number(get_bus(get_component(PowerLoad, sys, i))) | |
for t=1:NT bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]=bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]+ald[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 82 to 84 in 0075692
try b=get_number(get_bus(get_component(ThermalStandard, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__ThermalStandard[t,b]=bus_ActivePowerVariable__ThermalStandard[t,b]+ac[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 88 to 92 in 0075692
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); area=get_name(get_area(b)); | |
push!(bus_df,(t,bn,area, bus_ActivePowerVariable__ThermalStandard[t,bn], bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn], | |
bus_ActivePowerBalance__ACBus[t,bn], bus_StateEstimationInjections__ACBus[t,bn], ptdf[line,bn], | |
bus_ActivePowerBalance__ACBus[t,bn]*ptdf[line,bn],bus_StateEstimationInjections__ACBus[t,bn]*ptdf[line,bn])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 96 to 97 in 0075692
bus_df[!,"buscheck"]=bus_df[!,"ActivePowerBalance__ACBus"]-bus_df[!,"ThermalStandard"]/100-bus_df[!,"PowerLoad"]/100 | |
println("bus check ActivePowerBalance__ACBus<>ThermalStandard/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 99 to 100 in 0075692
return(bus_df) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 102 to 105 in 0075692
function check_models(uc0,uc2a) | |
sol0=Dict() | |
v0=uc0.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol0=Dict(zip(name.(v0),value.(v0))) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 107 to 108 in 0075692
fix(v,value.(v),force=true) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
v01=uc0.variables[InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, AreaInterchange}("")] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 112 to 116 in 0075692
fix(v,value.(v),force=true) | |
end | |
v2a=uc2a.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol2a=Dict(zip(name.(v2a),value.(v2a))) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 118 to 124 in 0075692
for (k,v) in sol2a | |
if abs(sol2a[k]-sol0[k])>0.00001 | |
println("k,",k,",",sol2a[k],",",sol0[k]) | |
var0=variable_by_name(uc0.JuMPmodel,k) | |
fix(var0,sol2a[k],force=true) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 128 to 131 in 0075692
function objterms(uc0,ff) | |
objd0=Dict(); sol0=Dict(); objv0=0 | |
obj0=objective_function(uc0.JuMPmodel); objd0=Dict(zip(name.(keys(obj0.terms)),values(obj0.terms))); | |
av0 = JuMP.all_variables(uc0.JuMPmodel); sol0=Dict(zip(name.(av0), value.(av0))) |
[JuliaFormatter] reported by reviewdog 🐶
open(ff,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 135 to 137 in 0075692
for (k,v) in objd0 | |
objv0=objv0+sol0[k]*objd0[k] | |
println("name;value;objcoef;obj_contribution;",k,";",sol0[k],";",objd0[k],";", sol0[k]*objd0[k]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 140 to 142 in 0075692
end | |
return(objd0,sol0, objv0) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 144 to 146 in 0075692
function write_param_acbus(name,uc2a,line) | |
parameter_ACBus_2a=uc2a.parameters[InfrastructureSystems.Optimization.ParameterKey{PowerSimulationsDecomposition.StateEstimationInjections, ACBus}("")] | |
i=axes(parameter_ACBus_2a.parameter_array) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 148 to 154 in 0075692
for j1 in i[1] | |
con=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][line,j2] | |
param=parameter_ACBus_2a.parameter_array[j1,j2] | |
println(name,",j1,j2,",j1,",",j2,",value,",value(parameter_ACBus_2a.parameter_array[j1,j2]),",coeff,",normalized_coefficient(con,param)) | |
end | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 158 to 161 in 0075692
function write_coeff(uc2a,linename,t,fnm,use_monitoredline) | |
fixedmw=0; fixedflow=0; areamw=Dict(); areaflow=Dict(); areaload=Dict(); arealoadflow=Dict() | |
for j=1:3 areamw[j]=0; areaflow[j]=0 end | |
c=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{CopperPlateBalanceConstraint, Area}("")][:,t] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 163 to 164 in 0075692
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(c[i], k)!=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 166 to 168 in 0075692
if name(k)=="param" | |
areaload[i]=-normalized_coefficient(c[i], k) | |
println("area,",i,",",areaload[i]) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 174 to 179 in 0075692
if use_monitoredline==1 | |
con2a=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][linename,t] | |
else | |
con2a=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, Line}("")][linename,t] | |
end | |
open(fnm,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 181 to 186 in 0075692
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(con2a, k)!=0 | |
println("coef;",name(k),";",normalized_coefficient(con2a, k), ";is_fixed;",is_fixed(k),";value;",value(k)) | |
if name(k)=="param" | |
fixedmw=fixedmw+value(k); | |
fixedflow=fixedflow+value(k)*normalized_coefficient(con2a, k) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 188 to 193 in 0075692
str=split(name(k),"{"); | |
println("name,",name(k),",str,",str) | |
if first(str[1],1)=="A" | |
a= parse(Int64,first(str[2],1));# tt=firstindex(split(str[2],", ")) | |
areamw[a]=areamw[a]+value(k) | |
areaflow[a]=areaflow[a]+value(k)*normalized_coefficient(con2a, k) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 197 to 198 in 0075692
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
return(fixedmw,areamw,fixedflow,areaflow) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 204 to 206 in 0075692
function write_param_internalload(name,uc0,line) | |
parameter_load_0=uc0.parameters[InfrastructureSystems.Optimization.ParameterKey{ActivePowerTimeSeriesParameter, PowerLoad}("")] | |
i=axes(parameter_load_0.parameter_array) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 208 to 228 in 0075692
for j1 in i[1] | |
con=uc0.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][line,j2] | |
param=parameter_load_0.parameter_array[j1,j2] | |
println(name,",load,j1,j2,",j1,",",j2,",value,",value(parameter_load_0.parameter_array[j1,j2]),",coeff,",normalized_coefficient(con,param)) | |
end | |
end | |
end | |
function write_acbus(ucname,uc0,ax,t, debug=0) | |
area_param=Dict(); area_gen=Dict() | |
area_param[1]=0;area_param[2]=0;area_param[3]=0 | |
area_gen[1]=0;area_gen[2]=0;area_gen[3]=0 | |
for bus in ax[1] | |
for k in keys(PSI.get_expression(uc0, ActivePowerBalance(), PSY.ACBus)[bus,t].terms) | |
coef=PSI.get_expression(uc0, ActivePowerBalance(),PSY.ACBus)[bus,t].terms[k] | |
v=value(k); | |
if debug==1 | |
println(ucname,";bus;t;",bus,";",t,";",k,";coefficient;", coef,";solution;",v,";coef*v;",coef*v) | |
end | |
n=Int64(floor(bus/100)) | |
if name(k)=="param" area_param[n]=area_param[n]+coef*v else area_gen[n]=area_gen[n]+coef*v end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 230 to 231 in 0075692
end | |
return(area_gen,area_param) |
[JuliaFormatter] reported by reviewdog 🐶
if get_name(get_area(get_bus(b))) == enforced_region[1] || get_name(get_area(get_bus(b))) == enforced_region[2] |
[JuliaFormatter] reported by reviewdog 🐶
if get_name(get_area(b)) == enforced_region[1] || get_name(get_area(b)) == enforced_region[2] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 265 to 266 in 0075692
for b in selected_line | |
l=PSY.get_component(ACBranch, sys,b) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 270 to 272 in 0075692
add_component_to_subsystem!(sys, "b", l) | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
JuliaFormatter
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 99 to 100 in d441db7
return(bus_df) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 102 to 105 in d441db7
function check_models(uc0,uc2a) | |
sol0=Dict() | |
v0=uc0.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol0=Dict(zip(name.(v0),value.(v0))) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 107 to 108 in d441db7
fix(v,value.(v),force=true) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
v01=uc0.variables[InfrastructureSystems.Optimization.VariableKey{FlowActivePowerVariable, AreaInterchange}("")] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 112 to 116 in d441db7
fix(v,value.(v),force=true) | |
end | |
v2a=uc2a.variables[PowerSimulations.VariableKey{ActivePowerVariable, ThermalStandard}("")] | |
sol2a=Dict(zip(name.(v2a),value.(v2a))) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 118 to 124 in d441db7
for (k,v) in sol2a | |
if abs(sol2a[k]-sol0[k])>0.00001 | |
println("k,",k,",",sol2a[k],",",sol0[k]) | |
var0=variable_by_name(uc0.JuMPmodel,k) | |
fix(var0,sol2a[k],force=true) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 128 to 131 in d441db7
function objterms(uc0,ff) | |
objd0=Dict(); sol0=Dict(); objv0=0 | |
obj0=objective_function(uc0.JuMPmodel); objd0=Dict(zip(name.(keys(obj0.terms)),values(obj0.terms))); | |
av0 = JuMP.all_variables(uc0.JuMPmodel); sol0=Dict(zip(name.(av0), value.(av0))) |
[JuliaFormatter] reported by reviewdog 🐶
open(ff,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 135 to 137 in d441db7
for (k,v) in objd0 | |
objv0=objv0+sol0[k]*objd0[k] | |
println("name;value;objcoef;obj_contribution;",k,";",sol0[k],";",objd0[k],";", sol0[k]*objd0[k]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 140 to 142 in d441db7
end | |
return(objd0,sol0, objv0) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 144 to 146 in d441db7
function write_param_acbus(name,uc2a,line) | |
parameter_ACBus_2a=uc2a.parameters[InfrastructureSystems.Optimization.ParameterKey{PowerSimulationsDecomposition.StateEstimationInjections, ACBus}("")] | |
i=axes(parameter_ACBus_2a.parameter_array) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 148 to 154 in d441db7
for j1 in i[1] | |
con=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][line,j2] | |
param=parameter_ACBus_2a.parameter_array[j1,j2] | |
println(name,",j1,j2,",j1,",",j2,",value,",value(parameter_ACBus_2a.parameter_array[j1,j2]),",coeff,",normalized_coefficient(con,param)) | |
end | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 158 to 161 in d441db7
function write_coeff(uc2a,linename,t,fnm,use_monitoredline) | |
fixedmw=0; fixedflow=0; areamw=Dict(); areaflow=Dict(); areaload=Dict(); arealoadflow=Dict() | |
for j=1:3 areamw[j]=0; areaflow[j]=0 end | |
c=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{CopperPlateBalanceConstraint, Area}("")][:,t] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 163 to 164 in d441db7
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(c[i], k)!=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 166 to 168 in d441db7
if name(k)=="param" | |
areaload[i]=-normalized_coefficient(c[i], k) | |
println("area,",i,",",areaload[i]) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 174 to 179 in d441db7
if use_monitoredline==1 | |
con2a=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][linename,t] | |
else | |
con2a=uc2a.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, Line}("")][linename,t] | |
end | |
open(fnm,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 181 to 186 in d441db7
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(con2a, k)!=0 | |
println("coef;",name(k),";",normalized_coefficient(con2a, k), ";is_fixed;",is_fixed(k),";value;",value(k)) | |
if name(k)=="param" | |
fixedmw=fixedmw+value(k); | |
fixedflow=fixedflow+value(k)*normalized_coefficient(con2a, k) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 188 to 193 in d441db7
str=split(name(k),"{"); | |
println("name,",name(k),",str,",str) | |
if first(str[1],1)=="A" | |
a= parse(Int64,first(str[2],1));# tt=firstindex(split(str[2],", ")) | |
areamw[a]=areamw[a]+value(k) | |
areaflow[a]=areaflow[a]+value(k)*normalized_coefficient(con2a, k) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 197 to 198 in d441db7
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
return(fixedmw,areamw,fixedflow,areaflow) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 204 to 206 in d441db7
function write_param_internalload(name,uc0,line) | |
parameter_load_0=uc0.parameters[InfrastructureSystems.Optimization.ParameterKey{ActivePowerTimeSeriesParameter, PowerLoad}("")] | |
i=axes(parameter_load_0.parameter_array) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 208 to 228 in d441db7
for j1 in i[1] | |
con=uc0.constraints[InfrastructureSystems.Optimization.ConstraintKey{NetworkFlowConstraint, MonitoredLine}("")][line,j2] | |
param=parameter_load_0.parameter_array[j1,j2] | |
println(name,",load,j1,j2,",j1,",",j2,",value,",value(parameter_load_0.parameter_array[j1,j2]),",coeff,",normalized_coefficient(con,param)) | |
end | |
end | |
end | |
function write_acbus(ucname,uc0,ax,t, debug=0) | |
area_param=Dict(); area_gen=Dict() | |
area_param[1]=0;area_param[2]=0;area_param[3]=0 | |
area_gen[1]=0;area_gen[2]=0;area_gen[3]=0 | |
for bus in ax[1] | |
for k in keys(PSI.get_expression(uc0, ActivePowerBalance(), PSY.ACBus)[bus,t].terms) | |
coef=PSI.get_expression(uc0, ActivePowerBalance(),PSY.ACBus)[bus,t].terms[k] | |
v=value(k); | |
if debug==1 | |
println(ucname,";bus;t;",bus,";",t,";",k,";coefficient;", coef,";solution;",v,";coef*v;",coef*v) | |
end | |
n=Int64(floor(bus/100)) | |
if name(k)=="param" area_param[n]=area_param[n]+coef*v else area_gen[n]=area_gen[n]+coef*v end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 230 to 231 in d441db7
end | |
return(area_gen,area_param) |
[JuliaFormatter] reported by reviewdog 🐶
if get_name(get_area(get_bus(b))) == enforced_region[1] || get_name(get_area(get_bus(b))) == enforced_region[2] |
[JuliaFormatter] reported by reviewdog 🐶
if get_name(get_area(b)) == enforced_region[1] || get_name(get_area(b)) == enforced_region[2] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 265 to 266 in d441db7
for b in selected_line | |
l=PSY.get_component(ACBranch, sys,b) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/YC_test_function.jl
Lines 270 to 272 in d441db7
add_component_to_subsystem!(sys, "b", l) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 35 to 36 in d441db7
function write_cons_coeff(uc2a,con2a,fnm) | |
open(fnm,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 38 to 42 in d441db7
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(con2a, k)!=0 | |
println("coef;",name(k),";",normalized_coefficient(con2a, k), ";is_fixed;",is_fixed(k),";value;",value(k)) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 47 to 48 in d441db7
function write_model(uc0,fnm) | |
open(fnm,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 51 to 54 in d441db7
for k in all_constraints(uc0.JuMPmodel,; include_variable_in_set_constraints = true) | |
println(name(k),",",k) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 58 to 61 in d441db7
function objterms(uc0,ff) | |
objd0=Dict(); sol0=Dict(); objv0=0 | |
obj0=objective_function(uc0.JuMPmodel); objd0=Dict(zip(name.(keys(obj0.terms)),values(obj0.terms))); | |
av0 = JuMP.all_variables(uc0.JuMPmodel); sol0=Dict(zip(name.(av0), value.(av0))) |
[JuliaFormatter] reported by reviewdog 🐶
open(ff,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 65 to 67 in d441db7
for (k,v) in objd0 | |
objv0=objv0+sol0[k]*objd0[k] | |
println("name;value;objcoef;obj_contribution;",k,";",sol0[k],";",objd0[k],";", sol0[k]*objd0[k]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 70 to 72 in d441db7
end | |
return(objd0,sol0, objv0) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
function read_bus_df(results_rt,line="",se=0,standardload=0) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 80 to 82 in d441db7
if se==1 al = read_realized_variable(results_rt, "StateEstimationInjections__ACBus") end | |
if standardload==1 | |
ald = read_realized_variable(results_rt, "ActivePowerTimeSeriesParameter__StandardLoad") |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 84 to 103 in d441db7
ald = read_realized_variable(results_rt, "ActivePowerTimeSeriesParameter__PowerLoad") | |
end | |
if line!="" am = read_realized_variable(results_rt, "FlowActivePowerVariable__MonitoredLine") end | |
ahvdc=[] | |
try | |
ahvdc=read_realized_variable(results_rt, "FlowActivePowerVariable__TwoTerminalHVDCLine") | |
catch e end | |
bus_ActivePowerVariable__ThermalStandard=Dict() | |
bus_ActivePowerVariable__RenewableDispatch=Dict() | |
bus_ActivePowerVariable__HydroDispatch=Dict() | |
bus_ActivePowerTimeSeriesParameter__PowerLoad=Dict() | |
bus_ActivePowerBalance__ACBus=Dict() | |
bus_StateEstimationInjections__ACBus=Dict() | |
bus_ActivePowerVariable__HVDC=Dict() | |
bus_df=DataFrames.DataFrame(; | |
t =Int64[], bus=[], area = [], ThermalStandard=[],Renewable=[],Hydro=[], | |
PowerLoad=[], HVDC=[],ActivePowerBalance__ACBus=[], StateEstimationInjections__ACBus=[], | |
ptdf=[], flowcontribution=[], loopflowcontribution=[] |
[JuliaFormatter] reported by reviewdog 🐶
NT=size(ac,1) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 107 to 113 in d441db7
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); bus_ActivePowerVariable__ThermalStandard[t,bn]=0 | |
bus_ActivePowerVariable__RenewableDispatch[t,bn]=0 | |
bus_ActivePowerVariable__HydroDispatch[t,bn]=0 | |
bus_ActivePowerVariable__HVDC[t,bn]=0 | |
bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn]=0; bus_ActivePowerBalance__ACBus[t,bn]=0 | |
bus_StateEstimationInjections__ACBus[t,bn]=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 118 to 120 in d441db7
try b=parse(Int,i) | |
for t=1:NT bus_ActivePowerBalance__ACBus[t,b]=ab[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 124 to 126 in d441db7
try b=parse(Int,i) | |
for t=1:NT bus_StateEstimationInjections__ACBus[t,b]=al[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 131 to 134 in d441db7
if standardload==1 | |
try b=get_number(get_bus(get_component(StandardLoad, sys, i))) | |
for t=1:NT bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]=bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]+ald[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 136 to 139 in d441db7
try b=get_number(get_bus(get_component(PowerLoad, sys, i))) | |
for t=1:NT bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]=bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]+ald[t,i] end | |
catch e println("error= ",e,",i=",i) end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
if length(ahvdc)>0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 144 to 151 in d441db7
try b=get_number(get_from(get_arc(get_component(TwoTerminalHVDCLine, sys, i)))) | |
for t=1:NT | |
#bus_ActivePowerVariable__ThermalStandard[t,b]=bus_ActivePowerVariable__ThermalStandard[t,b]-ahvdc[t,i] | |
bus_ActivePowerVariable__HVDC[t,b]=bus_ActivePowerVariable__HVDC[t,b]-ahvdc[t,i] | |
end | |
catch e println("error ",e,",i=",i) end | |
try b=get_number(get_to(get_arc(get_component(TwoTerminalHVDCLine, sys, i)))) | |
for t=1:NT |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 153 to 155 in d441db7
bus_ActivePowerVariable__HVDC[t,b]=bus_ActivePowerVariable__HVDC[t,b]+ahvdc[t,i] | |
end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 157 to 158 in d441db7
end | |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 160 to 162 in d441db7
try b=get_number(get_bus(get_component(ThermalStandard, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__ThermalStandard[t,b]=bus_ActivePowerVariable__ThermalStandard[t,b]+ac[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 165 to 167 in d441db7
try b=get_number(get_bus(get_component(RenewableDispatch, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__RenewableDispatch[t,b]=bus_ActivePowerVariable__RenewableDispatch[t,b]+ac1[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 170 to 172 in d441db7
try b=get_number(get_bus(get_component(HydroDispatch, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__HydroDispatch[t,b]=bus_ActivePowerVariable__HydroDispatch[t,b]+ac2[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 176 to 183 in d441db7
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); area=get_name(get_area(b)); | |
if line=="" gsf=0 else gsf=ptdf[line,bn] end | |
push!(bus_df,(t,bn,area, bus_ActivePowerVariable__ThermalStandard[t,bn], | |
bus_ActivePowerVariable__RenewableDispatch[t,bn],bus_ActivePowerVariable__HydroDispatch[t,bn], | |
bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn],bus_ActivePowerVariable__HVDC[t,bn], | |
bus_ActivePowerBalance__ACBus[t,bn], bus_StateEstimationInjections__ACBus[t,bn], gsf, | |
bus_ActivePowerBalance__ACBus[t,bn]*gsf,bus_StateEstimationInjections__ACBus[t,bn]*gsf)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 187 to 188 in d441db7
bus_df[!,"buscheck"]=bus_df[!,"ActivePowerBalance__ACBus"]-bus_df[!,"ThermalStandard"]/100-bus_df[!,"Renewable"]/100-bus_df[!,"Hydro"]/100-bus_df[!,"PowerLoad"]/100 | |
println("bus check ActivePowerBalance__ACBus<>ThermalStandard/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 190 to 191 in d441db7
return(bus_df) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
subsys=unique(values(area_region_dict)) |
[JuliaFormatter] reported by reviewdog 🐶
println(b); |
[JuliaFormatter] reported by reviewdog 🐶
add_component_to_subsystem!(sys, v, b) |
[JuliaFormatter] reported by reviewdog 🐶
region=area_region_dict[get_name(b)] |
[JuliaFormatter] reported by reviewdog 🐶
region=area_region_dict[get_name(get_area(get_bus(b)))] |
[JuliaFormatter] reported by reviewdog 🐶
region=area_region_dict[get_name(get_area(b))] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 218 to 221 in d441db7
if length(selected_line)>0 | |
for b in selected_line | |
l=PSY.get_component(ACBranch, sys,b) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 224 to 231 in d441db7
add_component_to_subsystem!(sys, v, l) | |
end | |
end | |
end | |
if length(monitoredline_subsys) >0 | |
for (k,s) in monitoredline_subsys | |
l=PSY.get_component(ACBranch, sys,k) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 234 to 236 in d441db7
add_component_to_subsystem!(sys, v, l) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 240 to 242 in d441db7
tbus=get_to(get_arc(dc)); fbus=get_from(get_arc(dc)) | |
tregion=area_region_dict[get_name(get_area(tbus))] | |
fregion=area_region_dict[get_name(get_area(fbus))] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 244 to 245 in d441db7
add_component_to_subsystem!(sys, tregion, dc) | |
[JuliaFormatter] reported by reviewdog 🐶
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 296 to 298 in d441db7
selected_line=["CA-1", "CB-1", "AB1"] | |
ln="A28" | |
limit=1.0 #2.0 |
[JuliaFormatter] reported by reviewdog 🐶
standardload=0 |
[JuliaFormatter] reported by reviewdog 🐶
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "2"), |
[JuliaFormatter] reported by reviewdog 🐶
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "3"), |
[JuliaFormatter] reported by reviewdog 🐶
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "2"), to_area=get_component(Area, sys, "3"), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 344 to 365 in d441db7
area_dict=Dict("1" => "1", "2" => "2", "3" =>"3") | |
CF="NS3-0" | |
NS=3 | |
netmodels=["AreaPTDFPowerModel","AreaPTDFPowerModel","AreaPTDFPowerModel"] | |
copperplates=[1,0,0] | |
NTS=[24,24,1] | |
area_region_dicts=[Dict(), | |
Dict(), | |
Dict()] | |
CF="NS3-1" | |
NS=3 | |
netmodels=["AreaPTDFPowerModel","SplitAreaPTDFPowerModel","SplitAreaPTDFPowerModel"] | |
copperplates=[1,0,0] | |
NTS=[24,24,1] | |
area_region_dicts=[Dict(), | |
Dict("1" => "a", "2" => "b", "3" =>"c"), | |
Dict("1" => "a", "2" => "b", "3" =>"c")] | |
monitoredline_subsys=[Dict(),Dict(ln => ["a"]),Dict(ln => ["a"])] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 397 to 399 in d441db7
syss=[sys] | |
templates=[] | |
ptdf = VirtualPTDF(sys; tol = 1e-4, max_cache_size = 10000) |
[JuliaFormatter] reported by reviewdog 🐶
set_rating!(l,limit) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 404 to 406 in d441db7
monitoredlined_line=[ln] | |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 413 to 416 in d441db7
NT=NTS[i] | |
if i>1 | |
sys2=deepcopy(sys) | |
push!(syss,sys2) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 420 to 422 in d441db7
area_region_dict=area_region_dicts[i] | |
if netmodels[i]=="SplitAreaPTDFPowerModel" | |
subsys=unique(values(area_region_dict)) |
[JuliaFormatter] reported by reviewdog 🐶
println("add sys",i," subsystem,",v) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 427 to 430 in d441db7
template = | |
MultiProblemTemplate(NetworkModel(SplitAreaPTDFPowerModel; use_slacks=true,PTDF_matrix = ptdf,), subsys) | |
else | |
template = ProblemTemplate(NetworkModel(AreaPTDFPowerModel; use_slacks = true, PTDF_matrix = ptdf,)) |
[JuliaFormatter] reported by reviewdog 🐶
push!(templates,template) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 435 to 436 in d441db7
if standardload==1 | |
PSI.set_device_model!(template, StandardLoad , StaticPowerLoad) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 442 to 447 in d441db7
PSI.set_device_model!(template, DeviceModel(HydroDispatch, HPS.HydroDispatchReservoirBudget, | |
time_series_names = Dict{Any, String}( | |
PSI.ActivePowerTimeSeriesParameter => "max_active_power", | |
HPS.EnergyBudgetTimeSeriesParameter => "hydro_budget",) | |
) | |
) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 449 to 452 in d441db7
set_device_model!(template, DeviceModel(MonitoredLine, StaticBranchUnbounded, use_slacks = true)) | |
if NT>1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 459 to 462 in d441db7
end | |
if copperplates[i]==0 | |
set_device_model!(template, DeviceModel(MonitoredLine, StaticBranch, use_slacks = true)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 464 to 466 in d441db7
set_device_model!(template, | |
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in selected_line),)) |
[JuliaFormatter] reported by reviewdog 🐶
subsys=unique(values(area_region_dict)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 470 to 472 in d441db7
if length(subsys)>1 | |
#buildsubsystem1(sys2, area_region_dict, union(selected_line,monitoredlined_line)) | |
buildsubsystem1(sys2, area_region_dict, selected_line,monitoredline_subsys[i]) |
[JuliaFormatter] reported by reviewdog 🐶
dm=[] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 480 to 501 in d441db7
if netmodels[i]=="SplitAreaPTDFPowerModel" | |
push!(dm, DecisionModel(MultiRegionProblem, templates[i], syss[i], name="UC"*string(i),optimizer=optimizer, | |
store_variable_names=true,initialize_model=false,optimizer_solve_log_print=false, | |
direct_mode_optimizer=true,check_numerical_bounds=false, | |
calculate_conflict=true,rebuild_model=false,system_to_file = true)) | |
else | |
push!(dm, DecisionModel(templates[i],syss[i], name="UC"*string(i), optimizer=optimizer, | |
store_variable_names=true,initialize_model=false,optimizer_solve_log_print=false, | |
direct_mode_optimizer=true,check_numerical_bounds=false, | |
calculate_conflict=true,rebuild_model=false, system_to_file = true)) | |
end | |
end | |
if NS==2 | |
models = PSI.SimulationModels(decision_models=[dm[1],dm[2]]) | |
else | |
models = PSI.SimulationModels(decision_models=[dm[1],dm[2],dm[3]]) | |
end | |
uc_simulation_ffs=[] | |
feedforwards_dict=Dict() | |
for i in 1:NS-1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 503 to 504 in d441db7
#feed forward area interchange | |
FVFF_area_interchange = FixValueFeedforward(;component_type=AreaInterchange,source=FlowActivePowerVariable,affected_values=[FlowActivePowerVariable],) |
[JuliaFormatter] reported by reviewdog 🐶
if NTS[i+1]==1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 512 to 513 in d441db7
component_type=ThermalStandard, source=OnVariable, affected_values=[ActivePowerVariable],) | |
push!(uc_simulation_ff, SCFF) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 517 to 518 in d441db7
push!(uc_simulation_ffs,uc_simulation_ff) | |
feedforwards_dict["UC"*string(i+1)]=uc_simulation_ff |
[JuliaFormatter] reported by reviewdog 🐶
results = SimulationResults(sim,ignore_status = true) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 546 to 549 in d441db7
results_uc=[]; uc_areainterchange=[];uc_monitoredline=[]; | |
bus_df_uc=[];area_df=[];areaflow_df=[] | |
tm=Array(1:NTS[1]) | |
af=DataFrames.DataFrame(;tm) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 552 to 563 in d441db7
push!(results_uc,get_decision_problem_results(results, "UC"*string(i))) | |
push!(uc_areainterchange,read_realized_variable(results_uc[i], "FlowActivePowerVariable__AreaInterchange")) | |
push!(uc_monitoredline,read_realized_variable(results_uc[i], "FlowActivePowerVariable__MonitoredLine")) | |
if netmodels[i]=="SplitAreaPTDFPowerModel" | |
push!(bus_df_uc,read_bus_df(results_uc[i], ln,1,standardload)) | |
else | |
push!(bus_df_uc,read_bus_df(results_uc[i], ln,0,standardload)) | |
end | |
bus_df_uc[i][!,"buscheck"]=bus_df_uc[i][!,"ActivePowerBalance__ACBus"]-bus_df_uc[i][!,"HVDC"]/100-bus_df_uc[i][!,"ThermalStandard"]/100-bus_df_uc[i][!,"Renewable"]/100-bus_df_uc[i][!,"Hydro"]/100-bus_df_uc[i][!,"PowerLoad"]/100 | |
println("UC0 bus check ActivePowerBalance__ACBus<>Gen/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df_uc[i])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 567 to 576 in d441db7
###### area MW check ######### | |
#area level net Gen, load and ActivePowerBalance__ACBus_sum check | |
push!(area_df,combine(groupby(bus_df_uc[i], [:t, :area]), [:ThermalStandard, :Renewable, :Hydro, :PowerLoad, :ActivePowerBalance__ACBus, :StateEstimationInjections__ACBus] .=> sum)) | |
area_df[i][!,"areacheck"]=area_df[i][!,"ActivePowerBalance__ACBus_sum"]-area_df[i][!,"ThermalStandard_sum"]/100-area_df[i][!,"Renewable_sum"]/100-area_df[i][!,"Hydro_sum"]/100-area_df[i][!,"PowerLoad_sum"]/100 | |
println("i,area_df check,",sum(area_df[i][!,"areacheck"])) #should be close to 0 | |
area_df[i][!,"TotalGen"]=area_df[i][!,"ThermalStandard_sum"]+area_df[i][!,"Renewable_sum"]+area_df[i][!,"Hydro_sum"] | |
area_df[i][!,"NetInterchange"]=area_df[i][!,"TotalGen"]+area_df[i][!,"PowerLoad_sum"] | |
area_df[i][!,"InterchangeCheck"]=area_df[i][!,"NetInterchange"]-100*area_df[i][!,"ActivePowerBalance__ACBus_sum"] | |
println(area_df[i][:,["t","area","ActivePowerBalance__ACBus_sum","NetInterchange","InterchangeCheck"]]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 578 to 580 in d441db7
####### area flow check ######### | |
#area flow contribution by area and interval | |
push!(areaflow_df, combine(groupby(bus_df_uc[i], [:t, :area]), [:flowcontribution, :loopflowcontribution] .=> sum)) |
[JuliaFormatter] reported by reviewdog 🐶
if length(area_region_dicts[i])==0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 585 to 594 in d441db7
area_region_dict=area_dict | |
else | |
area_region_dict=area_region_dicts[i] | |
end | |
subsys=unique(values(area_region_dict)) | |
calculated_flow_subsys=Dict() | |
calculated_loopflow_subsys=Dict() | |
NT=NTS[1] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 598 to 600 in d441db7
af[!,"uc"*string(i)*"_flow_subsys_"*s]=zeros(NT) | |
af[!,"uc"*string(i)*"_loopflow_subsys_"*s]=zeros(NT) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
if netmodels[i]!="SplitAreaPTDFPowerModel" |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 604 to 606 in d441db7
s=area_region_dict[r] | |
name="uc"*string(i)*"_flow_subsys_"*s | |
af[!,name]=af[!,name]+filter([:t,:area]=>(t,area)->(area==r),areaflow_df[i])[!,:flowcontribution_sum] |
[JuliaFormatter] reported by reviewdog 🐶
af[!,"uc"*string(i)*"_flow"]= zeros(NT) #calculated_flow_uc0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 619 to 620 in d441db7
af[!,"uc"*string(i)*"_flow"]=af[!,"uc"*string(i)*"_flow"]+af[!,"uc"*string(i)*"_flow_subsys_"*s]#calculated_flow_uc0_subsys[k] | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 629 to 631 in d441db7
s=area_region_dict[r] | |
name="uc"*string(i)*"_flow_subsys_"*s | |
af[!,name]=af[!,name]+filter([:t,:area]=>(t,area)->(area==r),areaflow_df[i])[!,:flowcontribution_sum] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 633 to 634 in d441db7
name="uc"*string(i)*"_loopflow_subsys_"*s | |
af[!,name]=af[!,name]+filter([:t,:area]=>(t,area)->(area==r),areaflow_df[i])[!,:loopflowcontribution_sum] |
[JuliaFormatter] reported by reviewdog 🐶
calculated_flow_uc2=Dict() |
[JuliaFormatter] reported by reviewdog 🐶
af[!,"uc"*string(i)*"_seflow"]=zeros(NT) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 643 to 644 in d441db7
af[!,"uc"*string(i)*"_flow_"*s]=zeros(NT) | |
af[!,"uc"*string(i)*"_seflow"]=af[!,"uc"*string(i)*"_seflow"]+af[!,"uc"*string(i)*"_flow_subsys_"*s]#calculated_flow_subsys[s] |
[JuliaFormatter] reported by reviewdog 🐶
if s==s1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 648 to 649 in d441db7
name="uc"*string(i)*"_flow_"*s | |
af[!,name]=af[!,name]+af[!,"uc"*string(i)*"_flow_subsys_"*s1]#calculated_flow_subsys[s1] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 652 to 655 in d441db7
name="uc"*string(i)*"_flow_"*s | |
af[!,name]=af[!,name]+af[!,"uc"*string(i)*"_loopflow_subsys_"*s1]#calculated_loopflow_subsys[s1] | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 658 to 659 in d441db7
end | |
[JuliaFormatter] reported by reviewdog 🐶
CSV.write("af_"*CF*".csv",af) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 724 to 725 in d441db7
=# |
Multi-Stage/Manifest.toml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This files shouldn't be in the repositories
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
JuliaFormatter
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 35 to 36 in 823f960
function write_cons_coeff(uc2a,con2a,fnm) | |
open(fnm,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 38 to 42 in 823f960
for k in all_variables(uc2a.JuMPmodel) | |
if normalized_coefficient(con2a, k)!=0 | |
println("coef;",name(k),";",normalized_coefficient(con2a, k), ";is_fixed;",is_fixed(k),";value;",value(k)) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 47 to 48 in 823f960
function write_model(uc0,fnm) | |
open(fnm,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 51 to 54 in 823f960
for k in all_constraints(uc0.JuMPmodel,; include_variable_in_set_constraints = true) | |
println(name(k),",",k) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 58 to 61 in 823f960
function objterms(uc0,ff) | |
objd0=Dict(); sol0=Dict(); objv0=0 | |
obj0=objective_function(uc0.JuMPmodel); objd0=Dict(zip(name.(keys(obj0.terms)),values(obj0.terms))); | |
av0 = JuMP.all_variables(uc0.JuMPmodel); sol0=Dict(zip(name.(av0), value.(av0))) |
[JuliaFormatter] reported by reviewdog 🐶
open(ff,"w") do io |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 65 to 67 in 823f960
for (k,v) in objd0 | |
objv0=objv0+sol0[k]*objd0[k] | |
println("name;value;objcoef;obj_contribution;",k,";",sol0[k],";",objd0[k],";", sol0[k]*objd0[k]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 70 to 72 in 823f960
end | |
return(objd0,sol0, objv0) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
function read_bus_df(results_rt,line="",se=0,standardload=0) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 80 to 82 in 823f960
if se==1 al = read_realized_variable(results_rt, "StateEstimationInjections__ACBus") end | |
if standardload==1 | |
ald = read_realized_variable(results_rt, "ActivePowerTimeSeriesParameter__StandardLoad") |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 84 to 103 in 823f960
ald = read_realized_variable(results_rt, "ActivePowerTimeSeriesParameter__PowerLoad") | |
end | |
if line!="" am = read_realized_variable(results_rt, "FlowActivePowerVariable__MonitoredLine") end | |
ahvdc=[] | |
try | |
ahvdc=read_realized_variable(results_rt, "FlowActivePowerVariable__TwoTerminalHVDCLine") | |
catch e end | |
bus_ActivePowerVariable__ThermalStandard=Dict() | |
bus_ActivePowerVariable__RenewableDispatch=Dict() | |
bus_ActivePowerVariable__HydroDispatch=Dict() | |
bus_ActivePowerTimeSeriesParameter__PowerLoad=Dict() | |
bus_ActivePowerBalance__ACBus=Dict() | |
bus_StateEstimationInjections__ACBus=Dict() | |
bus_ActivePowerVariable__HVDC=Dict() | |
bus_df=DataFrames.DataFrame(; | |
t =Int64[], bus=[], area = [], ThermalStandard=[],Renewable=[],Hydro=[], | |
PowerLoad=[], HVDC=[],ActivePowerBalance__ACBus=[], StateEstimationInjections__ACBus=[], | |
ptdf=[], flowcontribution=[], loopflowcontribution=[] |
[JuliaFormatter] reported by reviewdog 🐶
NT=size(ac,1) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 107 to 113 in 823f960
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); bus_ActivePowerVariable__ThermalStandard[t,bn]=0 | |
bus_ActivePowerVariable__RenewableDispatch[t,bn]=0 | |
bus_ActivePowerVariable__HydroDispatch[t,bn]=0 | |
bus_ActivePowerVariable__HVDC[t,bn]=0 | |
bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn]=0; bus_ActivePowerBalance__ACBus[t,bn]=0 | |
bus_StateEstimationInjections__ACBus[t,bn]=0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 118 to 120 in 823f960
try b=parse(Int,i) | |
for t=1:NT bus_ActivePowerBalance__ACBus[t,b]=ab[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
if se==1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 124 to 126 in 823f960
try b=parse(Int,i) | |
for t=1:NT bus_StateEstimationInjections__ACBus[t,b]=al[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 131 to 134 in 823f960
if standardload==1 | |
try b=get_number(get_bus(get_component(StandardLoad, sys, i))) | |
for t=1:NT bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]=bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]+ald[t,i] end | |
catch e println("error= ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 136 to 139 in 823f960
try b=get_number(get_bus(get_component(PowerLoad, sys, i))) | |
for t=1:NT bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]=bus_ActivePowerTimeSeriesParameter__PowerLoad[t,b]+ald[t,i] end | |
catch e println("error= ",e,",i=",i) end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
if length(ahvdc)>0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 144 to 151 in 823f960
try b=get_number(get_from(get_arc(get_component(TwoTerminalHVDCLine, sys, i)))) | |
for t=1:NT | |
#bus_ActivePowerVariable__ThermalStandard[t,b]=bus_ActivePowerVariable__ThermalStandard[t,b]-ahvdc[t,i] | |
bus_ActivePowerVariable__HVDC[t,b]=bus_ActivePowerVariable__HVDC[t,b]-ahvdc[t,i] | |
end | |
catch e println("error ",e,",i=",i) end | |
try b=get_number(get_to(get_arc(get_component(TwoTerminalHVDCLine, sys, i)))) | |
for t=1:NT |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 153 to 155 in 823f960
bus_ActivePowerVariable__HVDC[t,b]=bus_ActivePowerVariable__HVDC[t,b]+ahvdc[t,i] | |
end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 157 to 158 in 823f960
end | |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 160 to 162 in 823f960
try b=get_number(get_bus(get_component(ThermalStandard, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__ThermalStandard[t,b]=bus_ActivePowerVariable__ThermalStandard[t,b]+ac[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 165 to 167 in 823f960
try b=get_number(get_bus(get_component(RenewableDispatch, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__RenewableDispatch[t,b]=bus_ActivePowerVariable__RenewableDispatch[t,b]+ac1[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 170 to 172 in 823f960
try b=get_number(get_bus(get_component(HydroDispatch, sys, i))) | |
for t=1:NT bus_ActivePowerVariable__HydroDispatch[t,b]=bus_ActivePowerVariable__HydroDispatch[t,b]+ac2[t,i] end | |
catch e println("error ",e,",i=",i) end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 176 to 183 in 823f960
for b in PSY.get_components(PSY.Bus,sys) | |
bn=get_number(b); area=get_name(get_area(b)); | |
if line=="" gsf=0 else gsf=ptdf[line,bn] end | |
push!(bus_df,(t,bn,area, bus_ActivePowerVariable__ThermalStandard[t,bn], | |
bus_ActivePowerVariable__RenewableDispatch[t,bn],bus_ActivePowerVariable__HydroDispatch[t,bn], | |
bus_ActivePowerTimeSeriesParameter__PowerLoad[t,bn],bus_ActivePowerVariable__HVDC[t,bn], | |
bus_ActivePowerBalance__ACBus[t,bn], bus_StateEstimationInjections__ACBus[t,bn], gsf, | |
bus_ActivePowerBalance__ACBus[t,bn]*gsf,bus_StateEstimationInjections__ACBus[t,bn]*gsf)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 187 to 188 in 823f960
bus_df[!,"buscheck"]=bus_df[!,"ActivePowerBalance__ACBus"]-bus_df[!,"ThermalStandard"]/100-bus_df[!,"Renewable"]/100-bus_df[!,"Hydro"]/100-bus_df[!,"PowerLoad"]/100 | |
println("bus check ActivePowerBalance__ACBus<>ThermalStandard/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 190 to 191 in 823f960
return(bus_df) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
subsys=unique(values(area_region_dict)) |
[JuliaFormatter] reported by reviewdog 🐶
println(b); |
[JuliaFormatter] reported by reviewdog 🐶
add_component_to_subsystem!(sys, v, b) |
[JuliaFormatter] reported by reviewdog 🐶
region=area_region_dict[get_name(b)] |
[JuliaFormatter] reported by reviewdog 🐶
region=area_region_dict[get_name(get_area(get_bus(b)))] |
[JuliaFormatter] reported by reviewdog 🐶
region=area_region_dict[get_name(get_area(b))] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 218 to 221 in 823f960
if length(selected_line)>0 | |
for b in selected_line | |
l=PSY.get_component(ACBranch, sys,b) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 224 to 231 in 823f960
add_component_to_subsystem!(sys, v, l) | |
end | |
end | |
end | |
if length(monitoredline_subsys) >0 | |
for (k,s) in monitoredline_subsys | |
l=PSY.get_component(ACBranch, sys,k) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 234 to 236 in 823f960
add_component_to_subsystem!(sys, v, l) | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 240 to 242 in 823f960
tbus=get_to(get_arc(dc)); fbus=get_from(get_arc(dc)) | |
tregion=area_region_dict[get_name(get_area(tbus))] | |
fregion=area_region_dict[get_name(get_area(fbus))] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 244 to 245 in 823f960
add_component_to_subsystem!(sys, tregion, dc) | |
[JuliaFormatter] reported by reviewdog 🐶
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 269 to 271 in 823f960
selected_line=["CA-1", "CB-1", "AB1"] | |
ln="A28" | |
limit=1.0 #2.0 |
[JuliaFormatter] reported by reviewdog 🐶
standardload=0 |
[JuliaFormatter] reported by reviewdog 🐶
name="1_2", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "2"), |
[JuliaFormatter] reported by reviewdog 🐶
name="1_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "1"), to_area=get_component(Area, sys, "3"), |
[JuliaFormatter] reported by reviewdog 🐶
name="2_3", available=true, active_power_flow=0.0, from_area=get_component(Area, sys, "2"), to_area=get_component(Area, sys, "3"), |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 317 to 338 in 823f960
area_dict=Dict("1" => "1", "2" => "2", "3" =>"3") | |
CF="NS3-0" | |
NS=3 | |
netmodels=["AreaPTDFPowerModel","AreaPTDFPowerModel","AreaPTDFPowerModel"] | |
copperplates=[1,0,0] | |
NTS=[24,24,1] | |
area_region_dicts=[Dict(), | |
Dict(), | |
Dict()] | |
CF="NS3-1" | |
NS=3 | |
netmodels=["AreaPTDFPowerModel","SplitAreaPTDFPowerModel","SplitAreaPTDFPowerModel"] | |
copperplates=[1,0,0] | |
NTS=[24,24,1] | |
area_region_dicts=[Dict(), | |
Dict("1" => "a", "2" => "b", "3" =>"c"), | |
Dict("1" => "a", "2" => "b", "3" =>"c")] | |
monitoredline_subsys=[Dict(),Dict(ln => ["a"]),Dict(ln => ["a"])] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 370 to 372 in 823f960
syss=[sys] | |
templates=[] | |
ptdf = VirtualPTDF(sys; tol = 1e-4, max_cache_size = 10000) |
[JuliaFormatter] reported by reviewdog 🐶
set_rating!(l,limit) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 377 to 379 in 823f960
monitoredlined_line=[ln] | |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 386 to 389 in 823f960
NT=NTS[i] | |
if i>1 | |
sys2=deepcopy(sys) | |
push!(syss,sys2) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 393 to 395 in 823f960
area_region_dict=area_region_dicts[i] | |
if netmodels[i]=="SplitAreaPTDFPowerModel" | |
subsys=unique(values(area_region_dict)) |
[JuliaFormatter] reported by reviewdog 🐶
println("add sys",i," subsystem,",v) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 400 to 403 in 823f960
template = | |
MultiProblemTemplate(NetworkModel(SplitAreaPTDFPowerModel; use_slacks=true,PTDF_matrix = ptdf,), subsys) | |
else | |
template = ProblemTemplate(NetworkModel(AreaPTDFPowerModel; use_slacks = true, PTDF_matrix = ptdf,)) |
[JuliaFormatter] reported by reviewdog 🐶
push!(templates,template) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 408 to 409 in 823f960
if standardload==1 | |
PSI.set_device_model!(template, StandardLoad , StaticPowerLoad) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 415 to 420 in 823f960
PSI.set_device_model!(template, DeviceModel(HydroDispatch, HPS.HydroDispatchReservoirBudget, | |
time_series_names = Dict{Any, String}( | |
PSI.ActivePowerTimeSeriesParameter => "max_active_power", | |
HPS.EnergyBudgetTimeSeriesParameter => "hydro_budget",) | |
) | |
) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 422 to 425 in 823f960
set_device_model!(template, DeviceModel(MonitoredLine, StaticBranchUnbounded, use_slacks = true)) | |
if NT>1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 432 to 435 in 823f960
end | |
if copperplates[i]==0 | |
set_device_model!(template, DeviceModel(MonitoredLine, StaticBranch, use_slacks = true)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 437 to 439 in 823f960
set_device_model!(template, | |
DeviceModel(Line, StaticBranchUnbounded; attributes=Dict("filter_function" => x -> get_name(x) in selected_line),)) |
[JuliaFormatter] reported by reviewdog 🐶
subsys=unique(values(area_region_dict)) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 443 to 445 in 823f960
if length(subsys)>1 | |
#buildsubsystem1(sys2, area_region_dict, union(selected_line,monitoredlined_line)) | |
buildsubsystem1(sys2, area_region_dict, selected_line,monitoredline_subsys[i]) |
[JuliaFormatter] reported by reviewdog 🐶
dm=[] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 453 to 474 in 823f960
if netmodels[i]=="SplitAreaPTDFPowerModel" | |
push!(dm, DecisionModel(MultiRegionProblem, templates[i], syss[i], name="UC"*string(i),optimizer=optimizer, | |
store_variable_names=true,initialize_model=false,optimizer_solve_log_print=false, | |
direct_mode_optimizer=true,check_numerical_bounds=false, | |
calculate_conflict=true,rebuild_model=false,system_to_file = true)) | |
else | |
push!(dm, DecisionModel(templates[i],syss[i], name="UC"*string(i), optimizer=optimizer, | |
store_variable_names=true,initialize_model=false,optimizer_solve_log_print=false, | |
direct_mode_optimizer=true,check_numerical_bounds=false, | |
calculate_conflict=true,rebuild_model=false, system_to_file = true)) | |
end | |
end | |
if NS==2 | |
models = PSI.SimulationModels(decision_models=[dm[1],dm[2]]) | |
else | |
models = PSI.SimulationModels(decision_models=[dm[1],dm[2],dm[3]]) | |
end | |
uc_simulation_ffs=[] | |
feedforwards_dict=Dict() | |
for i in 1:NS-1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 476 to 477 in 823f960
#feed forward area interchange | |
FVFF_area_interchange = FixValueFeedforward(;component_type=AreaInterchange,source=FlowActivePowerVariable,affected_values=[FlowActivePowerVariable],) |
[JuliaFormatter] reported by reviewdog 🐶
if NTS[i+1]==1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 485 to 486 in 823f960
component_type=ThermalStandard, source=OnVariable, affected_values=[ActivePowerVariable],) | |
push!(uc_simulation_ff, SCFF) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 490 to 491 in 823f960
push!(uc_simulation_ffs,uc_simulation_ff) | |
feedforwards_dict["UC"*string(i+1)]=uc_simulation_ff |
[JuliaFormatter] reported by reviewdog 🐶
results = SimulationResults(sim,ignore_status = true) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 519 to 522 in 823f960
results_uc=[]; uc_areainterchange=[];uc_monitoredline=[]; | |
bus_df_uc=[];area_df=[];areaflow_df=[] | |
tm=Array(1:NTS[1]) | |
af=DataFrames.DataFrame(;tm) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 525 to 536 in 823f960
push!(results_uc,get_decision_problem_results(results, "UC"*string(i))) | |
push!(uc_areainterchange,read_realized_variable(results_uc[i], "FlowActivePowerVariable__AreaInterchange")) | |
push!(uc_monitoredline,read_realized_variable(results_uc[i], "FlowActivePowerVariable__MonitoredLine")) | |
if netmodels[i]=="SplitAreaPTDFPowerModel" | |
push!(bus_df_uc,read_bus_df(results_uc[i], ln,1,standardload)) | |
else | |
push!(bus_df_uc,read_bus_df(results_uc[i], ln,0,standardload)) | |
end | |
bus_df_uc[i][!,"buscheck"]=bus_df_uc[i][!,"ActivePowerBalance__ACBus"]-bus_df_uc[i][!,"HVDC"]/100-bus_df_uc[i][!,"ThermalStandard"]/100-bus_df_uc[i][!,"Renewable"]/100-bus_df_uc[i][!,"Hydro"]/100-bus_df_uc[i][!,"PowerLoad"]/100 | |
println("UC0 bus check ActivePowerBalance__ACBus<>Gen/100-PowerLoad/100 ,",filter([:t,:buscheck] => (t,buscheck)-> (t>=1) && (abs(buscheck)>0.000001), bus_df_uc[i])) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 540 to 549 in 823f960
###### area MW check ######### | |
#area level net Gen, load and ActivePowerBalance__ACBus_sum check | |
push!(area_df,combine(groupby(bus_df_uc[i], [:t, :area]), [:ThermalStandard, :Renewable, :Hydro, :PowerLoad, :ActivePowerBalance__ACBus, :StateEstimationInjections__ACBus] .=> sum)) | |
area_df[i][!,"areacheck"]=area_df[i][!,"ActivePowerBalance__ACBus_sum"]-area_df[i][!,"ThermalStandard_sum"]/100-area_df[i][!,"Renewable_sum"]/100-area_df[i][!,"Hydro_sum"]/100-area_df[i][!,"PowerLoad_sum"]/100 | |
println("i,area_df check,",sum(area_df[i][!,"areacheck"])) #should be close to 0 | |
area_df[i][!,"TotalGen"]=area_df[i][!,"ThermalStandard_sum"]+area_df[i][!,"Renewable_sum"]+area_df[i][!,"Hydro_sum"] | |
area_df[i][!,"NetInterchange"]=area_df[i][!,"TotalGen"]+area_df[i][!,"PowerLoad_sum"] | |
area_df[i][!,"InterchangeCheck"]=area_df[i][!,"NetInterchange"]-100*area_df[i][!,"ActivePowerBalance__ACBus_sum"] | |
println(area_df[i][:,["t","area","ActivePowerBalance__ACBus_sum","NetInterchange","InterchangeCheck"]]) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 551 to 553 in 823f960
####### area flow check ######### | |
#area flow contribution by area and interval | |
push!(areaflow_df, combine(groupby(bus_df_uc[i], [:t, :area]), [:flowcontribution, :loopflowcontribution] .=> sum)) |
[JuliaFormatter] reported by reviewdog 🐶
if length(area_region_dicts[i])==0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 558 to 567 in 823f960
area_region_dict=area_dict | |
else | |
area_region_dict=area_region_dicts[i] | |
end | |
subsys=unique(values(area_region_dict)) | |
calculated_flow_subsys=Dict() | |
calculated_loopflow_subsys=Dict() | |
NT=NTS[1] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 571 to 573 in 823f960
af[!,"uc"*string(i)*"_flow_subsys_"*s]=zeros(NT) | |
af[!,"uc"*string(i)*"_loopflow_subsys_"*s]=zeros(NT) | |
end |
[JuliaFormatter] reported by reviewdog 🐶
if netmodels[i]!="SplitAreaPTDFPowerModel" |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 577 to 579 in 823f960
s=area_region_dict[r] | |
name="uc"*string(i)*"_flow_subsys_"*s | |
af[!,name]=af[!,name]+filter([:t,:area]=>(t,area)->(area==r),areaflow_df[i])[!,:flowcontribution_sum] |
[JuliaFormatter] reported by reviewdog 🐶
af[!,"uc"*string(i)*"_flow"]= zeros(NT) #calculated_flow_uc0 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 592 to 593 in 823f960
af[!,"uc"*string(i)*"_flow"]=af[!,"uc"*string(i)*"_flow"]+af[!,"uc"*string(i)*"_flow_subsys_"*s]#calculated_flow_uc0_subsys[k] | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 602 to 604 in 823f960
s=area_region_dict[r] | |
name="uc"*string(i)*"_flow_subsys_"*s | |
af[!,name]=af[!,name]+filter([:t,:area]=>(t,area)->(area==r),areaflow_df[i])[!,:flowcontribution_sum] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 606 to 607 in 823f960
name="uc"*string(i)*"_loopflow_subsys_"*s | |
af[!,name]=af[!,name]+filter([:t,:area]=>(t,area)->(area==r),areaflow_df[i])[!,:loopflowcontribution_sum] |
[JuliaFormatter] reported by reviewdog 🐶
calculated_flow_uc2=Dict() |
[JuliaFormatter] reported by reviewdog 🐶
af[!,"uc"*string(i)*"_seflow"]=zeros(NT) |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 616 to 617 in 823f960
af[!,"uc"*string(i)*"_flow_"*s]=zeros(NT) | |
af[!,"uc"*string(i)*"_seflow"]=af[!,"uc"*string(i)*"_seflow"]+af[!,"uc"*string(i)*"_flow_subsys_"*s]#calculated_flow_subsys[s] |
[JuliaFormatter] reported by reviewdog 🐶
if s==s1 |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 621 to 622 in 823f960
name="uc"*string(i)*"_flow_"*s | |
af[!,name]=af[!,name]+af[!,"uc"*string(i)*"_flow_subsys_"*s1]#calculated_flow_subsys[s1] |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 625 to 628 in 823f960
name="uc"*string(i)*"_flow_"*s | |
af[!,name]=af[!,name]+af[!,"uc"*string(i)*"_loopflow_subsys_"*s1]#calculated_loopflow_subsys[s1] | |
end | |
end |
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 631 to 632 in 823f960
end | |
[JuliaFormatter] reported by reviewdog 🐶
CSV.write("af_"*CF*".csv",af) |
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
[JuliaFormatter] reported by reviewdog 🐶
PowerSimulationsDecomposition.jl/Multi-Stage/final_run_simulations_3stage.jl
Lines 697 to 698 in 823f960
=# |
Thanks for opening a PR to PowerSimulationsDecomposition.jl, please take note of the following when making a PR:
Check the contributor guidelines