<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix"> Dear, Barry and Jed,<br>
<br>
Thanks for your replies.<br>
<br>
We understand your doubts, so let me to put our question into
context. In CFD it is standard practice to solve non-linear
equations of conservation for steady flows by means of a inexact
Newton method. The original Jacobian matrix is modified by adding
terms on the diagonal which are proportional to the Courant number
and to the lumped mass matrix. This allows us to obtain two
things, "relax" the solution update and increase the diagonal
dominance of the matrix itself. <br>
<br>
The latter is key when simple preconditioners are adopted, in our
case point Jacobi or SOR. Indeed, if the original matrix was to
be used, the GMRES method would converge only on very regular
meshes and only when adopting ILU preconditioners with a very high
level of fill-in. As result a higher number of non-linear
iterations is traded with a simpler linear system to be solved.<br>
<br>
While exploring the SNES+MF capabilities we found out that we
could successfully solve the linear system only with ILU(200) or
so. Of course we do not want to touch the function used to
evaluate the residual, which determines the final solution.
However we think that a suitable modification of the function that
Petsc differences to compute the matrix vector product would allow
us to obtain a behavior similar to the inexact Newton method.<br>
<br>
Best regards,<br>
Dario<br>
<br>
<br>
On 01/03/2014 12:32 PM, Song Gao wrote:<br>
</div>
<blockquote
cite="mid:CAJitgPWbNEO2Y52LWMs2vPz0fSMBoDXJ5LyPAwQcbE0_wALnaQ@mail.gmail.com"
type="cite">
<div dir="ltr"><br>
<br>
<div class="gmail_quote">---------- Forwarded message ----------<br>
From: <b class="gmail_sendername">Jed Brown</b> <span
dir="ltr"><<a moz-do-not-send="true"
href="mailto:jedbrown@mcs.anl.gov">jedbrown@mcs.anl.gov</a>></span><br>
Date: Thu, Jan 2, 2014 at 10:20 AM<br>
Subject: Re: [petsc-users] SNESSetFunction and
MatMFFDSetFunction<br>
To: Song Gao <<a moz-do-not-send="true"
href="mailto:song.gao2@mail.mcgill.ca">song.gao2@mail.mcgill.ca</a>>,
Barry Smith <<a moz-do-not-send="true"
href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>><br>
Cc: petsc-users <<a moz-do-not-send="true"
href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>><br>
<br>
<br>
<div class="im">Song Gao <<a moz-do-not-send="true"
href="mailto:song.gao2@mail.mcgill.ca">song.gao2@mail.mcgill.ca</a>>
writes:<br>
<br>
> Thanks, Barry.<br>
><br>
> I mean 2) providing a function that I want PETSc to
difference to evaluate<br>
> the matrix vector product.<br>
><br>
> I want to make a slight modification of the matrix
after PETSc evaluate the<br>
> matrix vector product.<br>
<br>
</div>
Performing a matrix-vector product is not supposed to modify
the matrix.<br>
It's unlikely that you really want this.<br>
</div>
<div class="gmail_quote"><br>
</div>
<div class="gmail_quote"><br class="">
<span
style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:12.727272033691406px">On
Wed, Jan 1, 2014 at 3:01 PM, Barry Smith </span><span
dir="ltr"
style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:12.727272033691406px"><<a
moz-do-not-send="true" href="mailto:bsmith@mcs.anl.gov"
target="_blank">bsmith@mcs.anl.gov</a>></span><span
style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:12.727272033691406px"> wrote:</span><br
style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:12.727272033691406px">
<blockquote class="gmail_quote"
style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:12.727272033691406px;margin:0px
0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><br>
On Jan 1, 2014, at 11:09 AM, Song Gao <<a
moz-do-not-send="true"
href="mailto:song.gao2@mail.mcgill.ca" target="_blank">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><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><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>
<font color="#888888"><br>
Barry<br>
</font>
<div><br>
<br>
<br>
><br>
> Any suggestion is appreciated. Thank you.<br>
><br>
><br>
> Song<br>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>