<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 17, 2013 at 6:15 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Bishesh,<br>
<br>
Do you need off process values? That is, might one process ask for a value that is not in the local part of the vector and belongs on a different process? If you know that the values accessed are always local then you can just use sol[k][j][i].vx the k,j,i are the global indices over the entire mesh.<br>
<br>
If any process might ask for any value on the entire mesh then you need to use DMDAGlobalToNaturalBegin/End() followed by VecScatterCreateToAll() and scatter all the values to all processes then you access them locally. Note this is not scalable.<br>
<br></blockquote><div>Thanks Barry. Any process might ask for any value on the entire mesh since this is a function I need to provide to the part of the code that "sees" my solver as an external object and that part does not use petsc explicity and not necessarily parallel. I did as you suggested and it works, thanks.<br>
<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Barry<br>
<br>
Note that though with sol[k][j][i].vx it looks like you can access any value for k,j,i if you use a k, j, i that do not correspond to a value that belongs to this process you will get a memory error.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
On Sep 17, 2013, at 11:06 AM, Bishesh Khanal <<a href="mailto:bisheshkh@gmail.com">bisheshkh@gmail.com</a>> wrote:<br>
<br>
> Dear all,<br>
> I have a vector say sol which is a vector created from a dmda with dof = 3.<br>
> Now I need to provide an interface to the part of my code which does not use petsc but needs access to the values of sol.<br>
><br>
> I was thinking of providing an interface such as:<br>
> double solver::getSolutionAtPosition(int x, int y, int z, int field);<br>
> which should return a value of the vector sol at the grid position (x,y,z) and dof = field.<br>
><br>
> I know how to get the array and loop through all the values such as:<br>
> DMDALocalInfo info;<br>
> ierr = DMDAGetLocalInfo(da,&info);CHKERRQ(ierr);<br>
><br>
> Field ***sol;<br>
> ierr = DMDAVecGetArray(da,b,&rhs);CHKERRQ(ierr);<br>
><br>
> for (PetscInt k = info.zs; k<info.zs+<a href="http://info.zm" target="_blank">info.zm</a>; ++k) {<br>
> for (PetscInt j = info.ys; j < info.ys+info.ym; ++j) {<br>
> for (PetscInt i = info.xs; i < info.xs+info.xm; ++i) {<br>
> //access sol[k][j][i].vx or sol[k][j][i].vy or sol[k][j][i].vz depending on field<br>
><br>
> }<br>
> }<br>
> }<br>
><br>
> But if I have a particular (x,y,z) based on global co-ordinate system, how do I get the value for the given field ?<br>
><br>
> Thanks,<br>
> Bishesh<br>
<br>
</div></div></blockquote></div><br></div></div>