-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.m
1240 lines (936 loc) · 46.9 KB
/
main.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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
clc
clear all
close all
%% Goal of the script
% This scripts reproduces the Figures from the article [1]:
% If you use this code, please cite this article:
% [1] Ildar Daminov, Anton Prokhorov, Raphael Caire, Marie-Cécile
% Alvarez-Herault, “Energy limit of oil-immersed transformers: A concept
% and its application in different climate conditions” in IET Generation,
% Transmission & Distribution, 2020, https://doi.org/10.1049/gtd2.12036
% Other articles on this topic are available:
% https://www.researchgate.net/profile/Ildar-Daminov-2
% Note that the figures generated in this script and those given in the
% article may differ a little bit as latter had been additionally redrawn
% for a publication.
% Each section (Plotting the Figure X) is independent from each other. So
% you may launch the entire script (using the button "Run") to get all
% figures at one moment or you may launch a special section (using the
% button "Run Section" at the top)to get a specific figure
% Execution time of entire script ≈ 30 min
tic
%% Plotting the Figure 1
% Figure name: Transformer, limiting an energy transfer between two zones .
% Figure 1 in the article [1] was ploted without using MATLAB
%% Plotting the Figure 2
% Figure name: Maximization of the energy generation using flexibilities by
% RES operators
% Figure 2 in the article [1] was ploted without using MATLAB
%% Plotting the Figure 3
% Figure name: Criteria of thermal ratings for DER interconnection in
% different countries
% Figure 3 in the article [1] was ploted without using MATLAB
%% Plotting the Figure 4
% Figure name: Case study for investigating the highest energy transfer
% through transformers
% Figure 4 in the article [1] was ploted without using MATLAB
%% Plotting the Figure 5
% Figure name: Transformer loadings equal to HST and TOT limits as a
% function of ambient temperatrure.
clc;clear all % clear a command window and a workspace
% Load the daily profile of ambient temperature
load('initial_data.mat','AMB')
% load('initial_data.mat','TIM')
% load('Tamb_february_1_2019.mat')
% Transforming the vector in minutes(1440x1) to a vector in hours (24x1).
% This is neccsary to reduce the size of optimization problem later;
if length(AMB)==1440 % if the length of vector is 1440
t=60; % 60 min per hour
% number of hours
nhours=fix(length(AMB)/t);
% reconstruct a daily vector in minutes
tt=(1:nhours)*t;
tt=tt';
% intermediate variable: ambient temperature per hour
AMB_hour=zeros(nhours,1);
for i=1:nhours % for each hour
% Set the mean ambient temperature
AMB_hour(i)=mean(AMB(((i-1)*t+1):i*t));
end
% Change a variable name
AMB=AMB_hour;
end % if length(AMB)==1440
% we'll also create a few variables for time
nHours = numel(AMB);
Time = (1:nHours)';
%--------------------------------------------------------------------------
% Create the optimization problem
Optim_problem=optimproblem('ObjectiveSense','maximize');
% Create a variable: Energy_limit in an hour for transformer
Energy_limit = optimvar('Energy_limit',nHours,'LowerBound',0,'UpperBound',1.5);
% Energy_limit has the lowest value of 0 and the maximal value of 1.5 pu
%--------------------------------------------------------------------------
% Define the objective function
Energy_transfer = sum(Energy_limit);
% Note that sum(Energy_limit) provides the approximate energy transfer.
% For better modelling, the energy transfer should be calculated as the
% integral of Energy_limit (not a sum of 24 values).
% set objective
Optim_problem.Objective = Energy_transfer;
% Show the objective function
showexpr(Energy_transfer)
%--------------------------------------------------------------------------
% ONAN power transformer
%--------------------------------------------------------------------------
% Set the constraints for ONAN power transformer in optimization problem
% "Optim_problem"
% Connect the function ONAN.m with constrained variables HST_max,
% TOT_max,AEQ
[HST_max,TOT_max,AEQ,~,~]=fcn2optimexpr(@ONAN,Energy_limit,AMB);
Optim_problem.Constraints.ageing=AEQ<=1; % ageing, pu
Optim_problem.Constraints.hst=HST_max<=120; % hot spot temperature, °C
Optim_problem.Constraints.tot=TOT_max<=105; % top-oil temperature, °C
%--------------------------------------------------------------------------
% Assuming the first guess as it was done in our simulations
Energy_limit_approx=[1.18506326493039;1.19545602469364;1.20235915543539;...
1.20407987179434;1.20838166269174;1.21010192640830;1.19804866192401;...
1.15710755064801;1.11896064125447;1.10007550940374;1.09735849634747;...
1.09735849634747;1.09645270170919;1.09373531779434;1.10818781817272;...
1.10277961232673;1.11985764546147;1.16062527323930;1.16491810895177;...
1.16500571784387;1.18072267414797;1.18679950124335;1.19113496264304;...
1.19804866192401];
x0.Energy_limit=Energy_limit_approx';
% Choosing the SQP as the algorithm for finding the optimal solution
options.Algorithm='sqp';
% options for the optimization algorithm, here we set the max time it can run for
% call the optimization solver to find the best solution
options.MaxIterations=100;
% Solving the optimization problem with initial guess x0
[sol,~,~,~] = solve(Optim_problem,x0,'Options',options);
% Results saving in one variable
Power_limit=sol.Energy_limit;
%--------------------------------------------------------------------------
% ONAF power transformer
%--------------------------------------------------------------------------
% Set the constraints for ONAF transformer in optimization problem
% "Optim_problem"
% Connect the function ONAN.m with constrained variables HST_max,
% TOT_max,AEQ
[HST_max,TOT_max,AEQ,~,~]=fcn2optimexpr(@ONAF,Energy_limit,AMB);
Optim_problem.Constraints.ageing=AEQ<=1; % ageing, pu
Optim_problem.Constraints.hst=HST_max<=120; % hot spot temperature, °C
Optim_problem.Constraints.tot=TOT_max<=105; % top-oil temperature, °C
%--------------------------------------------------------------------------
% Assuming the first guess as it was done in our simulations
Energy_limit_approx=[1.18506326493039;1.19545602469364;1.20235915543539;...
1.20407987179434;1.20838166269174;1.21010192640830;1.19804866192401;...
1.15710755064801;1.11896064125447;1.10007550940374;1.09735849634747;...
1.09735849634747;1.09645270170919;1.09373531779434;1.10818781817272;...
1.10277961232673;1.11985764546147;1.16062527323930;1.16491810895177;...
1.16500571784387;1.18072267414797;1.18679950124335;1.19113496264304;...
1.19804866192401];
x0.Energy_limit=Energy_limit_approx';
% Choosing the SQP as the algorithm for finding the optimal solution
options.Algorithm='sqp';
% options for the optimization algorithm, here we set the max time it can run for
% call the optimization solver to find the best solution
options.MaxIterations=100;
% Solving the optimization problem with initial guess x0
[sol,~,~,~] = solve(Optim_problem,x0,'Options',options);
% Results saving in one variable
Power_limit(:,end+1)=sol.Energy_limit;
%--------------------------------------------------------------------------
% OF power transformer
%--------------------------------------------------------------------------
% Set the constraints for OF transformer in optimization problem
% "Optim_problem"
% Connect the function OF.m with constrained variables HST_max,TOT_max,AEQ
[HST_max,TOT_max,AEQ,~,~]=fcn2optimexpr(@OF,Energy_limit,AMB);
Optim_problem.Constraints.ageing=AEQ<=1; % ageing, pu
Optim_problem.Constraints.hst=HST_max<=120; % hot spot temperature, °C
Optim_problem.Constraints.tot=TOT_max<=105; % top-oil temperature, °C
%--------------------------------------------------------------------------
% Assuming the first guess as it was done in our simulations
Energy_limit_approx=[1.18506326493039;1.19545602469364;1.20235915543539;...
1.20407987179434;1.20838166269174;1.21010192640830;1.19804866192401;...
1.15710755064801;1.11896064125447;1.10007550940374;1.09735849634747;...
1.09735849634747;1.09645270170919;1.09373531779434;1.10818781817272;...
1.10277961232673;1.11985764546147;1.16062527323930;1.16491810895177;...
1.16500571784387;1.18072267414797;1.18679950124335;1.19113496264304;...
1.19804866192401];
x0.Energy_limit=Energy_limit_approx';
% Choosing the SQP as the algorithm for finding the optimal solution
options.Algorithm='sqp';
% options for the optimization algorithm, here we set the max time it can run for
% call the optimization solver to find the best solution
options.MaxIterations=100;
% Solving the optimization problem with initial guess x0
[sol,~,~,~] = solve(Optim_problem,x0,'Options',options);
% Results saving in one variable
Power_limit(:,end+1)=sol.Energy_limit;
%--------------------------------------------------------------------------
% OD power transformer
%--------------------------------------------------------------------------
% Set the constraints for OD transformer in optimization problem
% "Optim_problem"
% Connect the function OD.m with constrained variables HST_max,
% TOT_max,AEQ
[HST_max,TOT_max,AEQ,~,~]=fcn2optimexpr(@OD,Energy_limit,AMB);
Optim_problem.Constraints.ageing=AEQ<=1; % ageing, pu
Optim_problem.Constraints.hst=HST_max<=120; % hot spot temperature, °C
Optim_problem.Constraints.tot=TOT_max<=105; % top-oil temperature, °C
%--------------------------------------------------------------------------
% Assuming the first guess as it was done in our simulations
Energy_limit_approx=[1.18506326493039;1.19545602469364;1.20235915543539;...
1.20407987179434;1.20838166269174;1.21010192640830;1.19804866192401;...
1.15710755064801;1.11896064125447;1.10007550940374;1.09735849634747;...
1.09735849634747;1.09645270170919;1.09373531779434;1.10818781817272;...
1.10277961232673;1.11985764546147;1.16062527323930;1.16491810895177;...
1.16500571784387;1.18072267414797;1.18679950124335;1.19113496264304;...
1.19804866192401];
x0.Energy_limit=Energy_limit_approx';
% Choosing the SQP as the algorithm for finding the optimal solution
options.Algorithm='sqp';
% options for the optimization algorithm, here we set the max time it can run for
% call the optimization solver to find the best solution
options.MaxIterations=100;
% Solving the optimization problem with initial guess x0
[sol,~,~,~] = solve(Optim_problem,x0,'Options',options);
% Results saving in one variable
Power_limit(:,end+1)=sol.Energy_limit;
%--------------------------------------------------------------------------
% ONAN distribution transformer
%--------------------------------------------------------------------------
% Set the constraints for ONAN distribution transformer in optimization
% problem "Optim_problem"
% Connect the function distribution_transformer.m with constrained
% variables HST_max, TOT_max,AEQ
[HST_max,TOT_max,AEQ,~,~]=fcn2optimexpr(@distribution_transformer,Energy_limit,AMB);
Optim_problem.Constraints.ageing=AEQ<=1; % ageing, pu
Optim_problem.Constraints.hst=HST_max<=120; % hot spot temperature,°C
Optim_problem.Constraints.tot=TOT_max<=105; % top-oil temperature,°C
%--------------------------------------------------------------------------
% Assuming the first guess as it was done in our simulations
Energy_limit_approx=[1.18506326493039;1.19545602469364;1.20235915543539;...
1.20407987179434;1.20838166269174;1.21010192640830;1.19804866192401;...
1.15710755064801;1.11896064125447;1.10007550940374;1.09735849634747;...
1.09735849634747;1.09645270170919;1.09373531779434;1.10818781817272;...
1.10277961232673;1.11985764546147;1.16062527323930;1.16491810895177;...
1.16500571784387;1.18072267414797;1.18679950124335;1.19113496264304;...
1.19804866192401];
% Energy_limit_approx=[1.18506326493037;1.19545602469363;1.19977708674424;...
% 1.20235915543537;1.20666094633278;1.20838166269176;1.19977708674430;...
% 1.16938616244847;1.13678728434752;1.11716663284052;1.10908918581378;...
% 1.10458234760882;1.10097687704482;1.09735849634756;1.10999055345481;...
% 1.10368097996778;1.11985764546152;1.15534723785361;1.15886786344255;...
% 1.16150136216023;1.17636558643679;1.18245891046095;1.18766761939983;...
% 1.19459181228351];
x0.Energy_limit=Energy_limit_approx;
% % Choosing the SQP as the algorithm for finding the optimal solution
options.Algorithm='sqp';
%
% % options for the optimization algorithm, here we set the max time it can run for
% % call the optimization solver to find the best solution
options.MaxIterations=100;
% Possible options (not used so far)
% options=optimset('disp','iter','Algorithm','interior-point',...
% 'TolFun',1e-20,'TolX',1e-20,'MaxIter',1000,'MaxFunEvals',100000);
% Solving the optimization problem with initial guess x0
[sol,~,exitflag,output] = solve(Optim_problem,x0,'Options',options);
% Results saving in one variable
Power_limit(:,end+1)=sol.Energy_limit;
% Converting the Power_limit from 1-hour to 1-min format
t=60; % number of minutes in one hour
[n_hours,ncolumn]=size(Power_limit);
% Create an intermediate variable
PUL_minute=zeros(n_hours*t,ncolumn);
for j=1:ncolumn % for each column (cooling system) in Power_limit
for i=1:n_hours % for each hour
% Convert to 1 minute format
PUL_minute(((i-1)*t+1):i*t,j)=Power_limit(i,j);
end % end of "for i=1:n_hours"
end % end of "for j=1:ncolumn"
% Change the variable back to "Power_limit" (1440x5)
Power_limit=PUL_minute;
AEQ=[]; % delete the variable content
% Caclulate HST and TOT for each Power_limit
[~,~,AEQ(:,1),HST(:,1),TOT(:,1)]=ONAN(Power_limit(:,1),AMB);
[~,~,AEQ(:,2),HST(:,2),TOT(:,2)]=ONAF(Power_limit(:,2),AMB);
[~,~,AEQ(:,3),HST(:,3),TOT(:,3)]=OF(Power_limit(:,3),AMB);
[~,~,AEQ(:,4),HST(:,4),TOT(:,4)]=OD(Power_limit(:,4),AMB);
[~,~,AEQ(:,5),HST(:,5),TOT(:,5)]=distribution_transformer(Power_limit(:,5),AMB);
% Create the datetime
t1 = datetime(2019,2,1,0,0,0);
t2 = datetime(2019,2,1,23,59,0);
time=[t1:minutes(1):t2]';
% Create figure
figure('InvertHardcopy','off','Color',[1 1 1]);
% Create axes
axes1 = axes('Position',...
[0.0973439767779389 0.109186154129887 0.799799426934097 0.872817869415808]);
hold(axes1,'on');
colororder([0 0.447 0.741]);
% Activate the left side of the axes
yyaxis(axes1,'left');
% Create multiple lines using matrix input to plot
plot1 = plot(time,[HST,TOT],'LineWidth',1);
set(plot1(1),'DisplayName','HST ONAN','Color',[0 0 1]);
set(plot1(2),'DisplayName','HST ONAF','LineStyle','--','Color',[0 0 1]);
set(plot1(3),'DisplayName','HST OF','LineStyle',':','Color',[0 0 1]);
set(plot1(4),'DisplayName','HST OD','LineStyle','-.','Color',[0 0 1]);
set(plot1(5),'DisplayName','HST Distribution',...
'MarkerIndices',[1 61 121 181 241 301 361 421 481 541 601 661 721 781 841 901 961 1021 1081 1141 1201 1261 1321 1381],...
'Marker','o',...
'Color',[0 0 1]);
set(plot1(6),'DisplayName','TOT ONAN','LineStyle','-','Color',[0 0 1],'Marker','none');
set(plot1(7),'DisplayName','TOT ONAF','LineStyle','--','Color',[0 0 1],'Marker','none');
set(plot1(8),'DisplayName','TOT OF','LineStyle',':');
set(plot1(9),'DisplayName','TOT OD','LineStyle','-.');
set(plot1(10),'DisplayName','TOT Distribution',...
'MarkerIndices',[1 61 121 181 241 301 361 421 481 541 601 661 721 781 841 901 961 1021 1081 1141 1201 1261 1321 1381],...
'Marker','o');
% Create datatip
datatip(plot1(10),'DataIndex',319);
% Create ylabel
ylabel('Temperature,℃');
% Uncomment the following line to preserve the Y-limits of the axes
% ylim(axes1,[30 110]);
% Set the remaining axes properties
set(axes1,'YColor',[0 0.447 0.741],'YDir','normal','YMinorTick','off');
% Activate the right side of the axes
yyaxis(axes1,'right');
% Create multiple lines using matrix input to plot
plot2 = plot(time,Power_limit,'LineWidth',1,'Color',[0.85 0.325 0.098]);
set(plot2(1),'DisplayName','Loading ONAN');
set(plot2(2),'DisplayName','Loading ONAF','LineStyle','--');
set(plot2(3),'DisplayName','Loading OF','LineStyle',':');
set(plot2(4),'DisplayName','Loading OD','LineStyle','-.');
set(plot2(5),'DisplayName','Loading Distribution',...
'MarkerIndices',[1 61 121 181 241 301 361 421 481 541 601 661 721 781 841 901 961 1021 1081 1141 1201 1261 1321 1381],...
'Marker','o');
% Create ylabel
ylabel('Transformer loading,pu','FontSize',15.4);
% Uncomment the following line to preserve the Y-limits of the axes
% ylim(axes1,[0.8 1.3]);
% Set the remaining axes properties
set(axes1,'YColor',[0.85 0.325 0.098],'YMinorTick','off');
% Uncomment the following line to preserve the Z-limits of the axes
% zlim(axes1,[-1 0]);
box(axes1,'on');
hold(axes1,'off');
% Set the remaining axes properties
set(axes1,'FontSize',14,'LineStyleOrderIndex',5);
% Create legend
legend1 = legend(axes1,'show');
set(legend1,...
'Position',[0.133064113804359 0.166065490504195 0.727703412449338 0.200515067101577],...
'NumColumns',3,...
'EdgeColor',[1 1 1]);
disp('-------------------------------------Attention to figure 5!-----------------------------')
disp('The Loading for distribution transformer is a bit different as in the article IET GTD [1]')
disp(' This code enables a better energy transfer for 1.2%. So we decided to keep it')
disp(' Anyway, this difference does not change the article conclusions')
disp('-------------------------------------Attention to figure 5!-----------------------------')
%% Plotting the Figure 6
% Figure 6 name: Heating of winding conductors
% Figure 6 in the article [1] was ploted without using MATLAB
%% Plotting the Figure 7
% Figure name: Transformer loadings equal to HST and TOT limits as a
% function of ambient temperatrure.
clc;clear all % clear a command window and a workspace
% Load the daily profile of ambient temperature at Tomsk
load('Tamb_february_1_2019.mat')
% Transforming the vector in minutes(1440x1) to a vector in hours (24x1).
% This is neccsary to reduce the size of optimization problem later;
if length(AMB)==1440 % if the length of vector is 1440
t=60; % 60 min per hour
% number of hours
nhours=fix(length(AMB)/t);
% reconstruct a daily vector in minutes
tt=(1:nhours)*t;
tt=tt';
% intermediate variable: ambient temperature per hour
AMB_hour=zeros(nhours,1);
for i=1:nhours % for each hour
% Set the mean ambient temperature
AMB_hour(i)=mean(AMB(((i-1)*t+1):i*t));
end
% Change a variable name
AMB=AMB_hour;
end % if length(AMB)==1440
% we'll also create a few variables for time
nHours = numel(AMB);
Time = (1:nHours)';
%--------------------------------------------------------------------------
% Create the optimization problem
Optim_problem=optimproblem('ObjectiveSense','maximize');
% Create a variable: Energy_limit in an hour for transformer
Energy_limit = optimvar('Energy_limit',nHours,'LowerBound',0,'UpperBound',1.5);
% Energy_limit has the lowest value of 0 and the maximal value of 1.5 pu
%--------------------------------------------------------------------------
% Define the objective function
Energy_transfer = sum(Energy_limit);
% Note that sum(Energy_limit) provides the approximate energy transfer.
% For better modelling, the energy transfer should be calculated as the
% integral of Energy_limit (not a sum of 24 values).
% set objective
Optim_problem.Objective = Energy_transfer;
% Show the objective function
showexpr(Energy_transfer)
%--------------------------------------------------------------------------
% ONAN power transformer
%--------------------------------------------------------------------------
% Set the constraints for ONAN power transformer in optimization problem
% "Optim_problem"
% Connect the function ONAN.m with constrained variables HST_max,
% TOT_max,AEQ
[HST_max,TOT_max,AEQ,~,~]=fcn2optimexpr(@ONAN,Energy_limit,AMB);
Optim_problem.Constraints.ageing=AEQ<=1; % ageing, pu
Optim_problem.Constraints.hst=HST_max<=120; % hot spot temperature, °C
Optim_problem.Constraints.tot=TOT_max<=105; % top-oil temperature, °C
%--------------------------------------------------------------------------
% Assuming the first guess as it was done in our simulations
Energy_limit_approx=[1.18506326493039;1.19545602469364;1.20235915543539;...
1.20407987179434;1.20838166269174;1.21010192640830;1.19804866192401;...
1.15710755064801;1.11896064125447;1.10007550940374;1.09735849634747;...
1.09735849634747;1.09645270170919;1.09373531779434;1.10818781817272;...
1.10277961232673;1.11985764546147;1.16062527323930;1.16491810895177;...
1.16500571784387;1.18072267414797;1.18679950124335;1.19113496264304;...
1.19804866192401];
x0.Energy_limit=Energy_limit_approx';
% Choosing the SQP as the algorithm for finding the optimal solution
options.Algorithm='sqp';
% options for the optimization algorithm, here we set the max time it can run for
% call the optimization solver to find the best solution
options.MaxIterations=100;
% Solving the optimization problem with initial guess x0
[sol,~,~,outputs] = solve(Optim_problem,x0,'Options',options);
% Results saving in one variable
Power_limit=sol.Energy_limit;
% Converting the Power_limit from 1-hour to 1-min format
t=60; % number of minutes in one hour
[n_hours,ncolumn]=size(Power_limit);
% Create an intermediate variable
PUL_minute=zeros(n_hours*t,ncolumn);
for j=1:ncolumn % for each column (cooling system) in Power_limit
for i=1:n_hours % for each hour
% Convert to 1 minute format
PUL_minute(((i-1)*t+1):i*t,j)=Power_limit(i,j);
end % end of "for i=1:n_hours"
end % end of "for j=1:ncolumn"
% Change the variable back to "Power_limit" (1440x5)
Power_limit=PUL_minute;
AEQ=[]; % delete the variable content
% Caclulate HST and TOT for ONAN power transformer
[~,~,AEQ,HST,TOT]=ONAN(Power_limit,AMB);
% Create a vector of design hot spot temperature 98 °C
HST_ref=linspace(98,98,1440)';
% Create the datetime
t1 = datetime(2019,2,1,0,0,0);
t2 = datetime(2019,2,1,23,59,0);
time=[t1:minutes(1):t2]';
% Create figure
figure('InvertHardcopy','off','Color',[1 1 1]);
% Create axes
axes1 = axes('Position',...
[0.113790504898267 0.11 0.791209495101733 0.847617411225658]);
hold(axes1,'on');
colororder([0 0.447 0.741]);
% Activate the left side of the axes
yyaxis(axes1,'left');
% Create multiple lines using matrix input to plot
plot1 = plot(time,[HST,TOT,HST_ref],'LineWidth',2,'Color',[0 0 1]);
set(plot1(1),'DisplayName','ONAN HST');
set(plot1(2),'DisplayName','ONAN TOT','Color',[0 0.447 0.741]);
set(plot1(3),'DisplayName','Reference HST');
% Create ylabel
ylabel('Hot spot temperature,℃');
% Preserve the Y-limits of the axes
ylim(axes1,[40 110]);
% Set the remaining axes properties
set(axes1,'YColor',[0 0.447 0.741],'YMinorTick','off');
% Activate the right side of the axes
yyaxis(axes1,'right');
% Create plot
plot(time,Power_limit,'DisplayName','ONAN energy limit','LineWidth',2,'Color',[0.85 0.325 0.098]);
% Create ylabel
ylabel('Transformer Loading, pu');
% Preserve the Y-limits of the axes
ylim(axes1,[1.46 1.505]);
% Set the remaining axes properties
set(axes1,'YColor',[0.85 0.325 0.098]);
% Preserve the Z-limits of the axes
zlim(axes1,[-1 0]);
box(axes1,'on');
hold(axes1,'off');
% Set the remaining axes properties
set(axes1,'FontSize',14);
% Create legend
legend1 = legend(axes1,'show');
set(legend1,...
'Position',[0.12157680156816 0.483747245435955 0.230778557667694 0.161657857352603],...
'EdgeColor',[1 1 1]);
% Create axes
axes2 = axes('Position',...
[0.113693467336683 0.108820160366552 0.791457286432158 0.849942726231386]);
hold(axes2,'on');
% Create plot
[AMB]=Convert2minute(AMB); % convert AMB from 24x1 to 1440x1
plot(time,AMB,'DisplayName','Ambient temperature','LineWidth',2,...
'LineStyle',':',...
'Color',[0 0 0]);
% Create ylabel
ylabel('Ambient temperature,℃');
hold(axes2,'off');
% Set the remaining axes properties
set(axes2,'Color','none','FontSize',14,'XTick',[],'YTick',...
[-44 -42 -40 -38 -36 -34 -32 -30],'YTickLabel',...
{'-44 ','-42 ','-40 ','-38 ','-36 ','-34 ','-32 ','-30 '});
% Create legend
legend2 = legend(axes2,'show');
set(legend2,...
'Position',[0.119144229862446 0.443665362464914 0.252603500074096 0.0450862281056797],...
'EdgeColor',[1 1 1]);
disp('-------------------------------------Attention to figure 7!---------------------------------')
disp(' The Loading for ONAN power transformer is a bit different than in the article IET GTD [1]')
disp('This (enhanced) code enables a better energy transfer for 0.3%. So we decided to keep it')
disp(' Anyway, this small difference does not change the article conclusions')
disp('-------------------------------------Attentionto figure 7!----------------------------------')
%% Plotting the Figure 8
% Figure 8 name: Hourly ambient temperature in Tomsk and Grenoble from
% 1985 to 2019
clc;clear all % clear a command window and a workspace
% Load T - historical ambient temperature (among others)
% from Jan 1, 1985 to 29 March 2019 (MeteoBlue data):
load('T_history_Tomsk.mat') % in Tomsk, Russia
% Extracting the ambient temperature
AMB_Tomsk=T(:,6);
% Round ambient temperature
AMB_Tomsk=round(AMB_Tomsk);
% Load T - historical ambient temperature (among others)
% from Jan 1, 1985 to 29 March 2019 (MeteoBlue data):
load('T_history_Grenoble.mat') % in Grenoble, France
% Extracting the ambient temperature
AMB_Grenoble=T(:,6);
% Round ambient temperature
AMB_Grenoble=round(AMB_Grenoble);
% Create figure
figure('InvertHardcopy','off','Color',[1 1 1]);
% Prepare a time vector
t1 = datetime(1985,1,1,0,0,0,'Format','HH:SS');
t2 = datetime(2019,3,29,23,59,0,'Format','HH:SS');
time = t1:hours(1):t2;
% plotting the ambient temperature in Tomsk and Grenoble
plot(time,[AMB_Tomsk,AMB_Grenoble],'LineWidth',2)
ylabel('Ambient temperature,°C')
legend('Tomsk','Grenoble')
%% Plotting the Figure 9
% Figure 9 name: Ambient temperature duration curves in Tomsk (Russia) and
% Grenoble (France)
clc;clear all % clear a command window and a workspace
% create a figure
figure1 = figure('InvertHardcopy','off','WindowState','maximized',...
'Color',[1 1 1]);
% Create axes
axes1 = axes('Parent',figure1);
% Create ylabel
ylabel('T_a_m_b,℃');
% Create xlabel
xlabel('T_a_m_b duration, %');
hold on
% Constructing the figure
for city=1:2 % for Tomsk and Grenoble
if city==1 % Tomsk
% Load T - historical ambient temperature (among others)
% from Jan 1, 1985 to 29 March 2019 (MeteoBlue data):
load('T_history_Tomsk.mat') % in Tomsk, Russia
AMB=T(:,6);
else % city==2 %Grenoble
% Load T - historical ambient temperature (among others)
% from Jan 1, 1985 to 29 March 2019 (MeteoBlue data):
load('T_history_Grenoble.mat') % in Grenoble, France
AMB=T(:,6);
end % end of if city==1
% Preparing the x axis (duration in %)
Duration_x_axis=[1:length(AMB)]*100/length(AMB);
Duration_x_axis=Duration_x_axis';
% Caclulating the duration curves
Duration_curve=sort(AMB,'descend');
% Ploting the Figure
plot(Duration_x_axis,Duration_curve,'LineWidth',2)
end % for city=1:2
% Set the remaining axes properties
set(axes1,'XGrid','on','YGrid','on');
% Show the legend
legend('Tomsk','Grenoble')
%% Plotting the Figure 10
% Figure 10 name: Loading duration for all transformers in Tomsk and
% Grenoble
clc;clear all % clear a command window and a workspace
% Create a vector of cooling systems
all_cooling=["ONAN" "ONAF" "OF" "OD" "distribution_transformer"];
% ------------------------------Calculations-------------------------------
for city=1:2 % for Tomsk and Grenoble
if city==1 % Tomsk
% Load T - historical ambient temperature (among others)
% from Jan 1, 1985 to 29 March 2019 (MeteoBlue data):
load('T_history_Tomsk.mat') % in Tomsk, Russia
AMB=T(:,6);
else % city==2 %Grenoble
% Load T - historical ambient temperature (among others)
% from Jan 1, 1985 to 29 March 2019 (MeteoBlue data):
load('T_history_Grenoble.mat') % in Grenoble, France
AMB=T(:,6);
end % end of if city==1
% Find indexes for beginning and ending of day
index_0h=find(T(1:end,4)==0);
index_23h=find(T(1:end,4)==23);
for ii=1:length(all_cooling)
for i=1:length(index_0h)
% Daily Tamb
AMB=T(index_0h(i):index_23h(i),6);
[AMB]=Convert2minute(AMB);
% Energy limit Pay attention to temperature limitations inside of function
[Energy_limit,HST_limit,AEQ_limit,TOT_limit,Energy]=approximated_energy_limit(round(AMB),all_cooling(ii));
if city==1 % Tomsk
% Save result
Result_Tomsk.Energy_limit{i,ii}=Energy_limit';
Result_Tomsk.HST_limit{i,ii}=HST_limit';
Result_Tomsk.TOT_limit{i,ii}=TOT_limit';
Result_Tomsk.AEQ_limit(i,ii)=AEQ_limit;
Result_Tomsk.Energy(i,ii)=Energy;
else % city==2 %Grenoble
Result_Grenoble.Energy_limit{i,ii}=Energy_limit';
Result_Grenoble.HST_limit{i,ii}=HST_limit';
Result_Grenoble.TOT_limit{i,ii}=TOT_limit';
Result_Grenoble.AEQ_limit(i,ii)=AEQ_limit;
Result_Grenoble.Energy(i,ii)=Energy;
end % end of "if city==1 % Tomsk"
end % end of "for i=1:length(index_0h)"
end % end of "for ii=1:length(all_cooling)"
end % end of "for city=1:2 % for Tomsk and Grenoble"
% ------------------------------Data analysis------------------------------
% create a figure
figure1 = figure('InvertHardcopy','off','WindowState','maximized',...
'Color',[1 1 1]);
% Create axes
axes1 = axes('Parent',figure1);
% Create ylabel
ylabel('Loading of energy limit,pu');
% Create xlabel
xlabel('Loading duration, %');
hold on
for city=1:2 % for Tomsk and Grenoble
for n=1:length(all_cooling)
for day=1:12506 % for all (12 506) days
% Convert from cell to double format
if city==1 % Tomsk
Energy_limit_interm=Result_Tomsk.Energy_limit{day,n};
else % city==2 Grenoble
Energy_limit_interm=Result_Grenoble.Energy_limit{day,n};
end % end of "city==1 % Tomsk"
% Convert from 1440-min format to 24-hour format. Otherwise
if length(Energy_limit_interm)==1440 % if the length of vector is 1440
t=60; % 60 min per hour
% number of hours
nhours=fix(length(Energy_limit_interm)/t);
% reconstruct a daily vector in minutes
tt=(1:nhours)*t;
tt=tt';
% intermediate variable: ambient temperature per hour
Energy_limit_interm_hour=zeros(nhours,1);
for iii=1:nhours % for each hour
% Set the mean ambient temperature
Energy_limit_interm_hour(iii)=mean(Energy_limit_interm(((iii-1)*t+1):iii*t));
end
% Change a variable name
Energy_limit_interm=Energy_limit_interm_hour;
end % if length(Energy_limit_interm)==1440
% Save in double format (24 hours)
Result.Energy_limit(24*day-23:24*day,n)=Energy_limit_interm;
end % end of "for day=1:12506 % for all (12 506) days"
% Duration Energy_limit
Duration_Energy_limit=sort(Result.Energy_limit(:,n),'descend');
Duration_Energy_limit_x_axis=[1:length(Duration_Energy_limit)]*100/length(Duration_Energy_limit);
Duration_Energy_limit_x_axis=Duration_Energy_limit_x_axis';
if city==1 % Tomsk
% plot figure
plot1(n)=plot(Duration_Energy_limit_x_axis,Duration_Energy_limit,'LineWidth',2)
else % city==2 Grenoble
% plot figure
plot2(n)=plot(Duration_Energy_limit_x_axis,Duration_Energy_limit,'LineWidth',2)
end %end of "if city==1 % Tomsk"
end % for n=1:length(all_cooling)
if city==1 % Tomsk
set(plot1(1),'DisplayName','Loading ONAN','LineStyle','-','Color',[0 0.4470 0.7410]);
set(plot1(2),'DisplayName','Loading ONAF','LineStyle','-','Color',[0 0.4470 0.7410]);
set(plot1(3),'DisplayName','Loading OF','LineStyle',':','Color',[0 0.4470 0.7410]);
set(plot1(4),'DisplayName','Loading OD','LineStyle','-.','Color',[0 0.4470 0.7410]);
set(plot1(5),'DisplayName','Loading Distribution','LineStyle','--','Color',[0 0.4470 0.7410]);
else % city==2 Grenoble
set(plot2(1),'DisplayName','Loading ONAN','LineStyle','-','Color',[0.8500 0.3250 0.0980]);
set(plot2(2),'DisplayName','Loading ONAF','LineStyle','-','Color',[0.8500 0.3250 0.0980]);
set(plot2(3),'DisplayName','Loading OF','LineStyle',':','Color',[0.8500 0.3250 0.0980]);
set(plot2(4),'DisplayName','Loading OD','LineStyle','-.','Color',[0.8500 0.3250 0.0980]);
set(plot2(5),'DisplayName','Loading Distribution','LineStyle','--','Color',[0.8500 0.3250 0.0980]);
end %end of "if city==1 % Tomsk"
end % for city=1:2 % for Tomsk and Grenoble
set(axes1,'XGrid','on','YGrid','on');
% Create legend
legend2 = legend(axes1,'show');
%% Plotting the Figure 11
% Figure 11 name: Maximal, minimal and mean loadings of energy limits in
% each month
clc;clear all % clear a command window and a workspace
% Create a vector of cooling systems
all_cooling=["ONAN" "ONAF" "OF" "OD" "distribution_transformer"];
% ------------------------------Calculations-------------------------------
for city=1:2 % for Tomsk and Grenoble
if city==1 % Tomsk
% Load T - historical ambient temperature (among others)
% from Jan 1, 1985 to 29 March 2019 (MeteoBlue data):
load('T_history_Tomsk.mat') % in Tomsk, Russia
AMB=T(:,6);
else % city==2 %Grenoble
% Load T - historical ambient temperature (among others)
% from Jan 1, 1985 to 29 March 2019 (MeteoBlue data):
load('T_history_Grenoble.mat') % in Grenoble, France
AMB=T(:,6);
end % end of if city==1
% Find indexes for beginning and ending of day
index_0h=find(T(1:end,4)==0);
index_23h=find(T(1:end,4)==23);
for ii=1:length(all_cooling)
for i=1:length(index_0h)
% Daily Tamb
AMB=T(index_0h(i):index_23h(i),6);
[AMB]=Convert2minute(AMB);
% Energy limit Pay attention to temperature limitations inside of function
[Energy_limit,HST_limit,AEQ_limit,TOT_limit,Energy]=approximated_energy_limit(round(AMB),all_cooling(ii));
if city==1 % Tomsk
% Save result
Result_Tomsk.Energy_limit{i,ii}=Energy_limit';
Result_Tomsk.HST_limit{i,ii}=HST_limit';
Result_Tomsk.TOT_limit{i,ii}=TOT_limit';
Result_Tomsk.AEQ_limit(i,ii)=AEQ_limit;
Result_Tomsk.Energy(i,ii)=Energy;
else % city==2 %Grenoble
Result_Grenoble.Energy_limit{i,ii}=Energy_limit';
Result_Grenoble.HST_limit{i,ii}=HST_limit';
Result_Grenoble.TOT_limit{i,ii}=TOT_limit';
Result_Grenoble.AEQ_limit(i,ii)=AEQ_limit;
Result_Grenoble.Energy(i,ii)=Energy;
end % end of "if city==1 % Tomsk"
end % end of "for i=1:length(index_0h)"
end % end of "for ii=1:length(all_cooling)"
end % end of "for city=1:2 % for Tomsk and Grenoble"
for city=1:2 % for Tomsk and Grenoble
for cooling=1:length(all_cooling)
for day=1:12506 % for all (12 506) days
% Convert from cell to double format
if city==1 % Tomsk
Energy_limit_interm=Result_Tomsk.Energy_limit{day,cooling};
else % city==2 Grenoble
Energy_limit_interm=Result_Grenoble.Energy_limit{day,cooling};
end % end of "city==1 % Tomsk"
% Convert from 1440-min format to 24-hour format. Otherwise
if length(Energy_limit_interm)==1440 % if the length of vector is 1440
t=60; % 60 min per hour
% number of hours
nhours=fix(length(Energy_limit_interm)/t);
% reconstruct a daily vector in minutes
tt=(1:nhours)*t;
tt=tt';
% intermediate variable: ambient temperature per hour
Energy_limit_interm_hour=zeros(nhours,1);
for iii=1:nhours % for each hour
% Set the mean ambient temperature
Energy_limit_interm_hour(iii)=mean(Energy_limit_interm(((iii-1)*t+1):iii*t));
end
% Change a variable name
Energy_limit_interm=Energy_limit_interm_hour;
end % if length(Energy_limit_interm)==1440
% Save in double format (24 hours)
Result.Energy_limit(24*day-23:24*day,cooling)=Energy_limit_interm;
end % end of "for day=1:12506 % for all (12 506) days"
% Max,min,mean power values of energy limits:
for month=1:12 % for each month
index_month=find((T(:,2)==month)); % find index of monthes
mean_month(month,cooling)=mean(Result.Energy_limit(index_month,cooling));
max_month(month,cooling)=max(Result.Energy_limit(index_month,cooling));