Home > matpower6.0 > makeSbus.m

makeSbus

PURPOSE ^

MAKESBUS Builds the vector of complex bus power injections.

SYNOPSIS ^

function [Sbus, dSbus_dVm] = makeSbus(baseMVA, bus, gen, mpopt, Vm, Sg)

DESCRIPTION ^

MAKESBUS   Builds the vector of complex bus power injections.
   SBUS = MAKESBUS(BASEMVA, BUS, GEN)
   SBUS = MAKESBUS(BASEMVA, BUS, GEN, MPOPT, VM)
   SBUS = MAKESBUS(BASEMVA, BUS, GEN, MPOPT, VM, SG)
   returns the vector of complex bus power injections, that is, generation
   minus load. Power is expressed in per unit. If the MPOPT and VM arguments
   are present it evaluates any ZIP loads based on the provided voltage
   magnitude vector. If VM is empty, it assumes nominal voltage. If SG is
   provided, it is a complex ng x 1 vector of generator power injections in
   p.u., and overrides the PG and QG columns in GEN, using GEN only for
   connectivity information.

   [SBUS, DSBUS_DVM] = MAKESBUS(BASEMVA, BUS, GEN, MPOPT, VM)
   With two output arguments, it computes the partial derivative of the
   bus injections with respect to voltage magnitude, leaving the first
   return value SBUS empty. If VM is empty, it assumes no voltage dependence
   and returns a sparse zero matrix.

   See also MAKEYBUS.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Sbus, dSbus_dVm] = makeSbus(baseMVA, bus, gen, mpopt, Vm, Sg)
0002 %MAKESBUS   Builds the vector of complex bus power injections.
0003 %   SBUS = MAKESBUS(BASEMVA, BUS, GEN)
0004 %   SBUS = MAKESBUS(BASEMVA, BUS, GEN, MPOPT, VM)
0005 %   SBUS = MAKESBUS(BASEMVA, BUS, GEN, MPOPT, VM, SG)
0006 %   returns the vector of complex bus power injections, that is, generation
0007 %   minus load. Power is expressed in per unit. If the MPOPT and VM arguments
0008 %   are present it evaluates any ZIP loads based on the provided voltage
0009 %   magnitude vector. If VM is empty, it assumes nominal voltage. If SG is
0010 %   provided, it is a complex ng x 1 vector of generator power injections in
0011 %   p.u., and overrides the PG and QG columns in GEN, using GEN only for
0012 %   connectivity information.
0013 %
0014 %   [SBUS, DSBUS_DVM] = MAKESBUS(BASEMVA, BUS, GEN, MPOPT, VM)
0015 %   With two output arguments, it computes the partial derivative of the
0016 %   bus injections with respect to voltage magnitude, leaving the first
0017 %   return value SBUS empty. If VM is empty, it assumes no voltage dependence
0018 %   and returns a sparse zero matrix.
0019 %
0020 %   See also MAKEYBUS.
0021 
0022 %   MATPOWER
0023 %   Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC)
0024 %   by Ray Zimmerman, PSERC Cornell
0025 %
0026 %   This file is part of MATPOWER.
0027 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0028 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0029 
0030 %% define named indices into bus, gen matrices
0031 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0032     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0033 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0034     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0035     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0036 
0037 %% default inputs
0038 if nargin < 5
0039     Vm = [];
0040     if nargin < 4
0041         mpopt = [];
0042     end
0043 end
0044 nb = size(bus, 1);
0045 
0046 %% get load parameters
0047 Sd = makeSdzip(baseMVA, bus, mpopt);
0048 
0049 if nargout == 2
0050     Sbus = [];
0051     if isempty(Vm)
0052         dSbus_dVm = sparse(nb, nb);
0053     else
0054         dSbus_dVm = -(spdiags(Sd.i + 2 * Vm .* Sd.z, 0, nb, nb));
0055     end
0056 else
0057     %% compute per-bus generation in p.u.
0058     on = find(gen(:, GEN_STATUS) > 0);      %% which generators are on?
0059     gbus = gen(on, GEN_BUS);                %% what buses are they at?
0060     ngon = size(on, 1);
0061     Cg = sparse(gbus, (1:ngon)', 1, nb, ngon);  %% connection matrix
0062                                                 %% element i, j is 1 if
0063                                                 %% gen on(j) at bus i is ON
0064     if nargin > 5 && ~isempty(Sg)
0065         Sbusg = Cg * Sg(on);
0066     else
0067         Sbusg = Cg * (gen(on, PG) + 1j * gen(on, QG)) / baseMVA;
0068     end
0069 
0070     %% compute per-bus loads in p.u.
0071     if isempty(Vm)
0072         Vm = ones(nb, 1);
0073     end
0074     Sbusd = Sd.p + Sd.i .* Vm + Sd.z .* Vm.^2;
0075 
0076     %% form net complex bus power injection vector
0077     %% (power injected by generators + power injected by loads)
0078     Sbus = Sbusg - Sbusd;
0079 end

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005