Hi Ray,

Thank you for the reply. 

I didn't change the BUS_TYPE, and doing so may have avoided the error entirely 
(I can't verify at the moment, sorry). Regardless, it may still be reasonable 
to add the pre-allocation of Bf to makeBdc() to ensure the code is robust 
against odd use-cases like mine. Otherwise I'm sure people running into the 
error will google this discussion and be able to solve the problem on their own.

Kind Regards,

Samuel

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Ray Zimmerman
Sent: 15. ágúst 2016 19:56
To: MATPOWER Discussion List <[email protected]>
Subject: Re: Matpower6.0b1 - bug report: makeBdc() dimensioning of Bf

Thank you for your detailed description.

Did you make bus 24 as an isolated bus after disconnecting it, by setting it’s 
BUS_TYPE to NONE?  MATPOWER does not automatically check for connectivity, so 
an isolated bus that is not marked as such will produce errors.

As to the reasons for the syntax used in line 66 of makeBdc() 
<http://www.pserc.cornell.edu/matpower/docs/ref/matpower6.0b1/makeBdc.html>, 
I’m pretty sure it was computational efficiency.

    Ray


> On Aug 9, 2016, at 12:05 PM, Samuel Perkin <[email protected]> wrote:
> 
> 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); TCL MERGE ERROR ( 08/15/2016 
> 15:55:43 ): "extra characters after close-quote"
OutmailID: 120690811, List: 'matpower-l', MemberID: 76238625
SCRIPT: "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   --Apple-Mail=_678BB122-59B1-42C2-9B13-C203C7D3D134 
Content-Transfer-Encoding: quoted-printable Content-Type: text/html;  
charset="utf-8"  <html><head><meta http-equiv="Content-Type" content="text/html 
charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: 
space; -webkit-line-break: after-white-space;" class=""><div class="">Thank you 
for your detailed description.</div><div class=""><br class=""></div>Did you 
make bus 24 as an isolated bus after disconnecting it, by setting it’s BUS_TYPE 
to NONE? &nbsp;MATPOWER does not automatically check for connectivity, so an 
isolated bus that is not marked as such will produce errors.<div class=""><br 
class=""></div><div class="">As to the reasons for the syntax used in line 66 
of&nbsp;<a 
href="http://www.pserc.cornell.edu/matpower/docs/ref/matpower6.0b1/makeBdc.html";
 class=""><font face="Courier" class="">makeBdc()</font></a>, I’m pretty sure 
it was computational efficiency.</div><div class=""><br class=""></div><div 
class="">&nbsp; &nbsp; Ray<br class=""><div class=""><br class=""><div 
class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 
Aug 9, 2016, at 12:05 PM, Samuel Perkin &lt;<a 
href="mailto:[email protected]"; class="">[email protected]</a>&gt; 
wrote:</div><br class="Apple-interchange-newline"><div class=""><div 
class="WordSection1" style="page: WordSection1; font-family: Helvetica; 
font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 
normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 
0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 
0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0cm 0cm 0.0001pt; 
font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" 
class="">Dear all/any,<o:p class=""></o:p></span></div><div style="margin: 0cm 
0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" 
class=""><span lang="IS" class=""><o:p class="">&nbsp;</o:p></span></div><div 
style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, 
sans-serif;" class=""><span lang="IS" class="">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.<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; 
font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" 
class=""><o:p class="">&nbsp;</o:p></span></div><div style="margin: 0cm 0cm 
0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b 
class=""><span lang="IS" class="">Scenario:<span 
class="Apple-converted-space">&nbsp;</span></span></b><span lang="IS" 
class="">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.<o:p class=""></o:p></span></div><div 
style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, 
sans-serif;" class=""><b class=""><span lang="IS" class="">Fatal error 
output:</span></b><span lang="IS" class=""><span 
class="Apple-converted-space">&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
 class="Apple-converted-space">&nbsp;</span><span style="color: red;" 
class="">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<o:p class=""></o:p></span></span></div><div 
style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, 
sans-serif;" class=""><span lang="IS" style="color: red;" 
class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 Error in toggle_iflims&gt;userfcn_iflims_formulation (line 158) om= 
add_constraints(om,‘iflims‘,Aif,lif,uif,{‚Va‘})<o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" style="color: 
red;" 
class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 Error in run_userfcn (line 37) rv = feval(userfcn.(stage)(k).fcn,rv,args);"
 nifs<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; 
font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" 
style="color: red;" 
class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 Error in opf_setup (line 260) om = run_userfcn(userfcn, ‚formulation´,om);<o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" style="color: 
red;" 
class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 Error in opf (line 198) om = opf_setup(mpc,mpopt);<o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" style="color: 
red;" 
class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 Error in runopf (line 75) [r, success] = opf(casedata,mpopt);<o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" style="color: 
red;" class=""><o:p class="">&nbsp;</o:p></span></div><div style="margin: 0cm 
0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" 
class=""><span lang="IS" class="">I traced this fatal error back to the 
formulation of ‚Bf‘ on line 66 of makeBdc():<o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" class=""><o:p 
class="">&nbsp;</o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; 
font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span 
style="font-size: 10pt; font-family: 'Courier New';" class="">Bf = sparse(i, 
[f; t], [b; -b]);&nbsp;&nbsp;&nbsp;<span 
class="Apple-converted-space">&nbsp;</span></span><span style="font-size: 10pt; 
font-family: 'Courier New'; color: rgb(34, 139, 34);" class="">% = spdiags(b, 
0, nl, nl) * Cft;</span><span style="font-size: 10pt; font-family: 'Courier 
New';" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 
0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span 
lang="IS" class=""><o:p class="">&nbsp;</o:p></span></div><div style="margin: 
0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" 
class=""><span lang="IS" class="">The size of the sparse array is defined by 
[f;t], which contains the from and to bus for all<span 
class="Apple-converted-space">&nbsp;</span><b class="">active</b><span 
class="Apple-converted-space">&nbsp;</span>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:<o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" class=""><o:p 
class="">&nbsp;</o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; 
font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span 
style="font-size: 10pt; font-family: 'Courier New';" class="">Bf = spdiags(b, 
0, nl, nl) * Cft;</span><span style="font-size: 10pt; font-family: 'Courier 
New'; color: rgb(34, 139, 34);" class=""><span 
class="Apple-converted-space">&nbsp;</span>%solution option 1</span><span 
style="font-size: 10pt; font-family: 'Courier New';" class=""><o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" class=""><o:p 
class="">&nbsp;</o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; 
font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" 
class="">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():<o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 10pt; 
font-family: 'Courier New';" class=""><o:p 
class="">&nbsp;</o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; 
font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span 
style="font-size: 10pt; font-family: 'Courier New';" class="">Bf = 
sparse(0,nl,nb);</span><span class="Apple-converted-space">&nbsp;</span><span 
style="font-size: 10pt; font-family: 'Courier New'; color: rgb(34, 139, 34);" 
class="">%solution option 2</span><span lang="IS" class=""><o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" class=""><o:p 
class="">&nbsp;</o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; 
font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" 
class="">After implementing either of the above solutions in makeBdc(), the 
fatal error no longer occurred. I hope that this is useful.<o:p 
class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 
11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" class=""><o:p 
class="">&nbsp;</o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; 
font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="IS" 
class="">Kind Regards,<o:p class=""></o:p></span></div><div style="margin: 0cm 
0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" 
class=""><span lang="IS" class=""><o:p class="">&nbsp;</o:p></span></div><div 
style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, 
sans-serif;" class=""><span lang="IS" class="">Samuel 
Perkin</span></div></div></div></blockquote></div><br 
class=""></div></div></div></body></html>

Reply via email to