[petsc-users] A matrix-free Jacobian for SNES using MatShell

Barry Smith bsmith at mcs.anl.gov
Tue Aug 31 10:18:40 CDT 2010


On Aug 31, 2010, at 11:12 AM, Jeremy Roberts wrote:

> Hi folks,
> 
> I am trying to implement a sample problem for SNES using a shell matrix construct for the Jacobian (*not* finite differences).
> 
> However, I haven't yet found a straightforward example for this.  I've seen one for a shell-based PC but not for a shell-based Jacobian.
> 
> I thought a sequence like this would work, but I'm not sure how to set the Jacobian.  
> 
>           call MatCreateShell( PETSC_COMM_SELF, m, n, m, n, PETSC_NULL_OBJECT, Jshell, ierr )
>           call MatShellSetOperation( Jshell, MATOP_MULT, jac_shell, ierr )
>           call MatCreateSNESMF( snes, Jshell, ierr )
                    ^^^^ don't want this, don't need this, this line makes no sense

>           call SNESSetJacobian( snes, Jshell, Jshell, ???, PETSC_NULL_OBJECT, ierr )
                                                                                          ^^^^^^^^^^
         You would write a function with the correct calling sequence. This function would keep a copy of the input vector (this is the place WHERE the Jacobian is evaulated in J(u)*x this is the u so you need to keep a copy of it here to use when you do your jac_shell multiply)

    Barry

> 
> I need no PC right now, jac_shell computes the result J*v, and Jshell is an empty Mat. 
> 
> How do I finish this calling sequence?  Am I way off base here?
> 
> Thanks,
> Jeremy



More information about the petsc-users mailing list