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

📄 pst2psat.m

📁 这是一个很适合研究和学习用的电力系统仿真软件
💻 M
📖 第 1 页 / 共 2 页
字号:
  Tq2 = mac_con(i,15);
  if Tq2 & Tq1 & Td2, ord = 6;
  elseif Tq2 & Td2,   ord = 5.2;
  elseif Tq1 & Tq2,   ord = 5.1;
  elseif Tq1,         ord = 4;
  elseif Td1,         ord = 3;
  else,               ord = 2;
  end
  data = [mac_con(i,[2,3]),kV,60,ord,mac_con(i,[4:15]),2*mac_con(i,16), ...
          mac_con(i,[17]),0,0,mac_con(i,[22,23]),0];
  count = fprintf(fid, [format, '];\n\n\n'],data);
end

% Induction motor data Mot.con
% ------------------------------------------------------------------------

if ~isempty(ind_con) & ~isempty(mld_con) & length(ind_con(:,1))==length(mld_con(:,1))
  fm_disp('ind_con -> Mot.con')
  fm_disp('    Some approximations are used for induction motors:')
  fm_disp('    Check mechanical torque parameters before running the power flow.')
  nmot = length(ind_con(:,1));
  nrow = length(ind_con(1,:));
  if nrow < 15, ind_con = [ind_con,zeros(nmot,15-nrow)]; end
  format = ['%4d %8.4g %8.4g %8.4g %4d %4d %8.4g %8.4g %8.4g ' ...
            '%8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g'];
  ind_con = ind_con(mld_con(:,1),:);
  count = fprintf(fid, 'Mot.con = [ ...\n');
  for i = 1:nmot-1
    kV = bus(find(bus(:,1)==ind_con(i,2)),13);
    r2 = ind_con(i,10);
    x2 = ind_con(i,11);
    r1 = ind_con(i,4);
    if r2 | x2, ord = 5;
    elseif r1,  ord = 3;
    else,       ord = 1;
    end
    %sup = ind_con(i,15);
    %if sup, sup = 1; end
    sup = 1;
    data = [ind_con(i,[2,3]),kV,60,ord,sup,ind_con(i,[4,5,7,8,10,11,6,9]), ...
            mld_con(i,3),-mld_con(i,3),mld_con(i,5)];
    count = fprintf(fid,[format, ';\n'],data);
  end
  i = nmot;
  kV = bus(find(bus(:,1)==ind_con(i,2)),13);
  r2 = ind_con(i,10);
  x2 = ind_con(i,11);
  r1 = ind_con(i,4);
  if r2 | x2, ord = 5;
  elseif r1,  ord = 3;
  else,       ord = 1;
  end
  sup = ind_con(i,15);
  if sup, sup = 1; end
  data = [ind_con(i,[2,3]),kV,60,ord,sup,ind_con(i,[4,5,7,8,10,11,6,9]), ...
          mld_con(i,3),-mld_con(i,3),mld_con(i,5)];
  count = fprintf(fid,[format, '];\n\n\n'],data);
end

% Polinomial load data Pl.con
% ---------------------------------------------------------------------

if ~isempty(load_con)
  fm_disp('load_con -> Pl.con')
  format = ['%4d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g ' ...
  '%8.4g %2d'];
  P = load_con(:,2);
  Q = load_con(:,3);
  Ip = load_con(:,4);
  Iq = load_con(:,5);
  idx = find(P+Q+Ip+Iq == 0);
  if ~isempty(idx)
    load_con(idx,:) = [];
  end
  npol = length(load_con(:,1));
  if npol, count = fprintf(fid, 'Pl.con = [ ...\n'); end
  for i = 1:npol-1
    kV = bus(find(bus(:,1)==load_con(i,1)),13);
    P = 100*load_con(i,2);
    Q = 100*load_con(i,3);
    Ip = 100*load_con(i,4);
    Iq = 100*load_con(i,5);
    data = [load_con(i,1),mvabas,kV,60,0,Ip,P,0,Iq,Q,1];
    count = fprintf(fid, [format, ';\n'],data);
  end
  if npol
    kV = bus(find(bus(:,1)==load_con(npol,1)),13);
    P = 100*load_con(npol,2);
    Q = 100*load_con(npol,3);
    Ip = 100*load_con(npol,4);
    Iq = 100*load_con(npol,5);
    data = [load_con(npol,1),mvabas,kV,60,0,Ip,P,0,Iq,Q,1];
    count = fprintf(fid, [format, '];\n\n\n'],data);
  end
end

% Automatic Voltage Regulator data Exc.con
% -------------------------------------------------------------------

if ~isempty(exc_con)
  fm_disp('exc_con -> Exc.con')
  idx = find(exc_con(:,1) < 3);
  nexc = length(idx);
  if nexc < length(exc_con(:,1))
    fm_disp(['Model IEEE Type ST3 Exciters are approximated with AVR ' ...
             'type III.'])
  end
  if nexc ~= 0
    fm_disp('Model IEEE Type DC1 and DC2 Exciters are approximated with AVR type II.')
  end
  format = '%4d %4d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g';
  count = fprintf(fid, 'Exc.con = [ ...\n');
  for i = 1:length(exc_con(:,1))-1
    genn = find(mac_con(:,1) == exc_con(i,2));
    if exc_con(i,1) < 3
      Tf = exc_con(i,17);
      Te = exc_con(i,11);
      if ~Te & ~Tf
        data = [genn,3,exc_con(i,[8,9,4,5,7]),0,0,0,exc_con(i,3),0,0];
      else
        data = [genn,2,exc_con(i,[8,9,4,5,16,17]),0, ...
                exc_con(i,[11,3]),0.0006,0.9];
      end
    else
      data = [genn,3,exc_con(i,[8,9]),exc_con(i,[4,6,7]),0,0,0,0,0,0];
    end
    if data(3) < 2.5
      fm_disp('Found Vr_max <  2.5 p.u. -> reset to  2.5 p.u.')
      data(3) = 2.5;
    end
    if data(4) > -2.5
      fm_disp('Found Vr_min > -2.5 p.u. -> reset to -2.5 p.u.')
      data(4) = -2.5;
    end
    count = fprintf(fid, [format, ';\n'],data);
  end
  i = length(exc_con(:,1));
  genn = find(mac_con(:,1) == exc_con(i,2));
  if exc_con(i,1) < 3
    Tf = exc_con(i,17);
    Te = exc_con(i,11);
    if ~Te & ~Tf
      data = [genn,3,exc_con(i,[8,9,4,5,7]),0,0,0,exc_con(i,3),0,0];
    else
      data = [genn,2,exc_con(i,[8,9,4,5,16,17]),0, ...
              exc_con(i,[11,3]),0.0006,0.9];
    end
  else
    data = [genn,3,exc_con(i,[8,9]),exc_con(i,[4,6,7]),0,0,0,0,0,0];
  end
  if data(3) < 2.5
    fm_disp('Found Vr_max <  2.5 p.u. -> reset to  2.5 p.u.')
    data(3) = 2.5;
  end
  if data(4) > -2.5
    fm_disp('Found Vr_min > -2.5 p.u. -> reset to -2.5 p.u.')
    data(4) = -2.5;
  end
  count = fprintf(fid, [format, '];\n\n\n'],data);
end

% Turbine Governor data Tg.con
% ---------------------------------------------------------------------

if ~isempty(tg_con)
  fm_disp('tg_con -> Tg.con')
  ntg = length(tg_con(:,1));
  tg_con(:,4) = 1./tg_con(:,4);
  format = ['%4d %4d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g'];
  count = fprintf(fid, 'Tg.con = [ ...\n');
  for i = 1:ntg-1
    gen = find(mac_con(:,1) == tg_con(i,2));
    data = [gen,1,tg_con(i,[3,4,5]),0,tg_con(i,[6,7,8,9,10])];
    count = fprintf(fid, [format, ';\n'],data);
  end
  i = ntg;
  gen = find(mac_con(:,1) == tg_con(i,2));
  data = [gen,1,tg_con(i,[3,4,5]),0,tg_con(i,[6,7,8,9,10])];
  count = fprintf(fid, [format, '];\n\n\n'],data);
end

% Power System Stabilizer data Pss.con
% --------------------------------------------------------------------

if ~isempty(pss_con)
  fm_disp('pss_con -> Pss.con')
  npss = length(pss_con(:,1));
  format = ['%4d %4d %4d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g ', ...
            '%8.4g ... \n %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %4d'];
  count = fprintf(fid, 'Pss.con = [ ...\n');
  for i = 1:npss-1
    exc = find(exc_con(:,2) == pss_con(i,2));
    Kw = pss_con(i,3)/pss_con(i,4);
    data = [exc,2,pss_con(i,[1,9,10]),Kw, ...
            pss_con(i,[4,5,6,7,8]),0,0,0,0,0,0,0,0,0,0,0];
    count = fprintf(fid, [format, ';\n'],data);
  end
  i = npss;
  exc = find(exc_con(:,2) == pss_con(i,2));
  Kw = pss_con(i,3)/pss_con(i,4);
  data = [exc,2,pss_con(i,[1,9,10]),Kw, ...
          pss_con(i,[4,5,6,7,8]),0,0,0,0,0,0,0,0,0,0,0];
  count = fprintf(fid, [format, '];\n\n\n'],data);
end

% Static Var Compensator data Svc.con
% ---------------------------------------------------------------------

if ~isempty(svc_con)
  fm_disp('svc_con -> Svc.con')
  nsvc = length(svc_con(:,1));
  format = ['%4d %8.4g %8.4g %8.4g %4d %8.4g %8.4g %8.4g %8.4g ', ...
            '%8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g'];
  count = fprintf(fid, 'Svc.con = [ ...\n');
  for i = 1:nsvc-1
    kV = bus(find(bus(:,1)==svc_con(i,2)),13);
    Vref = bus(find(bus(:,1)==svc_con(i,2)),2);
    data = [svc_con(i,[2,3]),kV,60,1,svc_con(i,[7,6]), ...
            Vref,svc_con(i,[4,5]),0,0,0,0,0,0];
    count = fprintf(fid, [format, '; \n'],data);
  end
  i = nsvc;
  kV = bus(find(bus(:,1)==svc_con(i,2)),13);
  Vref = bus(find(bus(:,1)==svc_con(i,2)),2);
  data = [svc_con(i,[2,3]),kV,60,1,svc_con(i,[7,6]), ...
          Vref,svc_con(i,[4,5]),0,0,0,0,0,0];
  count = fprintf(fid, [format, ']; \n\n\n'],data);
end

% Switching operation data Breaker.con & Fault.con
% -----------------------------------------------------------------------

if ~isempty(sw_con)
  switch sw_con(2,6)
   case 5
    fm_disp('For describing a loss of load use a perturbation file.')
   case 4
    fm_disp('sw_con -> Breaker.con')
    format = '%4d %4d %4d %8.4g %8.4g';
    linen = find(net_line(:,1) == sw_con(2,2) & ...
                 net_line(:,2) == sw_con(2,3));
    if isempty(linen)
      linen = find(net_line(:,2) == sw_con(2,2) & ...
                   net_line(:,1) == sw_con(2,3));
    end
    if isempty(linen),
      fm_disp('No line was found with the terminals as specified in sw_con')
    else
      kV = bus(find(bus(:,1)==sw_con(2,2)),13);
      data = [linen, sw_con(2,2),1,sw_con(2,1),sw_con(5,1)+1];
      count = fprintf(fid, ['Breaker.con = [',format,'];\n\n\n'],data);
    end
   case 6
    fm_disp('No fault operations.')
   otherwise
    fm_disp('sw_con -> Fault.con')
    switch sw_con(2,6)
     case 1
      fm_disp('Line-to-ground fault is approximated as a three phase fault.')
     case 2
      fm_disp('Line-to-line-to-ground fault is approximated as a three phase fault.')
     case 3
      fm_disp('Line-to-line fault is approximated as a three phase fault.'),
    end
    format = '%4d %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g %8.4g';
    kV = bus(find(bus(:,1)==sw_con(2,2)),13);
    data = [sw_con(2,2),mvabas,kV,60,sw_con(2,1),sw_con(4,1),0, 0];
    count = fprintf(fid, ['Fault.con = [',format,'];\n\n\n'],data);
  end

  fm_disp('sw_con -> Settings')
  count = fprintf(fid, ['Settings.t0 = ',num2str(sw_con(1,1)),';\n']);
  count = fprintf(fid, ['Settings.tf = ',num2str(sw_con(5,1)),';\n']);

end

% end of operations
count = fclose(fid);
fm_disp(['Conversion into data file "',pathname,newfile,'" completed.'])
if Settings.beep, beep, end

⌨️ 快捷键说明

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