⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fm_set.m

📁 电力系统的psat
💻 M
📖 第 1 页 / 共 2 页
字号:
  OPF.vmin = opf_vmin;  OPF.vmax = opf_vmax;  CPF.hopf = cpf_hopf;  Settings.local = set_local;  Settings.hostver = set_hostv;  % needed for compatibility issue because the  % Lrload structure has been renamed Exload  if exist('Lrload') == 1     Exload = Lrload;    clear Lrload  end  for i = 1:length(Comp.number)    if strcmp(Comp.number{i},'Lrload.n')      Comp.number{i} = 'Exload.n';      Comp.funct{i} = 'fm_exload';      break    end  end  for i = 1:length(Varname.comp)    if strcmp(Varname.comp{i},'Lrload')      Varname.comp{i} = 'Exload';         end  end  for i = 1:length(Varname.fcomp)    if strcmp(Varname.fcomp{i},'Lrload')      Varname.fcomp{i} = 'Exload';      break    end  end    % following lines are needed for  % compatibility with old OPF structure  OPF.obj = 0;  OPF.ms = 0;  OPF.dy = 0;  OPF.dF = 0;  OPF.dG = 0;  OPF.NCP = [];  OPF.iter = [];  OPF.gpc = [];  OPF.gqc = [];   case 'setdata'  if ~isempty(Path.data), cd(Path.data); end  [filedata,pathdata] = uigetfile('d*.m*','Select Data File');  if pathdata == 0    fm_disp(['No data file has been selected or file does not exist'],2)    return  end  if strcmp(computer,'GLNX86'),    pathdata = strrep(pathdata,getenv('HOME'),'~');  end  cd(pathdata)  if exist([pathdata,filedata(1:end-2)]) == 4 ...        & strcmp(filedata(end-1:end),'.m')    fm_choice(['Simulink model with the same name of the ', ...               'selected data exists. No file set.'],2)    fm_disp(['Simulink model with the same name of the ', ...               'selected data exists.'])    fm_disp('No file data set.',2)    cd(Path.local)  else    File.data = filedata;    Path.data = pathdata;    if ~isempty(findstr(File.data,'.mdl'))      exist(File.data(1:end-4));      File.data = strrep(File.data,'.mdl','(mdl)');      check = fm_sim;      if ~check, cd(Path.local), return, end    end    File.data = strrep(File.data,'.m','');    hdltext = findobj(Fig.main,'Tag','EditText9');    set(hdltext,'String',File.data, ...                'TooltipString',[Path.data,File.data]);    if ~isempty(findstr(File.data,'(mdl)'))      set(hdltext,'ForegroundColor',[0 0.592 0])    else      set(hdltext,'ForegroundColor',Theme.color07)    end    fm_disp(['Data file "',Path.data,File.data,'" set'],1)    Settings.init = 0;  end  cd(Path.local) case 'setpert'  File.pert = '';  if ~isempty(Path.pert), cd(Path.pert);  end  [filepert,pathpert] = uigetfile('p*.m',['Select Perturbation ' ...                      'File']);  if pathpert == 0    fm_disp('No perturbation file selected or file does not exist',2)  else    Path.pert = pathpert;    File.pert = filepert;    if strcmp(computer,'GLNX86'),      Path.pert = strrep(Path.pert,getenv('HOME'),'~');    end    cd(Path.pert)    lfile = length(File.pert);    File.pert = File.pert(1:lfile-2);    if Settings.hostver >= 6        Hdl.pert = str2func(File.pert);    else        Hdl.pert = File.pert;    end    cd(Path.local)    hdltext = findobj(Fig.main,'Tag','EditText10');    set(hdltext,'String',File.pert, ...        'ForegroundColor',Theme.color07, ...        'TooltipString',[Path.pert,File.pert]);    fm_disp(['Perturbation file "',Path.pert,File.pert,'" set'],1)  end case 'command'  hdl = findobj(gcbf,'Tag','EditCommand');  stringa = get(hdl,'String');  set(hdl,'String','');  hdl = findobj(gcbf,'Tag','ListCommand');  comandi = get(hdl,'String');  if strcmp(comandi{1},'<empty>'),    comandi{1,1} = stringa;  else,    comandi{end+1,1} = stringa;  end  if length(comandi) > 100, comandi(1) = []; end  set(hdl,'String',comandi,'Value',length(comandi));  if strcmp(stringa,'command'),    fm_disp('Invalid command',2),    return,  end  if strcmp(stringa,'<empty>'), return, end  try    try,      eval(['fm_set ',stringa])    catch,      eval(stringa);      fm_disp(['Command "',stringa,'" executed.'])    end  catch    fm_disp(lasterr,2)  end case 'listcommand'  if strcmp(get(Fig.main,'SelectionType'),'open')    hdl = findobj(gcbf,'Tag','ListCommand');    stringa = get(hdl,'String');    value = get(hdl,'Value');    hdl = findobj(gcbf,'Tag','EditCommand');    set(hdl,'String',stringa{value});    fm_set('command')  end case 'lf'  if isempty(File.data),    fm_disp('Set a data file before running Power Flow.',2),    return,  end  if Fig.main    hdl1 = findobj(Fig.main,'Tag','EditText1');    Settings.freq = str2num(get(hdl1,'String'));    Settings.rad = 2*pi*Settings.freq;    hdl2 = findobj(Fig.main,'Tag','EditText2');    Settings.mva = str2num(get(hdl2,'String'));    hdl3 = findobj(Fig.main,'Tag','EditText3');    Settings.t0 = str2num(get(hdl3,'String'));    hdl4 = findobj(Fig.main,'Tag','EditText4');    Settings.tf = str2num(get(hdl4,'String'));    hdl5 = findobj(Fig.main,'Tag','EditText5');    Settings.lftol = str2num(get(hdl5,'String'));    hdl6 = findobj(Fig.main,'Tag','EditText6');    Settings.lfmit = str2num(get(hdl6,'String'));  end  fm_inilf;  if clpsat.readfile    filedata = [File.data,'  '];    filedata = strrep(filedata,'@ ','');    if ~isempty(findstr(filedata,'(mdl)'))      filedata1 = File.data(1:end-5);      open_sys = find_system('type','block_diagram');      donotclose = 0;      for i = 1:length(open_sys)        if strcmp(open_sys{i},filedata1)          donotclose = 1;        break        end      end      if donotclose,        if strcmp(get_param(filedata1,'Dirty'),'on') | ...              str2num(get_param(filedata1,'ModelVersion')) > Settings.mv,          check = fm_sim;          if ~check,            cd(Path.data),            return,          end        end      end    end    cd(Path.data)    filedata = deblank(strrep(filedata,'(mdl)','_mdl'));    a = exist(filedata);    if ~a      fm_disp('Data file does not exist (maybe it was removed).',2)      cd(Path.local)      return    end    clear(filedata)    if a == 2,      lasterr('');      try,        eval(filedata);      catch,        fm_disp(lasterr),        fm_disp(['Something wrong with the data file "',filedata,'"']),        cd(Path.local)        return      end    else,      fm_disp(['File "',filedata,'" not found or not an m-file'],2)    end    cd(Path.local)  end  if Settings.static % do not use dynamic components    for i = 1:Comp.n      comp_con = eval(['~isempty(',strrep(Comp.number{i},'.n','.con'),')']);      if comp_con & ~Comp.prop(i,6)        eval([strrep(Comp.number{i},'.n','.con'),' = [];']);      end    end  end  if Fig.main    hdl = findobj(Fig.main,'Tag','EditText3');    time0 = str2num(get(hdl,'String'));    if time0 ~= Settings.t0,      set(hdl,'String',num2str(Settings.t0)),      fm_disp(['Initial simulation time "t0" set to ',num2str(Settings.t0),' s'])    end    hdl = findobj(Fig.main,'Tag','EditText4');    timef = str2num(get(hdl,'String'));    if timef ~= Settings.tf,      set(hdl,'String',num2str(Settings.tf)),      fm_disp(['Final simulation time "tf" set to ',num2str(Settings.tf),' s'])    end    set(Fig.main,'Pointer','watch');  end  Settings.init = 0;  fm_spf  if Fig.main, set(Fig.main,'Pointer','arrow'); end  SNB.init = 0;  LIB.init = 0;  CPF.init = 0;  OPF.init = 0; case 'simcv'  filedata2 = File.data;  pathdata2 = Path.data;  [filedata,pathdata] = uigetfile('d*.mdl','Select Data File');  if pathdata == 0    fm_disp('No Simulink Model selected or not existent file',2)    return  end  if isempty(findstr(filedata,'.mdl'))    fm_disp(['The selected file is not a Simulink Model or has an ' ...             'invalid extension'],2)    return  end  exist(filedata(1:end-4));  File.data = strrep(filedata,'.mdl','(mdl)');  Path.data = pathdata;  check = fm_sim;  if check,    fm_disp(['Data File "',strrep(filedata,'.mdl','(mdl)'),'" built ' ...                        'from Simulink Model.'],1);  end  File.data = filedata2;  Path.data = pathdata2;  % ---------------------------------------------------------------------------  %case 'stabrep'  %if isempty(Snapshot), return, end  %for i = 1:Bus.n;  [Istab(i),Vnew(i),angnew(i)]= fm_stab(i,0);  %end  %fid = fopen([Path.data,'vstab.txt'], 'wt');  %count = fprintf(fid, 'Voltage Stability Index at Network  %Buses\n\n');  %count = fprintf(fid, '#bus         Index       DAE.V  %phase\n\n');  %for i = 1:Bus.n  %    count = fprintf(fid,[fvar(Varname.bus{i},12),  %    fvar(Istab(i),12), ...  %                         fvar(Vnew(i),12),  %                         fvar(angnew(i),12),'\n']);  %end  %count = fclose(fid);  %fm_text(13,[Path.data,'vstab.txt'])  % --------------------------------------------------------------------------- case 'opf'  if max(OPF.lmin) > OPF.lmax    fm_disp('Lambda_min must be less than Lambda_max.',2)    return  end  [ao,bo] = size(OPF.omega);  [al,bl] = size(OPF.lmin);  ao = ao*bo;  a1 = al*bl;  switch OPF.type   case 1    OPF.show = 1;    if ao > 1,      fm_disp(['Single OPF selected. Only the 1th value of ' ...               'the weighting factor will be used.'])    end    if a1 > 1,      fm_disp(['Single OPF selected. Only the 1th value ' ...               'of the min load parameter will be used.'])    end    OPF.w = OPF.omega(1);    OPF.lmin = OPF.lmin(1);    if Fig.opf      hdl_omeg = findobj(Fig.opf,'Tag','EditText1');      hdl_lmin = findobj(Fig.opf,'Tag','EditText2');      set(hdl_omeg,'String',num2str(OPF.omega_s))      set(hdl_lmin,'String',num2str(OPF.lmin))    end    if OPF.w == 0,      fm_opfm    else,      fm_opfsdr    end   case 2    if ao == 1,      OPF.show = 1;      OPF.w = OPF.omega;      fm_disp(['The weighting factor is scalar. Single OPF will be ' ...               'run.'])      if OPF.w == 0,        fm_opfm      else,        fm_opfsdr      end    else      OPF.fun = 'fm_opfsdr';      fm_pareto    end   case 3,    fm_disp('Sorry! Daily forecast not implemented yet ...',2)    uiwait(fm_choice('Sorry! Daily forecast not implemented yet ...',2))   case 4,    fm_atc   case 5,    fm_atc  end case 'appendV'  if isempty(File.data),    fm_disp('No data file loaded.',2),    return,  end  filedata = strrep(File.data,'@ ','');  if Settings.init == 0,    fm_disp('Run power flow before saving voltages.',2),    return,  end  fid = fopen([Path.data,strrep(filedata,'(mdl)','_mdl'),'.m'],'r+');  count = fseek(fid,0,1);  count = fprintf(fid, '\n\n\nBus.con(:,3) = [...\n      ');  for i = 1:Bus.n-1    count = fprintf(fid,'%10.7f;',DAE.V(i));    if rem(i,5) == 0;      count = fprintf(fid,'\n      ');    end  end  count = fprintf(fid,'%10.7f];\n\n',DAE.V(Bus.n));  count = fprintf(fid, 'Bus.con(:,4) = [...\n      ');  for i = 1:Bus.n-1    count = fprintf(fid, '%10.7f;',DAE.a(i));    if rem(i,5) == 0;      count = fprintf(fid,'\n      ');    end  end  count = fprintf(fid,'%10.7f];\n\n',DAE.a(Bus.n));  fclose(fid);  fm_disp(['Voltages appended in file "',Path.data,File.data,'"']) case 'libpmc'  if Settings.hostver >= 7 %& str2num(sps.Version) >= 3.1    warning('off')    fm_libpmc    warning('on')  else    fm_choice('Simulink PMC Library cannot be loaded.',2)    fm_disp('Simulink PMC Library cannot be loaded.',2)  end case 'libsps'  sps = ver('powersys');  if isempty(sps)    fm_disp('SymPowerSystems is not installed on your system!')    fm_disp('The Simulink SPS Library cannot be loaded')    return  end  if Settings.hostver >= 7 & str2num(sps.Version) >= 3.1    warning('off')    fm_libsps    warning('on')  else    fm_choice('Simulink SPS Library cannot be loaded.',2)    fm_disp('Simulink SPS Library cannot be loaded.',2)  end otherwise  error('The string is not a valid command')end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -