On Wed, Oct 9, 2013 at 3:13 PM, Christophe Ortiz <[email protected] > wrote:
> > On Wed, Oct 9, 2013 at 2:56 PM, Jed Brown <[email protected]> wrote: > >> Christophe Ortiz <[email protected]> writes: >> >> > Hi, >> > >> > I am building my Jacobian (IJacobian) with dof > 1 and I am considering >> to >> > use either MatSetValuesLocal (what you did in ex10.c from >> > advection-diffusion) or MatSetValuesBlocked. >> > >> > Which one do you recommend ? >> >> MatSetValuesBlocked or MatSetValuesBlockedLocal. >> > > Ok. > > >> >> > For the moment I am trying to understand how MatSetValuesBlocked works >> from >> > the various examples given in ts tutorials, but there is a mistery for >> > me...In these examples, the block size is not set. So when m and idxm[] >> (n >> > and idxn[]) are passed in, how does PETSc know the correspondance with >> > global row and column indices in the matrix ? >> > >> > For instance, ex22.c >> > >> > for (i=info.xs; i<info.xs+info.xm; i++) { >> > const PetscReal *k = user->k; >> > PetscScalar v[2][2]; >> > >> > v[0][0] = a + k[0]; v[0][1] = -k[1]; >> > v[1][0] = -k[0]; v[1][1] = a+k[1]; >> > MatSetValuesBlocked(*Jpre,1,&i,1,&i,&v[0][0],INSERT_VALUES); >> > } >> > >> > Here 4 terms due to chemical reactions are passed to the matrix at once. >> > &i is passed for indice of row and column, which is supposed to be the >> > indice of the block. But if the blocksize is not set, how PETSc knows to >> > which row/colum it really corresponds in the matrix ? >> >> DMCreateMatrix() set the block size to match the "dof" argument to >> DMDACreate1d. >> > > I suspected it ! It's smart ! > > >> >> > For instance, if we take the example from petsc (MatSetValuesBlocked >> page), >> > what should I do to pass the block of values 3, 4, 7 and 8 with >> > MatSetValuesBlocked ? >> > >> > 1 2 | 3 4 >> > 5 6 | 7 8 >> > - - - | - - - >> > 9 10 | 11 12 >> > 13 14 | 15 16 >> >> Block row 0, block column 1. (Count from 0.) >> > > > And if with the previous case I would like to pass the values 1, 2, 3, 4, 5, 6, 7 and 8 (the two first rows) what is the matrix val[ ] that I should pass ? Should it be a matrix val[2][4] ? If I understand correctly it would be 1 block row, the block row indice being 0; 2 block columns, the column block indices being 0 and 1: indices of block rows and block columns: row = 0 col[0]=0; col[1]=1 MatSetValuesBlocked(*Jpre,1,&row,2,&col,&v[0][0],INSERT_VALUES); Is it correct ? Is the matrix val correct ? Christophe
