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

Patrick Sanan patrick.sanan at gmail.com
Mon Mar 11 15:40:44 CDT 2019


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 <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMDA/DMDAGetCorners.html#DMDAGetCorners>(da,xs,ys,zs,xm,ym,zm,ierr)
> 107:       do 10,k=zs,zs+zm-1108:         do 20,j=ys,ys+ym-1109:           do 30,i=xs,xs+xm-1110:           row(MatStencil_i) = i111:           row(MatStencil_j) = j112:           row(MatStencil_k) = k113:           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) then114:             v(1) = 2.0*(HxHydHz + HxHzdHy + HyHzdHx)115:             call MatSetValuesStencil <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValuesStencil.html#MatSetValuesStencil>(jac,i1,row,i1,row,v,INSERT_VALUES <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES>,ierr)116:           else117:             v(1) = -HxHydHz118:              col(MatStencil_i,1) = i119:              col(MatStencil_j,1) = j120:              col(MatStencil_k,1) = k-1121:             v(2) = -HxHzdHy122:              col(MatStencil_i,2) = i123:              col(MatStencil_j,2) = j-1124:              col(MatStencil_k,2) = k125:             v(3) = -HyHzdHx126:              col(MatStencil_i,3) = i-1127:              col(MatStencil_j,3) = j128:              col(MatStencil_k,3) = k129:             v(4) = 2.0*(HxHydHz + HxHzdHy + HyHzdHx)130:              col(MatStencil_i,4) = i131:              col(MatStencil_j,4) = j132:              col(MatStencil_k,4) = k133:             v(5) = -HyHzdHx134:              col(MatStencil_i,5) = i+1135:              col(MatStencil_j,5) = j136:              col(MatStencil_k,5) = k137:             v(6) = -HxHzdHy138:              col(MatStencil_i,6) = i139:              col(MatStencil_j,6) = j+1140:              col(MatStencil_k,6) = k141:             v(7) = -HxHydHz142:              col(MatStencil_i,7) = i143:              col(MatStencil_j,7) = j144:              col(MatStencil_k,7) = k+1145:       call MatSetValuesStencil <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValuesStencil.html#MatSetValuesStencil>(jac,i1,row,i7,col,v,INSERT_VALUES <https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190311/8aac81b8/attachment.html>


More information about the petsc-users mailing list