<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><html>On May 10, 2008, at 10:38 AM, Ben Tay wrote:</html><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi Sean,</div> <div> </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> </div> <div>Thanks!</div></blockquote><div><br></div><div><br></div>Yes, that sounds like it would be faster. I suppose you would use INSERT_VALUES rather than ADD_VALUES.</div><div><br></div><div>In my case I copy the whole matrix because constructing the time-constant part of the diagonal is very complicated. But now that you mention it, I could store both the time-constant and time-varying diagonal components in two separate Vecs, and only have one Mat, and then do MatDiagonalSet() twice at each timestep - the first time with INSERT_VALUES, the second with ADD_VALUES. That sounds like it would be faster.</div><div><br></div><div>Thanks to you too,</div><div><br></div><div>Sean</div><div><br></div><div><br><blockquote type="cite"><div><br><br></div> <div class="gmail_quote">On Fri, May 9, 2008 at 8:50 PM, Sean Dettrick <<a href="mailto:sdettrick@gmail.com">sdettrick@gmail.com</a>> 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. A is constructed only on the first step. On subsequent steps, A is copied into B, and then D is added to the diagonal:<br> <br> ierr = MatCopy( A, B, SAME_NON_ZERO_PATTERN );<br> ierr = MatDiagonalSet( B, D, ADD_VALUES );<br><br>The KSP uses B as the matrix, not A.<br><br>I don't know if this approach is efficient or not. 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'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'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> ksptype=KSPRICHARDSON<br><br> call KSPSetType(ksp_semi_x,ksptype,ierr)<br> <br> ptype = PCILU<br><br> call PCSetType(pc_semi_x,ptype,ierr)<br><br> call KSPSetFromOptions(ksp_semi_x,ierr)<br><br> call KSPSetInitialGuessNonzero(ksp_semi_x,PETSC_TRUE,ierr)<br><br> tol=1.e-5<br><br> 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> 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></blockquote></div><br></body></html>