<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 25, 2017 at 9:17 AM, Xiangdong <span dir="ltr"><<a href="mailto:epscodes@gmail.com" target="_blank">epscodes@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello everyone,<div><br></div><div>I have a question on setting matrix entries which are not in the stencil width. Take ksp ex45.c as an example, </div><div><a href="http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex45.c.html" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>petsc-current/src/ksp/ksp/<wbr>examples/tutorials/ex45.c.html</a></div><div><br></div><div>Instead of setting up the standard 7-point stencil, now for each cell, the matrix also has a additional dependency on the cell (Mx, My, Mz). Namely, for each row, the col corresponding to (Mx, My, Mz) is always nonzero. I modify the example code to add this entries:</div><div><br></div><div><div>+  MatSetOption(B,MAT_NEW_<wbr>NONZERO_LOCATIONS,PETSC_TRUE);</div><div>+  MatSetOption(jac,MAT_NEW_<wbr>NONZERO_LOCATIONS,PETSC_TRUE);</div></div><div><br></div><div><div>+<span class="m_-8867078549042271816gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>  v[7] = 100; col[7].i = mx-1; col[7].j = my-1; col[7].k = mz-1;</div><div>+<span class="m_-8867078549042271816gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>  ierr = MatSetValuesStencil(B,1,&row,<wbr>8,col,v,INSERT_VALUES);<wbr>CHKERRQ(ierr);</div></div><div><br></div><div>It is okay to for np=1, but crash for np>=2 with the error message:</div></div></blockquote><div><br></div><div>You can do this, but</div><div><br></div><div>1) You cannot use MatSetStencil, since your entry is not actually in your stencil. You will have to make a separate call to MatSetValues() using the global index.</div><div><br></div><div>2) The nonzero pattern we have allocated will be wrong. You will have to set the MatOption which gives an error on new nonzeros to PETSC_FALSE.</div><div><br></div><div>3) You will have a dense row in your Jacobian, which is hard to make perform well, and also stymies most preconditioners.</div><div><br></div><div>  Thanks,</div><div><br></div><div>    Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>[0]PETSC ERROR: --------------------- Error Message ------------------------------<wbr>------------------------------<wbr>--</div><div>[0]PETSC ERROR: Argument out of range</div><div>[0]PETSC ERROR: Local index 342 too large 244 (max) at 7</div></div><div><br></div><div><div>[0]PETSC ERROR: #1 ISLocalToGlobalMappingApply() line 423 in petsc-3.7.4/src/vec/is/utils/<wbr>isltog.c</div><div>[0]PETSC ERROR: #2 MatSetValuesLocal() line 2052 in petsc-3.7.4/src/mat/interface/<wbr>matrix.c</div><div>[0]PETSC ERROR: #3 MatSetValuesStencil() line 1447 in petsc-3.7.4/src/mat/interface/<wbr>matrix.c</div><div>[0]PETSC ERROR: #4 ComputeMatrix() line 151 in extest.c</div></div><div><br></div><div>Can I add new entries to the cols not in the stencil width into the dmda matrix or Jacobian?</div><div><br></div><div>Attached please find the modifed ex45 example, the diff file as well as the run log.</div><div><br></div><div>Thanks for your help.</div><div><br></div><div>Best,</div><div>Xiangdong</div><div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div>