<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 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 href="mailto:timothee.nicolas@gmail.com" target="_blank">timothee.nicolas@gmail.com</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 href="mailto:zonexo@gmail.com" target="_blank"></a><a 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,<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 href="http://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank"></a><a 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>