<div dir="ltr"><div class="gmail_extra"><br>
<br><br><div class="gmail_quote">On Thu, Oct 10, 2013 at 2:33 PM, Jed Brown <span dir="ltr"><<a href="mailto:jedbrown@mcs.anl.gov" target="_blank">jedbrown@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">Christophe Ortiz <<a href="mailto:christophe.ortiz@ciemat.es">christophe.ortiz@ciemat.es</a>> writes:<br>
> I am facing some problems with this when filling in the Jacobian for a<br>
> problem of 2 diffusion equations (dof=2). See ex25.c.<br>
><br>
> If I'm right, then for node i, there should be 3 blocks of 2x2:<br>
><br>
> X 0 | Y 0 | X 0<br>
> 0 X | 0 Y | 0 X<br>
><br>
> Is it correct ?<br>
><br>
> First I tried what you said, to pass a one dimensional array:<br>
> row = i;<br>
> cols[0] = i-1; cols[1] = i; cols[2] = i+1;<br>
><br>
> j = 0;<br>
> vallin[j] = X; vallin[j++] = 0;<br>
<br>
</div>The expression j++ in vallin[j++] is post-increment, so the two<br>
statements above both write to vallin[0] and vallin[11] is undefined<br>
(whatever garbage was in the array before).<br></blockquote><div><br></div><div>Thanks.</div><div>I just found out few minutes ago :-). Hehe. The point is that I come from 15 years of Fortran...I have to refresh the C that I learnt at Faculty and that is deeply buried in my memory !</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
> Then, I tried a 2-dimensional array. I saw in some examples of ts/tutorials<br>
> that it is also possible to pass a multi-dimensional arrays. After all, in<br>
> memory the rows are stored contiguously, so I guess it is equivalent to a<br>
> one-dimensional array.<br>
><br>
> j = 0; k = 0;<br>
> valdiff[j][k] = X; valdiff[j][k++] = 0;<br>
<br>
</div>Same problem here.<br>
<div class="im"><br>
> valdiff[j][k++] = Y; valdiff[j][k++] = 0;<br>
> valdiff[j][k++] = X; valdiff[j][k++] = 0;<br>
><br>
> j= 1; k = 0;<br>
> valdiff[j][k] = 0; valdiff[j][k++] = X;<br>
> valdiff[j][k++] = 0; valdiff[j][k++] = Y;<br>
> valdiff[j][k++] = 0; valdiff[j][k++] = X;<br>
><br>
> ierr =<br>
> MatSetValuesBlocked(*Jpre,1,&row,3,cols,&valdiff[0][0],INSERT_VALUES);<br>
><br>
> I get the same error message.<br>
> What did I do wrong ?<br>
><br>
> In ex25.c they use a 3-dimensional array:<br>
><br>
> const PetscScalar vals[2][3][2] = {{{dxxL,0},{a *hx+dxx0,0},{dxxR,0}},<br>
><br>
> {{0,dxxL},{0,a*hx+dxx0},{0,dxxR}}};<br>
><br>
> and &vals[0][0][0] is passed in MatSetValuesBlocked (....,....,<br>
> &vals[0][0][0],...), and it works, though I don't understand how.<br>
<br>
</div>That grouping in the 3D array is the same ordering, but (perhaps) makes<br>
it easier to see which expression refers to which entry of the matrix.<br></blockquote><div><br></div><div>Yes, probably. </div></div><br></div></div>