<div dir="ltr">I made a fix for this:<div><br></div><div> <a href="https://gitlab.com/petsc/petsc/-/merge_requests/4729">https://gitlab.com/petsc/petsc/-/merge_requests/4729</a></div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 18, 2022 at 3:20 PM Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<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 dir="ltr"><div dir="ltr">On Thu, Dec 16, 2021 at 11:09 AM Marco Cisternino <<a href="mailto:marco.cisternino@optimad.it" target="_blank">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-US">
<div>
<p class="MsoNormal">Hello Matthew,<u></u><u></u></p>
<p class="MsoNormal">as promised I prepared a minimal (112960 rows. I’m not able to produce anything smaller than this and triggering the issue) example of the behavior I was talking about some days ago.<u></u><u></u></p>
<p class="MsoNormal">What I did is to produce matrix, right hand side and initial solution of the linear system.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">As I told you before, this linear system is the discretization of the pressure equation of a predictor-corrector method for NS equations in the framework of finite volume method.<u></u><u></u></p>
<p class="MsoNormal">This case has homogeneous Neumann boundary conditions. Computational domain has two independent and separated sub-domains.<u></u><u></u></p>
<p class="MsoNormal">I discretize the weak formulation and I divide every row of the linear system by the volume of the relative cell.<u></u><u></u></p>
<p class="MsoNormal">The underlying mesh is not uniform, therefore cells have different volumes.
<u></u><u></u></p>
<p class="MsoNormal">The issue I’m going to explain does not show up if the mesh is uniform, same volume for all the cells.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I usually build the null space sub-domain by sub-domain with<u></u><u></u></p>
<p class="MsoNormal" style="text-indent:36pt">MatNullSpaceCreate(getCommunicator(), PETSC_FALSE, nConstants, constants, &nullspace);<u></u><u></u></p>
<p class="MsoNormal">Where nConstants = 2 and constants contains two normalized arrays with constant values on degrees of freedom relative to the associated sub-domain and zeros elsewhere.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">However, as a test I tried the constant over the whole domain using 2 alternatives that should produce the same null space:<u></u><u></u></p>
<ol style="margin-top:0cm" start="1" type="1">
<li style="margin-left:0cm">MatNullSpaceCreate(getCommunicator(), PETSC_TRUE, 0, nullptr, &nullspace);<u></u><u></u></li><li style="margin-left:0cm">Vec* nsp;<u></u><u></u></li></ol>
<p>VecDuplicateVecs(solution, 1, &nsp);<u></u><u></u></p>
<p>VecSet(nsp[0],1.0);<u></u><u></u></p>
<p>VecNormalize(nsp[0], nullptr);<u></u><u></u></p>
<p>MatNullSpaceCreate(getCommunicator(), PETSC_FALSE, 1, nsp, &nullspace);<u></u><u></u></p>
<p><u></u> <u></u></p>
<p class="MsoNormal" style="text-align:justify">Once I created the null space I test it using:<u></u><u></u></p>
<p class="MsoNormal" style="text-align:justify;text-indent:36pt"><span lang="IT">MatNullSpaceTest(nullspace, m_A, &isNullSpaceValid);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-align:justify"><span lang="IT"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-align:justify">The case 1 pass the test while case 2 don’t.<u></u><u></u></p>
<p class="MsoNormal" style="text-align:justify"><u></u> <u></u></p>
<p class="MsoNormal" style="text-align:justify">I have a small code for matrix loading, null spaces creation and testing.<u></u><u></u></p>
<p class="MsoNormal" style="text-align:justify">Unfortunately I cannot implement a small code able to produce that linear system.<u></u><u></u></p>
<p class="MsoNormal" style="text-align:justify"><u></u> <u></u></p>
<p class="MsoNormal" style="text-align:justify">As attachment you can find an archive containing the matrix, the initial solution (used to manually build the null space) and the rhs (not used in the test code) in binary format.<u></u><u></u></p>
<p class="MsoNormal" style="text-align:justify">You can also find the testing code in the same archive.<u></u><u></u></p>
<p class="MsoNormal" style="text-align:justify">I used petsc 3.12(gcc+openMPI) and petsc 3.15.2(intelOneAPI) same results.<u></u><u></u></p>
<p class="MsoNormal" style="text-align:justify">If the attachment is not delivered, I can share a link to it.</p></div></div></blockquote><div><br></div><div>Marco, please forgive me for taking so long to get to your issue. It has been crazy.</div><div><br></div><div>You are correct, we had a bug. it is in MatNullSpaceTest. The normalization for the constant vector was wrong:</div><div><br></div><div>diff --git a/src/mat/interface/matnull.c b/src/mat/interface/matnull.c<br>index f8ab2925988..0c4c3855be0 100644<br>--- a/src/mat/interface/matnull.c<br>+++ b/src/mat/interface/matnull.c<br>@@ -429,7 +429,7 @@ PetscErrorCode MatNullSpaceTest(MatNullSpace sp,Mat mat,PetscBool *isNull)<br> if (sp->has_cnst) {<br> ierr = VecDuplicate(l,&r);CHKERRQ(ierr);<br> ierr = VecGetSize(l,&N);CHKERRQ(ierr);<br>- sum = 1.0/N;<br><br>+ sum = 1.0/PetscSqrtReal(N);<br> ierr = VecSet(l,sum);CHKERRQ(ierr);<br> ierr = MatMult(mat,l,r);CHKERRQ(ierr);<br> ierr = VecNorm(r,NORM_2,&nrm);CHKERRQ(ierr);<br></div><div><br></div><div>With this fix, your two cases give the same answer, namely that the constant vector is not a null vector of your</div><div>operator, but it is close, as your can see using -mat_null_space_test_view.</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-US"><div>
<p class="MsoNormal" style="text-align:justify">Thanks for any help.<u></u><u></u></p>
<p class="MsoNormal" style="text-align:justify"><u></u> <u></u></p>
<p class="MsoNormal">Marco Cisternino <u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><span lang="IT">Marco Cisternino, PhD<br>
<a href="mailto:marco.cisternino@optimad.it" target="_blank">marco.cisternino@optimad.it</a><u></u><u></u></span></p>
<p class="MsoNormal">______________________<u></u><u></u></p>
<p class="MsoNormal">Optimad Engineering Srl<u></u><u></u></p>
<p class="MsoNormal">Via Bligny 5, <span style="font-family:"Segoe UI",sans-serif;color:rgb(32,31,30);background:white">
Torino, Italia.</span><span style="font-family:"Segoe UI",sans-serif;color:rgb(32,31,30)"><br>
<span style="background:white">+3901119719782</span><br>
</span><span lang="IT"><a href="http://www.optimad.it/" target="_blank"><span lang="EN-US" style="font-family:"Segoe UI",sans-serif;border:1pt none windowtext;padding:0cm;background:white">www.optimad.it</span></a></span><u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<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>From:</b> Marco Cisternino <<a href="mailto:marco.cisternino@optimad.it" target="_blank">marco.cisternino@optimad.it</a>> <br>
<b>Sent:</b> martedì 7 dicembre 2021 19:36<br>
<b>To:</b> Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>><br>
<b>Cc:</b> petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject:</b> Re: [petsc-users] Nullspaces<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="background:white"><span style="color:rgb(33,33,33)">I will, as soon as possible...<u></u><u></u></span></p>
</div>
<div id="gmail-m_774479102612054469gmail-m_-3783333818967129010ms-outlook-mobile-signature">
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">Scarica <a href="https://aka.ms/AAb9ysg" target="_blank">Outlook per Android</a><u></u><u></u></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="gmail-m_774479102612054469gmail-m_-3783333818967129010divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>><br>
<b>Sent:</b> Tuesday, December 7, 2021 7:25:43 PM<br>
<b>To:</b> Marco Cisternino <<a href="mailto:marco.cisternino@optimad.it" target="_blank">marco.cisternino@optimad.it</a>><br>
<b>Cc:</b> petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject:</b> Re: [petsc-users] Nullspaces</span> <u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">On Tue, Dec 7, 2021 at 11:19 AM Marco Cisternino <<a href="mailto:marco.cisternino@optimad.it" target="_blank">marco.cisternino@optimad.it</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-left:4.8pt;margin-right:0cm">
<div>
<div>
<p><span lang="IT">Good morning,<u></u><u></u></span></p>
<p><span lang="EN-GB">I’m still struggling with the Poisson equation with Neumann BCs.</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">I discretize the equation by finite volume method and I divide every line of the linear system by the volume of the cell. I could avoid this division, but I’m trying to understand.</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">My mesh is not uniform, i.e. cells have different volumes (it is an octree mesh).</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">Moreover, in my computational domain there are 2 separated sub-domains.</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">I build the null space and then I use MatNullSpaceTest to check it.</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB"> </span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">If I do this:</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">MatNullSpaceCreate(getCommunicator(), PETSC_TRUE, 0, nullptr, &nullspace);</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">It works</span><span lang="IT"><u></u><u></u></span></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This produces the normalized constant vector.<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-left:4.8pt;margin-right:0cm">
<div>
<div>
<p><span lang="EN-GB">If I do this:</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="FR">Vec nsp;</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="FR">VecDuplicate(m_rhs, &nsp);</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="FR">VecSet(nsp,1.0);</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="FR">VecNormalize(nsp, nullptr);</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">MatNullSpaceCreate(getCommunicator(), PETSC_FALSE, 1, &nsp, &nullspace);</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">It does not work</span><span lang="IT"><u></u><u></u></span></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This is also the normalized constant vector.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">So you are saying that these two vectors give different results with MatNullSpaceTest()?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Something must be wrong in the code. Can you send a minimal example of this? I will go<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">through and debug it.<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-left:4.8pt;margin-right:0cm">
<div>
<div>
<p><span lang="EN-GB">Probably, I have wrong expectations, but should not it be the same?</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB"> </span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">Thanks</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB"> </span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="IT">Marco Cisternino, PhD<br>
<a href="mailto:marco.cisternino@optimad.it" target="_blank">marco.cisternino@optimad.it</a><u></u><u></u></span></p>
<p><span lang="EN-GB">______________________</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">Optimad Engineering Srl</span><span lang="IT"><u></u><u></u></span></p>
<p><span lang="EN-GB">Via Bligny 5, </span><span lang="EN-GB" style="font-family:"Segoe UI",sans-serif;color:rgb(32,31,30);background:white">Torino, Italia.</span><span lang="EN-GB" style="font-family:"Segoe UI",sans-serif;color:rgb(32,31,30)"><br>
<span style="background:white">+3901119719782</span><br>
</span><span lang="IT"><a href="http://www.optimad.it/" target="_blank"><span lang="EN-GB" style="font-family:"Segoe UI",sans-serif;border:1pt none windowtext;padding:0cm;background:white">www.optimad.it</span></a><u></u><u></u></span></p>
<p><span lang="EN-GB"> </span><span lang="IT"><u></u><u></u></span></p>
</div>
</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>
</div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><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>
</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>