Dear all/any,

Whilst using Matpower for contingency analysis I was recieving a fatal error, 
which I tracked back to the makeBdc() function. I have provided a description 
of the scenario, the fatal error output, and a description of the underlying 
bug, followed by a solution.

Scenario: IEEE RTS96 test case with user-defined constraints related to 
interface flows, and failure of lines 27 and 7 which disconnects the 24th bus 
(of 24) from the rest of the system.
Fatal error output:          Error using opt_model/add_constraints (line 168) 
@opt_model/add_constraints: number of columns of A does not match number of 
variables, A is 1 x 23, nv = 24
                                                Error in 
toggle_iflims>userfcn_iflims_formulation (line 158) om= 
add_constraints(om,'iflims',Aif,lif,uif,{'Va'})
                                                Error in run_userfcn (line 37) 
rv = feval(userfcn.(stage)(k).fcn,rv,args); %% nifs
                                                Error in opf_setup (line 260) 
om = run_userfcn(userfcn, 'formulation´,om);
                                                Error in opf (line 198) om = 
opf_setup(mpc,mpopt);
                                                Error in runopf (line 75) [r, 
success] = opf(casedata,mpopt);

I traced this fatal error back to the formulation of 'Bf' on line 66 of 
makeBdc():

Bf = sparse(i, [f; t], [b; -b]);    % = spdiags(b, 0, nl, nl) * Cft;

The size of the sparse array is defined by [f;t], which contains the from and 
to bus for all active branches, and therefore the maximum value of 'f' or 't' 
will be 23 if the 24th bus is disconnected. This error then propagates through 
a few functions until it results in the fatal error stated above. Calculating 
Bf using the commented out part of line 66:

Bf = spdiags(b, 0, nl, nl) * Cft; %solution option 1

results in the correct dimensions, and solves the error. I wonder why this 
formulation was replaced? Is it for syntax or readability reasons? If the new 
syntax is preferred, the problem can also be address by adding the following 
preallocation of 'Bf' before line 66 in makeBdc():

Bf = sparse(0,nl,nb); %solution option 2

After implementing either of the above solutions in makeBdc(), the fatal error 
no longer occurred. I hope that this is useful.

Kind Regards,

Samuel Perkin

Reply via email to