-
Notifications
You must be signed in to change notification settings - Fork 7
/
PFtestcase.m
84 lines (62 loc) · 2.17 KB
/
PFtestcase.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
function resultPF = PFtestcase(mpcreduced,timeStamp,savefig,savedata,addrenew)
%PFTESTCASE Run power flow at a specified timestamp and show results.
%
% Inputs:
% mpcreduced - struct, reduced MATPOWER case
% timeStamp - datetime, in "MM/dd/uuuu HH:mm:ss"
% savefig - boolean, default to be true
% savedata - boolean, default to be true
% addrenew - boolean, default to false
% Outputs:
% resultPF - struct, power flow results
% Created by Vivienne Liu, Cornell University
% Last modified on Sept. 24, 2021
%% Input parameters
% Read reduced MATPOWER case
if isempty(mpcreduced)
mpcfilename = fullfile('Result',string(year(timeStamp)),'mpcreduced',...
"mpcreduced_"+datestr(timeStamp,"yyyymmdd_hh")+".mat");
load(mpcfilename,"mpcreduced");
end
% Save figure or not (default to save)
if isempty(savefig)
savefig = true;
end
% Save OPF results or not (default to save)
if isempty(savedata)
savedata = true;
end
% Add additional renewable or not (default to not)
if isempty(addrenew)
addrenew = false;
end
% Create directory for store OPF results and plots
resultDir = fullfile('Result',string(year(timeStamp)),'PF');
createDir(resultDir);
figDir = fullfile('Result',string(year(timeStamp)),'Figure','PF');
createDir(figDir);
%% Read operation condition for NYS
[fuelMix,interFlow,flowLimit,~,~,~] = readOpCond(timeStamp);
define_constants;
%% Add additional renewables
if addrenew
fprintf("Start allocating additional renewables ...\n");
mpcreduced.bus = addRenewable(mpcreduced.bus,timeStamp);
fprintf("Finished allocating additional renewables in NY!\n");
end
%% Run reduced MATPOWER case
resultPF = rundcpf(mpcreduced);
fprintf("Finished solving power flow!\n");
if savedata
timeStampStr = datestr(timeStamp,"yyyymmdd_hh");
outfilename = fullfile(resultDir,"resultPF_"+timeStampStr+".mat");
save(outfilename,"resultPF");
fprintf("Saved power flow results!\n");
end
%% Create plots
type = "PF";
% Plot interface flow and error
plotFlow(timeStamp,resultPF,interFlow,flowLimit,type,savefig,figDir);
% Plot fuel mix and error
plotFuel(timeStamp,resultPF,fuelMix,interFlow,type,savefig,figDir);
end