[petsc-users] MatSetValues vs MatSetValuesBlocked

Nidish nb25 at rice.edu
Mon Aug 10 17:48:27 CDT 2020


Ah I get it, thanks!

On 8/10/20 5:40 PM, Matthew Knepley wrote:
> On Mon, Aug 10, 2020 at 6:26 PM Nidish <nb25 at rice.edu 
> <mailto:nb25 at rice.edu>> wrote:
>
>     Ah I get it now, MatSetBlocked has to be set node-wise. I tried
>     this and
>     it works, thank you.
>
>     The other question I had was why are the arguments for MatSetValues()
>     and MatSetValuesBlocked() set to const PetscInt* and const
>     PetscScalar*
>     instead of just PetscInt* and PetscScalar* ? I have the typecast
>     there
>     so my flycheck doesn't keep throwing me warnings on emacs ;)
>
>
> Jed is correct that this cast is implicit. The idea here is to tell 
> the caller that we will not change the contents of the arrays that you 
> pass in.
>
>   Thanks,
>
>      Matt
>
>     Thank You,
>     Nidish
>
>     On 8/10/20 5:16 PM, Jed Brown wrote:
>     > Nidish <nb25 at rice.edu <mailto:nb25 at rice.edu>> writes:
>     >
>     >> It's a 1D model with displacements and rotations as DoFs at
>     each node.
>     >>
>     >> I couldn't find much in the manual on MatSetBlockSize - could you
>     >> provide some more information on its use?
>     >>
>     >> I thought since I've setup the system using DMDACreate1d (I've
>     given
>     >> 2dofs per node and a stencil width of 1 there), the matrix
>     object should
>     >> have the nonzero elements preallocated. Here's the call to
>     DMDACreate1d:
>     >>
>     >>     DMDACreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, N, 2, 1,
>     NULL, &mshdm);
>     > Ah, that will set the block size, but then it'll expect elstiff
>     to be an 8x8 matrix where you've only passed 4x4.
>     >
>     >      idx[0] = 2*e; idx[1] = 2*e+1; idx[2] = 2*e+2; idx[3] = 2*e+3;
>     >
>     >      MatSetValuesBlocked(jac, 4, (const PetscInt*)idx, 4, (const
>     PetscInt*)idx,
>     >                       (const PetscScalar*)elstiff, ADD_VALUES);
>     >
>     > You don't need the casts in either case, BTW.  You probably want
>     something like this.
>     >
>     >      idx[0] = e; idx[1] = e + 1;
>     >
>     >      MatSetValuesBlocked(jac, 2, idx, 2, idx, elstiff, ADD_VALUES);
>     >
>     > Also, it might be more convenient to call
>     MatSetValuesBlockedStencil(), especially if you move to a
>     multi-dimensional problem at some point.
>     -- 
>     Nidish
>
>
>
> -- 
> What most experimenters take for granted before they begin their 
> experiments is infinitely more interesting than any results to which 
> their experiments lead.
> -- Norbert Wiener
>
> https://www.cse.buffalo.edu/~knepley/ 
> <http://www.cse.buffalo.edu/~knepley/>
-- 
Nidish
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200810/39416196/attachment-0001.html>


More information about the petsc-users mailing list