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

📄 fm_uwpflow.m

📁 这是一个很适合研究和学习用的电力系统仿真软件
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = fm_uwpflow(varargin)
% FM_UWPFLOW PSAT/UWPFLOW interface function.
%
% FM_UWPFLOW run UWPFLOW using current settings
%
% FM_UWPFLOW(OPTION)
%     OPTION:  'init' initialise UWPFLOW.opt structure
%
%
%see UWPFLOW structure for settings
%
%Author:    Federico Milano
%Date:      01-May-2003
%Version:   1.0.0
%
%E-mail:    fmilano@thunderbox.uwaterloo.ca
%Web-site:  http://thunderbox.uwaterloo.ca/~fmilano
%
% Copyright (C) 2002-2006 Federico Milano

global UWPFLOW DAE Bus Settings clpsat
global Fig File Path History Hdl
global Supply Demand PQ SW PV

if ~nargin, return, end

switch varargin{1}
 case 'init'

  if ~isempty(UWPFLOW.opt), return, end

  % ----------------------------------------------------------------- %
  %                                                                   %
  %   Legend:                                                         %
  %                                                                   %
  %    1 -a    2 -A    3 -b    4 -B    5 -c    6 -C    7 -d    8 -D   %
  %    9 -e   10 -E   11 -f   12 -F   13 -g   14 -G   15 -h   16 -H   %
  %   17 -i   18 -I   19 -j   20 -J   21 -k   22 -K   23 -l   24 -L   %
  %   25 -m   26 -M   27 -n   28 -N   29 -o   30 -O   31 -p   32 -P   %
  %   33 -q   34 -qx  35 -qz  36 -Q   37 -QX  38 -r   39 -R   40 -s   %
  %   41 -S   42 -t   43 -T   44 -u   45 -U   46 -v   47 -V   48 -w   %
  %   49 -W   50 -x   51 -X   52 -y   53 -Y   54 -z   55 -Z   56 -0   %
  %   57 -1   58 -2   59 -3   60 -4   61 -5   62 -6   63 -7   64 -8   %
  %   65 -9   66 -$   67 -#                                           %
  %                                                                   %
  % ----------------------------------------------------------------- %

  UWPFLOW.opt = ...
      struct('a', [], 'A', [], 'b', [], 'B', [], 'c', [], 'C', [], ...
             'd', [], 'D', [], 'e', [], 'E', [], 'f', [], 'F', [], ...
             'g', [], 'G', [], 'h', [], 'H', [], 'i', [], 'I', [], ...
             'j', [], 'J', [], 'k', [], 'K', [], 'l', [], 'L', [], ...
             'm', [], 'M', [], 'n', [], 'N', [], 'o', [], 'O', [], ...
             'p', [], 'P', [], 'q', [], 'qx',[], 'qz',[], 'Q', [], ...
             'QX',[], 'r', [], 'R', [], 's', [], 'S', [], 't', [], ...
             'T', [], 'u', [], 'U', [], 'v', [], 'V', [], 'w', [], ...
             'W', [], 'x', [], 'X', [], 'y', [], 'Y', [], 'z', [], ...
             'Z', [], ...
             'zero',  [], ...
             'one',   [], ...
             'two',   [], ...
             'three', [], ...
             'four',  [], ...
             'five',  [], ...
             'six',   [], ...
             'seven', [], ...
             'eight', [], ...
             'nine',  [], ...
             'dollar',[], ...
             'bound', []);

  fields = fieldnames(UWPFLOW.opt);
  status = logical(zeros(length(fields),1));
  values = zeros(length(fields),1);
  extens = cell(length(fields),1);

  %status([4,12,29,42]) = ~status([4,12,29,42]);
  values([4,11,12,21,24,29,30,41,42,44,45,46,54,57,58]) = ...
      [1,1,0.01,1,1e-8,0.000001,6,1,0.1,1e-3,10,1,50,1,5]';

  extens{22} = '.k';   % -K option
  extens{52} = '.w';   % -y option
  extens{53} = '.v';   % -Y option
  extens{17} = '.vp';  % -i option
  extens{23} = '.log'; % -l option
  extens{48} = '.cf';  % -w option
  extens{49} = '.cf';  % -W option
  extens{47} = '.ini'; % -V option
  extens{5}  = '.cpf'; % -c option
  extens{6}  = '.cpf'; % -C option
  extens{8}  = '.oh';  % -D option
  extens{59} = '.gen'; % -3 option
  extens{10} = '.poc'; % -E option
  extens{55} = '.ntv'; % -Z option

  for i = 1:length(fields)
    optnum = {'zero', 'one', 'two', 'three', 'four', ...
              'five', 'six', 'seven', 'eight', 'nine'};
    idxnum = strmatch(fields{i},optnum,'exact');
    if idxnum,
      name = num2str(idxnum-1);
    elseif strcmp(fields{i},'bound')
      name = '#';
    elseif strcmp(fields{i},'dollar')
      name = '$';
    else
      name = fields{i};
    end
    if values(i)
      value = values(i);
    else
      value = [];
    end
    UWPFLOW.opt = setfield( ...
        UWPFLOW.opt,fields{i}, ...
        struct('status',status(i),'name',['-',name], ...
               'num',value,'ext',extens{i}));
  end

 case 'methods' % [-c], [-C] and [-H] options

  value = get(gcbo,'Value');
  UWPFLOW.method = value;

  switch value
   case 1 % power flow

    UWPFLOW.opt.c.status = 0;
    UWPFLOW.opt.C.status = 0;
    UWPFLOW.opt.H.status = 0;

   case 2 % continuation method

    UWPFLOW.opt.c.status = 1;
    UWPFLOW.opt.C.status = 0;
    UWPFLOW.opt.H.status = 0;

   case 3 % direct method

    UWPFLOW.opt.c.status = 0;
    UWPFLOW.opt.C.status = 1;
    UWPFLOW.opt.H.status = 0;

   case 4 % parameterized continuation method

    UWPFLOW.opt.c.status = 0;
    UWPFLOW.opt.C.status = 0;
    UWPFLOW.opt.H.status = 1;

  end

 case 'filename'

  string = fm_input('File name:', ...
                    'UWPFLOW Input/Output File Name',1,{UWPFLOW.file});
  if isempty(string), return, end
  if ~isempty(string{1})
    UWPFLOW.file = string{1};
    output = {'.k';   '.v';   '.w';   '.pf'; '.jac'; '.cf'; '.cpf';
              '.mis'; '.var'; '.log'; '.oh'; '.vp'; '.gen'; '.ini';
              '.poc'; '.ntv'};
    output = strcat(UWPFLOW.file,output);
    hdl = findobj(Fig.uwpflow,'Tag','PopupUWFile');
    set(hdl,'String',output)
  end

 case 'uwrun'

  [u,w] = system('uwpflow');
  if isempty(strmatch('UW Continuation Power Flow',w))
    uiwait(fm_choice('UWPFLOW is not properly installed on your system.',2))
    return
  end

  % check for file data
  if isempty(File.data)
    fm_disp(['Load file data before running PSAT-UWPFLOW ' ...
             'interface.'])
    return
  end

  % create IEEE CDF file
  file = strrep(File.data,'(mdl)','_mdl');
  file = strrep(file,'@ ','');
  check = psat2ieee([file,'.m'],Path.data);
  if ~check
    fm_disp(['Something wrong when converting data file in IEEE ' ...
             'CDF'])
    return
  end

  % create UWPFLOW command line
  uwcom = fm_uwpflow('makecom',1);
  if isempty(uwcom), return, end

  if ~isempty(UWPFLOW.command) & clpsat.init
    uwcom = UWPFLOW.command;
  end

  if ~strcmp(UWPFLOW.command,uwcom) & ~isempty(UWPFLOW.command)
    uiwait(fm_choice(['User defined UWPFLOW command differs from current ' ...
               'settings. Use custom UWPFLOW command?']))
    if Settings.ok, uwcom = UWPFLOW.command; end
  end

  % Current solution is stored in a IEEE CDF file
  if isempty(findstr(uwcom,'-W'))
    fm_disp(['System results are stored in "',UWPFLOW.file, ...
             '.cf" (IEEE TAPE format).'])
    uwcom = [uwcom, ' -W',UWPFLOW.file,'.cf'];
  end

  % Jacobian, variables and equation mismatches of the current solution
  if ~isempty(findstr(uwcom,'-j'))
    uwcom = strrep(uwcom,'-j','-J');
  end
  if isempty(findstr(uwcom,'-J'))
    uwcom = [uwcom, ' -J',UWPFLOW.file];
  end
  fm_disp(['System Jacobian, variables and mismatches are stored ' ...
           'in:'])
  fm_disp([UWPFLOW.file,'.jac, ',UWPFLOW.file,'.var, and ', ...
           UWPFLOW.file,'.mis files.'])

  % write psatuw.k file, if needed
  copt = UWPFLOW.opt.c.status;
  Copt = UWPFLOW.opt.C.status;
  Bopt = UWPFLOW.opt.B.status;
  Hopt = UWPFLOW.opt.H.status;
  vopt = UWPFLOW.opt.v.status;
  if copt | Copt | Bopt | Hopt | vopt
    linef = '%5d    %5d         %8.5f %8.5f %8.5f %5d %5d %8.5f %8.5f\n';
    fid = fopen([Path.data,UWPFLOW.file,'.k'],'wt');
    if fid == -1
      fm_disp(['Could not create file ''psatuw.k'' for power ' ...
               'directions.'],2)
      return
    end
    count = fprintf(fid,'C %5d BUS AC TEST SYSTEM \n',Bus.n);
    count = fprintf(fid,'C Generation and Load Directions \nC \n');
    count = fprintf(fid,['C This file contains the generation (DPg) ' ...
                        'and load (Pnl, Qnl, and optional\n']);
    count = fprintf(fid,['C Pzl and Qzl) direction, and the maximum P ' ...
                        'generation (PgMax) needed for \n']);
    count = fprintf(fid,['C finding the bifurcation point.  Since the ' ...
                        'IEEE Common Format does not\n']);
    count = fprintf(fid,['C allow for the definition of PgMax, this value ' ...
                        'is ignored in this file\n']);
    count = fprintf(fid,'C by making it equal to 0.\nC \n');
    count = fprintf(fid,['C The file must be read with the -K option ' ...
                        'whenever one wants to do\n']);
    count = fprintf(fid,['C bifurcation studies (-c, -C, -H and -B ' ...
                        'options).\n']);
    count = fprintf(fid,['C The unformatted data is given in the ', ...
                        'following order:\nC \n']);
    count = fprintf(fid,['C BusNumber  BusName    DPg      Pnl      ' ...
                        'Qnl      PgMax [ Smax Vmax Vmin Pzl  Qzl ]\n']);

⌨️ 快捷键说明

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