[petsc-users] Matrix-free preconditioner using shell matrix

Praveen C cpraveen at gmail.com
Sat May 19 11:42:57 CDT 2018


Thanks a lot.

> On 19-May-2018, at 9:16 PM, Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
> 
>   Praveen,
> 
>   Ahh, we didn't have support for passing PETSC_NULL_MAT from Fortran for this routine. I have added it in the branch barry/fix-null-matrix-set-jacobian/maint  which after testing will go into the maint branch. 
> 
>   Could you please try this branch and let us know if it resolves the problem (or a new problem pops up)?
> 
>    Barry
> 
>   Unfortunately handling null objects from Fortran requires us to manually tweak the Fortran interface functions and sometimes we forget or don't realize they need fixing until someone reports a problem.

I meanwhile passed a Mat object to TSSetRHSJacobian function. It seems that with -snes_mf and PCSHELL, my RHSJacobian is never invoked. Is this the correct behaviour ?

In RHSJacobian, I am storing the current solution into my usercontext so that I can use it in my shell preconditioner

subroutine RHSJacobian(ts, time, u, J, P, ctx, ierr)

   call VecCopy(u, ctx%p%v_u, ierr); CHKERRQ(ierr)

end

However, since my RHSJacobian is never invoked, I dont have access to the current solution needed in my ApplyPC. How can I access the current solution in my ApplyPC function ?

Another issue I am facing is this. I attach my user context to the PC

      call TSGetSNES(ts, snes, ierr); CHKERRQ(ierr)
      call SNESGetKSP(snes, ksp, ierr); CHKERRQ(ierr)
      call KSPGetPC(ksp, pc, ierr); CHKERRQ(ierr)
      call PCSetType(pc, PCSHELL, ierr); CHKERRQ(ierr)
      call PCShellSetContext(pc, ctx, ierr); CHKERRQ(ierr)
      call PCShellSetApply(pc, ApplyPC, ierr); CHKERRQ(ierr)

Inside my ApplyPC, I access ctx using 

subroutine ApplyPC(pc, x, y, ierr)
   use petscpc
   use mtsdata
   implicit none
   PC             :: pc
   Vec            :: x, y
   PetscErrorCode :: ierr
   ! Local variables
   type(tsdata)   :: ctx

   call PCShellGetContext(pc, ctx, ierr); CHKERRQ(ierr)

end

But the ctx I get from above is not correct, since it does not have the data I stored in my original ctx.

I am rather clueless at this stage.

Thanks for your help.
Best regards
praveen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180519/db89e92e/attachment-0001.html>


More information about the petsc-users mailing list