/
debug.jl
93 lines (66 loc) · 2.65 KB
/
debug.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# These problem formulations are used to debug Distribution datasets
# that do not converge using the standard formulations
"Solve OPF problem with slack power at every bus"
function solve_mc_opf_pbs(data::Union{Dict{String,<:Any},String}, model_type::Type, solver; kwargs...)
return solve_mc_model(data, model_type, solver, build_mc_opf_pbs; kwargs...)
end
"Solve PF problem with slack power at every bus"
function solve_mc_pf_pbs(data::Union{Dict{String,<:Any},String}, model_type::Type, solver; kwargs...)
return solve_mc_model(data, model_type, solver, build_mc_pf_pbs; kwargs...)
end
"OPF problem with slack power at every bus"
function build_mc_opf_pbs(pm::AbstractUnbalancedPowerModel)
variable_mc_bus_voltage(pm)
variable_mc_branch_power(pm)
variable_mc_switch_power(pm)
variable_mc_transformer_power(pm)
variable_mc_generator_power(pm)
variable_mc_slack_bus_power(pm)
constraint_mc_model_voltage(pm)
for i in ids(pm, :ref_buses)
constraint_mc_theta_ref(pm, i)
end
for i in ids(pm, :bus)
constraint_mc_power_balance_slack(pm, i)
end
for i in ids(pm, :branch)
constraint_mc_ohms_yt_from(pm, i)
constraint_mc_ohms_yt_to(pm, i)
constraint_mc_voltage_angle_difference(pm, i)
constraint_mc_thermal_limit_from(pm, i)
constraint_mc_thermal_limit_to(pm, i)
end
objective_mc_min_slack_bus_power(pm)
end
"PF problem with slack power at every bus"
function build_mc_pf_pbs(pm::AbstractUnbalancedPowerModel)
variable_mc_bus_voltage(pm; bounded=false)
variable_mc_branch_power(pm; bounded=false)
variable_mc_switch_power(pm; bounded=false)
variable_mc_transformer_power(pm; bounded=false)
variable_mc_generator_power(pm; bounded=false)
variable_mc_slack_bus_power(pm)
constraint_mc_model_voltage(pm)
for (i,bus) in ref(pm, :ref_buses)
constraint_mc_theta_ref(pm, i)
@assert bus["bus_type"] == 3
constraint_mc_voltage_magnitude_only(pm, i)
end
for (i,bus) in ref(pm, :bus)
constraint_mc_power_balance_slack(pm, i)
# PV Bus Constraints
if length(ref(pm, :bus_gens, i)) > 0 && !(i in ids(pm,:ref_buses))
# this assumes inactive generators are filtered out of bus_gens
@assert bus["bus_type"] == 2
constraint_mc_voltage_magnitude_only(pm, i)
for j in ref(pm, :bus_gens, i)
constraint_mc_gen_power_setpoint_real(pm, j)
end
end
end
for i in ids(pm, :branch)
constraint_mc_ohms_yt_from(pm, i)
constraint_mc_ohms_yt_to(pm, i)
end
objective_mc_min_slack_bus_power(pm)
end