Home > matpower5.0 > psse_convert.m

psse_convert

PURPOSE ^

PSSE_CONVERT Converts data read from PSS/E RAW file to MATPOWER case.

SYNOPSIS ^

function [mpc, warns] = psse_convert(warns, data, verbose)

DESCRIPTION ^

PSSE_CONVERT  Converts data read from PSS/E RAW file to MATPOWER case.
   [MPC, WARNINGS] = PSSE_CONVERT(WARNINGS, DATA)
   [MPC, WARNINGS] = PSSE_CONVERT(WARNINGS, DATA, VERBOSE)

   Converts data read from a version RAW data file into a
   MATPOWER case struct.

   Input:
       WARNINGS :  cell array of strings containing accumulated
                   warning messages
       DATA : struct read by PSSE_READ (see PSSE_READ for details).
       VERBOSE :   1 to display progress info, 0 (default) otherwise

   Output:
       MPC : a MATPOWER case struct created from the PSS/E data
       WARNINGS :  cell array of strings containing updated accumulated
                   warning messages

   See also PSSE_READ.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mpc, warns] = psse_convert(warns, data, verbose)
0002 %PSSE_CONVERT  Converts data read from PSS/E RAW file to MATPOWER case.
0003 %   [MPC, WARNINGS] = PSSE_CONVERT(WARNINGS, DATA)
0004 %   [MPC, WARNINGS] = PSSE_CONVERT(WARNINGS, DATA, VERBOSE)
0005 %
0006 %   Converts data read from a version RAW data file into a
0007 %   MATPOWER case struct.
0008 %
0009 %   Input:
0010 %       WARNINGS :  cell array of strings containing accumulated
0011 %                   warning messages
0012 %       DATA : struct read by PSSE_READ (see PSSE_READ for details).
0013 %       VERBOSE :   1 to display progress info, 0 (default) otherwise
0014 %
0015 %   Output:
0016 %       MPC : a MATPOWER case struct created from the PSS/E data
0017 %       WARNINGS :  cell array of strings containing updated accumulated
0018 %                   warning messages
0019 %
0020 %   See also PSSE_READ.
0021 
0022 %   MATPOWER
0023 %   $Id: psse_convert.m 2371 2014-08-05 01:28:35Z ray $
0024 %   by Yujia Zhu, PSERC ASU
0025 %   and Ray Zimmerman, PSERC Cornell
0026 %   Based on mpraw2mp.m, written by: Yujia Zhu, Jan 2014, yzhu54@asu.edu.
0027 %   Copyright (c) 2014 by Power System Engineering Research Center (PSERC)
0028 %
0029 %   This file is part of MATPOWER.
0030 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0031 %
0032 %   MATPOWER is free software: you can redistribute it and/or modify
0033 %   it under the terms of the GNU General Public License as published
0034 %   by the Free Software Foundation, either version 3 of the License,
0035 %   or (at your option) any later version.
0036 %
0037 %   MATPOWER is distributed in the hope that it will be useful,
0038 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0039 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0040 %   GNU General Public License for more details.
0041 %
0042 %   You should have received a copy of the GNU General Public License
0043 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0044 %
0045 %   Additional permission under GNU GPL version 3 section 7
0046 %
0047 %   If you modify MATPOWER, or any covered work, to interface with
0048 %   other modules (such as MATLAB code and MEX-files) available in a
0049 %   MATLAB(R) or comparable environment containing parts covered
0050 %   under other licensing terms, the licensors of MATPOWER grant
0051 %   you additional permission to convey the resulting work.
0052 
0053 %% define named indices into bus, gen, branch matrices
0054 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0055     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0056 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0057     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0058     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0059 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0060     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0061     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0062 
0063 %% options
0064 sort_buses = 1;
0065 
0066 %% defaults
0067 if nargin < 3
0068     verbose = 0;
0069 end
0070 haveVlims = 0;
0071 Vmin = 0.9;
0072 Vmax = 1.1;
0073 
0074 %%-----  case identification data  -----
0075 baseMVA = data.id.SBASE;
0076 rev = data.id.REV;
0077 
0078 %%-----  bus data  -----
0079 numbus = data.bus.num;
0080 [nb, ncols] = size(numbus); %% number of buses, number of cols
0081 bus = zeros(nb, VMIN);      %% initialize bus matrix
0082 if rev < 24
0083     bus_name_col = 10;
0084 else
0085     bus_name_col = 2;
0086 end
0087 if sort_buses
0088     [numbus, i] = sortrows(numbus, 1);
0089     bus_name = data.bus.txt(i, bus_name_col);
0090 else
0091     bus_name = data.bus.txt(:, bus_name_col);
0092 end
0093 if rev < 24     %% includes loads
0094     bus(:, [BUS_I BUS_TYPE PD QD GS BS BUS_AREA VM VA BASE_KV ZONE]) = ...
0095         numbus(:, [1:9 11:12]);
0096 elseif rev < 31     %% includes GL, BL
0097     bus(:, [BUS_I BASE_KV BUS_TYPE GS BS BUS_AREA ZONE VM VA]) = ...
0098         numbus(:, [1 3 4 5 6 7 8 9 10]);
0099 else                %% fixed shunts and loads are in their own tables
0100     bus(:, [BUS_I BASE_KV BUS_TYPE BUS_AREA ZONE VM VA]) = ...
0101         numbus(:, [1 3 4 5 6 8 9]);
0102     if ncols >= 11 && all(all(~isnan(numbus(:, [10 11]))))
0103         haveVlims = 1;
0104         bus(:, [VMAX VMIN]) = numbus(:, [10 11]);
0105     end
0106 end
0107 if ~haveVlims  %% add default voltage magnitude limits if not provided
0108     warns{end+1} = sprintf('Using default voltage magnitude limits: VMIN = %g p.u., VMAX = %g p.u.', Vmin, Vmax);
0109     if verbose
0110         fprintf('WARNING: No bus voltage magnitude limits provided.\n         Using defaults: VMIN = %g p.u., VMAX = %g p.u.\n', Vmin, Vmax);
0111     end
0112     bus(:, VMIN) = Vmin;
0113     bus(:, VMAX) = Vmax;
0114 end
0115 
0116 %% create map of external bus numbers to bus indices
0117 i2e = bus(:, BUS_I);
0118 e2i = sparse(i2e, ones(nb, 1), 1:nb, max(i2e), 1);
0119 
0120 %%-----  load data  -----
0121 if rev >= 24
0122     nld = size(data.load.num, 1);
0123     loadbus = e2i(data.load.num(:,1));
0124     %% PSS/E loads are divided into:
0125     %%  1. constant MVA, (I=1)
0126     %%  2. constant current (I=I)
0127     %%  3. constant reactance/resistance (I = I^2)
0128     %% NOTE: reactive power component of constant admittance load is negative
0129     %%       quantity for inductive load and positive for capacitive load
0130     Pd = data.load.num(:,6) + data.load.num(:,8) .* bus(loadbus, VM) ...
0131             + data.load.num(:,10) .* bus(loadbus, VM).^2;
0132     Qd = data.load.num(:,7) + data.load.num(:,9) .* bus(loadbus, VM) ...
0133             - data.load.num(:,11) .* bus(loadbus, VM).^2;
0134     Cld = sparse(1:nld, loadbus, data.load.num(:,3), nld, nb);    %% only in-service-loads
0135     bus(:, [PD QD]) = Cld' * [Pd Qd];
0136 end
0137 
0138 %%-----  fixed shunt data  -----
0139 if isfield(data, 'shunt')   %% rev > 30
0140     nsh = size(data.shunt.num, 1);
0141     shuntbus = e2i(data.shunt.num(:,1));
0142     Csh = sparse(1:nsh, shuntbus, data.shunt.num(:,3), nsh, nb);  %% only in-service shunts
0143     bus(:, [GS BS]) = Csh' * data.shunt.num(:, 4:5);
0144 end
0145 
0146 %%-----  switched shunt data  -----
0147 nswsh = size(data.swshunt.num, 1);
0148 swshuntbus = e2i(data.swshunt.num(:,1));
0149 Cswsh = sparse(1:nswsh, swshuntbus, 1, nswsh, nb);
0150 if rev <= 27
0151     bus(:, BS) = bus(:, BS) + Cswsh' * data.swshunt.num(:, 6);
0152 elseif rev <= 29
0153     bus(:, BS) = bus(:, BS) + Cswsh' * data.swshunt.num(:, 7);
0154 elseif rev < 32
0155     bus(:, BS) = bus(:, BS) + Cswsh' * data.swshunt.num(:, 8);
0156 else
0157     bus(:, BS) = bus(:, BS) + Cswsh' * data.swshunt.num(:, 10);
0158 end
0159 
0160 %%-----  branch data  -----
0161 nbr = size(data.branch.num, 1);
0162 branch = zeros(nbr, ANGMAX);
0163 branch(:, ANGMIN) = -360;
0164 branch(:, ANGMAX) = 360;
0165 branch(:, [F_BUS BR_R BR_X BR_B RATE_A RATE_B RATE_C]) = ...
0166     data.branch.num(:, [1 4 5 6 7 8 9]);
0167 branch(:, T_BUS) = abs(data.branch.num(:, 2));  %% can be negative to indicate metered end
0168 if rev <= 27        %% includes transformer ratio, angle
0169     branch(:, BR_STATUS) = data.branch.num(:, 16);
0170     branch(~isnan(data.branch.num(:, 10)), TAP) = ...
0171         data.branch.num(~isnan(data.branch.num(:, 10)), 10);
0172     branch(~isnan(data.branch.num(:, 11)), SHIFT) = ...
0173         data.branch.num(~isnan(data.branch.num(:, 11)), 11);
0174 else
0175     branch(:, BR_STATUS)    = data.branch.num(:, 14);
0176 end
0177 %% integrate branch shunts (explicit shunts, not line-charging)
0178 ibr = (1:nbr)';
0179 fbus = e2i(branch(:, F_BUS));
0180 tbus = e2i(branch(:, T_BUS));
0181 nzf = find(fbus);               %% ignore branches with bad bus numbers
0182 nzt = find(tbus);
0183 if length(nzf) < nbr
0184     warns{end+1} = sprintf('%d branches have bad ''from'' bus numbers', nbr-length(nzf));
0185     if verbose
0186         fprintf('WARNING: %d branches have bad ''from'' bus numbers\n', nbr-length(nzf));
0187     end
0188 end
0189 if length(nzt) < nbr
0190     warns{end+1} = sprintf('%d branches have bad ''to'' bus numbers', nbr-length(nzt));
0191     if verbose
0192         fprintf('WARNING: %d branches have bad ''to'' bus numbers\n', nbr-length(nzt));
0193     end
0194 end
0195 Cf = sparse(ibr(nzf), fbus(nzf), branch(nzf, BR_STATUS), nbr, nb);  %% only in-service branches
0196 Ct = sparse(ibr(nzt), tbus(nzt), branch(nzt, BR_STATUS), nbr, nb);  %% only in-service branches
0197 if rev <= 27
0198     bus(:, [GS BS]) = bus(:, [GS BS]) + ...
0199         Cf' * data.branch.num(:, 12:13)*baseMVA + ...
0200         Ct' * data.branch.num(:, 14:15)*baseMVA;
0201 else
0202     bus(:, [GS BS]) = bus(:, [GS BS]) + ...
0203         Cf' * data.branch.num(:, 10:11)*baseMVA + ...
0204         Ct' * data.branch.num(:, 12:13)*baseMVA;
0205 end
0206 
0207 %%-----  generator data  -----
0208 ng = size(data.gen.num, 1);
0209 genbus = e2i(data.gen.num(:,1));
0210 gen = zeros(ng, APF);
0211 gen = zeros(ng, MU_QMIN);
0212 gen(:, [GEN_BUS PG QG QMAX QMIN VG MBASE GEN_STATUS PMAX PMIN]) = ...
0213     data.gen.num(:, [1 3 4 5 6 7 9 15 17 18]);
0214 
0215 %%-----  transformer data  -----
0216 if rev > 27
0217     [transformer, bus, warns, bus_name] = psse_convert_xfmr(warns, data.trans2.num, data.trans3.num, verbose, baseMVA, bus, bus_name);
0218     branch = [branch; transformer];
0219 end
0220 
0221 %%-----  two-terminal DC transmission line data  -----
0222 dcline = psse_convert_hvdc(data.twodc.num, bus);
0223 
0224 %% assemble MPC
0225 mpc = struct( ...
0226     'baseMVA',  baseMVA, ...
0227     'bus', bus, ...
0228     'bus_name', {bus_name}, ...
0229     'branch', branch, ...
0230     'gen', gen ...
0231 );
0232 if ~isempty(dcline)
0233     mpc.dcline = dcline;
0234     mpc = toggle_dcline(mpc, 'on');
0235 end

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005