[petsc-users] In a 2D DMDA object, how to convert (i, j) to a global index?
Fande Kong
fdkong.jd at gmail.com
Tue Jan 8 16:56:42 CST 2019
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?
Thanks,
Fande Kong,
On Tue, Jan 8, 2019 at 3:40 PM Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
>
>
> > On Jan 8, 2019, at 4:35 PM, Jed Brown <jed at jedbrown.org> wrote:
> >
> > "Smith, Barry F. via petsc-users" <petsc-users at mcs.anl.gov> writes:
> >
> >>> On Jan 8, 2019, at 4:11 PM, Fande Kong via petsc-users <
> petsc-users at mcs.anl.gov> wrote:
> >>>
> >>> Hi All,
> >>>
> >>> I was wondering how to convert a regular (2D DMDA) grid coordinate
> (i,j) to a global index that is used for global matrices and vectors. Do we
> have any API on this?
> >>
> >> You can convert the global i,j to a local I,J by subtracting off the
> xs, ys, then convert to the local vector numbering with something like
> I+J*xm then add that value to the rstart returned from
> VecGetOwnershipRange()
> >
> > If the value may be in your ghosted/halo region, you can use
> >
> > VecGetLocalToGlobalMapping(vec, ltog);
> > ISLocalToGlobalMappingApply(ltog, 1, &local, &global);
>
> Oh, yes I was ignoring the case where the questioning process didn't
> own the value.
>
> In the general case where the i,j may not be within the ghost region of
> the process it is on you can use the ao obtained from DMDAGetAO() to map
> from the natural (application) ordering to the PETSc ordering. Obtain the
> natural ordering value with something like i + j*M.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190108/59eefb57/attachment-0001.html>
More information about the petsc-users
mailing list