On Wed, Sep 26, 2012 at 10:18 AM, Chris Eldred <span dir="ltr"><<a href="mailto:chris.eldred@gmail.com" target="_blank">chris.eldred@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a vector (created from a PetscSection) that holds a set of<br>
values distributed over various points in my mesh. It represents<br>
multiple fields with different dofs. I was wondering which approach<br>
for modifying (or just getting) the values for a given field from the<br>
vector was preferred? The vector is created using<br>
DMCreateLocal/GlobalVector.<br>
<br>
Approach 1 (get the underlying array, find the points using<br>
PetscSection, do whatever, restore the array)<br></blockquote><div><br></div><div>Yes, this is the way I work. However, it can be simpler, if you are making more</div><div>structured changes, to use</div><div><br></div><div>
  call DMComplexVecGet/SetClosure()</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
call VecGetArrayF90( varvector , varptr , ierr)<br>
CHKERRQ(ierr)<br>
call DMComplexGetDepthStratum(model_mesh, vardepth , pStart, pEnd, ierr)<br>
CHKERRQ(ierr)<br></blockquote><div><br></div><div>Here if you want the entire section its simpler to use</div><div><br></div><div>  call PetscSectionGetChart(varsection, pStart, pEnd, ierr)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

do p=pStart,pEnd-1<br>
call PetscSectionGetFieldOffset( varsection, p, varnum , poffset, ierr)<br>
CHKERRQ(ierr)<br>
call PetscSectionGetFieldDof( varsection, p, varnum , ndof, ierr)<br>
CHKERRQ(ierr)<br>
do something with the values (modify them, read them, etc.)<br>
enddo<br>
call VecRestoreArrayF90( varvector , varptr , ierr)<br>
CHKERRQ(ierr)<br>
<br>
Approach 2 (find the points using PetscSection, get the values using<br>
VecGetValues, do whatever, set the values using VecSetValues (if<br>
needed), call VecAssemblyBegin/End )<br></blockquote><div><br></div><div>Definitely do not do this. Its cumbersome and adds nothing.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

call DMComplexGetDepthStratum(model_mesh, vardepth , pStart, pEnd, ierr)<br>
CHKERRQ(ierr)<br>
do p=pStart,pEnd-1<br>
call PetscSectionGetFieldOffset( varsection, p, varnum , poffset, ierr)<br>
CHKERRQ(ierr)<br>
call PetscSectionGetFieldDof( varsection, p, varnum , ndof, ierr)<br>
CHKERRQ(ierr)<br>
add points to a list (points are a contiguos list so its easy)- ie for<br>
each dof add poffset+dof to the list<br>
enddo<br>
call VecGetValues( varvector, npts, ptslist, vals, ierr)<br>
CHKERRQ(ierr)<br>
do something with the values (modify them, read them, etc.)<br>
call VecSetValues( varvector, npts, ptslist, vals, INSERT_MODE, ierr)<br>
!if need to<br>
CHKERRQ(ierr)<br>
call VecAssemblyBegin/End (if i set values)<br>
CHKERRQ(ierr)<br>
<br>
Instead of VecAssemblyBegin/End, should I be using the DMGlobaltoLocal<br>
/ DMLocaltoGlobal routines?<br></blockquote><div><br></div><div>With this setup there should never be a need for VecAssembly. Just use</div><div>GlobalToLocal or LocalToGlobal for communication.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

On a related note, should I be calling VecAssemblyBegin/End (or<br>
DMGlobaltoLocal, etc.) when I modify the values in the array using<br>
Approach 1?<br></blockquote><div><br></div><div>No need, since anything you can modify in the array is process local.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Is there another, third approach I should be using?<br>
<span class="HOEnZb"><font color="#888888"><br>
-Chris<br>
--<br>
Chris Eldred<br>
DOE Computational Science Graduate Fellow<br>
Graduate Student, Atmospheric Science, Colorado State University<br>
B.S. Applied Computational Physics, Carnegie Mellon University, 2009<br>
<a href="mailto:chris.eldred@gmail.com">chris.eldred@gmail.com</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>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<br>