Dear All, <br>Now I am confused with the way to access a global vector defined from DMDA.<br><br>Here is the codes. When I switch on _DEBUG1_ the results get wrong. While if it's off,<br><br>the results fine. I just wonder why I gave to use the local form of ul,vl,wl to access the<br>values such as ul[k][j][i+1], and etc.<br><br>Thank you first for any suggestion.<br><br>Zhenyu<br><br>ierr = DMCreateGlobalVector(ctxu->grid, &ctxu->x );CHKERRQ(ierr);<br> ierr = VecDuplicate(ctxu->x,&ctxu->b);CHKERRQ(ierr);<br>ierr = DMCreateGlobalVector(ctxv->grid, &ctxv->x );CHKERRQ(ierr);<br> ierr = VecDuplicate(ctxv->x,&ctxv->b);CHKERRQ(ierr);<br>ierr = DMCreateGlobalVector(ctxw->grid, &ctxw->x );CHKERRQ(ierr);<br> ierr = VecDuplicate(ctxw->x,&ctxw->b);CHKERRQ(ierr);<br>...<br> VecCopy(ctxu->x,ctxu->b);<br> VecCopy(ctxv->x,ctxv->b);<br> VecCopy(ctxw->x
,ctxw->b);<br><br> DMDAVecGetArray( ctxu->grid, ctxu->b, &ustar );<br> DMDAVecGetArray( ctxv->grid, ctxv->b, &vstar );<br> DMDAVecGetArray( ctxw->grid, ctxw->b, &wstar );<br><br>#if defined(_DEBUG1_)<br> DMDAVecGetArray( ctxu->grid, ctxu->x, &u );<br> DMDAVecGetArray( ctxv->grid, ctxv->x, &v );<br> DMDAVecGetArray( ctxw->grid, ctxw->x, &w );<br>#else<br> DMGetLocalVector(ctxu->grid,&ctxu->local);<br> DMGetLocalVector(ctxv->grid,&ctxv->local);<br> DMGetLocalVector(ctxw->grid,&ctxw->local);<br> DMGlobalToLocalBegin(ctxu->grid,ctxu->x,INSERT_VALUES,ctxu->local);<br> DMGlobalToLocalEnd(ctxu->grid,ctxu->x,INSERT_VALUES,ctxu->local);<br> DMGlobalToLocalBegin(ctxv->grid,ctxv->x,INSERT_VALUES,ctxv->local);<br> DMGlobalToLocalEnd(ctxv->grid,ctxv->x,INSERT_VALUES,ctxv->local);<br>&
nbsp; DMGlobalToLocalBegin(ctxw->grid,ctxw->x,INSERT_VALUES,ctxw->local);<br> DMGlobalToLocalEnd(ctxw->grid,ctxw->x,INSERT_VALUES,ctxw->local);<br> DMDAVecGetArray( ctxu->grid, ctxu->local, &ul );<br> DMDAVecGetArray( ctxv->grid, ctxv->local, &vl );<br> DMDAVecGetArray( ctxw->grid, ctxw->local, &wl );<br>#endif<br><br>//----------------------------------------------------------------<br> // U<br> DMDAGetCorners( ctxu->grid, &is, &js, &ks, &in, &jn, &kn );<br> ie = is + in - 1;<br> je = js + jn - 1;<br> ke = ks + kn - 1;<br><br> is=max(is,1);<br> js=max(js,1);<br> ks=max(ks,1);<br> ie=min(ie,ctxu->l-2);<br> je=min(je,ctxu->m-2);<br> ke=min(ke,ctxu->n-2);<br><br><br> for (k=ks; k<=ke; k++) {<br> for (j=js; j<=je; j++) {<br> for (i=is; i<=ie; i+
+) {<br><br>#if defined(_DEBUG1_)<br> ustar[k][j][i] +=<br> - dtdx*(0.25*((u[k][j][i]+u[k][j][i+1])*(u[k][j][i]+u[k][j][i+1]))<br> - 0.25*((u[k][j][i]+u[k][j][i-1])*(u[k][j][i]+u[k][j][i-1])))<br> - dtdy*(0.25*(u [k][j][i]+u [k][j+1][i])*(v [k][j][i]+v [k][j][i+1])<br>
- 0.25*(u [k][j][i]+u [k][j-1][i])*(v [k][j-1][i]+v [k][j-1][i+1]))<br> - dtdz*(0.25*(u [k][j][i]+u [k+1][j][i])*(w [k][j][i]+w [k][j][i+1])<br> - 0.25*(u [k][j][i]+u [k-1][j][i])*(w [k-1][j][i]+w [k-1][j][i+1]))<br> + dtdxx*(u [k][j][i-1]-2*u [k][j][i]+u [k][j]
[i+1])<br> + dtdyy*(u [k][j-1][i]-2*u [k][j][i]+u [k][j+1][i])<br> + dtdzz*(u [k-1][j][i]-2*u [k][j][i]+u [k+1][j][i]);<br>#else<br> ustar[k][j][i] +=<br> - dtdx*(0.25*((ul[k][j][i]+ul[k][j][i+1])*(ul[k][j][i]+ul[k][j][i+1]))<br> &nbs
p; - 0.25*((ul[k][j][i]+ul[k][j][i-1])*(ul[k][j][i]+ul[k][j][i-1])))<br> - dtdy*(0.25*(ul[k][j][i]+ul[k][j+1][i])*(vl[k][j][i]+vl[k][j][i+1])<br> - 0.25*(ul[k][j][i]+ul[k][j-1][i])*(vl[k][j-1][i]+vl[k][j-1][i+1]))<br> - dtdz*(0.25*(ul[k][j][i]+ul[k+1][j][i])*(wl[k][j][i]+wl[k][j][i+1])<br> &nb
sp; - 0.25*(ul[k][j][i]+ul[k-1][j][i])*(wl[k-1][j][i]+wl[k-1][j][i+1]))<br> + dtdxx*(ul[k][j][i-1]-2*ul[k][j][i]+ul[k][j][i+1])<br> + dtdyy*(ul[k][j-1][i]-2*ul[k][j][i]+ul[k][j+1][i])<br> + dtdzz*(ul[k-1][j][i]-2*ul[k][j][i]+ul[k+1][j][i]);<br>
#endif<br> }<br> }<br> }<br><br>.....<br><br>#if defined(_DEBUG1_)<br>DMDAVecRestoreArray( ctxu->grid, ctxu->x, &u );<br>DMDAVecRestoreArray( ctxv->grid, ctxv->x, &v );<br>DMDAVecRestoreArray( ctxw->grid, ctxw->x, &w );<br>#else<br>DMDAVecRestoreArray( ctxu->grid, ctxu->local, &ul );<br>DMDAVecRestoreArray( ctxv->grid, ctxv->local, &vl );<br>DMDAVecRestoreArray( ctxw->grid, ctxw->local, &wl );<br>DMRestoreLocalVector(ctxu->grid,&ctxu->local);<br>DMRestoreLocalVector(ctxv->grid,&ctxv->local);<br>DMRestoreLocalVector(ctxw->grid,&ctxw->local);<br>#endif<br><br>DMDAVecRestoreArray( ctxu->grid, ctxu->b, &ustar );<br>DMDAVecRestoreArray( ctxv->grid, ctxv->b, &vstar );<br>DMDAVecRestoreArray( ctxw->grid, ctxw->b, &wstar );<br><br><br>