[petsc-users] SNESSetFunction and MatMFFDSetFunction
Barry Smith
bsmith at mcs.anl.gov
Wed Jan 1 14:01:43 CST 2014
On Jan 1, 2014, at 11:09 AM, Song Gao <song.gao2 at mail.mcgill.ca> wrote:
> Dear all,
>
> Happy new year!
>
> I'm using the matrix-free method to solve NS equations. I call the SNESSetFunction to set the RHS function. I think SNES also uses that RHS function to evaluate the matrix vector product.
Yes, PETSc differences this function to evaluate the matrix vector product.
>
> But I want to set one function to evaluate the residual, and another different function to evaluate the matrix vector product.
Are you providing a function that
1) actually evaluates the matrix vector product or are you
2) providing a function that you want PETSc to difference to evaluate the matrix vector product?
> How can I do that? Does MatMFFDSetFunction do this job?
For 2) yes, but if the function you provide is different than the function provided with SNESSetFunction then the matrix-vector product obtained from differencing it will not be “correct” Jacobian for the SNESSetFunction() you are providing so I don’t see why you would do it.
For 1) you should use MatCreateShell() and MatShellSetOperation(mat,MATOP_MULT, ….) and then pass that matrix to SNESSetJacobian(), then PETSc will use that “matrix” to do its matrix-vector products.
Barry
>
> Any suggestion is appreciated. Thank you.
>
>
> Song
More information about the petsc-users
mailing list