<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <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 class="moz-cite-prefix">On 15/10/21 14:03, Matthew Knepley
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAMYG4Gk+ibpcAdCrCByUebYt6p=dRS9fE3xjA04VeMkmQS65wg@mail.gmail.com">
      <div dir="ltr">
        <div dir="ltr">On Fri, Oct 15, 2021 at 7:31 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>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" 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>