[petsc-users] Using operators in KSP

Barry Smith bsmith at mcs.anl.gov
Sat Jun 14 17:43:12 CDT 2014


   MatCreateShell() is what I think you need.  You provide a “matrix-free” linear operator with MatShellSetOperation(mat,MATOP_MULT,yourfunction) and yourfunction applies the linear operator any way it likes.

   You then provide this matrix as the first Mat argument to KSPSetOperators().


   Barry



On Jun 14, 2014, at 5:18 PM, Sun, Hui <hus003 at ucsd.edu> wrote:

> I try to program 2D Stokes equation solver, so it is a linear PDE, and there are u, v, p on every grid point. One way on my mind is to form a matrix-free block matrix. In that way, if the discretization is n by n, then the matrix is 3n by 3n. However, I'm also thinking if it is possible to define the PDE operator as what DMDASNESSetFunctionLocal does in SNES example ex19? In that example, the unknowns (u, v, omega, T) are defined as a struct of four PestsScalar on every grid point, and then the interface converts PestcScalar** to Vec, and an operator instead of a matrix is formed. 
> 
> Is there a function in KSP similar to DMDASNESSetFunctionLocal in SNES? 



More information about the petsc-users mailing list