<div dir="ltr">Thanks, Barry.<div><br></div><div>I mean 2) <span style="font-family:arial,sans-serif;font-size:12.727272033691406px">providing a function that I want PETSc to difference to evaluate the matrix vector product.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">I want to make a </span><font face="arial, sans-serif">slight modification of the matrix after PETSc </font><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">evaluate the matrix vector product. So I think provide another different function is a feasible way to do that.</span></div>
<br style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 1, 2014 at 3:01 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On Jan 1, 2014, at 11:09 AM, Song Gao <<a href="mailto:song.gao2@mail.mcgill.ca">song.gao2@mail.mcgill.ca</a>> wrote:<br>
<br>
> Dear all,<br>
><br>
> Happy new year!<br>
><br>
> 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.<br>
<br>
</div> Yes, PETSc differences this function to evaluate the matrix vector product.<br>
<div class="im"><br>
><br>
> But I want to set one function to evaluate the residual, and another different function to evaluate the matrix vector product.<br>
<br>
</div> Are you providing a function that<br>
<br>
1) actually evaluates the matrix vector product or are you<br>
<br>
2) providing a function that you want PETSc to difference to evaluate the matrix vector product?<br>
<div class="im"><br>
> How can I do that? Does MatMFFDSetFunction do this job?<br>
<br>
</div> 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.<br>
<br>
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.<br>
<span class="HOEnZb"><font color="#888888"><br>
Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
><br>
> Any suggestion is appreciated. Thank you.<br>
><br>
><br>
> Song<br>
<br>
</div></div></blockquote></div><br></div>