-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmd-opf-ts-flat.jl
170 lines (124 loc) · 4.85 KB
/
gmd-opf-ts-flat.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using PowerModels, PowerModelsGMD, Ipopt, JuMP, JSON, Plots, Memento
#CSV, DataFrames
const _LOGGER = Memento.getlogger(@__MODULE__)
const PMs = PowerModels
include("thermal-variable.jl")
include("thermal-constraint.jl")
include("thermal-constraint-template.jl")
include("thermal-solution.jl")
include("thermal-objective.jl")
# -- F U N C T I O N S -- #
# FUNCTION: convinience function
function run_gic_opf_ts(file, model_constructor, solver; kwargs...)
return run_model(file, model_constructor, solver, post_gic_opf_ts; solution_builder = get_gmd_ts_solution, multinetwork=true, kwargs...)
end
# FUNCTION: problem formulation
function post_gic_opf_ts(pm::GenericPowerModel)
for (n, network) in nws(pm)
PMs.variable_voltage(pm, nw=n)
PMs.variable_generation(pm, nw=n)
PMs.variable_branch_flow(pm, nw=n)
PMs.variable_dcline_flow(pm, nw=n)
PowerModelsGMD.variable_dc_voltage(pm, nw=n)
PowerModelsGMD.variable_dc_current_mag(pm, nw=n)
PowerModelsGMD.variable_qloss(pm, nw=n)
PowerModelsGMD.variable_dc_line_flow(pm, nw=n)
btemp = true
variable_delta_oil_ss(pm, nw=n, bounded=btemp)
variable_delta_oil(pm, nw=n, bounded=btemp)
variable_delta_hotspot_ss(pm, nw=n, bounded=btemp)
variable_delta_hotspot(pm, nw=n, bounded=btemp)
variable_hotspot(pm, nw=n, bounded=btemp)
PMs.constraint_model_voltage(pm, nw=n)
for i in PMs.ids(pm, :ref_buses, nw=n)
PMs.constraint_theta_ref(pm, i, nw=n)
end
for i in PMs.ids(pm, :bus, nw=n)
PowerModelsGMD.constraint_kcl_gmd(pm, i, nw=n)
end
for i in PMs.ids(pm, :branch, nw=n)
PowerModelsGMD.constraint_dc_current_mag(pm, i, nw=n)
PowerModelsGMD.constraint_qloss_vnom(pm, i, nw=n)
PMs.constraint_ohms_yt_from(pm, i, nw=n)
PMs.constraint_ohms_yt_to(pm, i, nw=n)
PMs.constraint_voltage_angle_difference(pm, i, nw=n)
PMs.constraint_thermal_limit_from(pm, i, nw=n)
PMs.constraint_thermal_limit_to(pm, i, nw=n)
constraint_temperature_state_ss(pm, i, nw=n)
constraint_hotspot_temperature_state_ss(pm, i, nw=n)
constraint_hotspot_temperature_state(pm, i, nw=n)
constraint_absolute_hotspot_temperature_state(pm, i, nw=n)
end
### DC network constraints ###
for i in PMs.ids(pm, :gmd_bus)
PowerModelsGMD.constraint_dc_kcl_shunt(pm, i, nw=n)
end
for i in PMs.ids(pm, :gmd_branch)
PowerModelsGMD.constraint_dc_ohms(pm, i, nw=n)
end
for i in PMs.ids(pm, :dcline, nw=n)
PMs.constraint_dcline(pm, i, nw=n)
end
end
#for i in PMs.ids(pm, :branch, nw=1)
# constraint_avg_absolute_hotspot_temperature_state(pm, i)
#end
network_ids = sort(collect(nw_ids(pm)))
n_1 = network_ids[1]
for i in ids(pm, :branch, nw=n_1)
constraint_temperature_state(pm, i, nw=n_1)
end
for n_2 in network_ids[2:end]
for i in ids(pm, :branch, nw=n_2)
constraint_temperature_state(pm, i, n_1, n_2)
end
n_1 = n_2
end
objective_gmd_min_transformer_heating(pm)
# PowerModelsGMD.objective_gmd_min_fuel(pm)
end
println("")
# Load waveform data
# Not using for now
println("Load waveform data\n")
wf_path = "data/b4gic-gmd-wf.json"
h = open(wf_path)
wf_data = JSON.parse(h)
close(h)
# Load case data
println("Load case data\n")
path = joinpath(dirname(pathof(PowerModelsGMD)), "../test/data/epri21_ots.m")
raw_net = PMs.parse_file(path)
#raw_net["name"] = "B4GIC"
base_mva = raw_net["baseMVA"]
println("")
# Running model
solver = JuMP.with_optimizer(Ipopt.Optimizer, tol=1e-6, print_level=0)
#solver = JuMP.with_optimizer(CPLEX.Optimizer, tol=1e-6, print_level=0)
setting = Dict{String,Any}("output" => Dict{String,Any}("branch_flows" => true))
results = []
mod_net = deepcopy(raw_net)
mod_net["time_elapsed"] = 60
for (k,gb) in mod_net["gmd_branch"]
gb["br_v"] /= 10
end
# Create replicates (multiples) of the network
net = PMs.replicate(mod_net, n)
println("Running model: $(raw_net["name"]) \n")
#results = run_gic_opf_ts(net, PowerModelsGMD.ACPPowerModel, solver; setting=setting)
results = run_gic_opf_ts(net, PowerModelsGMD.SOCWRPowerModel, solver; setting=setting)
println("Done running model")
termination_status = results["termination_status"]
primal_status = results["primal_status"]
objective = results["objective"]
println("Termination status $termination_status")
println("Primal status $primal_status")
println("Objective $objective")
output = Dict()
output["case"] = net
output["result"] = results
outfile = string("data/", raw_net["name"], "_gmd_opf_ts.json")
println("\nSaving results to $outfile")
f = open(outfile,"w")
JSON.print(f,output)
close(f)