[petsc-users] Options to set when solving Ax=b if matrix A changes its non-zero position at each solve

Matthew Knepley knepley at gmail.com
Sun Jun 10 07:42:42 CDT 2012


On Sun, Jun 10, 2012 at 5:42 PM, TAY wee-beng <zonexo at gmail.com> wrote:

>  Hi,
>
> Currently, my matrix A changes its non zero position at each time step.
>
> For e.g.: At a particular node, at time step = 1, I  will insert values
> into its east, west neighbours. At time step = 2, I  will insert values
> into its east, north neighbours. Hence, the non-zero positions at each row
> will be different at each time step. However, the max values per row will
> always be 5 or less.
>
> Currently, after MatSetValues and MatAssemblyBegin/End, I call:
>
> *call MatSetOption(A_mat,MAT_NEW_NONZERO_LOCATIONS,PETSC_TRUE,ierr)
>
> call KSPSetOperators(ksp,A_mat,A_mat,DIFFERENT_NONZERO_PATTERN,ierr)
>
> call KSPGetPC(ksp,pc,ierr)
>
> ksptype=KSPBCGS
>
> call KSPSetType(ksp,ksptype,ierr)
>
> call KSPSetFromOptions(ksp,ierr)
>
> call KSPSolve(ksp,b_rhs,xx,ierr)*
>
> Is this sufficient and correct? If so, apart from KSPSolve, MatSetValues
> and MatAssemblyBegin/End, can I only call the other subroutines once at the
> 1st time step?
>
> Or do I have to explicitly destroy the matrix and create a new one? I
> think I ask this question a while ago but I can't find the email now.
>

After assembly the nonzero pattern is fixed. The right thing to do is put
in explicit zeros for the rest of the stencil.

  Matt


>
> --
> Yours sincerely,
>
> TAY wee-beng
>
>


-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120610/587b42ff/attachment.html>


More information about the petsc-users mailing list