<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 20, 2020, at 7:45 PM, baikadi pranay <<a href="mailto:pranayreddy865@gmail.com" class="">pranayreddy865@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thank you for the clarification. <br class=""><br class=""> I also want to get two more things clarified. After i^th call to KSPSolve(), I get x^i as the solution vector. I do a bunch of updates to A matrix and b vector using this x^i and copy x^i into a vector called x_old. <br class=""><br class="">1) When I call KSPSolve for the (i+1)th time using KSPSolve(ksp,b,x,ierr), the variable x already has the solution of the previous iteration in it. Does that mean I need to create a new x vector each time I call KSPSolve? <br class="">2) On the similar lines, do I need to create new x_old after each iteration? <br class=""></div></div></blockquote><div><br class=""></div> No, you do not have to do anything special with the vectors, the KSP does not track them like it tracks the matrix.</div><div><br class=""></div><div> Separate note: If you are using the previous solution as an initial guess for the next solve you need to call KSPSetInitialGuessNonzero() go tell KSP to use the initial guess (otherwise it always starts with a zero initial guess)</div><div><br class=""></div><div> Barry</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><br class="">Please let me know if the questions are unclear, so that I can elaborate. </div><div hspace="streak-pt-mark" style="max-height:1px" class=""><img alt="" style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=acHJhbmF5cmVkZHk4NjVAZ21haWwuY29t&type=zerocontent&guid=e319e5b0-7be4-4fd8-ba0f-6007ca55e1bf" class=""><font color="#ffffff" size="1" class="">ᐧ</font></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 19, 2020 at 9:06 PM Barry Smith <<a href="mailto:bsmith@petsc.dev" class="">bsmith@petsc.dev</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class=""><div class=""><br class=""></div> KSP knows if the matrix has changed and rebuilds the parts of the preconditioner it needs if the matrix has changed. When the matrix has not changed it uses the exact same preconditioner as before.<div class=""><br class=""></div><div class=""><br class=""></div><div class=""> Barry</div><div class=""><br class=""></div><div class=""> This "trick" is done by having an integer state variable inside the matrix object. Each time the matrix is changed by MatSetValues() etc. the state variable is incremented. KSPSolve() keeps a record of the state variable of the matrix for each call to SNESSolve(), if the state variable has increased it knows the matrix has changed so updates the preconditioner. <br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Aug 19, 2020, at 9:05 PM, baikadi pranay <<a href="mailto:pranayreddy865@gmail.com" target="_blank" class="">pranayreddy865@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">Hello,<br class=""><br class="">I am trying to solve the poisson equation iteratively using BiCGStab in FORTRAN 90. After every call to KSPSolve, I update the central coefficients of A matrix and the b vector (and then solve the new linear equation system, repeating the process until convergence is achieved). I want to know whether the A matrix and b vector that are created initially can be used in the iteration process or do I need to create a new A matrix and b vector in each iteration.<br class=""><br class="">Please let me know if you need any further information.<br class=""><br class="">Thank you.<br class=""><br class="">Sincerely,<br class="">Pranay.</div><div hspace="streak-pt-mark" style="max-height:1px" class=""><img alt="" style="width: 0px; max-height: 0px; overflow: hidden;" src="https://mailfoogae.appspot.com/t?sender=acHJhbmF5cmVkZHk4NjVAZ21haWwuY29t&type=zerocontent&guid=56fdbc37-6f85-4d2a-abee-a6ec6fe11bbf" class=""><font color="#ffffff" size="1" class="">ᐧ</font></div>
</div></blockquote></div><br class=""></div></div></blockquote></div>
</div></blockquote></div><br class=""></body></html>