wierd behaviour from MatGetRow?

Matthew Knepley knepley at gmail.com
Thu Sep 27 08:14:37 CDT 2007


On 9/27/07, Toby D. Young <tyoung at ippt.gov.pl> wrote:
> Hello,
>
> I apologize in advance if this message is garbled.
>
> I'm trying to set non-zero values of a column to zero, so I do the
> following:
>
> MatGetRow()     <- get the column numbers of non-zero elements
> MatSetValues()  <- set those elements to zero
> MatGetRow()     <- check that element is set to zero
>
> The output from my program gives:
>
>    num = 0x56f024        <- pointer to column number
>    values = 0.666667     <- it's value
>    num = 0x56f024        <- pointer to column number
>    values = 0            <- it's value
>
> So it looks like it has worked the matrix value is zero!
>
> ...but if the matrix element has been set to zero, why does MatGetRow
> tell mne this? Should not MatGetRow see that it is zero and return
> nothing?
>
> Is this behaviour be correct? I'd be interested to know it seems like
> a riddle to me.

Yes, this is correct. The default matrix type, AIJ, distinguishes between

  a) Structural zeros:  Elements not present in the sparse matrix graph

  b) Numerical zeros: Elements that have value 0.0

PETSc matrices are not designed to change the nonzero structure once set.
This optimizes the MatMult time at the expense of more complicated assembly.
This tradeoff is usually the correct one for PDEs.

If you are trying to impose Dirichlet conditions, I suggest the
following. Execute
a first loop to calculate just the nonzero structure of the operator,
incorporating
all boundary conditions. Then execute a second loop to calculate and store the
values. The time increase is usually negligible compared to the total
simulation.

  Thanks,

    Matt

> Thanks.
>
> Best,
>         Toby
>
>
>
> --
>
> Toby D. Young ( Adiunkt )
> Department of Computational Science
> Institute of Fundamental Technological Research, Polish Academy of
> Sciences, Room 206, Swietokrzyska 21, 00-049 Warsaw, POLAND
>
>


-- 
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




More information about the petsc-users mailing list