<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Timothée,<br>
    <br>
    Maybe I can send you part of it 1st. I'm trying to pinpoint why my
    matrix using MatView shows zero for a lot of the values<br>
    <br>
    For i=1,j=1,k=1,<br>
    <br>
    It should be :<br>
    <br>
    Mat Object: 1 MPI processes<br>
      type: seqaij<br>
    row 0: (0, 2)  (12, -2)<br>
    <br>
    but now it's:<br>
    <br>
    row 0: (0, 0)  (1, 0)  (2, 0)  (3, 0)  (4, 0)  (5, 0)  (6, 0)  (7,
    0)  (8, 0)  (12, 0)  (13, 0)  (14, 0)  (24, 0)  (25, 0)  (26, 0) 
    (96, 0)  (97, 0)  (98, 0)  (192, 0)  (193, 0)  (194, 0) <br>
    <br>
    I used:<br>
    <br>
    <i>call
DMDACreate3d(MPI_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,size_x,size_y,&</i><i><br>
    </i><i><br>
    </i><i>size_z,1,PETSC_DECIDE,PETSC_DECIDE,3,stencil_width,lx,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,da_uvw_ast,ierr)</i><i><br>
    </i><i><br>
    </i><i>call DMSetMatType(da_uvw_ast,MATAIJ,ierr)</i><i><br>
    </i><i>        </i><i><br>
    </i><i>    call DMCreateMatrix(da_uvw_ast,A_semi_xyz,ierr)</i><i><br>
    </i><i><br>
    </i><i>    call MatSetFromOptions(A_semi_xyz,ierr)</i><i><br>
    </i><i><br>
    </i><i>i = 1, j = 1, k = 1</i><i><br>
    </i><i><br>
    </i><i>row(MatStencil_i,1) = i - 1</i><i><br>
    </i><i>                </i><i><br>
    </i><i>                    row(MatStencil_j,1) = j - 1</i><i><br>
    </i><i>                    </i><i><br>
    </i><i>                    row(MatStencil_k,1) = k - 1</i><i><br>
    </i><i>                    </i><i><br>
    </i><i>                    row(MatStencil_c,1) = 0</i><i><br>
    </i><i>                    </i><i><br>
    </i><i>                    col(MatStencil_i,1) = i - 1</i><i><br>
    </i><i>                </i><i><br>
    </i><i>                    col(MatStencil_j,1) = j - 1</i><i><br>
    </i><i>                </i><i><br>
    </i><i>                    col(MatStencil_k,1) = k - 1</i><i><br>
    </i><i>                </i><i><br>
    </i><i>                    col(MatStencil_c,1) = 0</i><i><br>
    </i><i>                    </i><i><br>
    </i><i>                    value_insert(1) = 2.</i><i><br>
    </i><i><br>
    </i><i>                    call
MatSetValuesStencil(A_mat,ione,row,ione,col(:,1),value_insert(1),INSERT_VALUES,ierr)</i><i><br>
    </i><i><br>
    </i><i>                    col(MatStencil_i,2) = i - 1 !north</i><i><br>
    </i><i>                    </i><i><br>
    </i><i>                    col(MatStencil_j,2) = j + 1 - 1</i><i><br>
    </i><i>                        </i><i><br>
    </i><i>                    col(MatStencil_k,2) = k - 1</i><i><br>
    </i><i>                        </i><i><br>
    </i><i>                    col(MatStencil_c,2) = 0</i><i><br>
    </i><i>                    </i><i><br>
    </i><i>                    value_insert(2) = -2.</i><i><br>
    </i><i><br>
    </i><i>                    call
MatSetValuesStencil(A_mat,ione,row,ione,col(:,2),value_insert(2),INSERT_VALUES,ierr)</i><br>
    <pre class="moz-signature" cols="72">Thank you

Yours sincerely,

TAY wee-beng</pre>
    <div class="moz-cite-prefix">On 23/9/2015 4:45 PM, Timothée Nicolas
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAGi1ndQ9gCf-_u9H0r=o+S8z0P4pWU2LeQLGffb_wOSt-dx8EQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>Yes, I had understood that, I am doing the same, but with
            8 dof. This does not change the declaration for row and col.<br>
            <br>
          </div>
          Can you send (i) the commands you use to create the DMDA, (ii)
          the commands to create the matrix and (iii) those for the
          definitions of ksta2,kend2,jsta2,jend2,size_x ?<br>
          <br>
        </div>
        Timothée<br>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">2015-09-23 17:37 GMT+09:00 TAY wee-beng
          <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:zonexo@gmail.com" target="_blank">zonexo@gmail.com</a>></span>:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000"> Hi Timothée,<br>
              <br>
              The matrix is created with 3 dof - u,v,w. So for each
              i,j,k, there are 3 values. Actually I got 3 eqns from the
              u,v,w momentum eqns. They are not coupled together so I
              can also solve them individually. But I was told it's
              faster to group them together. The global indices is
              something like this:<br>
              <br>
              i, j, k, ijk global indices, dof<br>
              1 1 1 1 u<br>
              1 1 1 2 v<br>
              1 1 1 3 w<br>
              2 1 1 4 u<br>
              <br>
              ...<br>
              <br>
              Hope it's clearer now. <br>
              <br>
              Ok, I changed the stencil, it's now working.<span class=""><br>
                <pre cols="72">Thank you

Yours sincerely,

TAY wee-beng</pre>
              </span>
              <div>
                <div class="h5">
                  <div>On 23/9/2015 4:22 PM, Timothée Nicolas wrote:<br>
                  </div>
                  <blockquote type="cite">
                    <div dir="ltr">Can you also tell how you created the
                      matrix ? Just in case you created it with the 1
                      dof DMDA, it would not work if you try to input
                      values at places where it is not allocated (which
                      could explain the error message)<br>
                    </div>
                    <div class="gmail_extra"><br>
                      <div class="gmail_quote">2015-09-23 17:18
                        GMT+09:00 Timothée Nicolas <span dir="ltr"><<a
                            moz-do-not-send="true"
                            href="mailto:timothee.nicolas@gmail.com"
                            target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:timothee.nicolas@gmail.com">timothee.nicolas@gmail.com</a></a>></span>:<br>
                        <blockquote class="gmail_quote" style="margin:0
                          0 0 .8ex;border-left:1px #ccc
                          solid;padding-left:1ex">
                          <div dir="ltr">
                            <div>
                              <div>
                                <div>
                                  <div>The first thing that strikes me
                                    is your definition of the stencils <br>
                                    <br>
                                    <b><i>MatStencil  ::
                                        row(6,1),col(6,7)</i></b><b><i><br>
                                        <br>
                                      </i></b></div>
                                  Why is it not defined with <br>
                                  <br>
                                  <b><i>MatStencil  :: row(4,1),col(4,7)</i></b><b><i><br>
                                    </i></b><br>
                                </div>
                                instead ?<br>
                                <br>
                              </div>
                              Where does the 6 come from ?<span><font
                                  color="#888888"><br>
                                  <br>
                                </font></span></div>
                            <span><font color="#888888">Timothée<br>
                                <div>
                                  <div>
                                    <div><br>
                                    </div>
                                  </div>
                                </div>
                              </font></span></div>
                          <div>
                            <div>
                              <div class="gmail_extra"><br>
                                <div class="gmail_quote">2015-09-23
                                  17:14 GMT+09:00 TAY wee-beng <span
                                    dir="ltr"><<a
                                      moz-do-not-send="true"
                                      href="mailto:zonexo@gmail.com"
                                      target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:zonexo@gmail.com">zonexo@gmail.com</a></a>></span>:<br>
                                  <blockquote class="gmail_quote"
                                    style="margin:0 0 0
                                    .8ex;border-left:1px #ccc
                                    solid;padding-left:1ex">
                                    <div bgcolor="#FFFFFF"
                                      text="#000000"> Hi,<br>
                                      <br>
                                      I have successfully used
                                      MatSetValuesStencil to insert
                                      values into a Poisson eqn matrix
                                      which has 1 DOF (pressure). Now
                                      I'm trying to insert values in a
                                      momentum eqn matrix which has 3
                                      DOF (u,v,w)<br>
                                      <br>
                                      However, I got the error: <br>
                                      <br>
                                      <i><b>[0]PETSC ERROR:
                                          --------------------- Error
                                          Message
                                          ----------------------------</b></i><i><b><br>
                                        </b></i><i><b>----------------------------------</b></i><i><b><br>
                                        </b></i><i><b>[0]PETSC ERROR:
                                          Argument out of range</b></i><i><b><br>
                                        </b></i><i><b>[0]PETSC ERROR:
                                          Inserting a new nonzero at
                                          (111,5) in the matrix</b></i><i><b><br>
                                        </b></i><i><b>[0]PETSC ERROR:
                                          See <a moz-do-not-send="true"
href="http://www.mcs.anl.gov/petsc/documentation/faq.html"
                                            target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html</a>
                                          for trou</b></i><i><b><br>
                                        </b></i><i><b>ble shooting.</b></i><br>
                                      <br>
                                      I wonder what's wrong.  For the
                                      momentum eqn, for each DOF, at at
                                      node (dof,i,j,k), I have coupling
                                      i +/- 1, j +/- 1 and k +/- 1.<br>
                                      <br>
                                      The error happens at 111,5, which
                                      corresponds to i = 2, j = 2, k =
                                      2, which is an internal node.<br>
                                      <br>
                                      Here's part of my code below. Hope
                                      someone can help. Thanks!<br>
                                      <b><i><br>
                                        </i></b><b><i>PetscScalar ::
                                          value_insert(7)</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>MatStencil  ::
                                          row(6,1),col(6,7)</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>ione = 1;   iseven
                                          = 7</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>if (cell_type ==
                                          'u') then</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>    offset = 1</i></b><b><i><br>
                                        </i></b><b><i>    </i></b><b><i><br>
                                        </i></b><b><i>else if (cell_type
                                          == 'v') then</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>    offset = 2</i></b><b><i><br>
                                        </i></b><b><i>    </i></b><b><i><br>
                                        </i></b><b><i>else if (cell_type
                                          == 'w') then</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>    offset = 3</i></b><b><i><br>
                                        </i></b><b><i>    </i></b><b><i><br>
                                        </i></b><b><i>end if</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>do k=ksta2,kend2</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>    do j =
                                          jsta2,jend2</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>        do
                                          i=2,size_x-1</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          row(MatStencil_i,1) = i - 1</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          row(MatStencil_j,1) = j - 1</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          row(MatStencil_k,1) = k - 1</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          row(MatStencil_c,1) = offset -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          value_insert = 0.d0</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_i,3) = i + 1 -
                                          1 !east</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_j,3) = j - 1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_k,3) = k - 1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_c,3) = offset -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          value_insert(3) = -(
1./(cell_x(i)%pd_E+cell_x(i+1)%pd_W))*(c_yz(j,k)%fc_E)*inv_Re</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_i,5) = i - 1 -
                                          1 !west</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_j,5) = j - 1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_k,5) = k - 1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_c,5) = offset -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          value_insert(5) = -(
1./(cell_x(i)%pd_W+cell_x(i-1)%pd_E))*(c_yz(j,k)%fc_E)*inv_Re</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_i,2) = i - 1
                                          !north</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_j,2) = j + 1 -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_k,2) = k - 1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_c,2) = offset -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          value_insert(2) = -(
1./(cell_y(j)%pd_N+cell_y(j+1)%pd_S))*(c_zx(i,k)%fc_N)*inv_Re</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_i,4) = i - 1
                                          !south</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_j,4) = j - 1 -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_k,4) = k - 1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_c,4) = offset -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          value_insert(4) = -(
1./(cell_y(j)%pd_S+cell_y(j-1)%pd_N))*(c_zx(i,k)%fc_N)*inv_Re</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_i,6) = i - 1
                                          !front</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_j,6) = j - 1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_k,6) = k + 1 -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_c,6) = offset -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          value_insert(6) = -(
1./(cell_z(k)%pd_F+cell_z(k+1)%pd_B))*(c_xy(i,j)%fc_F)*inv_Re</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_i,7) = i - 1
                                          !back</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_j,7) = j - 1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_k,7) = k - 1 -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_c,7) = offset -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>                </i></b><b><i><br>
                                        </i></b><b><i>           
                                          value_insert(7) = -(
1./(cell_z(k)%pd_B+cell_z(k-1)%pd_F))*(c_xy(i,j)%fc_F)*inv_Re</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_i,1) = i - 1</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_j,1) = j - 1</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_k,1) = k - 1</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          col(MatStencil_c,1) = offset -
                                          1</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>           
                                          value_insert(1) =
                                          2.*c(i,j,k)%vol/del_t -
(value_insert(2)+value_insert(3)+value_insert(4)+value_insert(5)+value_insert(6)+value_insert(7))</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>            call
MatSetValuesStencil(A_semi_xyz,ione,row,iseven,col,value_insert,INSERT_VALUES,ierr)</i></b><b><i><br>
                                        </i></b><b><i>            </i></b><b><i><br>
                                        </i></b><b><i>        end do</i></b><b><i><br>
                                        </i></b><b><i>        </i></b><b><i><br>
                                        </i></b><b><i>    end do</i></b><b><i><br>
                                        </i></b><b><i><br>
                                        </i></b><b><i>end do    </i></b><br>
                                      <pre cols="72">Thank you

Yours sincerely,

TAY wee-beng</pre>
                                      <br>
                                    </div>
                                  </blockquote>
                                </div>
                                <br>
                              </div>
                            </div>
                          </div>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>