<div dir="ltr"><div dir="ltr">On Mon, Mar 21, 2022 at 1:25 PM Marco Cisternino <<a href="mailto:marco.cisternino@optimad.it">marco.cisternino@optimad.it</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-GB" style="overflow-wrap: break-word;">
<div class="gmail-m_464936641958984018WordSection1">
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Thank you, Matt.<u></u><u></u></span></p>
<ol style="margin-top:0cm" start="1" type="1">
<li class="gmail-m_464936641958984018MsoListParagraph" style="margin-left:0cm"><span style="font-family:"Mulish Light",serif">I already set the null space and test it in the toy code</span></li></ol></div></div></blockquote><div>If you set this and it is not working, something is wrong. This will remove null space components from each update in the Krylov space.</div><div>This is done in an example where I check convergence to the exact solution: <a href="https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c">https://gitlab.com/petsc/petsc/-/blob/main/src/snes/tutorials/ex69.c</a></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="gmail-m_464936641958984018WordSection1"><ol style="margin-top:0cm" start="1" type="1"><li class="gmail-m_464936641958984018MsoListParagraph" style="margin-left:0cm"><span style="font-family:"Mulish Light",serif"><u></u><u></u></span></li><li class="gmail-m_464936641958984018MsoListParagraph" style="margin-left:0cm"><span style="font-family:"Mulish Light",serif">I tried your suggestion: the norm and the mean of the solution using -mg_coarse_pc_type svd with PCGAMG is
 much closer to the one of PCNONE (the norm is the same up to the 6<sup>th</sup> digit, the mean is about 10e-4 with “svd” PCGAMG and 10e-17 with PCNONE). I’m going to try with the real code and see what happens on larger meshes</span></li></ol></div></div></blockquote><div>This is not perfect since null space components can be introduced by the rest of the preconditioner, but when I use range-space smoothers and</div><div>local interpolation it tends to be much better for me. Maybe it is just my problems.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="gmail-m_464936641958984018WordSection1">
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Thank you all.
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="IT" style="font-family:"Mulish Medium"">Marco Cisternino</span><span lang="IT"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="IT"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"><u></u> <u></u></span></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>>
<br>
<b>Sent:</b> lunedì 21 marzo 2022 18:16<br>
<b>To:</b> Mark Adams <<a href="mailto:mfadams@lbl.gov" target="_blank">mfadams@lbl.gov</a>><br>
<b>Cc:</b> Marco Cisternino <<a href="mailto:marco.cisternino@optimad.it" target="_blank">marco.cisternino@optimad.it</a>>; <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><br>
<b>Subject:</b> Re: [petsc-users] Null space and preconditioners<u></u><u></u></span></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Mon, Mar 21, 2022 at 12:06 PM Mark Adams <<a href="mailto:mfadams@lbl.gov" target="_blank">mfadams@lbl.gov</a>> wrote:<u></u><u></u></p>
</div>
<div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<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.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">You should use a special coarse grid solver for GAMG but it seems to be working for you.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">can someone help Marco?<u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I have not had time to look at the code. However, here are two ways we use to fix the pure Neumann solution:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">1) Attach a null space to the operator using <a href="https://petsc.org/main/docs/manualpages/Mat/MatSetNullSpace.html" target="_blank">https://petsc.org/main/docs/manualpages/Mat/MatSetNullSpace.html</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">2) Use a coarse grid solver that does least-squares<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">  -mg_coarse_pc_type svd<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">  Thanks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">     Matt<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal">Mark<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<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:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Good morning,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">I’m observing an unexpected (to me) behaviour of my code.</span><u></u><u></u></p>
<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><u></u><u></u></p>
<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><u></u><u></u></p>
<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><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">It has been cooked as tiny as possible (16 cells!).</span><u></u><u></u></p>
<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><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><u></u><u></u></p>
<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><u></u><u></u></p>
<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><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">PCNONE gives me the zero mean solution I expected. What about the others?</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><u></u><u></u></p>
<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><u></u><u></u></p>
<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><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Generalizing to larger mesh the behaviour is similar.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif">Thank you for any help.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Light",serif"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Mulish Medium"">Marco Cisternino</span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>