<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    On 15/10/21 22:30, Matthew Knepley wrote:<br>
    <blockquote type="cite"
cite="mid:CAMYG4GnhLHEbJCfcULZ5dcc9uN+5jyvDLe+HPZw4tpMtttC_pg@mail.gmail.com">
      <div dir="ltr">
        <div dir="ltr">On Fri, Oct 15, 2021 at 10:16 AM Pierre Seize
          <<a href="mailto:pierre.seize@onera.fr"
            moz-do-not-send="true">pierre.seize@onera.fr</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 bgcolor="#FFFFFF">
              <p>I read everything again, I think I did not understand
                you at first. The first solution is to modify the DAG,
                so that the rightmost cell is linked to the leftmost
                face, right ? To do that, do I have to manually edit the
                DAG (the mesh is read from a file) ?</p>
            </div>
          </blockquote>
          <div>Yes, the DAG would be modified if you want it for some
            particular mesh that we cannot read automatically. For
            example, we can read periodic GMsh meshes. </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
            0.8ex;border-left:1px solid
            rgb(204,204,204);padding-left:1ex">
            <div bgcolor="#FFFFFF">
              <p> If so, the mesh connectivity is like the one of a
                torus, then how does it work with the cells/faces
                coordinates ?</p>
            </div>
          </blockquote>
          <div>You let the coordinate field be in a DG space, so that it
            can have jumps. <br>
          </div>
        </div>
      </div>
    </blockquote>
    I'm not sure I fully understand this, what I'll do is that I will
    experiment with a periodic GMSH mesh.<br>
    <br>
    <blockquote type="cite"
cite="mid:CAMYG4GnhLHEbJCfcULZ5dcc9uN+5jyvDLe+HPZw4tpMtttC_pg@mail.gmail.com">
      <div dir="ltr">
        <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 bgcolor="#FFFFFF">
              <p>Now I think the second method may be more
                straightforward. What's the idea ? Get the mapping with
                DMGetLocalToGlobalMapping, then create the mapping
                corresponding to the periodicity with
                ISLocalToGlobalMappingCreate, and finally
                ISLocalToGlobalMappingConcatenate ? I'm not sure this is
                the way, and I did not find something like
                DMSetLocalToGlobalMapping to restore the modified
                mapping.</p>
            </div>
          </blockquote>
          <div>It is more complicated. We make the LocalToGlobalMap by
            looking at the PetscSection (essentially if gives function
            space information)  and deciding which unknowns are removed
            from the global space.</div>
          <div>You would need to decide that unknowns constrained by
            periodicity are not present in the global space. Actually,
            this is not hard. You just mark them as constrained in the
            PetscSection, and all the layout</div>
          <div>functions will function correctly. However, then the
            LocalToGlobalMap will not be exactly right because the
            constrained unknowns will not be filled in (just like
            Dirichlet conditions). You would augment the</div>
          <div>map so that it fills those in by looking up their
            periodic counterparts. Jed has argued for this type of
            periodicity.</div>
        </div>
      </div>
    </blockquote>
    I also don't understand. One one side of my mesh I have :   | ghost1
    | cell1 | cell2 | ...  and on the other | cell_n-1 | cell_n |
    ghost_n |. Are not the ghosts (from DMPlexConstructGhostCells)
    already constrained ?<br>
    I experimented on that too, I did:<br>
    <br>
    DMGetSectionSF<br>
    PetscSFGetGraph<br>
    augment the graph by adding the local ghost cells to the leaves, and
    the correct remote "true" cells to the roots<br>
    PetscSFSetGraph<br>
    <br>
    and it seems to do what I want. Is this what you meant ? Is this a
    correct way to use the PETSc objects ? Or is this just hacky and I'm
    lucky it works ?<br>
    <br>
    Pierre<br>
    <br>
    <blockquote type="cite"
cite="mid:CAMYG4GnhLHEbJCfcULZ5dcc9uN+5jyvDLe+HPZw4tpMtttC_pg@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote">
          <div><br>
          </div>
          <div>To me, the first kind is much more straightforward, but
            maybe this is because I find the topology code more clear.</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 bgcolor="#FFFFFF">
              <p>Pierre<br>
              </p>
              <br>
              <div>On 15/10/21 15:33, Pierre Seize wrote:<br>
              </div>
              <blockquote type="cite">
                <p>When I first tried to handle the periodicity, I found
                  the <tt>DMPlexCreateBoxMesh</tt> function (I cannot
                  find the cylinder one).</p>
                <p>From reading the sources, I understand that we do
                  some work either in <tt>DMPlexCreateCubeMesh_Internal</tt>
                  or with <tt>DMSetPeriodicity</tt>.</p>
                <p>I tried to use <tt>DMSetPeriodicity</tt> before, for
                  example with a 2x2 box on length 10. I did something
                  like:<br>
                </p>
                <tt> const PetscReal maxCell[] = {2, 2};</tt><tt><br>
                </tt><tt>const PetscReal L[] = {10, 10};</tt><tt><br>
                </tt><tt>const DMBoundaryType bd[] =
                  {DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC}</tt><tt>;<br>
                </tt><tt>DMSetPeriodicity(dm, PETSC_TRUE, maxCell, L,
                  bd);<br>
                </tt><tt>// or:<br>
                </tt><tt>DMSetPeriodicity(dm, PETSC_TRUE, NULL, L, bd);</tt><br>
                <p>but it did not work: <br>
                </p>
                <tt>VecSet(X, 1);<br>
                  DMGetLocalVector(dm, &locX);</tt><tt><br>
                </tt><tt>VecZeroEntries(locX);</tt><tt><br>
                </tt><tt>DMGlobalToLocalBegin(dm, X, INSERT_VALUES,
                  locX);</tt><tt><br>
                </tt><tt>DMGlobalToLocalEnd(dm, X, INSERT_VALUES, locX);</tt><br>
                <tt>VecView(locX, PETSC_VIEWER_STDOUT_WORLD);</tt>
                <p>but the ghost cells values are all 0, only the real
                  cells are 1. So I guess <tt>DMSetPeriodicity</tt>
                  alone is not sufficient to handle the periodicity. Is
                  there a way to do what I want ? That is set up my
                  DMPlex in a way that  <tt>DMGlobalToLocalBegin/</tt><tt>DMGlobalToLocalEnd</tt>
                  do exchange values between procs AND exchange the
                  periodic values?</p>
                <p><br>
                </p>
                <p>Thanks for the help</p>
                <p><br>
                </p>
                <p>Pierre<br>
                </p>
                <br>
                <div>On 15/10/21 14:03, Matthew Knepley wrote:<br>
                </div>
                <blockquote type="cite">
                  <div dir="ltr">
                    <div dir="ltr">On Fri, Oct 15, 2021 at 7:31 AM
                      Pierre Seize <<a
                        href="mailto:pierre.seize@onera.fr"
                        target="_blank" moz-do-not-send="true">pierre.seize@onera.fr</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 bgcolor="#FFFFFF">
                          <p>It makes sense, thank you. In fact, both
                            ways seems better than my way. The first one
                            looks the most straightforward.
                            Unfortunately I do not know how to implement
                            either of them. Could you please direct me
                            to the corresponding PETSc functions ?<br>
                          </p>
                        </div>
                      </blockquote>
                      <div>The first way is implemented for example in
                        DMPlexCreateBoxMesh() and
                        DMPlexCreateCylinderMesh(). The second is not
                        implemented since</div>
                      <div>there did not seem to be a general way to do
                        it. I would help if you wanted to try coding it
                        up.</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 bgcolor="#FFFFFF">
                          <p>Pierre<br>
                          </p>
                          <br>
                          <div>On 15/10/21 13:25, Matthew Knepley wrote:<br>
                          </div>
                          <blockquote type="cite">
                            <div dir="ltr">
                              <div dir="ltr">On Fri, Oct 15, 2021 at
                                7:08 AM Pierre Seize <<a
                                  href="mailto:pierre.seize@onera.fr"
                                  target="_blank" moz-do-not-send="true">pierre.seize@onera.fr</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">Hi,<br>
                                  <br>
                                  I'm writing a code using PETSc to
                                  solve NS equations with FV on an <br>
                                  unstructured mesh. Therefore I use
                                  DMPlex.<br>
                                  <br>
                                  Regarding periodicity, I manage to
                                  implement it this way:<br>
                                  <br>
                                     - for each couple of boundaries
                                  that is linked with periodicity, I <br>
                                  create a buffer vector with an
                                  ISLocalToGlobalMapping<br>
                                  <br>
                                     - then, when I need to fill the
                                  ghost cells corresponding to the <br>
                                  periodicity, the i "true" cell of the
                                  local vector fills the buffer <br>
                                  vector on location i with
                                  VecSetValuesBlockedLocal, then <br>
                                  VecAssemblyBegin/VecAssemblyEnd ensure
                                  each value is send to the correct <br>
                                  location thanks to the mapping, then
                                  the i "ghost" cell of the local <br>
                                  vector reads the vector on location i
                                  to get it's value.<br>
                                  <br>
                                  <br>
                                  It works, but it seems to me there is
                                  a better way, with maybe PetscSF, <br>
                                  VecScatter, or something I don't know
                                  yet. Does anyone have any advice ?<br>
                                </blockquote>
                                <div><br>
                                </div>
                                <div>There are at least two other ways
                                  to handle this. First, the method that
                                  is advocated in</div>
                                <div>Plex is to actually make a periodic
                                  geometry, meaning connect the cells
                                  that are meant</div>
                                <div>to be connected. Then, if you
                                  partition with overlap = 1,
                                  PetscGlobalToLocal() will fill in</div>
                                <div>these cell values automatically.</div>
                                <div><br>
                                </div>
                                <div>Second, you could use a
                                  non-periodic geometry, but alter the
                                  LocalToGlobal map such</div>
                                <div>that the cells gets filled in
                                  anyway. Many codes use this scheme and
                                  it is straightforward</div>
                                <div>with Plex just by augmenting the
                                  map it makes automatically.</div>
                                <div><br>
                                </div>
                                <div>Does this make sense?</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">
                                  Pierre Seize<br>
                                </blockquote>
                              </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/%7Eknepley/"
                                              target="_blank"
                                              moz-do-not-send="true">https://www.cse.buffalo.edu/~knepley/</a><br>
                                          </div>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </blockquote>
                          <br>
                        </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/%7Eknepley/"
                                    target="_blank"
                                    moz-do-not-send="true">https://www.cse.buffalo.edu/~knepley/</a><br>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </blockquote>
                <br>
              </blockquote>
              <br>
            </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/%7Eknepley/"
                        target="_blank" moz-do-not-send="true">https://www.cse.buffalo.edu/~knepley/</a><br>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>