📄 sim2psat.m
字号:
fm_disp(strcat('* * Warning: Block <',get_param(block(idx),'Name'), ...
'> does not belong to the PSAT Simulink Library.'))
Settings.ok = 0;
uiwait(fm_choice(['Some blocks do not seem to belong to the ', ...
'PSAT library, but could be old blocks. ', ...
'Do you want to fix them?']))
if Settings.ok
for iii = 1:length(idx)
blocktype = mask{idx(iii)};
if isempty(blocktype)
blocktype = get_param(block{idx(iii)},'BlockType');
end
switch blocktype
case {'Bus','Link','Goto','From'}
prop = 'Connection';
case {'Supply','Demand','Rmpg','Rrsv','Vltn','Rmpl','Ypdp'}
prop = 'OPF & CPF';
case {'Breaker','Fault'}
prop = 'Faults & Breakers';
case 'Busfreq'
prop = 'Measurements';
case {'Mn','Pl','Thload','Fl','Exload'}
prop = 'Loads';
case {'Syn','Mot'}
prop = 'Machines';
case {'Ltc','Tap'}
prop = 'ULTC';
case 'Phs'
prop = 'Phase Shifter';
case {'Tg','Exc','Cac','Cluster','Pss','Oxl'}
prop = 'Controls';
case {'Statcom','Upfc','Svc','Hvdc','Tcsc','Sssc'}
prop = 'FACTS';
case {'Dfig','Cswt','Ddsg'}
prop = 'Wind Turbines';
case {'Sofc','SSR','RLC','Mass'}
prop = 'Sparse Dynamic Component';
case {'SAE1','SAE2','SAE3'}
prop = 'SAE';
otherwise
prop = 'Power Flow';
end
set_param(block{idx(iii)}, ...
'Tag','PSATblock', ...
'Description',prop)
end
save_system(sys);
end
else
fm_disp(' ')
fm_disp('* * All blocks belong to the PSAT-Simulink Library.')
end
% check for old models
slackbus = find_system(sys,'MaskType','SW');
ports = get_param(slackbus,'Ports');
if iscell(ports)
check = sum(ports{1});
elseif isnumeric(ports)
check = sum(ports);
end
% check if model needs to be updated
if ~check
fm_disp(' ')
fm_disp('* * Warning: The model is referring to an old PSAT-Simulink')
fm_disp(' library. PSAT will try to update models.')
fm_disp(' ')
Settings.ok = 0;
uiwait(fm_choice(['The model refer to an old PSAT-Simulink ' ...
'library. Update?'],1))
if ~Settings.ok, return, end
else
return
end
load_system('fm_lib');
open_system(sys);
for i = 1:nblock
% fix source block if it has changed
try
source = get_param(block{i},'SourceBlock');
switch source
case 'fm_lib/Power Flow/Transf5'
set_param(block{i},'SourceBlock','fm_lib/Power Flow/Twt')
case ['fm_lib/Wind',char(10),'Turbines/Cswt1']
set_param(block{i},'SourceBlock',['fm_lib/Wind',char(10),'Turbines/Cswt'])
case ['fm_lib/Wind',char(10),'Turbines/Dfig1']
set_param(block{i},'SourceBlock',['fm_lib/Wind',char(10),'Turbines/Ddsg'])
case ['fm_lib/Wind',char(10),'Turbines/Dfig2']
set_param(block{i},'SourceBlock',['fm_lib/Wind',char(10),'Turbines/Dfig'])
case ['fm_lib/Wind',char(10),'Turbines/Wind1']
set_param(block{i},'SourceBlock',['fm_lib/Wind',char(10),'Turbines/Wind'])
case 'fm_lib/Power Flow/Extra Line'
set_param(block{i},'SourceBlock','fm_lib/Power Flow/Lines')
case 'fm_lib/Power Flow/PQ1'
set_param(block{i},'SourceBlock','fm_lib/Power Flow/PQgen')
case 'fm_lib/Machines/Gen'
set_param(block{i},'SourceBlock','fm_lib/Machines/Syn')
case 'fm_lib/ULTC/LTC'
set_param(block{i},'SourceBlock','fm_lib/ULTC/Ltc')
case 'fm_lib/ULTC/OLTC'
set_param(block{i},'SourceBlock','fm_lib/ULTC/Tap')
case 'fm_lib/ULTC/PHS'
set_param(block{i},'SourceBlock','fm_lib/ULTC/Phs')
case 'fm_lib/Others/SOFC'
set_param(block{i},'SourceBlock','fm_lib/Others/Sofc')
case 'fm_lib/Others/SSR'
set_param(block{i},'SourceBlock','fm_lib/Others/Ssr')
case 'fm_lib/Measurements/PMU'
set_param(block{i},'SourceBlock','fm_lib/Measurements/Pmu')
case 'fm_lib/Loads/FDL'
set_param(block{i},'SourceBlock','fm_lib/Loads/Fl')
case 'fm_lib/Loads/LRL'
set_param(block{i},'SourceBlock','fm_lib/Loads/Exload')
case 'fm_lib/Loads/TCL'
set_param(block{i},'SourceBlock','fm_lib/Loads/Thload')
case 'fm_lib/Loads/Mixed'
set_param(block{i},'SourceBlock','fm_lib/Loads/Mixload')
case 'fm_lib/Loads/VDL'
set_param(block{i},'SourceBlock','fm_lib/Loads/Mn')
case 'fm_lib/Loads/ZIP'
set_param(block{i},'SourceBlock','fm_lib/Loads/Pl')
case 'fm_lib/FACTS/HVDC'
set_param(block{i},'SourceBlock','fm_lib/FACTS/Hvdc')
case 'fm_lib/FACTS/SSSC'
set_param(block{i},'SourceBlock','fm_lib/FACTS/Sssc')
case 'fm_lib/FACTS/SVC (1)'
set_param(block{i},'SourceBlock','fm_lib/FACTS/Svc')
case 'fm_lib/FACTS/SVC (2)'
set_param(block{i},'SourceBlock','fm_lib/FACTS/Svc2')
case 'fm_lib/FACTS/StatCom'
set_param(block{i},'SourceBlock','fm_lib/FACTS/Statcom')
case 'fm_lib/FACTS/TCSC (1)'
set_param(block{i},'SourceBlock','fm_lib/FACTS/Tcsc')
case 'fm_lib/FACTS/TCSC (2)'
set_param(block{i},'SourceBlock','fm_lib/FACTS/Tcsc2')
case 'fm_lib/FACTS/UPFC'
set_param(block{i},'SourceBlock','fm_lib/FACTS/Upfc')
case 'fm_lib/Connections/Link'
set_param(block{i},'SourceBlock','fm_lib/Connections/Link1')
case 'fm_lib/OPF & CPF/RMPG'
set_param(block{i},'SourceBlock','fm_lib/OPF & CPF/Rmpg')
case 'fm_lib/OPF & CPF/RMPL'
set_param(block{i},'SourceBlock','fm_lib/OPF & CPF/Rmpl')
case 'fm_lib/OPF & CPF/RSRV'
set_param(block{i},'SourceBlock','fm_lib/OPF & CPF/Rsrv')
case 'fm_lib/OPF & CPF/VLTN'
set_param(block{i},'SourceBlock','fm_lib/OPF & CPF/Vltn')
case 'fm_lib/OPF & CPF/YPDP'
set_param(block{i},'SourceBlock','fm_lib/OPF & CPF/Ypdp')
case 'fm_lib/OPF & CPF/YPDP1'
set_param(block{i},'SourceBlock','fm_lib/OPF & CPF/Ypdp1')
case 'fm_lib/Controls/AVR'
set_param(block{i},'SourceBlock','fm_lib/Controls/Exc')
case 'fm_lib/Controls/TG'
set_param(block{i},'SourceBlock','fm_lib/Controls/Tg')
case 'fm_lib/Controls/SSCL'
set_param(block{i},'SourceBlock','fm_lib/Controls/Pod')
case 'fm_lib/Controls/OXL'
set_param(block{i},'SourceBlock','fm_lib/Controls/Oxl')
case 'fm_lib/Controls/PSS'
set_param(block{i},'SourceBlock','fm_lib/Controls/Pss')
case 'fm_lib/Controls/CAC'
set_param(block{i},'SourceBlock','fm_lib/Controls/Cac')
case 'fm_lib/Controls/Shaft'
set_param(block{i},'SourceBlock','fm_lib/Others/Mass')
end
mask{i} = get_param(block{i},'MaskType');
catch
% the source block has not changed
end
switch mask{i}
case {'Bus','Link','Line','Lines','Breaker','Twt' ...
'Phs','Tcsc','Sssc','Upfc','Hvdc','Dfig', ...
'Cswt','Ddsg','RLC','PV','SW','PQgen', ...
'Rmpg','Rsrv','Vltn','Wind','Sofc','Ssr', ...
'PQ','Shunt','Rmpl','Fault','Mn','Pl','Mot', ...
'Fl','Exload','Mixload','Thload','Jimma','Tap', ...
'Svc','Statcom','Busfreq','Pmu','Supply', ...
'Demand','Syn','Ltc','SAE1','SAE2','SAE3', ...
'Exc','Tg','Sscl','Cac','Oxl','Pss','Cluster'}
CloneBlock(block{i},sys)
end
end
lines = find_system(sys,'FindAll','on','type','line');
for i = 1:length(lines)
points = get_param(lines(i),'Points');
parent = get_param(lines(i),'Parent');
delete_line(parent,points(1,:));
try
add_line(parent,points);
catch
fm_disp(['* * Connection line ',num2str(i),' could not be replaced.'])
end
end
uiwait(fm_choice('Now please take a moment to doublecheck connections...',2))
fm_disp(' ')
fm_disp(['* * Update of model <',sys,'> completed.'])
%------------------------------------------------------------------
function CloneBlock(block,sys)
%------------------------------------------------------------------
name = get_param(block,'Name');
clone = find_system(sys,'Name',name);
type = get_param(block,'MaskType');
pos = get_param(block,'Position');
orient = get_param(block,'Orientation');
bgcolor = get_param(block,'BackgroundColor');
fontname = get_param(block,'FontName');
fontsize = get_param(block,'FontSize');
maskvalue = get_param(block,'MaskValueString');
nameplace = get_param(block,'NamePlacement');
switch type
case 'Bus'
template = 'Bus1';
case 'Link'
template = 'Link1';
case 'SW'
template = 'Slack';
case 'Shunt'
a = get_param(block,'MaskPrompts');
if strmatch('Conductance',a{2})
template = 'Shunt';
elseif strmatch('Susceptance',a{2})
template = 'Shunt1';
end
case 'PV'
if length(get_param(block,'MaskVarAliases')) == 6
template = 'PV';
else
template = 'SC';
end
case 'Line'
if length(get_param(block,'MaskVarAliases')) == 6
a = get_param(block,'MaskDescription');
if ~isempty(strfind(a,'shifter'))
template = 'Transf3';
elseif ~isempty(strfind(a,'cable'))
template = 'Line1';
elseif ~isempty(strfind(a,'tap ratio'))
template = 'Transf2';
else
template = 'Line';
end
elseif length(get_param(block,'MaskVarAliases')) == 7
template = 'Transf4';
elseif length(get_param(block,'MaskVarAliases')) == 5
a = get_param(block,'MaskDescription');
if ~isempty(strfind(a,'auto'))
template = 'Auto';
else
template = 'Transf1';
end
end
otherwise
template = type;
end
updatesyn = 0;
updatesup = 0;
updatedem = 0;
updatebus = 0;
if strcmp(type,'Syn')
values = get_param(block,'MaskValues');
if length(values) == 12
in = get_param(block,'in');
updatesyn = 1;
end
elseif strcmp(type,'Supply')
values = get_param(block,'MaskValues');
if length(values) == 8
in = get_param(block,'in');
updatesup = 1;
end
elseif strcmp(type,'Demand')
values = get_param(block,'MaskValues');
if length(values) == 9
out = get_param(block,'out');
updatedem = 1;
end
elseif strcmp(type,'Bus')
values = get_param(block,'MaskValues');
if length(values) == 4, updatebus = 1; end
end
ancestor = find_system('fm_lib','LookUnderMasks','functional','Name',template);
if isempty(clone)
fm_disp('* * Troubles in defining destination block')
elseif isempty(ancestor)
fm_disp('* * Troubles in finding library source (broken library link)')
else
if iscell(clone), clone = clone{1}; end
if iscell(ancestor), ancestor = ancestor{1}; end
try
delete_block(block)
newblock = add_block(ancestor,clone);
set_param(newblock, ...
'Name',name, ...
'Position',pos, ...
'Orientation',orient, ...
'BackgroundColor',bgcolor, ...
'FontName',fontname, ...
'FontSize',fontsize, ...
'NamePlacement',nameplace, ...
'MaskValueString',maskvalue)
if updatesup
set_param(newblock,'p15q','1')
set_param(newblock,'p16_17q','[0 0]')
set_param(newblock,'p18_19q','[0 0]')
set_param(newblock,'in',in)
end
if updatedem
set_param(newblock,'p16_17q','[0 0]')
set_param(newblock,'out',out)
end
if updatesyn
set_param(newblock,'p25_26q','[0 0]')
set_param(newblock,'in',in)
end
if updatebus
set_param(newblock,'p5q','1')
set_param(newblock,'p6q','1')
end
catch
lasterr
fm_disp(['* * Troubles in replacing block <', ...
clone,'> with <',ancestor,'>'])
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -