[petsc-users] DMDA and ksp(ex46.c & ex22f.F90)

Smith, Barry F. bsmith at mcs.anl.gov
Mon Mar 11 20:46:44 CDT 2019



> On Mar 11, 2019, at 7:07 PM, Maahi Talukder via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> 
> Thank you for your reply. 
> 
> I still have some confusion. So if (i,j) is a point on the structured grid( Where "i" is the column and "j" is the row), and the information associated with the (i,j) point on the grid is stored in some (m,n) location of the matrix A (Where Ax =b),

   Almost. Think about the vector (not the matrix) first. The point (i,j) on the mesh has location m in the vector (m is a function of both i and j) Now think about another point on the mesh (say next to the first point), call it (i',j') this point also has a location in the vector, call it n. Now consider the matrix entry containing the value that connects m and n. On the mesh it is associated with the point (i,j) AND the point (i',j') hence the row in the matrix is a function of the first point (i,j) while the column is a function of the second point (i',j'). 

  Now the diagonal entry in matrix a_{mm} has (i,j) for both "row" and "column" stencils, but the off-diagonal entries a_{mn} has (i,j) for the row but (i',j') for the column. 

> I still don't 
> understand why both of  row(MatStencil_i,1) and row(MatStencil_j,1) are necessary? I mean is it something like mapping "i" from grid to its location in the matrix?


> Would you please explain that?

 
> 
> Regards,
> Maahi 
> 
> On Mon, Mar 11, 2019 at 4:41 PM Patrick Sanan <patrick.sanan at gmail.com> wrote:
> There are two different types of rows and columns:
> 1. Rows and columns in a grid
> 2. Rows and columns in a matrix
> 
> "i" and "j"  refer to rows and columns in the grid, but "row" and "col"  refer to rows and columns in the matrix.
> 
> 
> 
> Am Mo., 11. März 2019 um 21:18 Uhr schrieb Maahi Talukder via petsc-users <petsc-users at mcs.anl.gov>:
> Hello all, 
> 
> I am trying to solve Poisson Equation on structured grid using 9-point stencil in 2D. Now to setup my matrix, I came across C structure MatStencil in ex22f.F90
> 
> ...........................................................................................................
> call DMDAGetCorners
> (da,xs,ys,zs,xm,ym,zm,ierr)
> 
> 
> 107:       do
>  10,k=zs,zs+zm-1
> 
> 108:         do
>  20,j=ys,ys+ym-1
> 
> 109:           do
>  30,i=xs,xs+xm-1
> 
> 110: 
>           row(MatStencil_i) = i
> 
> 111: 
>           row(MatStencil_j) = j
> 
> 112: 
>           row(MatStencil_k) = k
> 
> 113:           if
>  (i.eq.0 .or. j.eq.0 .or. k.eq.0 .or. i.eq.mx-1 .or. j.eq.my-1 .or. k.eq.mz-1) then
> 
> 114: 
>             v(1) = 2.0*(HxHydHz + HxHzdHy + HyHzdHx)
> 
> 115:             call MatSetValuesStencil(jac,i1,row,i1,row,v,INSERT_VALUES
> ,ierr)
> 
> 116:           else
> 117: 
>             v(1) = -HxHydHz
> 
> 118: 
>              col(MatStencil_i,1) = i
> 
> 119: 
>              col(MatStencil_j,1) = j
> 
> 120: 
>              col(MatStencil_k,1) = k-1
> 
> 121: 
>             v(2) = -HxHzdHy
> 
> 122: 
>              col(MatStencil_i,2) = i
> 
> 123: 
>              col(MatStencil_j,2) = j-1
> 
> 124: 
>              col(MatStencil_k,2) = k
> 
> 125: 
>             v(3) = -HyHzdHx
> 
> 126: 
>              col(MatStencil_i,3) = i-1
> 
> 127: 
>              col(MatStencil_j,3) = j
> 
> 128: 
>              col(MatStencil_k,3) = k
> 
> 129: 
>             v(4) = 2.0*(HxHydHz + HxHzdHy + HyHzdHx)
> 
> 130: 
>              col(MatStencil_i,4) = i
> 
> 131: 
>              col(MatStencil_j,4) = j
> 
> 132: 
>              col(MatStencil_k,4) = k
> 
> 133: 
>             v(5) = -HyHzdHx
> 
> 134: 
>              col(MatStencil_i,5) = i+1
> 
> 135: 
>              col(MatStencil_j,5) = j
> 
> 136: 
>              col(MatStencil_k,5) = k
> 
> 137: 
>             v(6) = -HxHzdHy
> 
> 138: 
>              col(MatStencil_i,6) = i
> 
> 139: 
>              col(MatStencil_j,6) = j+1
> 
> 140: 
>              col(MatStencil_k,6) = k
> 
> 141: 
>             v(7) = -HxHydHz
> 
> 142: 
>              col(MatStencil_i,7) = i
> 
> 143: 
>              col(MatStencil_j,7) = j
> 
> 144: 
>              col(MatStencil_k,7) = k+1
> 
> 145:       call MatSetValuesStencil(jac,i1,row,i7,col,v,INSERT_VALUES
> ,ierr)
> 
> 146:           endif
> .....................................................................................
> What I am confused about is what it means to have the value of row in i and j directions(row(MatStencil_i,1) & row(MatStencil_j,1)).
> Same confusion goes for the column values as well. I mean generally in a  2D Matrix row values are in j/y direction and column values are in i/x direction.
> Could you please explain that?
> 
> Regards,
> Maahi Talukder
> Department of Mechanical Engineering
> Clarkson University



More information about the petsc-users mailing list