<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Mulish Light";
panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Mulish Medium";
panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:Menlo;
panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Mulish Light",serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 2.0cm 2.0cm 2.0cm;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif;mso-fareast-language:EN-US">Thank you Barry!<br>
No, no reason for FGMRES (some old tests showed shorter wall-times relative to GMRES), I’m going to use GMRES.<br>
I tried GMRES with GAMG using PCSVD on the coarser level on real cases, larger than the toy case, I cannot get machine epsilon mean value of the solution, as in the toy case but about 10e-5, which is much better than before. The rest of GAMG is on default configuration.
The mesh is much more complicated being an octree with immersed geometries. I get the same behaviour using GMRES+ASM+ILU as well.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif;mso-fareast-language:EN-US">I cannot really get why the solution is not at zero mean value. I’m using a rtol~1.0e-8 but I get the same mean value using rtol~1.o-6, I tried 1.0-12 too, but no
improvement in the constant, definitely tiny but not zero.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif;mso-fareast-language:EN-US">Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span lang="IT" style="font-family:"Mulish Medium"">Marco Cisternino</span><span lang="IT"><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Barry Smith <bsmith@petsc.dev>
<br>
<b>Sent:</b> lunedì 21 marzo 2022 19:49<br>
<b>To:</b> Marco Cisternino <marco.cisternino@optimad.it><br>
<b>Cc:</b> Mark Adams <mfadams@lbl.gov>; petsc-users@mcs.anl.gov<br>
<b>Subject:</b> Re: [petsc-users] Null space and preconditioners<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal"> Marco,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> I have confirmed your results. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> Urgg, it appears we do not have something well documented. The removal of the null space only works for left preconditioned solvers and FGMRES only works with right preconditioning. Here is the reasoning. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> The Krylov space for left preconditioning is built from [r, BAr, (BA)^2 r, ...] and the solution space is built from this basis. If A has a null space of n then the left preconditioned Krylov methods simply remove n from the "full"
Krylov space after applying each B preconditioner and the resulting "reduced" Krylov space has no components in the n directions hence the solution built by GMRES naturally has no component in the n. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> But with right preconditioning the Krylov space is [s ABs (AB)^2 s, ....] We would need to remove B^-1 n from the Krylov space so that (A B) B^-1 n = 0 In general we don't have any way of applying B^-1 to a vector so we cannot create
the appropriate "reduced" Krylov space. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> If I run with GMRES (which defaults to left preconditioner) and the options <span style="font-size:10.5pt;font-family:"Menlo",serif">./testPreconditioners -pc_type gamg -ksp_type gmres -ksp_monitor_true_residual -ksp_rtol 1.e-12 -ksp_view
-mg_coarse_pc_type svd</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> Then it handles the null space correctly and the solution has <span style="font-size:10.5pt;font-family:"Menlo",serif">Solution mean = 4.51028e-17</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Is there any reason to use FGMRES instead of GMRES? You just cannot use GMRES as the smoother inside GAMG if you use GMRES on the outside, but for pressure equations you don't want use such a strong smoother anyways.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> Barry<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> I feel we should add some information to the documentation on the removal of the null space to the user's manual when using right preconditioning and maybe even have an error check in the code so that people don't fall into this trap.
But I am not sure exactly what to do. When the A and B are both symmetric I think special stuff happens that doesn't require providing a null space; but I am not sure. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Mar 21, 2022, at 12:41 PM, Marco Cisternino <<a href="mailto:marco.cisternino@optimad.it">marco.cisternino@optimad.it</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Thank you, Mark.<br>
However, doing this with my toy code</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">mpirun -n 1 ./testpreconditioner -pc_type gamg -pc_gamg_use_parallel_coarse_grid_solver -mg_coarse_pc_type jacobi -mg_coarse_ksp_type cg</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">I get 16 inf elements. Do I miss anything?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Thanks again</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="IT" style="font-family:"Mulish Medium"">Marco Cisternino</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span lang="IT"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><o:p></o:p></p>
</div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<div>
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span class="apple-converted-space"><span lang="EN-US"> </span></span><span lang="EN-US">Mark Adams <<a href="mailto:mfadams@lbl.gov">mfadams@lbl.gov</a>><span class="apple-converted-space"> </span><br>
<b>Sent:</b><span class="apple-converted-space"> </span>lunedì 21 marzo 2022 17:31<br>
<b>To:</b><span class="apple-converted-space"> </span>Marco Cisternino <<a href="mailto:marco.cisternino@optimad.it">marco.cisternino@optimad.it</a>><br>
<b>Cc:</b><span class="apple-converted-space"> </span><a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a><br>
<b>Subject:</b><span class="apple-converted-space"> </span>Re: [petsc-users] Null space and preconditioners</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">And for GAMG you can use:<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">-pc_gamg_use_parallel_coarse_grid_solver -mg_coarse_pc_type jacobi -mg_coarse_ksp_type cg<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Note if you are using more that one MPI process you can use 'lu' instead of 'jacobi'<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">If GAMG converges fast enough it can solve before the constant creeps in and works without cleaning in the KSP method.<o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">On Mon, Mar 21, 2022 at 12:06 PM Mark Adams <<a href="mailto:mfadams@lbl.gov">mfadams@lbl.gov</a>> wrote:<o:p></o:p></p>
</div>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal">The solution for Neumann problems can "float away" if the constant is not controlled in some way because floating point errors can introduce it even if your RHS is exactly orthogonal to it.<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">You should use a special coarse grid solver for GAMG but it seems to be working for you.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">I have lost track of the simply way to have the KSP solver clean the constant out, which is what you want.<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">can someone help Marco?<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Mark<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">On Mon, Mar 21, 2022 at 8:18 AM Marco Cisternino <<a href="mailto:marco.cisternino@optimad.it" target="_blank">marco.cisternino@optimad.it</a>> wrote:<o:p></o:p></p>
</div>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Good morning,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">I’m observing an unexpected (to me) behaviour of my code.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">I tried to reduce the problem in a toy code here attached.<br>
The toy code archive contains a small main, a matrix and a rhs.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">The toy code solves the linear system and check the norms and the mean of the solution.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">The problem into the matrix and the rhs is the finite volume discretization of the pressure equation of an incompressible NS solver.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">It has been cooked as tiny as possible (16 cells!).</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">It is important to say that it is an elliptic problem with homogeneous Neumann boundary conditions only, for this reason the toy code sets a null space containing the constant.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">The unexpected (to me) behaviour is evident by launching the code using different preconditioners, using -pc-type <pctype><br>
I tested using PCNONE (“none”), PCGAMG (“gamg”) and PCILU (“ilu”). The default solver is KSPFGMRES.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Using the three PC, I get 3 different solutions. It seems to me that they differ in the mean value, but GAMG is impressive.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">PCNONE gives me the zero mean solution I expected. What about the others?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Asking for residuals monitor, the ratio ||r||/||b|| shows convergence for PCNONE and PCILU (~10^-16), but it stalls for PCGAMG (~10^-4).</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">I cannot see why. Am I doing anything wrong or incorrectly thinking about the expected behaviour?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Generalizing to larger mesh the behaviour is similar.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Thank you for any help.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Medium"">Marco Cisternino</span><o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>