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

Matthew Knepley knepley at gmail.com
Mon Mar 11 20:56:08 CDT 2019


On Mon, Mar 11, 2019 at 8:09 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), 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?
>

I don't think you are understanding. (i, j) is a grid location, so it
corresponds to a dof number n. A location (m, n) in the Jacobian
relates two variables, one at some location (i_m, j_m) in the grid and
another at location (i_n, j_n) in the grid. The matrix grid
and spatial grid are completely different things. For example, you could
have a 3D spatial grid, but you still have a 2D matrix.

  Matt


> 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 <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
>>>
>>>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190311/e26fd8ef/attachment-0001.html>


More information about the petsc-users mailing list