<div dir="ltr"><div dir="ltr">On Sun, May 7, 2023 at 9:21 AM Edoardo alinovi <<a href="mailto:edoardo.alinovi@gmail.com">edoardo.alinovi@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello guys,<div><br></div><div>Today I am about to write a custom convergence test for KSP doing the following job:</div><div><br></div><div>- if the number of ksp iterations is less than a given threshold, iterate until that threshold is met</div><div>- if the number of ksp iterations is bigger than the threshold, use the standard convergence checks.</div><div><br></div><div>As far as I understood from the examples, this is the function I need to use:</div><div><pre width="80" style="color:rgb(0,0,0)"><a href="https://petsc.org/main/manualpages/KSP/KSPSetConvergenceTest/" target="_blank">KSPSetConvergenceTest</a>(ksp,MyKSPConverged,0,PETSC_NULL_FUNCTION,ierr)</pre><pre width="80" style="color:rgb(0,0,0)"><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal">With MyKSPConverge a subroutine (I am in fortran) where my custom checks are implemented.</div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><br></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal">Here is how I have coded  <span style="color:rgb(0,0,0)">MyKSPConverged:</span></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><span style="color:rgb(0,0,0)"><i><br></i></span></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><i>    subroutine MyKSPConverged(ksp,n,rnorm,flag,dummy,ierr)<br><br>       KSP              ksp<br>       PetscErrorCode ierr<br>       PetscInt n,dummy<br>       KSPConvergedReason flag<br>       PetscReal rnorm<br><br>       if (n>1) then<br>         call KSPConvergedDefault(ksp, n, rnorm, flag, ierr)<br></i></div></pre></div></div></blockquote><div><br></div><div>Isn't this call missing an argument?</div><div><br></div><div>  THanks,</div><div><br></div><div>    Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><pre width="80" style="color:rgb(0,0,0)"><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><i>       else<br>         flag = 0<br>       endif<br>       ierr = 0<br><br>    end subroutine MyKSPConverged</i><span style="color:rgb(0,0,0)"><br></span></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><br></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal">However I get this error: </div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal">[0]PETSC ERROR: KSPSolve has not converged, reason DIVERGED_DTOL<br></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal">which I believe to be triggered by <span style="background-image:url("");background-repeat:repeat-x;border-bottom:2px solid transparent;outline:none"><i>KSPConvergedDefault. </i>This is odd, as this simulation converge perfectly if I comment ou my dodgy convergence test.</span></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><i><span style="background-image:url("");background-repeat:repeat-x;border-bottom:2px solid transparent;outline:none"><br></span></i></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><span style="background-image:url("");background-repeat:repeat-x;border-bottom:2px solid transparent;outline:none"><i>Do you have any advice for me?</i></span></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><span style="background-image:url("");background-repeat:repeat-x;border-bottom:2px solid transparent;outline:none"><i><br></i></span></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><span style="background-image:url("");background-repeat:repeat-x;border-bottom:2px solid transparent;outline:none"><i>thank you! </i></span></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><span style="background-image:url("");background-repeat:repeat-x;border-bottom:2px solid transparent;outline:none"><i><br></i></span></div><div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><span style="background-image:url("");background-repeat:repeat-x;border-bottom:2px solid transparent;outline:none"><i> </i></span><br></div>
<div style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal"><br></div>


</pre></div></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>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><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>