[petsc-users] Accessing array indices in 3D

Barry Smith bsmith at mcs.anl.gov
Tue Nov 30 16:38:14 CST 2010


On Nov 30, 2010, at 4:32 PM, khalid ashraf wrote:

> Thanks Barry. It works fine. Another question, I have a Periodic Boundary
> condition along x and y. So I want to use the two commented out line below.
>    for (j=ys; j<ys+ym; j++) {
> 
>    for (i=xs; i<xs+xm; i++) {
> 
>      if (i<(mx-1))
> 
>      {
> 
>      Cx=u_localptr[k][j][i+1]-u_localptr[k][j][i];
> 
>      }
> 
>  else
> 
>      {
> 
> //     Cx=u_localptr[k][j][i]-u_localptr[k][j][0];
> 
>      }
> 
>      if (j<(my-1))
> 
>      {
> 
>      Cy=v_localptr[k][j+1][i]-v_localptr[k][j][i];
> 
>      }
> 
>  else
> 
>      {
>  //    Cy=v_localptr[k][j][i]-v_localptr[k][0][i];
> 
>      }
> 
> 
> Is it possible to include these non-local points [k][j][0] or [k][0][i].

   Why do you call those points nonlocal? The are local on the appropriate process.  0 is just the first entry.  [k][j][-1] would be a ghost point and just like all other ghost points would be available in the ghosted (local) vectors. Also the ghost points on the other side are at locations [mx] or [my] or [mz] 

> Or I have to 
> include the boundary points in the grid ? The same question when forming the A matrix with 
> PBC. How to include the non-neighbour elements within the if statement. 

   You can use MatSetValuesStencil() for setting values in the matrix and include the ghost points into the stencil, you do nothing special. 

   Things just work with periodic boundaries, don't overthink things and get yourself in a tangle.

  Barry

> 
> Thanks.
> 
> Khalid
> 
> 



More information about the petsc-users mailing list