-
Notifications
You must be signed in to change notification settings - Fork 52
/
test_services_constructor.jl
391 lines (357 loc) · 14.3 KB
/
test_services_constructor.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
@testset "Test Reserves from Thermal Dispatch" begin
template = get_thermal_dispatch_template_network(CopperPlatePowerModel)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve1"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve11"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveDown}, RangeReserve, "Reserve2"),
)
set_service_model!(
template,
ServiceModel(ReserveDemandCurve{ReserveUp}, StepwiseCostReserve, "ORDC1"),
)
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc"; add_reserves = true)
model = DecisionModel(template, c_sys5_uc)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 648, 0, 120, 216, 72, false)
reserve_variables = [
:ActivePowerReserveVariable__VariableReserve__ReserveUp__Reserve1
:ActivePowerReserveVariable__ReserveDemandCurve__ReserveUp__ORDC1
:ActivePowerReserveVariable__VariableReserve__ReserveDown__Reserve2
:ActivePowerReserveVariable__VariableReserve__ReserveUp__Reserve11
]
found_vars = 0
for (k, var_array) in IS.get_optimization_container(get_internal(model)).variables
if PSI.encode_key(k) in reserve_variables
for var in var_array
@test JuMP.has_lower_bound(var)
@test JuMP.lower_bound(var) == 0.0
end
found_vars += 1
end
end
@test found_vars == 4
end
@testset "Test Ramp Reserves from Thermal Dispatch" begin
template = get_thermal_dispatch_template_network(CopperPlatePowerModel)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RampReserve, "Reserve1"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RampReserve, "Reserve11"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveDown}, RampReserve, "Reserve2"),
)
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc"; add_reserves = true)
model = DecisionModel(template, c_sys5_uc)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 384, 0, 336, 192, 24, false)
reserve_variables = [
:ActivePowerReserveVariable__VariableReserve_ReserveDown_Reserve2,
:ActivePowerReserveVariable__VariableReserve_ReserveUp_Reserve1,
:ActivePowerReserveVariable__VariableReserve_ReserveUp_Reserve11,
]
for (k, var_array) in IS.get_optimization_container(get_internal(model)).variables
if PSI.encode_key(k) in reserve_variables
for var in var_array
@test JuMP.has_lower_bound(var)
@test JuMP.lower_bound(var) == 0.0
end
end
end
end
@testset "Test Reserves from Thermal Standard UC" begin
template = get_thermal_standard_uc_template()
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve1"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve11"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveDown}, RangeReserve, "Reserve2"),
)
set_service_model!(
template,
ServiceModel(ReserveDemandCurve{ReserveUp}, StepwiseCostReserve, "ORDC1"),
)
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc"; add_reserves = true)
model = DecisionModel(template, c_sys5_uc; optimizer = cbc_optimizer)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 1008, 0, 480, 216, 192, true)
end
@testset "Test Reserves from Thermal Standard UC with NonSpinningReserve" begin
template = get_thermal_standard_uc_template()
set_device_model!(
template,
DeviceModel(ThermalMultiStart, ThermalStandardUnitCommitment),
)
set_service_model!(
template,
ServiceModel(VariableReserveNonSpinning, NonSpinningReserve, "NonSpinningReserve"),
)
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc_non_spin"; add_reserves = true)
model = DecisionModel(template, c_sys5_uc; optimizer = HiGHS_optimizer)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 1032, 0, 888, 192, 288, true)
end
@testset "Test Upwards Reserves from Renewable Dispatch" begin
template = ProblemTemplate(CopperPlatePowerModel)
set_device_model!(template, PowerLoad, StaticPowerLoad)
set_device_model!(template, RenewableDispatch, RenewableFullDispatch)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve3"),
)
set_service_model!(
template,
ServiceModel(ReserveDemandCurve{ReserveUp}, StepwiseCostReserve, "ORDC1"),
)
c_sys5_re = PSB.build_system(PSITestSystems, "c_sys5_re"; add_reserves = true)
model = DecisionModel(template, c_sys5_re)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 360, 0, 72, 120, 72, false)
end
@testset "Test Reserves from Hydro" begin
template = ProblemTemplate(CopperPlatePowerModel)
set_device_model!(template, PowerLoad, StaticPowerLoad)
set_device_model!(template, HydroEnergyReservoir, HydroDispatchRunOfRiver)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve5"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveDown}, RangeReserve, "Reserve6"),
)
set_service_model!(
template,
ServiceModel(ReserveDemandCurve{ReserveUp}, StepwiseCostReserve, "ORDC1"),
)
c_sys5_hyd = PSB.build_system(PSITestSystems, "c_sys5_hyd"; add_reserves = true)
model = DecisionModel(template, c_sys5_hyd)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 240, 0, 48, 96, 72, false)
end
@testset "Test Reserves from with slack variables" begin
template = get_thermal_dispatch_template_network(
NetworkModel(CopperPlatePowerModel; use_slacks = true),
)
set_service_model!(
template,
ServiceModel(
VariableReserve{ReserveUp},
RangeReserve,
"Reserve1";
use_slacks = true,
),
)
set_service_model!(
template,
ServiceModel(
VariableReserve{ReserveUp},
RangeReserve,
"Reserve11";
use_slacks = true,
),
)
set_service_model!(
template,
ServiceModel(
VariableReserve{ReserveDown},
RangeReserve,
"Reserve2";
use_slacks = true,
),
)
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc"; add_reserves = true)
model = DecisionModel(template, c_sys5_uc;)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 504, 0, 120, 192, 24, false)
end
@testset "Test AGC" begin
c_sys5_reg = PSB.build_system(PSITestSystems, "c_sys5_reg")
@test_throws ArgumentError template_agc_reserve_deployment(; dummy_arg = 0.0)
template_agc = template_agc_reserve_deployment()
set_service_model!(template_agc, ServiceModel(PSY.AGC, PIDSmoothACE, "AGC_Area1"))
agc_problem = DecisionModel(AGCReserveDeployment, template_agc, c_sys5_reg)
@test build!(agc_problem; output_dir = mktempdir(; cleanup = true)) ==
PSI.BuildStatus.BUILT
# These values might change as the AGC model is refined
moi_tests(agc_problem, 696, 0, 480, 0, 384, false)
end
@testset "Test GroupReserve from Thermal Dispatch" begin
template = get_thermal_dispatch_template_network()
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve1"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve11"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveDown}, RangeReserve, "Reserve2"),
)
set_service_model!(
template,
ServiceModel(ReserveDemandCurve{ReserveUp}, StepwiseCostReserve, "ORDC1"),
)
set_service_model!(
template,
ServiceModel(StaticReserveGroup{ReserveDown}, GroupReserve, "init"),
)
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc"; add_reserves = true)
services = get_components(Service, c_sys5_uc)
contributing_services = Vector{Service}()
for service in services
if !(typeof(service) <: PSY.ReserveDemandCurve)
push!(contributing_services, service)
end
end
groupservice = StaticReserveGroup{ReserveDown}(;
name = "init",
available = true,
requirement = 0.0,
ext = Dict{String, Any}(),
)
add_service!(c_sys5_uc, groupservice, contributing_services)
model = DecisionModel(template, c_sys5_uc)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 648, 0, 120, 240, 72, false)
end
@testset "Test GroupReserve Errors" begin
template = get_thermal_dispatch_template_network()
set_service_model!(template, ServiceModel(VariableReserve{ReserveUp}, RangeReserve))
set_service_model!(template, ServiceModel(VariableReserve{ReserveDown}, RangeReserve))
set_service_model!(
template,
ServiceModel(ReserveDemandCurve{ReserveUp}, StepwiseCostReserve),
)
set_service_model!(
template,
ServiceModel(StaticReserveGroup{ReserveDown}, GroupReserve),
)
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc"; add_reserves = true)
services = get_components(Service, c_sys5_uc)
contributing_services = Vector{Service}()
for service in services
if !(typeof(service) <: PSY.ReserveDemandCurve)
push!(contributing_services, service)
end
end
groupservice = StaticReserveGroup{ReserveDown}(;
name = "init",
available = true,
requirement = 0.0,
ext = Dict{String, Any}(),
)
add_service!(c_sys5_uc, groupservice, contributing_services)
off_service = VariableReserve{ReserveUp}("Reserveoff", true, 0.6, 10)
push!(groupservice.contributing_services, off_service)
model = DecisionModel(template, c_sys5_uc)
@test build!(
model;
output_dir = mktempdir(; cleanup = true),
console_level = Logging.AboveMaxLevel,
) == BuildStatus.FAILED
end
@testset "Test StaticReserve" begin
template = get_thermal_dispatch_template_network()
set_service_model!(
template,
ServiceModel(StaticReserve{ReserveUp}, RangeReserve, "Reserve3"),
)
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc")
static_reserve = StaticReserve{ReserveUp}("Reserve3", true, 30, 100)
add_service!(c_sys5_uc, static_reserve, get_components(ThermalGen, c_sys5_uc))
model = DecisionModel(template, c_sys5_uc)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
@test typeof(model) <: DecisionModel{<:PSI.DecisionProblem}
end
@testset "Test Reserves with Feedforwards" begin
template = get_thermal_dispatch_template_network()
service_model = ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve1")
ff_lb = LowerBoundFeedforward(;
component_type = VariableReserve{ReserveUp},
source = ActivePowerReserveVariable,
affected_values = [ActivePowerReserveVariable],
meta = "Reserve1",
)
PSI.attach_feedforward!(service_model, ff_lb)
set_service_model!(template, service_model)
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc"; add_reserves = true)
model = DecisionModel(template, c_sys5_uc; optimizer = HiGHS_optimizer)
# set manually to test cases for simulation
IS.get_optimization_container(get_internal(model)).built_for_recurrent_solves = true
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 456, 0, 120, 264, 24, false)
end
@testset "Test Reserves with Participation factor limits" begin
c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc"; add_reserves = true)
for service in get_components(Reserve, c_sys5_uc)
set_max_participation_factor!(service, 0.8)
end
template = get_thermal_dispatch_template_network(CopperPlatePowerModel)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve1"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveUp}, RangeReserve, "Reserve11"),
)
set_service_model!(
template,
ServiceModel(VariableReserve{ReserveDown}, RangeReserve, "Reserve2"),
)
set_service_model!(
template,
ServiceModel(ReserveDemandCurve{ReserveUp}, StepwiseCostReserve, "ORDC1"),
)
model = DecisionModel(template, c_sys5_uc)
@test build!(model; output_dir = mktempdir(; cleanup = true)) == PSI.BuildStatus.BUILT
moi_tests(model, 648, 0, 384, 216, 72, false)
reserve_variables = [
:ActivePowerReserveVariable__VariableReserve__ReserveUp__Reserve1
:ActivePowerReserveVariable__ReserveDemandCurve__ReserveUp__ORDC1
:ActivePowerReserveVariable__VariableReserve__ReserveDown__Reserve2
:ActivePowerReserveVariable__VariableReserve__ReserveUp__Reserve11
]
found_vars = 0
for (k, var_array) in IS.get_optimization_container(get_internal(model)).variables
if PSI.encode_key(k) in reserve_variables
for var in var_array
@test JuMP.has_lower_bound(var)
@test JuMP.lower_bound(var) == 0.0
end
found_vars += 1
end
end
@test found_vars == 4
participation_constraints = [
:ParticipationFractionConstraint__VariableReserve__ReserveUp__Reserve11,
:ParticipationFractionConstraint__VariableReserve__ReserveDown__Reserve2,
]
found_constraints = 0
for (k, _) in IS.get_optimization_container(get_internal(model)).constraints
if PSI.encode_key(k) in participation_constraints
found_constraints += 1
end
end
@test found_constraints == 2
end