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

Smith, Barry F. bsmith at mcs.anl.gov
Tue Jan 8 17:03:00 CST 2019


  Yes because the i,j are global indices into the entire array.


> On Jan 8, 2019, at 4:59 PM, Fande Kong <fdkong.jd at gmail.com> wrote:
> 
> 
> 
> 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. 
> 
> Is M the number of points (for all processors) along x direction? 
> 
> Thanks,
> 
> Fande Kong
>  
>  



More information about the petsc-users mailing list