<div dir="ltr"><div dir="ltr"><div><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 7, 2020 at 8:27 AM Victoria Hamtiaux <<a href="mailto:victoria.hamtiaux@uclouvain.be" target="_blank">victoria.hamtiaux@uclouvain.be</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>
    <p>Thanks for all the answers,</p>
    <p><br>
    </p>
    <p>How can I do the "semi-coarsening"? I don't really know how those
      preconditionners work so I don't how how to change them or so..</p>
    <p><br></p></div></blockquote>You have to write custom code to do semi-coarsening. PETSc does not provide that and you would not want to do it yourself, most likely.<div></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><p>
    </p>
    <p>I have a question because you both seem to say that my matrix is
      supposed to be symmetric which is not the case. \</p></div></blockquote><div>You said "my matrix is symmetric." </div><div><br></div><div>Then you said " I suspect that by stretching the grid, my matrix is not symmetric anymore and that it might cause a problem."</div><div><br></div><div>We are saying that by stretchin the grid the matrix is still symmetric even if the grid has lost a symmetry. I don't know of a mechanism for stretching the grid to make the matrix asymmetric. So we are suggesting that you verify your suspicion that the matrix is symmetric.</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><p>And in fact, I
      don't get how it can be symmetric. Because you will have something
      close to symmetric. For example when you are at the center of your
      domain it will be symmetric, but when your at a point at the
      boundaries I don't get how you can be symmetric, you won't have
      something at the left and the right of your main diagonal... (I
      don't know if my explanations are understandable)</p></div></blockquote><div>You can make a discretization that is not symmetric because of boundary conditions but I assume that is not the case because you said your matrix is symmetric.</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>
    <p>Best regards, <br>
    </p>
    <p><br>
    </p>
    <p>Victoria<br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
    <div>On 7/10/20 14:20, Mark Adams wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">GMG (geometric MG) is stronger as Matt said, but it
        is affected by stretched grids in a similar way. A way to fix
        this in GMG is semi-coarsening, which AMG _can_ do
        automatically.<br>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Wed, Oct 7, 2020 at 8:02 AM
          Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">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 Wed, Oct 7, 2020 at 7:07 AM Victoria
              Hamtiaux <<a href="mailto:victoria.hamtiaux@uclouvain.be" target="_blank">victoria.hamtiaux@uclouvain.be</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>
                  <p>Hello Matt, <br>
                  </p>
                  <p><br>
                  </p>
                  <p>I just checked the symmetry of my matrix and it is
                    not symmetric. But it is not symmetric either when I
                    use a uniform grid.</p>
                  <p>The domain is 3D and I'm using finite differences,
                    so I guess it is normal that at multiple places
                    (when I deal with points near the boundaries), the
                    matrix is not symmetric.<br>
                  </p>
                  <p>So I was wrong, the problem doesn't come from the
                    fact that the matrix is not symmetric. I don't know
                    where it comes from, but when I switch from uniform
                    to stretched grid, the solver stops working
                    properly. Could it be from the preconditionner of
                    the solver that I use?<br>
                  </p>
                  <p>Do you have any other idea ? </p>
                </div>
              </blockquote>
              <div>I would consider using GMG. As Mark says, AMG is very
                fiddly with stretched grids. For Poisson, GMG works
                great and you seem to have regular grids.</div>
              <div><br>
              </div>
              <div>  Thanks,</div>
              <div><br>
              </div>
              <div>    Matt </div>
              <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                <div>
                  <p>Thanks for your help, <br>
                  </p>
                  <p><br>
                  </p>
                  <p>Victoria<br>
                  </p>
                  <p><br>
                  </p>
                  <div>On 7/10/20 12:48, Matthew Knepley wrote:<br>
                  </div>
                  <blockquote type="cite">
                    <div dir="ltr">
                      <div dir="ltr">On Wed, Oct 7, 2020 at 6:40 AM
                        Victoria Hamtiaux <<a href="mailto:victoria.hamtiaux@uclouvain.be" target="_blank">victoria.hamtiaux@uclouvain.be</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">Dear all,<br>
                          <br>
                          <br>
                          After the discretization of a poisson equation
                          with purely Neumann (or <br>
                          periodic) boundary conditions, I get a matrix
                          which is singular.<br>
                          <br>
                          <br>
                          The way I am handling this is by using a
                          NullSpace with the following <br>
                          code :<br>
                          <br>
                          MatNullSpace nullspace;<br>
                          MatNullSpaceCreate(PETSC_COMM_WORLD,
                          PETSC_TRUE, 0, 0, &nullspace);<br>
                          MatSetNullSpace(p_solverp->A, nullspace);<br>
                          MatSetTransposeNullSpace(p_solverp->A,
                          nullspace);<br>
                          MatNullSpaceDestroy(&nullspace);<br>
                          <br>
                          <br>
                          Note that I am using the hypre preconditionner
                          BOOMERANG and the default <br>
                          solver GMRES.<br>
                          <br>
                          <br>
                              
                          KSPCreate(PETSC_COMM_WORLD,&p_solverp->ksp);<br>
                               KSPSetOperators(p_solverp->ksp,
                          p_solverp->A, p_solverp->A);<br>
                               PC prec;<br>
                               KSPGetPC(p_solverp->ksp, &prec);<br>
                               PCSetType(prec,PCHYPRE);//PCHYPRE seems
                          the best<br>
                               PCHYPRESetType(prec,"boomeramg");
                          //boomeramg is the best<br>
                              
                          KSPSetInitialGuessNonzero(p_solverp->ksp,PETSC_TRUE);<br>
                               KSPSetFromOptions(p_solverp->ksp);<br>
                               KSPSetTolerances(p_solverp->ksp,
                          1.e-10, 1e-10, PETSC_DEFAULT, <br>
                          PETSC_DEFAULT);<br>
                              
                          KSPSetReusePreconditioner(p_solverp->ksp,PETSC_TRUE);<br>
                              
                          KSPSetUseFischerGuess(p_solverp->ksp,1,5);<br>
                              
                          KSPGMRESSetPreAllocateVectors(p_solverp->ksp);<br>
                               KSPSetUp(p_solverp->ksp);<br>
                          <br>
                          <br>
                          <br>
                          And this works fine when my grid is uniform,
                          so that my matrix is <br>
                          symmetric.<br>
                          <br>
                          <br>
                          But when I stretch the grid near the boundary
                          (my grid is then <br>
                          non-uniform), it doesn't work properly
                          anymore. I suspect that by <br>
                          stretching the grid, my matrix is not
                          symmetric anymore and that it <br>
                          might cause a problem.<br>
                        </blockquote>
                        <div><br>
                        </div>
                        <div>Symmetry is a property of the operator, so
                          you should be symmetric on your</div>
                        <div>stretched grid. If not, I think you have
                          the discretization wrong. You can check</div>
                        <div>symmetry using</div>
                        <div><br>
                        </div>
                        <div>  <a href="https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.mcs.anl.gov%2Fpetsc%2Fpetsc-current%2Fdocs%2Fmanualpages%2FMat%2FMatIsSymmetric.html&data=02%7C01%7Cvictoria.hamtiaux%40uclouvain.be%7C494a0f05bd214b5974f008d86abb6e02%7C7ab090d4fa2e4ecfbc7c4127b4d582ec%7C0%7C0%7C637376700525925749&sdata=nWt0sejio7o1PzMoc7tPu7JOvcNqofRuMQ91ynW54r4%3D&reserved=0" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatIsSymmetric.html</a></div>
                        <div><br>
                        </div>
                        <div>Also, if you suspect your discretization,
                          you should probably do an MMS test to</div>
                        <div>verify that you discretization converges at
                          the correct rate.</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"> I tried
                          fixing the solution at an arbitrary point, but
                          sometimes doing <br>
                          this, I get errors near that fixed point. I
                          've seen on the petsc-users <br>
                          forum that you usually don't recommend to fix
                          a point, but I don't <br>
                          really know how to proceed differently.<br>
                          <br>
                          <br>
                          What would you recommend to solve this
                          problem?<br>
                          <br>
                          <br>
                          Thanks for your help,<br>
                          <br>
                          <br>
                          Best regards,<br>
                          <br>
                          <br>
                          Victoria<br>
                          <br>
                          <br>
                        </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="https://eur03.safelinks.protection.outlook.com/?url=http:%2F%2Fwww.cse.buffalo.edu%2F~knepley%2F&data=02%7C01%7Cvictoria.hamtiaux%40uclouvain.be%7C494a0f05bd214b5974f008d86abb6e02%7C7ab090d4fa2e4ecfbc7c4127b4d582ec%7C0%7C0%7C637376700525925749&sdata=LHARUv3BxSwWnxN2LUJnX3vr2ZJ9f50EMQzw44Hy%2FqY%3D&reserved=0" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </blockquote>
                </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="https://eur03.safelinks.protection.outlook.com/?url=http:%2F%2Fwww.cse.buffalo.edu%2F~knepley%2F&data=02%7C01%7Cvictoria.hamtiaux%40uclouvain.be%7C494a0f05bd214b5974f008d86abb6e02%7C7ab090d4fa2e4ecfbc7c4127b4d582ec%7C0%7C0%7C637376700525935751&sdata=kOKe%2FLj7pvAdzldpTNlRfC7BS6Vv4S5mU6Cb8pPpmrE%3D&reserved=0" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </blockquote>
      </div>
    </blockquote>
  </div>

</blockquote></div>
</div>