<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Hi Patrick,</p>
<p><br>
</p>
<p>Thanks for your responses. </p>
<p>As for the code, I was not granted permission to share it yet. So, I cannot send it to you for the moment. I apologize for that.</p>
<p><br>
</p>
<p>I wanted to let you know that while I was testing my code, I discovered that when the periodic boundary conditions are activated, the coordinates accessed might be incorrect on one side of the boundary. </p>
<p>Let me give you an example in cylindrical coordinates with a 3x3x3 DMStag mesh: </p>
<p> </p>
<p><br>
</p>
<p><br>
</p>
<p>PetscInt<span class="Apple-tab-span" style="white-space:pre"> </span> startr,startphi,startz,nr,nphi,nz,d;</p>
<p></p>
<p>PetscInt<span class="Apple-tab-span" style="white-space:pre"> </span> er,ephi,ez,<span style="font-size: 12pt;">icErmphip[3];</span></p>
<p></p>
<p>DM dmCoorda, coordDA;</p>
<p>Vec coordaLocal;</p>
<p>PetscScalar ****arrCoord;</p>
<p>PetscScalar surf;</p>
<p><br>
</p>
<p>DMStagCreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,3,3,3,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,1,1,DMSTAG_STENCIL_BOX,1,NULL,NULL,NULL,&coordDA);<br>
</p>
<p><br>
</p>
<p>DMSetFromOptions(coordDA);</p>
<p>DMSetUp(coordDA);</p>
<p><br>
</p>
<p>DMStagGetCorners(coordDA,&startr,&startphi,&startz,&nr,&nphi,&nz,NULL,NULL,NULL);</p>
<p><br>
</p>
<p>DMGetCoordinateDM(coordDA,&dmCoorda);</p>
<p>DMGetCoordinatesLocal(coordDA,&coordaLocal);</p>
<p> DMStagVecGetArrayRead(dmCoorda,coordaLocal,&arrCoord);</p>
<p><br>
</p>
<p>for (d=0; d< 3; ++d){</p>
<p>DMStagGetLocationSlot(dmCoorda,UP_LEFT,d,&icErmphip[d]);<br>
</p>
<p>}</p>
<p><br>
</p>
<p>er = 1; ez = 0;</p>
<p>for (ephi=0; ephi< 3; ++ephi){</p>
<p><span style="font-size: 12pt;"> PetscPrintf(PETSC_COMM</span><span style="font-size: 12pt;">_</span><span style="font-size: 12pt;">WORLD,"Phi_p(%d,%d,%d) = %E</span><span style="font-size: 12pt;">\</span><span style="font-size: 12pt;">n</span><span style="font-size: 12pt;">",</span><span style="font-size: 12pt;">er</span><span style="font-size: 12pt;">,</span><span style="font-size: 12pt;">ephi</span><span style="font-size: 12pt;">,</span><span style="font-size: 12pt;">ez</span><span style="font-size: 12pt;">,(double)</span><span style="font-size: 12pt;">arrCoord[ez][ephi][er][icErmphip[1]</span><span style="font-size: 12pt;">);</span></p>
<p>}</p>
<p><br>
</p>
<p>When I execute this example, I get this output:</p>
<p><span style="font-size: 12pt;">Phi_p(1,0</span><span style="font-size: 12pt;">,0) =</span><span style="font-size: 12pt;"> </span><span style="font-size: 12pt;">2</span><span style="font-size: 12pt;">.094395</span><span style="font-size: 12pt;">E+00</span></p>
<p><span style="font-size: 12pt;"></span>Phi_p(1,1,0) = 4.188790E+00<br>
</p>
<p>Phi_p(1,2,0) = 0.000000E+00</p>
<p><br>
</p>
<p>Note here that the first two lines correspond to 2<span style="caret-color: rgb(33, 33, 33); color: rgb(33, 33, 33); font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 12pt;">ð / 3 and 4</span><span style="caret-color: rgb(33, 33, 33); color: rgb(33, 33, 33); font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 12pt;">ð
/ 3 respectively. Thus, nothing is wrong here. </span></p>
<p><span style="caret-color: rgb(33, 33, 33); color: rgb(33, 33, 33); font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 12pt;">But the last line should rather give 2</span><span style="caret-color: rgb(33, 33, 33); color: rgb(33, 33, 33); font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 12pt;">ð
instead of 0.</span></p>
<p><span style="caret-color: rgb(33, 33, 33); color: rgb(33, 33, 33); font-family: Calibri, Helvetica, sans-serif, serif, EmojiFont; font-size: 12pt;"><br>
</span></p>
<p><span style="font-size: 12pt;">I understand that degrees of freedom should be the same on both sides of the boundary, but should the coordinates not be preserved? </span></p>
<p><span style="font-size: 12pt;">Thank you.</span></p>
<p><span style="font-size: 12pt;">Best regards,</span></p>
<p><span style="font-size: 12pt;"><br>
</span></p>
<p><span style="font-size: 12pt;">Zakariae Jorti</span></p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Patrick Sanan <patrick.sanan@gmail.com><br>
<b>Sent:</b> Tuesday, March 23, 2021 11:37:04 AM<br>
<b>To:</b> Jorti, Zakariae<br>
<b>Cc:</b> petsc-users@mcs.anl.gov<br>
<b>Subject:</b> [EXTERNAL] Re: Question about periodic conditions</font>
<div> </div>
</div>
<div>Hi Zakariae - sorry about the delay - responses inline below.
<div class=""><br class="">
</div>
<div class="">I'd be curious to see your code (which you can send directly to me if you don't want to post it publicly), so I can give you more comments, as DMStag is a new component. <br class="">
<div class=""><br class="">
</div>
<div class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">Am 23.03.2021 um 00:54 schrieb Jorti, Zakariae <<a href="mailto:zjorti@lanl.gov" class="">zjorti@lanl.gov</a>>:</div>
<br class="Apple-interchange-newline">
<div class="">
<div id="divtagdefaultwrapper" dir="ltr" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">
<div style="margin-top: 0px; margin-bottom: 0px;" class="">Hi, </div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class="">
</div>
<div style="margin-top: 0px; margin-bottom: 0px;" class="">I implemented a PETSc code to solve Maxwell's equations for the magnetic and electric fields (B and E) in a cylinder: </div>
<div style="margin-top: 0px; margin-bottom: 0px;" class="">0 < r_min <= r <= r_max; with <span style="font-size: 12pt;" class="">r_max</span><span style="font-size: 12pt;" class=""> > r_min</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class="">phi_min = 0 <span style="font-size: 12pt;" class=""><= r <= phi_max</span><span style="font-size: 12pt;" class=""> = 2 </span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">ð</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">z_min <= z =< z_max; </span><span style="font-size: 12pt;" class="">with </span><span style="font-size: 12pt;" class="">z_max</span><span style="font-size: 12pt;" class=""> >
z_min.</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-size: 12pt;" class=""><br class="">
</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><font size="3" class="">I am using a PETSc staggered grid with the electric field E defined on edge centers and the magnetic field B </font>defined<font size="3" class=""> on face centers. (</font><span style="font-size: 12pt;" class="">dof0
= 0, dof1 = 1,dof2 = 1, dof3 = 0;</span><font size="3" class="">). </font><font size="3" class=""> </font></div>
</div>
</div>
</blockquote>
<blockquote type="cite" class="">
<div class="">
<div id="divtagdefaultwrapper" dir="ltr" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class="">
</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-size: 12pt;" class=""></span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">I have two versions of my code: </span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><font face="Calibri, Helvetica, sans-serif" size="3" class="">1 - A first version<span class="Apple-converted-space"> </span></font><font face="Calibri, Helvetica, sans-serif" class="">in which I set
the boundary type to DM_BOUNDARY_NONE in the three directions r, phi and z</font></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">2- A second version in which I set </span><span style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">the boundary
type to DM_BOUNDARY_NONE in the r and z directions</span><span style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">, </span><font face="Calibri, Helvetica, sans-serif" size="3" class="">and DM_BOUNDARY_PERIODIC in the phi di</font><font face="Calibri, Helvetica, sans-serif" class="">rection.</font><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""> </span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class="">
</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">When I print the solution vector X, which contains both E and B components, I notice that the vector is shorter with
the second version compared to the first one. </span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">Is it normal? </span></div>
</div>
</div>
</blockquote>
Yes - with the periodic boundary conditions, there will be fewer points since there won't be the "extra" layer of faces and edges at phi = 2 * pi .</div>
<div><br class="">
</div>
<div>If you consider a 1-d example with 1 dof on vertices and cells, with three elements, the periodic case looks like this, globally,</div>
<div><br class="">
</div>
<div> x ---- x ---- x ----</div>
<div><br class="">
</div>
<div>as opposed to the non-periodic case,</div>
<div><br class="">
</div>
<div> x ---- x ---- x ---- x</div>
<div><br class="">
</div>
<div><br class="">
</div>
<div>
<blockquote type="cite" class="">
<div class="">
<div id="divtagdefaultwrapper" dir="ltr" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class="">
</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">Besides, I was wondering if I have to change the way I define the value of the solution on the boundary. What I am
doing so far in both versions is something like:</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">B_phi [phi = 0] = 1.0;</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif;" class="">B_phi </span><span style="font-family: Calibri, Helvetica, sans-serif;" class="">[phi = 2</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">ð</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">]
= 1.0;</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">E_z [r, phi = 0</span><span style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">] = 1/r;</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class="">
</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">E_z [r, phi = 2</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">ð</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">]
= 1/r;</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class="">
</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><font face="Calibri, Helvetica, sans-serif" class="">Assuming that values at phi = 0 should be the same as at phi=2</font><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">ð
with the periodic boundary conditions, </span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">is it sufficient for example </span><font face="Calibri, Helvetica, sans-serif" size="3" class="">to </font><font face="Calibri, Helvetica, sans-serif" class="">have</font><font face="Calibri, Helvetica, sans-serif" size="3" class=""> only
the following boundary conditions</font><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">:</span></div>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">B_phi [phi = 0] = 1.0;</span></div>
<p style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""></span></p>
<div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">E_z [r, phi = 0</span><span style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">] = 1/r
? </span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class="">
</span></div>
</div>
</div>
</blockquote>
<div><br class="">
</div>
Yes - this is the intention, since the boundary at phi = 2 * pi is represented by the same entries in the global vector. </div>
<div><br class="">
</div>
<div>Of course, you need to make sure that your continuous problem is well-posed, which in general could change when using different boundary conditions. </div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">
<div id="divtagdefaultwrapper" dir="ltr" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">
<div class=""><span style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">Thank you.</span></div>
<div class=""><font face="Calibri, Helvetica, sans-serif" class="">Best regards,</font></div>
<div class=""><font face="Calibri, Helvetica, sans-serif" class=""><br class="">
</font></div>
<div class=""><font face="Calibri, Helvetica, sans-serif" class="">Zakariae Jorti</font></div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</body>
</html>