📄 fm_uwpflow.m
字号:
[Vmax,Vmin] = fm_vlim(1.2,0.8);
for i = 1:Bus.n
busnum = Bus.int(Bus.con(i,1));
idxSu = findbus(Supply,busnum);
idxDe = findbus(Demand,busnum);
idxSw = findbus(SW,busnum);
idxPv = findbus(PV,busnum);
idxPq = findbus(PQ,busnum);
% Generator Active Power direction (DPg)
if Supply.n
DPg = getpg(Supply,idxSu);
else % if no Supply, use base case powers
DPg = getpg(SW,idxSw)+getpg(PV,idxPv);
end
% Load Power Directions (Pnl,Qnl)
if Demand.n
[Pnl,Qnl] = pqdir(Demand,idxDe);
else % if no Demand, use base case powers
[Pnl,Qnl] = pqdir(PQ,idxPq);
end
count = fprintf(fid,linef,Bus.con(i,1),0,DPg,Pnl,Qnl,0, ...
0,Vmax(i),Vmin(i));
end
count = fclose(fid);
end
% run UWPFLOW
cd(Path.data)
[status,result] = system(uwcom);
cd(Path.local)
if status == 2
fm_disp(['Something wrong in the execution of UWPFLOW. Check ' ...
'options.'])
return
else
fm_disp('UWPFLOW computations completed.')
end
% load and plot nose curves
if findstr(uwcom,[UWPFLOW.file,'.cpf'])
fid = fopen([Path.data,UWPFLOW.file,'.cpf'],'rt');
output = [];
if fid == -1
fm_disp(['Could not open file ''',UWPFLOW.file, ...
'.cpf'' for loading nose curves.'])
else
row = fgetl(fid);
if row == -1
fm_disp(['* * * The file ',UWPFLOW.file, ...
'.cpf is empty * * *'])
return
end
pattern = [char(92),'w*',char(92),'.*', ...
char(92),'w*',char(92),'.*'];
b = [1,findstr(row,'V')];
c = b+3;
names = cell(length(b)-1,1);
for i = 2:length(b)
volts{i-1} = row([b(i):c(i)]);
end
while 1
row = fgetl(fid);
if row == -1, break, end
output = [output; str2num(row)];
end
count = fclose(fid);
end
% plot continuation curves
if ~clpsat.init
figure
plot(output(:,1),output(:,2:end))
legend(volts)
if Settings.hostver >= 7, legend(gca,'boxoff'), end
xlabel('Loading Factor')
ylabel('Voltages')
end
end
% read UWPFLOW output and import results in PSAT
if isempty(findstr(uwcom,[UWPFLOW.file,'.cf'])) | ...
~isempty(findstr(uwcom,[UWPFLOW.file,'.cpf']))
return
end
if ~clpsat.init
Settings.ok = 0;
uiwait(fm_choice('Do you want to load UWPFLOW solution to PSAT?'))
if ~Settings.ok
return
end
end
fm_disp('Read from IEEE Common Data Format...');
fm_disp(['Source data file "',UWPFLOW.file,'.cf"'])
fid = fopen([Path.data,UWPFLOW.file,'.cf']);
if fid == -1,
fm_disp(['Can''t open file ',Path.data,UWPFLOW.file,'.cf'],2),
return
end
% skip the first two rows ...
foo = fgetl(fid);
foo = fgetl(fid); % headings ...
% get the number of buses
row = fgetl(fid);
idx = findstr(row,' ITEMS');
busnum = str2num(row(17:idx-1));
bus = zeros(busnum,7);
for i = 1:busnum
row = fgetl(fid);
if row == -1
fm_disp(['Bus Data abnormally terminated. ', ...
'Conversion Process Interrupted'],2);
fclose(fid);
return
end
bus(i,1) = str2num(row(1:4)); % bus #
bus(i,2) = str2num(row(28:33)); % voltage
bus(i,3) = str2num(row(34:40)); % angle
bus(i,4) = str2num(row(60:67)); % generation P
bus(i,5) = str2num(row(68:75)); % generation Q
bus(i,6) = str2num(row(41:49)); % load P
bus(i,7) = str2num(row(50:59)); % load Q
end
fclose(fid);
bus(:,4:7) = bus(:,4:7)/Settings.mva;
bus(:,3) = bus(:,3)*pi/180;
DAE.V = bus(:,2);
DAE.a = bus(:,3);
Bus.Pg = bus(:,4);
Bus.Qg = bus(:,5);
Bus.Pl = bus(:,6);
Bus.Ql = bus(:,7);
case 'view'
file = popupstr(findobj(Fig.uwpflow,'Tag','PopupUWFile'));
if exist([Path.data,file]) == 2
fm_text(13,[Path.data,file])
else
uiwait(fm_choice(['File "',file,'" not found.',char(10), ...
'Check options and/or launch UWPFLOW.'],2))
end
case 'makecom'
fm_disp
fm_disp('UWPFLOW command line:')
file = File.data;
file = strrep(file,'(mdl)','_mdl');
file = strrep(file,'@ ','');
if isempty(file)
fm_disp('No file data found. A generic file name will be used.')
file = '<file_in>';
end
file_in = [file,'.cf'];
file_out = [UWPFLOW.file,'.pf'];
uwcom = ['uwpflow -I ',file_in,' ',file_out];
fields = fieldnames(UWPFLOW.opt);
Kopt = 1;
Output = 1;
vopt = 0;
for i = 1:length(fields)
opt = getfield(UWPFLOW.opt,fields{i});
if opt.status
uwcom = [uwcom,' ',opt.name];
if ~isempty(opt.ext)
uwcom = [uwcom,UWPFLOW.file,opt.ext];
elseif ~isempty(opt.num)
uwcom = [uwcom,num2str(opt.num)];
end
switch fields{i}
case 'B'
if ~UWPFLOW.opt.v.status
UWPFLOW.opt.v.status = 1;
vopt = 1;
end
case {'c','C','H','v'}
if Kopt
uwcom = [uwcom,' -K',UWPFLOW.file,'.k'];
Kopt = 0;
end
case {'j','J'}
if Output
uwcom = [uwcom,UWPFLOW.file];
Output = 0;
end
end
end
end
if vopt
UWPFLOW.opt.v.status = 0;
end
if ~isempty(uwcom)
fm_disp(repmat('-',1,length(uwcom)))
fm_disp(uwcom)
fm_disp(repmat('-',1,length(uwcom)))
else
fm_disp('Something wrong in UWPFLOW options.')
fm_disp('No command line was generated.')
end
if Fig.uwpflow
hdl = findobj(Fig.uwpflow,'Tag','EditCom');
set(hdl,'String',uwcom)
end
if nargin == 1
UWPFLOW.command = uwcom;
end
if nargout
varargout{1} = uwcom;
end
case 'help' % [-h] option
if Settings.hostver < 6.1 | clpsat.init
!uwpflow -h
return
end
[status,result] = system('uwpflow -h');
retidx = findstr(result,char(10));
retidx = [0,retidx,length(result)+1];
text = cell(length(retidx)-1,1);
for i = 1:length(retidx)-1
text{i} = result([retidx(i)+1:retidx(i+1)-1]);
end
if History.Max < 500,
History.Max = 500;
if Fig.hist
set(findobj(Fig.hist,'Tag','Fmax1'),'Checked','off')
set(findobj(Fig.hist,'Tag','Fmax2'),'Checked','off')
set(findobj(Fig.hist,'Tag','Fmax3'),'Checked','off')
set(findobj(Fig.hist,'Tag','Fmax4'),'Checked','on')
end
end
fm_disp(text)
if Fig.hist, figure(Fig.hist), else, fm_hist, end
set(Hdl.hist, ...
'ListboxTop',length(History.text)-length(text)+1, ...
'Value',length(History.text)-length(text)+1)
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -