<div>Hi Sean,</div>
<div>&nbsp;</div>
<div>Maybe for me, I can just insert vector diagonal D into the matrix A and call Assembly and KSP at every time step. Should that be better since there is no need to copy A into B?</div>
<div>&nbsp;</div>
<div>Thanks!<br><br></div>
<div class="gmail_quote">On Fri, May 9, 2008 at 8:50 PM, Sean Dettrick &lt;<a href="mailto:sdettrick@gmail.com">sdettrick@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>One way to do it is to have two Mats, A and B, and a Vec, D, to store the diagonal. &nbsp;A is constructed only on the first step. &nbsp;On subsequent steps, A is copied into B, and then D is added to the diagonal:<br>
<br>&nbsp;ierr = MatCopy( A, B, SAME_NON_ZERO_PATTERN );<br>&nbsp;ierr = MatDiagonalSet( B, D, ADD_VALUES );<br><br>The KSP uses B as the matrix, not A.<br><br>I don&#39;t know if this approach is efficient or not. &nbsp;Can anybody comment?<br>
<br>Thanks,<br><font color="#888888">Sean</font> 
<div>
<div></div>
<div class="Wj3C7c"><br><br><br><br>On May 9, 2008, at 2:33 PM, Ben Tay wrote:<br><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi,<br>I have a matrix and I inserted all the relevant values during the 1st step. I&#39;ll then solve it. For the subsequent steps, I only need to change the diagonal vector of the matrix before solving. I wonder how I can do it efficiently. Of course, the RHS vector also change but I&#39;ve not included them here.<br>
<br>I set these at the 1st step:<br><br>call KSPSetOperators(ksp_semi_x,A_semi_x,A_semi_x,SAME_NONZERO_PATTERN,ierr)<br><br>call KSPGetPC(ksp_semi_x,pc_semi_x,ierr)<br><br>&nbsp;ksptype=KSPRICHARDSON<br><br>&nbsp;call KSPSetType(ksp_semi_x,ksptype,ierr)<br>
<br>&nbsp;ptype = PCILU<br><br>&nbsp;call PCSetType(pc_semi_x,ptype,ierr)<br><br>&nbsp;call KSPSetFromOptions(ksp_semi_x,ierr)<br><br>&nbsp;call KSPSetInitialGuessNonzero(ksp_semi_x,PETSC_TRUE,ierr)<br><br>&nbsp;tol=1.e-5<br><br>&nbsp;call KSPSetTolerances(ksp_semi_x,tol,PETSC_DEFAULT_DOUBLE_PRECISION,PETSC_DEFAULT_DOUBLE_PRECISION,PETSC_DEFAULT_INTEGER,ierr)<br>
<br>and what I did at the subsequent steps is:<br><br>do II=1,total<br>&nbsp;call MatSetValues(A_semi_x,1,II,1,II,new_value,INSERT_VALUES,ierr)<br><br>end do<br><br>call MatAssemblyBegin(A_semi_x,MAT_FINAL_ASSEMBLY,ierr)<br><br>
call MatAssemblyEnd(A_semi_x,MAT_FINAL_ASSEMBLY,ierr)<br><br>call KSPSolve(ksp_semi_x,b_rhs_semi_x,xx_semi_x,ierr)<br><br>I realise that the answers are slightly different as compared to calling all the options such as KSPSetType, KSPSetFromOptions, KSPSetTolerances at every time step. Should that be so? Is this the best way?<br>
<br>Also, I can let the matrix be equal at every time step by fixing the delta_time. However, it may give stability problems. I wonder how expensive is these type of value changing and assembly for a matrix?<br><br>Thank you very much.<br>
<br>Regards.<br><br></blockquote><br></div></div></blockquote></div><br>