LOAD2DISP Converts fixed loads to dispatchable. MPC = LOAD2DISP(MPC0); MPC = LOAD2DISP(MPC0, FNAME); MPC = LOAD2DISP(MPC0, FNAME, IDX); MPC = LOAD2DISP(MPC0, FNAME, IDX, VOLL); Takes a MATPOWER case file or struct and converts fixed loads to dispatchable loads and returns the resulting case struct. Inputs are as follows: MPC0 - File name or struct with initial MATPOWER case. FNAME (optional) - Name to use to save resulting MATPOWER case. If empty, the case will not be saved to a file. IDX (optional) - Vector of bus indices of loads to be converted. If empty or not supplied, it will convert all loads with positive real power demand. VOLL (optional) - Scalar or vector specifying the value of lost load to use as the value for the dispatchable loads. If it is a scalar it is used for all loads, if a vector, the dimension must match that of IDX. Default is $5000 per MWh.
0001 function mpc1 = load2disp(mpc0, fname, idx, voll) 0002 %LOAD2DISP Converts fixed loads to dispatchable. 0003 % MPC = LOAD2DISP(MPC0); 0004 % MPC = LOAD2DISP(MPC0, FNAME); 0005 % MPC = LOAD2DISP(MPC0, FNAME, IDX); 0006 % MPC = LOAD2DISP(MPC0, FNAME, IDX, VOLL); 0007 % 0008 % Takes a MATPOWER case file or struct and converts fixed loads to 0009 % dispatchable loads and returns the resulting case struct. Inputs 0010 % are as follows: 0011 % 0012 % MPC0 - File name or struct with initial MATPOWER case. 0013 % 0014 % FNAME (optional) - Name to use to save resulting MATPOWER case. If empty, 0015 % the case will not be saved to a file. 0016 % 0017 % IDX (optional) - Vector of bus indices of loads to be converted. If empty 0018 % or not supplied, it will convert all loads with positive real 0019 % power demand. 0020 % 0021 % VOLL (optional) - Scalar or vector specifying the value of lost 0022 % load to use as the value for the dispatchable loads. If it is 0023 % a scalar it is used for all loads, if a vector, the dimension 0024 % must match that of IDX. Default is $5000 per MWh. 0025 0026 % MATPOWER 0027 % Copyright (c) 2010-2015 by Power System Engineering Research Center (PSERC) 0028 % by Alberto Lamadrid, PSERC Cornell 0029 % modified by Ray Zimmerman, PSERC Cornell 0030 % 0031 % $Id: load2disp.m 2644 2015-03-11 19:34:22Z ray $ 0032 % 0033 % This file is part of MATPOWER. 0034 % Covered by the 3-clause BSD License (see LICENSE file for details). 0035 % See http://www.pserc.cornell.edu/matpower/ for more info. 0036 0037 %% define constants 0038 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 0039 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 0040 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 0041 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 0042 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 0043 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost; 0044 0045 mpc = loadcase(mpc0); 0046 0047 %% which loads will be converted? 0048 if nargin < 3 || isempty(idx) 0049 idx = find(mpc.bus(:, PD) > 0); %% by default, all with PD > 0 0050 end 0051 0052 %% set some defaults 0053 voll0 = 5000; %% default value of lost load 0054 mBase = 100; %% generator MVA base 0055 nld = length(idx); 0056 v1 = ones(nld, 1); %% vector of ones 0057 v0 = zeros(nld, 1); %% vector of zeros 0058 0059 %% gen table 0060 gen = [ 0061 mpc.bus(idx, BUS_I), ... %% GEN_BUS 0062 -mpc.bus(idx, PD), ... %% PG 0063 -mpc.bus(idx, QD), ... %% QG 0064 max(0, -mpc.bus(idx, QD)), ... %% QMAX 0065 min(0, -mpc.bus(idx, QD)), ... %% QMIN 0066 mpc.bus(idx, VM), ... %% VG 0067 mBase * v1, ... %% MBASE 0068 v1, ... %% GEN_STATUS 0069 max(0, -mpc.bus(idx, PD)), ... %% PMAX 0070 min(0, -mpc.bus(idx, PD)), ... %% PMIN 0071 zeros(nld, 6), ... %% capability curve 0072 Inf(nld, 4), ... %% ramp rates 0073 zeros(nld, 1), ... %% participation factor 0074 ]; 0075 mpc.gen = [mpc.gen; gen]; %% add dispatchable loads 0076 0077 %% bus table 0078 mpc.bus(idx, [PD, QD]) = 0; %% zero out fixed loads 0079 0080 %% gencost table 0081 nc = size(mpc.gencost, 2); 0082 if nargin < 4 0083 voll = voll0 * v1; 0084 elseif length(voll) == 1 0085 voll = voll * v1; 0086 end 0087 gencost = [ %% use a linear, polynomial cost format 0088 POLYNOMIAL*v1, ... %% MODEL 0089 zeros(nld, 2), ... %% STARTUP, SHUTDOWN 0090 2 * v1, ... %% NCOST 0091 voll, ... %% COST, linear term 0092 zeros(nld, nc-5) ... %% constant term and zero-padding 0093 ]; 0094 mpc.gencost = [mpc.gencost; gencost]; 0095 0096 %% save case, if filename is given 0097 if nargin > 1 && ~isempty(fname) 0098 savecase(fname, mpc, '2'); 0099 end 0100 if nargout > 0 0101 mpc1 = mpc; 0102 end