[petsc-users] In a 2D DMDA object, how to convert (i, j) to a global index?

Jed Brown jed at jedbrown.org
Tue Jan 8 17:00:56 CST 2019


Fande Kong <fdkong.jd at gmail.com> writes:

> Thanks Barry and Jed,
>
> I think I understood now.
>
> One more question. We usually have a code pattern in some PETSc DMDA
> examples as follows:
>
> DMDAVecGetArrayRead(da,localU,&uarray);
> DMDAVecGetArray(da,F,&f);
>
> DMDAGetCorners(da,&xs,&ys,NULL,&xm,&ym,NULL);
>
> for (j=ys; j<ys+ym; j++) {
>     for (i=xs; i<xs+xm; i++) {\
>       f[j][i] = uarray[j][i] - uarray[j-1][i];
> }
> }
>
> Why we are using global i, j here? Should not we use i=i-xs, j=j-ys?
> Aren't uarray and f  local arrays?

DMDAVecGetArray (in contrast to VecGetArray) returns pointer-pointers
that have been set up to use global indices as u[j][i] instead of
something like uflat[(j-ys)*m+(i-xs)].


More information about the petsc-users mailing list