-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProblemOptions.m
360 lines (238 loc) · 8.68 KB
/
ProblemOptions.m
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
function [Opts, auxdata] = ProblemOptions(varargin)
% This function defines all the required options for the problem, including
% the time horizon, parameters assosiated with generator and storage,
% economic options, loads, etc.
%
%
% Saeed Azad, PhD
if nargin == 1
auxdata = varargin{1};
else
auxdata = [];
end
% Get appropriate indices for the problem
[gen_idx,str_idx] = Get_Indices(auxdata.General.PET);
if ~isempty(gen_idx)
auxdata.IDX.Generator = gen_idx;
end
if ~isempty(str_idx)
auxdata.IDX.Storage = str_idx;
end
% Set the time duration
auxdata.General.NumHours = 0; % 0 <= NumHours <= 24
auxdata.General.NumDays = 0; % 0 <= NumDays <= 365.25 (# days in a Julian day)
auxdata.General.NumYears = 30; %
% Set the time flag (only hourly works with existing price signals)
auxdata.General.TimeFlag = 'Hour';
% Plot flag
auxdata.General.PlotFlag = 1;
% Retrofit or new construction: If retrofit, the generators Mayer costs
% are excluded
auxdata.RetrofitFlag = 0;
% Set up the required parameters
[Gen_aux, Storage_aux] = Parameter_Setup;
% Generator options
Gen_aux = GeneratorOptions(auxdata.General.GeneratorFlag, Gen_aux,auxdata.General.TimeFlag);
% Storage options
if ~isempty(auxdata.General.StorageFlag)
Storage_aux = StorageOptions(auxdata.General.StorageFlag, Storage_aux,auxdata.General.TimeFlag);
end
% Primary, electricity, and tertiary price signals
PriceSignal = PriceFunctions(auxdata);
% Pass prices to the auxiliary data
auxdata.PriceFunctions = PriceSignal;
% Techno-economic options
Econ_aux = EconomicOptions(auxdata.General.GeneratorFlag, auxdata.General.StorageFlag);
% DTQP options
DTQP_Options = DTQPOptions(auxdata.General.GeneratorFlag,...
auxdata.General.StorageFlag ,auxdata.General.NumHours,...
auxdata.General.NumDays,auxdata.General.NumYears,...
auxdata.General.TimeFlag);
% Load options
Load_aux = Load_Functions(auxdata.General.GeneratorFlag, auxdata.General.StorageFlag);
% Color Options for ploting
Colors = PlotColors;
% Assemble all data and options
auxdata.Storage = Storage_aux;
auxdata.Generator = Gen_aux;
auxdata.Loads = Load_aux;
auxdata.Economics = Econ_aux;
auxdata.Colors = Colors;
Opts.DTQP = DTQP_Options;
% Wind speeds only for wind generator
if strcmpi(auxdata.General.GeneratorFlag{1,1}, 'Onshore_Wind')
[~, WP] = WindSpeedFunctions(auxdata);
auxdata.Generator.RenLim = WP;
end
% Discrete market demand constriant: sales can be made only at certain times
if isfield(auxdata.IDX,'Storage') && isfield(auxdata.IDX.Storage,'Tertiary')
F_fnc = DMD(auxdata);
auxdata.Storage.DMD = F_fnc;
end
% Define the demand-following constraints
auxdata.Demand_cons = 0;
if auxdata.Demand_cons
% Demand following starts every day at Demand_hours_min (3:00 pmn)
auxdata.Generator.Demand_hours_min = 16;
% Demand following ends every day at Demand_hours_max (7:00 pm)
auxdata.Generator.Demand_hours_max = 19;
% Demand level
auxdata.Generator.Demand_level = Gen_aux.x_Gmax-1;
% Construct the demand trajectory
F_demand_fnc = Demand_Following_traj(auxdata);
auxdata.Generator.F_demand_fnc = F_demand_fnc;
end
end
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
function opts = DTQPOptions(GeneratorFlag,StorageFlag,NumHours,...
NumDays,NumYears,TimeFlag)
% This function defines the required parameters for DTQP.
switch upper(TimeFlag)
case 'HOUR'
t_Length = NumYears*365*24 + NumDays*24 + NumHours;
case 'DAY'
t_Length = NumYears*365 + NumDays*24 + floor(NumHours/24);
end
if length(GeneratorFlag) == 1
% Number of plant optimization variables in generator
opts.subsys.Np_G = 0;
% Number of state variables in generator
opts.subsys.Nx_G = 1;
% Number of control variables in generator
opts.subsys.Nu_G = 1;
else
msg = 'So far, the code only works for a single generator.';
error(msg)
end
if length(StorageFlag) <= 3
% Number of plant optimization variables in storage system
opts.subsys.Np_S = 1*length(StorageFlag);
% Number of state variables in storage system
opts.subsys.Nx_S = 1*length(StorageFlag);
% Number of control variables in storage system
opts.subsys.Nu_S = 3*length(StorageFlag);
elseif length(StorageFlag) > 3
msg = 'So far, the code only works for only three storage devices.';
error(msg)
end
opts.method.form = 'linearprogram';
opts.solver.tolerance = 1e-6;
opts.solver.maxiters = 500;
opts.dt.defects = 'ZO'; % zero hold
opts.dt.quadrature = 'CEF'; % Composite Euler Forward
opts.dt.mesh = 'ED';
opts.dt.nt = t_Length + 1;
opts.general.displevel = 2;
opts.general.plotflag = 1;
opts.general.saveflag = 0;
opts.general.np = opts.subsys.Np_G+opts.subsys.Np_S;
opts.general.nu = opts.subsys.Nu_G+opts.subsys.Nu_S;
opts.general.ns = opts.subsys.Nx_G+opts.subsys.Nx_S;
opts.general.t0 = 0;
opts.general.tf = t_Length;
end
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
function Load_aux = Load_Functions(GeneratorFlag, StorageFlag)
% Pre-allocate all possible loads
% Primary Load (from carbon capture, district heating, etc.) defined as a
% function of the generator
LP_G = 0;
% Electrical Load (from carbon capture, district heating, auc=xiliary
% loads, etc.) defined as a function of the generator
LE = 0;
% Primary Load (from tertiary storage, such as HTSE operation) defined as a
% fucntion of the tertiary charging signal
LP_T = 0;
for i = 1:length(GeneratorFlag)
switch GeneratorFlag{1,1}
case 'CC221'
% 10% auxiliary loads
LE = LE+0.1;
case 'ONSHORE_WIND'
% 10% auxiliary loads
LE = LE+0.1;
case 'ADVANCED_NUCLEAR'
% 10% auxiliary loads
LE = LE+0.1;
end
end
if ~isempty(StorageFlag)
for i = 1:length(GeneratorFlag)
switch StorageFlag{1,1}
case 'THERMAL'
LP_G = 0.1;
% Additional 10% for carbon capture
LE = LE + 0.1;
case 'BESS'
% No additional electrical load
LE = LE;
case 'HYDROGEN_HTSE'
LP_T = 0.1;
% No additional electrical load
LE = LE;
end
end
end
% Add all loads
Load_aux.LP_G = LP_G;
Load_aux.LP_T = LP_T;
Load_aux.LE = LE;
end
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
function F_fnc = DMD(auxdata)
% Create upper bound for 30 years of hourly mesh
t_all = 0:30*365.25*24;
Fval = zeros(size(t_all));
% Sales occur every day at T_sell-1 to T_sell
T_sell = 9;
% number of days
num_days = 30*365.25;
for i = 0:num_days-1
t_idx = i*(24) + T_sell;
Fval(1,t_idx) = 1;
end
Fval = Fval.*auxdata.Storage.u3_Smax;
F_int = griddedInterpolant(t_all,Fval,'previous');
F_fnc = @(t)F_int(t);
end
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
function F_demand_fnc = Demand_Following_traj(auxdata)
% Create upper bound for 30 years of hourly mesh
t_all = 0:30*365.25*24;
% Initialize path constraint bounds
Limit_min = zeros(size(t_all));
% Sales occur every day at T_sell-1 to T_sell
T_min = auxdata.Generator.Demand_hours_min;
T_max = auxdata.Generator.Demand_hours_max;
% number of days
num_days = 30*365.25;
for i = 0:num_days-1
t_idx0 = i*(24) + T_min;
t_idxf = i*(24) + T_max;
t_idx = t_idx0:t_idxf;
Limit_min(1,t_idx) = 1;
end
Limit_min = auxdata.Generator.Demand_level*Limit_min;
Limit_min_int = griddedInterpolant(t_all,Limit_min,'previous');
Limit_min_fnc = @(t)Limit_min_int(t);
F_demand_fnc.Limit_min_fnc = Limit_min_fnc;
% Construct charging max path
max_charge = auxdata.Storage.u1_Smax*ones(size(t_all));
for i = 0:num_days-1
t_idx0 = i*(24) + T_min;
t_idxf = i*(24) + T_max;
t_idx = t_idx0:t_idxf;
max_charge(1,t_idx) = 0;
end
max_charge_int = griddedInterpolant(t_all,max_charge,'previous');
max_charge_fnc = @(t)max_charge_int(t);
F_demand_fnc.max_charge_fnc = max_charge_fnc;
end