<div dir="ltr">Hello all, <div><br></div><div>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</div><div><br></div><div>...........................................................................................................</div><div><pre width="80" style="color:rgb(0,0,0)"><pre width="80">call <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMDA/DMDAGetCorners.html#DMDAGetCorners" target="_blank">DMDAGetCorners</a>(da,xs,ys,zs,xm,ym,zm,ierr)
<a name="m_-1465235793313435427_line107">107: </a> <font color="#4169E1">do</font> 10,k=zs,zs+zm-1
<a name="m_-1465235793313435427_line108">108: </a> <font color="#4169E1">do</font> 20,j=ys,ys+ym-1
<a name="m_-1465235793313435427_line109">109: </a> <font color="#4169E1">do</font> 30,i=xs,xs+xm-1
<a name="m_-1465235793313435427_line110">110: </a> row(MatStencil_i) = i
<a name="m_-1465235793313435427_line111">111: </a> row(MatStencil_j) = j
<a name="m_-1465235793313435427_line112">112: </a> row(MatStencil_k) = k
<a name="m_-1465235793313435427_line113">113: </a> <font color="#4169E1">if</font> (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
<a name="m_-1465235793313435427_line114">114: </a> v(1) = 2.0*(HxHydHz + HxHzdHy + HyHzdHx)
<a name="m_-1465235793313435427_line115">115: </a> call <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValuesStencil.html#MatSetValuesStencil" target="_blank">MatSetValuesStencil</a>(jac,i1,row,i1,row,v,<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES" target="_blank">INSERT_VALUES</a>,ierr)
<a name="m_-1465235793313435427_line116">116: </a> <font color="#4169E1">else</font>
<a name="m_-1465235793313435427_line117">117: </a> v(1) = -HxHydHz
<a name="m_-1465235793313435427_line118">118: </a> col(MatStencil_i,1) = i
<a name="m_-1465235793313435427_line119">119: </a> col(MatStencil_j,1) = j
<a name="m_-1465235793313435427_line120">120: </a> col(MatStencil_k,1) = k-1
<a name="m_-1465235793313435427_line121">121: </a> v(2) = -HxHzdHy
<a name="m_-1465235793313435427_line122">122: </a> col(MatStencil_i,2) = i
<a name="m_-1465235793313435427_line123">123: </a> col(MatStencil_j,2) = j-1
<a name="m_-1465235793313435427_line124">124: </a> col(MatStencil_k,2) = k
<a name="m_-1465235793313435427_line125">125: </a> v(3) = -HyHzdHx
<a name="m_-1465235793313435427_line126">126: </a> col(MatStencil_i,3) = i-1
<a name="m_-1465235793313435427_line127">127: </a> col(MatStencil_j,3) = j
<a name="m_-1465235793313435427_line128">128: </a> col(MatStencil_k,3) = k
<a name="m_-1465235793313435427_line129">129: </a> v(4) = 2.0*(HxHydHz + HxHzdHy + HyHzdHx)
<a name="m_-1465235793313435427_line130">130: </a> col(MatStencil_i,4) = i
<a name="m_-1465235793313435427_line131">131: </a> col(MatStencil_j,4) = j
<a name="m_-1465235793313435427_line132">132: </a> col(MatStencil_k,4) = k
<a name="m_-1465235793313435427_line133">133: </a> v(5) = -HyHzdHx
<a name="m_-1465235793313435427_line134">134: </a> col(MatStencil_i,5) = i+1
<a name="m_-1465235793313435427_line135">135: </a> col(MatStencil_j,5) = j
<a name="m_-1465235793313435427_line136">136: </a> col(MatStencil_k,5) = k
<a name="m_-1465235793313435427_line137">137: </a> v(6) = -HxHzdHy
<a name="m_-1465235793313435427_line138">138: </a> col(MatStencil_i,6) = i
<a name="m_-1465235793313435427_line139">139: </a> col(MatStencil_j,6) = j+1
<a name="m_-1465235793313435427_line140">140: </a> col(MatStencil_k,6) = k
<a name="m_-1465235793313435427_line141">141: </a> v(7) = -HxHydHz
<a name="m_-1465235793313435427_line142">142: </a> col(MatStencil_i,7) = i
<a name="m_-1465235793313435427_line143">143: </a> col(MatStencil_j,7) = j
<a name="m_-1465235793313435427_line144">144: </a> col(MatStencil_k,7) = k+1
<a name="m_-1465235793313435427_line145">145: </a> call <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetValuesStencil.html#MatSetValuesStencil" target="_blank">MatSetValuesStencil</a>(jac,i1,row,i7,col,v,<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES" target="_blank">INSERT_VALUES</a>,ierr)
<a name="m_-1465235793313435427_line146">146: </a> endif</pre><pre width="80">.....................................................................................</pre><pre width="80">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)).</pre><pre width="80">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.</pre><pre width="80">Could you please explain that?</pre><pre width="80"><br></pre><pre width="80">Regards,</pre><pre width="80">Maahi Talukder</pre><pre width="80">Department of Mechanical Engineering</pre><pre width="80">Clarkson University</pre></pre></div></div>