forked from Vivienne16/Baseline-powergrid-model-for-NY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOPFtestcase.m
93 lines (67 loc) · 2.48 KB
/
OPFtestcase.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
function resultOPF = OPFtestcase(mpcreduced,timeStamp,savefig,savedata,addrenew)
%OPFTESTCASE Run optimal 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:
% resultOPF - struct, optimal 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)),'OPF');
createDir(resultDir);
figDir = fullfile('Result',string(year(timeStamp)),'Figure','OPF');
createDir(figDir);
%% Read operation condition for NYS
[fuelMix,interFlow,flowLimit,~,~,zonalPrice] = readOpCond(timeStamp);
busInfo = importBusInfo(fullfile("Data","npcc.csv"));
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 OPF
mpopt = mpoption( 'opf.dc.solver','GUROBI','opf.flow_lim','P');
mpcreduced = toggle_iflims(mpcreduced, 'on');
resultOPF = rundcopf(mpcreduced,mpopt);
fprintf("Finished solving optimal power flow!\n");
if savedata
timeStampStr = datestr(timeStamp,"yyyymmdd_hh");
outfilename = fullfile(resultDir,"resultPF_"+timeStampStr+".mat");
save(outfilename,"resultOPF");
fprintf("Saved optimal power flow results!\n");
end
%% Create plots
type = "OPF";
% Plot interface flow data and error
plotFlow(timeStamp,resultOPF,interFlow,flowLimit,type,savefig,figDir);
% Plot fuel mix data and error
plotFuel(timeStamp,resultOPF,fuelMix,interFlow,type,savefig,figDir);
% Plot price data and error
plotPrice(timeStamp,resultOPF,zonalPrice,busInfo,type,savefig,figDir)
end