[petsc-users] SNESSetFunction and MatMFFDSetFunction

Song Gao song.gao2 at mail.mcgill.ca
Thu Jan 2 09:04:26 CST 2014


Thanks, Barry.

I mean 2) providing a function that I want PETSc to difference to evaluate
the matrix vector product.

I want to make a slight modification of the matrix after PETSc evaluate the
matrix vector product. So I think provide another different function is a
feasible way to do that.




On Wed, Jan 1, 2014 at 3:01 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140102/a5c1c116/attachment.html>


More information about the petsc-users mailing list