[petsc-users] Mat indices

Feng Shi fshi at fit.edu
Sun Sep 21 13:21:11 CDT 2014


Hi all,

For 2-D finite difference problems with dof>1,to use MatSetValuesBlocked, what should be the indices used in that routine? Am I right if I just use the indices just like dof=1, but set (5*dof^2) values at one time?

Specifically, I'm trying to use implicit TS solver with dof>1, as in example src/ts/examples/tutorials/ex10. I understand for 1-D finite diffrence cases, we have (3 by dof^2) matrix elements, and we can use as in the example: 
MatSetValuesBlocked(B,1,&i,3,col,&K[0][0],INSERT_VALUES);
to insert/form the Jacobian. In my 2-D cases with dof=3, I use 5-point finite difference regime, which means I will have (5*3^2=45) elements Jacobian to be set at one time as in the example, right? If I use the statement "Matstencil row, col[5]" as indices to insert values, after we set: "row.i=i, row.j=j and col[1:5].i=..., col[1:5].j=...", then just simply use:
MatSetValuesBlocked(B,1,&row, 5, &col, &K[0][0],INSERT_VALUES);
to insert these (5*3^2) values to form the Jacobian?

I'm also confused by the dof defined in the Mat. Does it mean for each node, there are (dof^2) elements?

Thank you in advance!

Best regards,

________________________________________
From: Barry Smith [bsmith at mcs.anl.gov]
Sent: Sunday, September 21, 2014 11:57 AM
To: Feng  Shi
Cc: petsc-users at mcs.anl.gov
Subject: Re: [petsc-users] Mat indices

  Mat indices always start with 0 in global indexing used by MatSetValues, MatSetValuesBlocked

  With “local orderings” on can chose to use whatever indexing makes sense for your local ordering, this is used with MatSetValuesLocal(), MatSetValuesBlockedLocal().

   Barry

On Sep 21, 2014, at 10:35 AM, Feng Shi <fshi at fit.edu> wrote:

> Hi all,
>
> When setting the Mat indices, like the example: src/ts/examples/tutorials/ex10, I noticed that on line
>
> 508:     col[0] = i-1;
> 509:     col[1] = i;
> 510:     col[2] = i+1<info.mx ? i+1 : -1;
> 511:     MatSetValuesBlocked<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValuesBlocked.html#MatSetValuesBlocked>(B,1,&i,3,col,&K[0][0],INSERT_VALUES<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES>);
>
> How about the case that when i=0, then col[0]=-1 and i=info.mx then col[2]=-1?
> My question is, is the Mat default indices starting from -1?
>
> Thank you in advance!
>
> Best regards,
>
> Feng



More information about the petsc-users mailing list