<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">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.<div class=""><br class=""></div><div class="">Best</div><div class="">praveen<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 19-May-2018, at 10:31 PM, Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov" class="">bsmith@mcs.anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">On May 19, 2018, at 11:42 AM, Praveen C <<a href="mailto:cpraveen@gmail.com" class="">cpraveen@gmail.com</a>> wrote:<br class=""><br class="">Thanks a lot.<br class=""><br class=""><blockquote type="cite" class="">On 19-May-2018, at 9:16 PM, Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov" class="">bsmith@mcs.anl.gov</a>> wrote:<br class=""><br class=""> Praveen,<br class=""><br class=""> 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.<span class="Apple-converted-space"> </span><br class=""><br class=""> Could you please try this branch and let us know if it resolves the problem (or a new problem pops up)?<br class=""><br class="">  Barry<br class=""><br class=""> 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.<br class=""></blockquote><br class="">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 ?<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">  Yes, if you want your function to be called you need to use -snes_mf_operator instead.<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class="">In RHSJacobian, I am storing the current solution into my usercontext so that I can use it in my shell preconditioner<br class=""><br class="">subroutine RHSJacobian(ts, time, u, J, P, ctx, ierr)<br class=""><br class="">  call VecCopy(u, ctx%p%v_u, ierr); CHKERRQ(ierr)<br class=""><br class="">end<br class=""><br class="">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 ?<br class=""><br class="">Another issue I am facing is this. I attach my user context to the PC<br class=""><br class="">     call TSGetSNES(ts, snes, ierr); CHKERRQ(ierr)<br class="">     call SNESGetKSP(snes, ksp, ierr); CHKERRQ(ierr)<br class="">     call KSPGetPC(ksp, pc, ierr); CHKERRQ(ierr)<br class="">     call PCSetType(pc, PCSHELL, ierr); CHKERRQ(ierr)<br class="">     call PCShellSetContext(pc, ctx, ierr); CHKERRQ(ierr)<br class="">     call PCShellSetApply(pc, ApplyPC, ierr); CHKERRQ(ierr)<br class=""><br class="">Inside my ApplyPC, I access ctx using<span class="Apple-converted-space"> </span><br class=""><br class="">subroutine ApplyPC(pc, x, y, ierr)<br class="">  use petscpc<br class="">  use mtsdata<br class="">  implicit none<br class="">  PC             :: pc<br class="">  Vec            :: x, y<br class="">  PetscErrorCode :: ierr<br class="">  ! Local variables<br class="">  type(tsdata)   :: ctx<br class=""><br class="">  call PCShellGetContext(pc, ctx, ierr); CHKERRQ(ierr)<br class=""><br class="">end<br class=""><br class="">But the ctx I get from above is not correct, since it does not have the data I stored in my original ctx.<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">   This won't work. You need to use a pointer for the context not an entirely new context argument. See</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">src/mat/examples/tutorials/ex6f.F90</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">for how to use derived data types and pointers with contexts in Fortran.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""> Barry</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class="">I am rather clueless at this stage.<br class=""><br class="">Thanks for your help.<br class="">Best regards<br class="">praveen</blockquote></div></blockquote></div><br class=""></div></body></html>