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

Praveen C cpraveen at gmail.com
Wed May 23 00:24:14 CDT 2018


Thanks a lot Barry. I sorted out the user context problem with your help. But I have to fix some other issues to make it work.

Best
praveen

> On 19-May-2018, at 10:31 PM, Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
> 
> 
> 
>> On May 19, 2018, at 11:42 AM, Praveen C <cpraveen at gmail.com> wrote:
>> 
>> 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 ?
> 
>   Yes, if you want your function to be called you need to use -snes_mf_operator instead. 
>> 
>> 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.
> 
>    This won't work. You need to use a pointer for the context not an entirely new context argument. See
> 
> src/mat/examples/tutorials/ex6f.F90
> 
> for how to use derived data types and pointers with contexts in Fortran.
> 
>  Barry
> 
>> 
>> 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/20180523/65b33b3c/attachment.html>


More information about the petsc-users mailing list