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 https://matpower.org 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 [ng, nc] = size(mpc.gen); 0074 mpc.gen = [mpc.gen; zeros(nld, nc)]; 0075 mpc.gen(ng+1:ng+nld, 1:APF) = 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 %% (optional) generator fuel types 0097 if isfield(mpc, 'genfuel') && iscell(mpc.genfuel) 0098 genfuel = cell(nld, 1); 0099 for k = 1:nld 0100 genfuel{k} = 'dl'; 0101 end 0102 mpc.genfuel = [mpc.genfuel; genfuel]; 0103 end 0104 0105 %% (optional) generator unit types 0106 if isfield(mpc, 'gentype') && iscell(mpc.gentype) 0107 gentype = cell(nld, 1); 0108 for k = 1:nld 0109 gentype{k} = 'DL'; 0110 end 0111 mpc.gentype = [mpc.gentype; gentype]; 0112 end 0113 0114 %% save case, if filename is given 0115 if nargin > 1 && ~isempty(fname) 0116 savecase(fname, mpc, '2'); 0117 end 0118 if nargout > 0 0119 mpc1 = mpc; 0120 end