[petsc-users] Matrix-free functions for SNES

Barry Smith bsmith at mcs.anl.gov
Wed Dec 2 17:14:09 CST 2015


  Do "what you would do for KSP" but with "SNES" so use

> MatCreateShell( ....)
> MatShellSetOperation(....)

  SNESSetJacobian() and pass in your shell matrix as the Jacobian.

> On Dec 2, 2015, at 5:09 PM, DU Yongle <yongle.du at gmail.com> wrote:
> 
> Dear Sir/Madam:
> 
> Sorry to bother, but I didn't find any information I need to implement matrix-free functions for SNES after a long time search of the manual and sample codes.
> 
> Suppose I am solving nonlinear equation systems F(x) = 0, I have two choices:
> 
> (1) MatCreateMFFD(snes, matJ):
> This calculate matJ * x with a finite difference scheme. I can create a function to calculate matJ * x, and link it to SNES by SNESSetJacobian. However,  I do not prefer this feature because I am calculating the mat-vec product in another way.
> 
> (2) MatCreateMF(snes, matJ):
> Here, matJ is not defined explicitly. It is some operations (like mat-vec product). must be linked to SNES, and must be linked to SNES through  SNESSetJacobian. 
> 
> For KSP solvers, I know that a matshell type can be created and a mat-vec product can be assigned to matJ in this way:
> MatCreateShell( ....)
> MatShellSetOperation(....)
> KSPSetOperators(ksp, matJ, matJ)
> 
> How to do the similar operations for SNES if matJ is already created via MatCreateMF?

   You would not use MatCreateMF() in your case. It only does finite difference scheme which is not what you want so why would you even consider it?

> How to define the mat size and mat-vec product? What other operations are required in a customized function in order to link it to SNES via SNESSetJacobian?
> 
> Thanks a for your help.
> 
> Yongle Du 
> 
> 
> 
> 



More information about the petsc-users mailing list