[petsc-users] remove new zeros values with petsc4py

NENNIG Benoit benoit.nennig at isae-supmeca.fr
Wed Apr 16 07:36:09 CDT 2025


Dear petsc users,

I need to compute the difference of two matrices M(nu) and M(nu+epsilon) to estimate the derivative of the matrix with respect to the parameter nu.
Since only very few entries are modified by epsilon, D = M(nu+epsilon) - M(nu) contains many new zeros and I would like to remove them.

I am using PETSc from petsc4py.
I have seen the method `chop` which call `Filter` but without the `compress` argument.
At the end I need to store this matrix into a file. So my questions are:
- Is is possible to remove the zeros entries with petsc4py with Mat methods?
- Is is possible to do it when I save the file, ie with Viewer methods ?

Thanks a lot,

Benoit


More information about the petsc-users mailing list