0001 function mpc_vl = prepare_maxloadlim(mpc,dir_mll,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 define_constants;
0026 n_gen = size(mpc.gen,1);
0027 mpc0 = mpc;
0028
0029 input_checker = inputParser;
0030
0031
0032 default_qlim = 1;
0033 check_qlim = @(x)(isnumeric(x) && isscalar(x));
0034 addParameter(input_checker,'use_qlim',default_qlim,check_qlim);
0035
0036
0037 default_vlim = [];
0038 check_vlim = @(x)(isnumeric(x) && all(floor(x) == ceil(x)));
0039 addParameter(input_checker,'Vlims_bus_nb',default_vlim,check_vlim);
0040
0041
0042 default_dir_var_gen = [];
0043 check_dir_var_gen = @(x)(isempty(x) || (isnumeric(x) && iscolumn(x)));
0044 addParameter(input_checker,'dir_var_gen',default_dir_var_gen,check_dir_var_gen);
0045
0046
0047 default_idx_var_gen = [];
0048 check_idx_var_gen = @(x)(isempty(x) || (isnumeric(x) && iscolumn(x)));
0049 addParameter(input_checker,'idx_var_gen',default_idx_var_gen,check_idx_var_gen);
0050
0051
0052 input_checker.KeepUnmatched = true;
0053 parse(input_checker,varargin{:});
0054 options = input_checker.Results;
0055
0056
0057
0058
0059 if size(mpc.bus,1) ~= length(dir_mll)
0060 error_msg = ['The number of directions of load increases ' ...
0061 'is not equal to the number of buses'];
0062 error(error_msg);
0063 end
0064
0065
0066 idx_zero_loads = mpc.bus(:,PD) == 0;
0067 if sum(dir_mll(idx_zero_loads))>0
0068 error('Directions of load increases cannot be defined for zero loads.');
0069 end
0070
0071
0072
0073 if size(options.idx_var_gen,1) ~= size(options.dir_var_gen,1)
0074 error('The number of variable generators does not match the direction vector.');
0075 end
0076
0077
0078
0079 [ref_init, ~] = bustypes(mpc.bus, mpc.gen);
0080 idx_gen_slack = find(mpc.gen(1:n_gen,GEN_BUS) == ref_init);
0081 if sum(ismember(options.idx_var_gen,idx_gen_slack)) ~= 0
0082 error('The direction vector cannot include changes at the slack bus');
0083 end
0084
0085
0086
0087 mpopt = mpoption('pf.enforce_q_lims', options.use_qlim,'verbose',0,'out.all',0);
0088 mpc = runpf(mpc,mpopt);
0089
0090 mpc.bus(:,BUS_TYPE) = mpc0.bus(:,BUS_TYPE);
0091
0092 mpc_vl = load2disp(mpc);
0093
0094
0095 dir_mll = dir_mll(mpc.bus(:, PD) > 0);
0096
0097
0098 mpc_vl.dir_mll = dir_mll;
0099
0100
0101
0102
0103 dir_var_gen_all = sparse(options.idx_var_gen,1,options.dir_var_gen,...
0104 size(mpc_vl.gen,1),1);
0105
0106 mpc_vl.dir_var_gen = options.dir_var_gen;
0107 mpc_vl.idx_var_gen = options.idx_var_gen;
0108 mpc_vl.dir_var_gen_all = dir_var_gen_all;
0109
0110
0111
0112 idx_vl = isload(mpc_vl.gen);
0113 mpc_vl.gen(idx_vl,PMIN) = 300*mpc_vl.gen(idx_vl,PMIN);
0114
0115
0116 idx_vl_inductive = idx_vl & mpc_vl.gen(:,QMAX) == 0;
0117 idx_vl_capacitive = idx_vl & mpc_vl.gen(:,QMIN) == 0;
0118 tanphi_vl_ind = mpc_vl.gen(idx_vl_inductive,QG)./mpc_vl.gen(idx_vl_inductive,PG);
0119 tanphi_vl_cap = mpc_vl.gen(idx_vl_capacitive,QG)./mpc_vl.gen(idx_vl_capacitive,PG);
0120 mpc_vl.gen(idx_vl_inductive,QMIN) = mpc_vl.gen(idx_vl_inductive,PMIN).*tanphi_vl_ind;
0121 mpc_vl.gen(idx_vl_capacitive,QMAX) = mpc_vl.gen(idx_vl_capacitive,PMIN).*tanphi_vl_cap;
0122
0123 mpc_vl.gencost(:,COST:end) = 0;
0124
0125
0126
0127 [ref, pv, pq] = bustypes(mpc_vl.bus, mpc_vl.gen);
0128 idx_gen_pv = find(ismember(mpc_vl.gen(1:n_gen,GEN_BUS),pv));
0129
0130
0131 idx_non_var_pv = setdiff(idx_gen_pv,options.idx_var_gen(options.dir_var_gen~=0));
0132 mpc_vl.gen(idx_non_var_pv,PMIN) = mpc_vl.gen(idx_non_var_pv,PG);
0133 mpc_vl.gen(idx_non_var_pv,PMAX) = mpc_vl.gen(idx_non_var_pv,PG);
0134
0135 mpc_vl.branch(:,RATE_A) = 9999;
0136
0137 idx_gen_slack = find(mpc_vl.gen(1:n_gen,GEN_BUS) == ref);
0138 mpc_vl.gen(idx_gen_slack,[QMAX,PMAX]) = 9999;
0139
0140 mpc_vl.gen(idx_gen_slack,[QMIN,PMIN]) = -9999;
0141
0142
0143 mpc_vl.bus(pq,VMIN) = 0.01;
0144 mpc_vl.bus(pq,VMAX) = 10;
0145
0146 mpc_vl.bus(ref,VMAX) = mpc_vl.gen(idx_gen_slack(1),VG);
0147 mpc_vl.bus(ref,VMIN) = mpc_vl.gen(idx_gen_slack(1),VG);
0148
0149 for bb = 1:length(pv)
0150 idx_gen_at_bb = find(ismember(mpc_vl.gen(1:n_gen,GEN_BUS),pv(bb)));
0151 mpc_vl.bus(pv(bb),VMAX) = mpc_vl.gen(idx_gen_at_bb(1),VG);
0152 mpc_vl.bus(pv(bb),VMIN) = 0.01;
0153
0154
0155 end
0156
0157
0158 if ~options.use_qlim
0159 mpc_vl.gen(idx_gen_pv,QMAX) = 9999;
0160 mpc_vl.gen(idx_gen_pv,QMIN) = -9999;
0161 for bb = 1:length(pv)
0162 idx_gen_at_bb = find(ismember(mpc_vl.gen(1:n_gen,GEN_BUS),pv(bb)));
0163 mpc_vl.bus(pv(bb),VMAX) = mpc_vl.gen(idx_gen_at_bb(1),VG);
0164 mpc_vl.bus(pv(bb),VMIN) = mpc_vl.gen(idx_gen_at_bb(1),VG);
0165 end
0166 end
0167 if ~isempty(options.Vlims_bus_nb)
0168 idx_gen_vlim = find(ismember(mpc_vl.gen(:,GEN_BUS),options.Vlims_bus_nb));
0169 mpc_vl.bus(options.Vlims_bus_nb,VMAX) = mpc_vl.gen(idx_gen_vlim,VG);
0170 mpc_vl.bus(options.Vlims_bus_nb,VMIN) = mpc_vl.gen(idx_gen_vlim,VG);
0171 end
0172
0173
0174 mpc_vl = add_userfcn(mpc_vl, 'ext2int', @userfcn_direction_mll_ext2int);
0175
0176 mpc_vl = add_userfcn(mpc_vl, 'formulation', @userfcn_direction_mll_formulation);