How to efficiently change just the diagonal vector in a matrix at every time step

Barry Smith bsmith at mcs.anl.gov
Fri May 9 10:48:22 CDT 2008


>
> and what I did at the subsequent steps is:
>
> do II=1,total
>   call MatSetValues(A_semi_x,1,II,1,II,new_value,INSERT_VALUES,ierr)
>
> end do
>
> call MatAssemblyBegin(A_semi_x,MAT_FINAL_ASSEMBLY,ierr)
>
> call MatAssemblyEnd(A_semi_x,MAT_FINAL_ASSEMBLY,ierr)


    You can/should call KSPSetOperators() here EACH time, otherwise  
the KSPSolve does not know it has a new matrix and will not build
a new preconditioner. Hence it continues to use the original  
preconditioner. This is why "answers are slightly different".
If the original preconditioner works ok for all timesteps then you do  
not need to call the KSPSetOperators()

   Barry


>
>
> call KSPSolve(ksp_semi_x,b_rhs_semi_x,xx_semi_x,ierr)
>
> I realise that the answers are slightly different as compared to  
> calling all the options such as KSPSetType, KSPSetFromOptions,  
> KSPSetTolerances at every time step. Should that be so? Is this the  
> best way?
>
> Also, I can let the matrix be equal at every time step by fixing the  
> delta_time. However, it may give stability problems. I wonder how  
> expensive is these type of value changing and assembly for a matrix?
>
> Thank you very much.
>
> Regards.
>




More information about the petsc-users mailing list