<div style="color:black;font: 10pt arial;">
<div> <br>
</div>
<div> <br>
</div>
<div> <br>
</div>
<div style="font-family:arial,helvetica;font-size:10pt;color:black">-----Original Message-----<br>
From: Daniel Mckinnell <d_mckinnell@aol.co.uk><br>
To: knepley <knepley@gmail.com><br>
Sent: Mon, 19 Aug 2019 9:45<br>
Subject: Re: [petsc-users] Accessing Global Vector Data with<br>
<br>
<div id="yiv6893606478">
<div>
<div style="color:black;font:10pt arial;">
<div> <font size="2">Thank you for the help, the "</font>if (voff >= 0)<font size="2">" line was to prevent errors from looping over ghost vertices but it is better to just loop from the start of the vertices to the end of the physical vertices.</font></div>
<div><font size="2"><br clear="none">
</font></div>
<div><font size="2">I am really just trying to create an example file of a method to access the associated field data </font><font size="2">of a sample vertex </font><font size="2">in the global Vec, alter the field data and then set it back into the Vec object.</font></div>
<div><font size="2">Best Regards,</font></div>
<div><font size="2">Daniel<br clear="none">
</font></div>
<div> <br clear="none">
</div>
<div> <br clear="none">
</div>
<div class="yiv6893606478yqt9398620036" id="yiv6893606478yqt69351">
<div style="font-family:arial, helvetica;font-size:10pt;color:black;">-----Original Message-----<br clear="none">
From: Matthew Knepley <knepley@gmail.com><br clear="none">
To: Daniel Mckinnell <d_mckinnell@aol.co.uk><br clear="none">
CC: PETSc <petsc-maint@mcs.anl.gov><br clear="none">
Sent: Thu, 15 Aug 2019 17:19<br clear="none">
Subject: Re: [petsc-users] Accessing Global Vector Data with<br clear="none">
<br clear="none">
<div id="yiv6893606478">
<div>
<div dir="ltr">
<div dir="ltr">On Thu, Aug 15, 2019 at 12:05 PM Daniel Mckinnell <<a rel="noopener noreferrer" shape="rect" ymailto="mailto:d_mckinnell@aol.co.uk" target="_blank" href="mailto:d_mckinnell@aol.co.uk">d_mckinnell@aol.co.uk</a>> wrote:<br clear="none"></div>
<div class="yiv6893606478gmail_quote"><blockquote class="yiv6893606478gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">
<div style="color:black;font:10pt arial;">
<div> <font size="2">Thank you, it seemed to work nicely for the fields associated with cells but I'm having problems with the field on vertices. The code for altering the field is as follows:</font></div>
<div><font size="2"><br clear="none">
</font></div>
<div>for (int i = vStart; i < vEnd; i++)<br clear="none">
{<br clear="none">
PetscScalar *values;<br clear="none">
PetscInt vsize, voff;<br clear="none">
PetscSectionGetDof(globalsection, i, &vsize);<br clear="none">
PetscSectionGetOffset(globalsection, i, &voff);<br clear="none"></div>
</div>
</blockquote>
<div><br clear="none"></div>
<div>You do not need the Section calls I think.</div>
<div> </div>
<blockquote class="yiv6893606478gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">
<div style="color:black;font:10pt arial;">
<div>
VecGetArray(u, &values);<br clear="none"></div>
</div>
</blockquote>
<div><br clear="none"></div>
<div>Hoist GetArray out of v loop</div>
<div> </div>
<blockquote class="yiv6893606478gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">
<div style="color:black;font:10pt arial;">
<div>
if (voff >= 0)<br clear="none"></div>
</div>
</blockquote>
<div><br clear="none"></div>
<div>This check is not needed I think. What you are doing here is a mix of local and global.</div>
<div>What do you actually want to do?</div>
<div><br clear="none"></div>
<blockquote class="yiv6893606478gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">
<div style="color:black;font:10pt arial;">
<div>
{<br clear="none">
PetscScalar *p;<br clear="none">
DMPlexPointLocalRef(*dm, i, values, &p);<br clear="none">
p[0] = i + 1;<br clear="none">
}<br clear="none">
VecRestoreArray(u, &values);</div>
</div>
</blockquote>
<div><br clear="none"></div>
<div>Hoist RestoreArray out of v loop.</div>
<div><br clear="none"></div>
<div> Thanks,</div>
<div><br clear="none"></div>
<div> Matt</div>
<div> </div>
<blockquote class="yiv6893606478gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">
<div style="color:black;font:10pt arial;">
<div><br clear="none">
</div>
<div><font size="2">The Global PetscSection is:</font></div>
<div><font size="2"><br clear="none">
</font></div>
<div>PetscSection Object: 2 MPI processes<br clear="none">
type not yet set<br clear="none">
Process 0:<br clear="none">
( 0) dim 2 offset 0<br clear="none">
( 1) dim 2 offset 2<br clear="none">
( 2) dim -3 offset -13<br clear="none">
( 3) dim -3 offset -15<br clear="none">
( 4) dim 1 offset 4<br clear="none">
( 5) dim 1 offset 5<br clear="none">
( 6) dim 1 offset 6<br clear="none">
( 7) dim -2 offset -17<br clear="none">
( 8) dim -2 offset -18<br clear="none">
( 9) dim -2 offset -19<br clear="none">
( 10) dim -2 offset -20<br clear="none">
( 11) dim -2 offset -21<br clear="none">
( 12) dim -2 offset -22<br clear="none">
( 13) dim 1 offset 7<br clear="none">
( 14) dim 1 offset 8<br clear="none">
( 15) dim 1 offset 9<br clear="none">
( 16) dim 1 offset 10<br clear="none">
( 17) dim 1 offset 11<br clear="none">
( 18) dim -2 offset -23<br clear="none">
( 19) dim -2 offset -24<br clear="none">
( 20) dim -2 offset -25<br clear="none">
( 21) dim -2 offset -26<br clear="none">
( 22) dim -2 offset -27<br clear="none">
( 23) dim -2 offset -28<br clear="none">
( 24) dim -2 offset -29<br clear="none">
Process 1:<br clear="none">
( 0) dim 2 offset 12<br clear="none">
( 1) dim 2 offset 14<br clear="none">
( 2) dim -3 offset -1<br clear="none">
( 3) dim -3 offset -3<br clear="none">
( 4) dim 1 offset 16<br clear="none">
( 5) dim 1 offset 17<br clear="none">
( 6) dim 1 offset 18<br clear="none">
( 7) dim 1 offset 19<br clear="none">
( 8) dim 1 offset 20<br clear="none">
( 9) dim 1 offset 21<br clear="none">
( 10) dim -2 offset -5<br clear="none">
( 11) dim -2 offset -6<br clear="none">
( 12) dim -2 offset -7<br clear="none">
( 13) dim 1 offset 22<br clear="none">
( 14) dim 1 offset 23<br clear="none">
( 15) dim 1 offset 24<br clear="none">
( 16) dim 1 offset 25<br clear="none">
( 17) dim 1 offset 26<br clear="none">
( 18) dim 1 offset 27<br clear="none">
( 19) dim 1 offset 28<br clear="none">
( 20) dim -2 offset -8<br clear="none">
( 21) dim -2 offset -9<br clear="none">
( 22) dim -2 offset -10<br clear="none">
( 23) dim -2 offset -11<br clear="none">
( 24) dim -2 offset -12</div>
<div><br clear="none">
</div>
<div><font size="2">where points 4-6 on proc 0 and points 4-9 on proc 1 are vertices.</font></div>
<div><font size="2"><br clear="none">
</font></div>
<div><font size="2">The altered vec is:</font></div>
<div><font size="2"><br clear="none">
</font></div>
<div>Vec Object: 2 MPI processes<br clear="none">
type: mpi<br clear="none">
Process [0]<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
5.<br clear="none">
6.<br clear="none">
7.<br clear="none">
0.<br clear="none">
Process [1]<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
5.<br clear="none">
6.<br clear="none">
7.<br clear="none">
8.<br clear="none">
9.<br clear="none">
10.<br clear="none">
0.<br clear="none">
0.<br clear="none">
0.<br clear="none">
</div>
<div><br clear="none">
</div>
<div><font size="2">However the altered values do not correspond with the offsets in the PetscSection and I'm not sure what is going wrong.</font></div>
<div><font size="2">Thanks for all of the help.</font></div>
<div><font size="2">Daniel</font><br clear="none">
</div>
<div> <br clear="none">
</div>
<div> <br clear="none">
</div>
<div style="font-family:arial, helvetica;font-size:10pt;color:black;">-----Original Message-----<br clear="none">
From: Matthew Knepley via petsc-users <<a rel="noopener noreferrer" shape="rect" ymailto="mailto:petsc-users@mcs.anl.gov" target="_blank" href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>><br clear="none">
To: Daniel Mckinnell <<a rel="noopener noreferrer" shape="rect" ymailto="mailto:d_mckinnell@aol.co.uk" target="_blank" href="mailto:d_mckinnell@aol.co.uk">d_mckinnell@aol.co.uk</a>><br clear="none">
CC: PETSc <<a rel="noopener noreferrer" shape="rect" ymailto="mailto:petsc-users@mcs.anl.gov" target="_blank" href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>><br clear="none">
Sent: Thu, 15 Aug 2019 16:11<br clear="none">
Subject: Re: [petsc-users] Accessing Global Vector Data with<br clear="none">
<br clear="none">
<div id="yiv6893606478gmail-m_-4874593995683021422yiv6032237259">
<div>
<div dir="ltr">
<div dir="ltr">On Thu, Aug 15, 2019 at 10:59 AM Daniel Mckinnell via petsc-users <<a rel="noopener noreferrer" shape="rect" ymailto="mailto:petsc-users@mcs.anl.gov" target="_blank" href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br clear="none"></div>
<div class="yiv6893606478gmail-m_-4874593995683021422yiv6032237259gmail_quote"><blockquote class="yiv6893606478gmail-m_-4874593995683021422yiv6032237259gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">
<div style="color:black;font:10pt arial;">
<div style="font-family:arial, helvetica;font-size:10pt;color:black;">
<div id="yiv6893606478gmail-m_-4874593995683021422yiv6032237259gmail-m_4572011321480561676yiv8682774075">
<div style="color:black;font:10pt arial;">
<div><font size="2">Hi,</font></div>
<div><font size="2">Attached is a way I came up with to access data in a global vector, is this the best way to do this or are there other ways? It would seem intuitive to use the global PetscSection and VecGetValuesSection but this doesn't seem to work on global vectors.</font></div>
<div><font size="2"><br clear="none">
</font></div>
<div><font size="2">Instead I have used VecGetValues and </font><font size="2"><font size="2">VecSetValues</font>, however I also have a problem with these when extracting more than one value, I initialise the output of </font><font size="2"><font size="2">VecGetValues as PetscScalar *values; and then call </font></font><font size="2"><font size="2"><font size="2"><font size="2">VecGetValues(Other stuff... ,</font></font></font></font><font size="2"><font size="2"> values). This seems to work some times and not others and I can't find any rhyme or reason to it?</font></font></div>
</div>
</div>
</div>
</div>
</blockquote>
<div><br clear="none"></div>
<div>I guess I should write something about this. I like to think of it as a sort of decision tree.</div>
<div><br clear="none"></div>
<div>1) Get just local values, meaning those owned by this process</div>
<div><br clear="none"></div>
<div> These can be obtained from either a local or global vector.</div>
<div><br clear="none"></div>
<div>2) Get ghosted values, meaning those values lying on unowned points that exist in the default PetscSF</div>
<div><br clear="none"></div>
<div> These can only get obtained from a local vector</div>
<div><br clear="none"></div>
<div>3) Get arbitrary values</div>
<div><br clear="none"></div>
<div> You must use a VecScatter or custom PetscSF to get these</div>
<div><br clear="none"></div>
<div>For 1) and 2), I think the best way to get values normally is to use</div>
<div><br clear="none"></div>
<div> <a rel="noopener noreferrer" shape="rect" target="_blank" href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexPointLocalRef.html">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexPointLocalRef.html</a></div>
<div> <a rel="noopener noreferrer" shape="rect" target="_blank" href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexPointGlobalRef.html">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexPointGlobalRef.html</a></div>
<div><br clear="none"></div>
<div>These also have Read versions, and Field version to split off a particular field in the Section.</div>
<div><br clear="none"></div>
<div> Does this help?</div>
<div><br clear="none"></div>
<div> Thanks,</div>
<div><br clear="none"></div>
<div> Matt</div>
<div class="yiv6893606478gmail-m_-4874593995683021422yiv6032237259yqt4791470925" id="yiv6893606478gmail-m_-4874593995683021422yiv6032237259yqtfd19019">
<div> </div>
</div>
<blockquote class="yiv6893606478gmail-m_-4874593995683021422yiv6032237259gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;">
<div style="color:black;font:10pt arial;">
<div style="font-family:arial, helvetica;font-size:10pt;color:black;">
<div id="yiv6893606478gmail-m_-4874593995683021422yiv6032237259gmail-m_4572011321480561676yiv8682774075">
<div style="color:black;font:10pt arial;">
<div class="yiv6893606478gmail-m_-4874593995683021422yiv6032237259yqt4791470925" id="yiv6893606478gmail-m_-4874593995683021422yiv6032237259yqtfd61992">
<div><font size="2">Finally I was wondering if there is a good reference code base on Github including DMPlex that would be helpful in viewing applications of the DMPlex functions?</font></div>
<div><font size="2">Thanks,</font></div>
</div>
<div>
<div class="yiv6893606478gmail-m_-4874593995683021422yiv6032237259yqt4791470925" id="yiv6893606478gmail-m_-4874593995683021422yiv6032237259yqtfd52428"><font size="2">Daniel Mckinnell</font></div>
<br clear="none">
<font size="2"><a rel="nofollow" shape="rect" name="m_-4874593995683021422_m_4572011321480561676_VecGetValuesSection"></a></font></div>
</div>
</div>
</div>
</div>
</blockquote></div>
<br clear="all">
<div><br clear="none"></div>
-- <br clear="none">
<div class="yiv6893606478gmail-m_-4874593995683021422yiv6032237259gmail_signature" 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 clear="none">-- Norbert Wiener</div>
<div><br clear="none"></div>
<div><a rel="noopener noreferrer" shape="rect" target="_blank" href="http://www.cse.buffalo.edu/~knepley/">https://www.cse.buffalo.edu/~knepley/</a>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd79205">
<div class="yiv6893606478gmail-m_-4874593995683021422yiv6032237259yqt4791470925" id="yiv6893606478gmail-m_-4874593995683021422yiv6032237259yqtfd09046"><br clear="none"></div>
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd49406">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd23473">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd67337">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd30080">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd83922">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd67964">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd07750">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd99589">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd37812">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd41409">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd66243">
</div>
</div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd93502">
</div>
</blockquote></div>
<div class="yiv6893606478yqt3250618416" id="yiv6893606478yqtfd59830"><br clear="all">
<div><br clear="none"></div>
-- <br clear="none">
<div class="yiv6893606478gmail_signature" 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 clear="none">-- Norbert Wiener</div>
<div><br clear="none"></div>
<div><a rel="noopener noreferrer" shape="rect" target="_blank" href="http://www.cse.buffalo.edu/~knepley/">https://www.cse.buffalo.edu/~knepley/</a><br clear="none"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>