[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 16:35:47 CST 2019


"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);


More information about the petsc-users mailing list