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-2016, Power Systems Engineering Research Center (PSERC) 0028 % by Alberto Lamadrid, PSERC Cornell 0029 % modified by Ray Zimmerman, PSERC Cornell 0030 % 0031 % This file is part of MATPOWER. 0032 % Covered by the 3-clause BSD License (see LICENSE file for details). 0033 % See http://www.pserc.cornell.edu/matpower/ for more info. 0034 0035 %% define constants 0036 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 0037 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 0038 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 0039 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 0040 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 0041 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost; 0042 0043 mpc = loadcase(mpc0); 0044 0045 %% which loads will be converted? 0046 if nargin < 3 || isempty(idx) 0047 idx = find(mpc.bus(:, PD) > 0); %% by default, all with PD > 0 0048 end 0049 0050 %% set some defaults 0051 voll0 = 5000; %% default value of lost load 0052 mBase = 100; %% generator MVA base 0053 nld = length(idx); 0054 v1 = ones(nld, 1); %% vector of ones 0055 v0 = zeros(nld, 1); %% vector of zeros 0056 0057 %% gen table 0058 gen = [ 0059 mpc.bus(idx, BUS_I), ... %% GEN_BUS 0060 -mpc.bus(idx, PD), ... %% PG 0061 -mpc.bus(idx, QD), ... %% QG 0062 max(0, -mpc.bus(idx, QD)), ... %% QMAX 0063 min(0, -mpc.bus(idx, QD)), ... %% QMIN 0064 mpc.bus(idx, VM), ... %% VG 0065 mBase * v1, ... %% MBASE 0066 v1, ... %% GEN_STATUS 0067 max(0, -mpc.bus(idx, PD)), ... %% PMAX 0068 min(0, -mpc.bus(idx, PD)), ... %% PMIN 0069 zeros(nld, 6), ... %% capability curve 0070 Inf(nld, 4), ... %% ramp rates 0071 zeros(nld, 1), ... %% participation factor 0072 ]; 0073 mpc.gen = [mpc.gen; gen]; %% add dispatchable loads 0074 0075 %% bus table 0076 mpc.bus(idx, [PD, QD]) = 0; %% zero out fixed loads 0077 0078 %% gencost table 0079 nc = size(mpc.gencost, 2); 0080 if nargin < 4 0081 voll = voll0 * v1; 0082 elseif length(voll) == 1 0083 voll = voll * v1; 0084 end 0085 gencost = [ %% use a linear, polynomial cost format 0086 POLYNOMIAL*v1, ... %% MODEL 0087 zeros(nld, 2), ... %% STARTUP, SHUTDOWN 0088 2 * v1, ... %% NCOST 0089 voll, ... %% COST, linear term 0090 zeros(nld, nc-5) ... %% constant term and zero-padding 0091 ]; 0092 mpc.gencost = [mpc.gencost; gencost]; 0093 0094 %% save case, if filename is given 0095 if nargin > 1 && ~isempty(fname) 0096 savecase(fname, mpc, '2'); 0097 end 0098 if nargout > 0 0099 mpc1 = mpc; 0100 end