<div dir="ltr"><div dir="ltr"><div dir="ltr">On Sun, Feb 3, 2019 at 2:24 PM Smith, Barry F. via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</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"><br>
<br>
> On Feb 3, 2019, at 1:16 PM, Edoardo alinovi <<a href="mailto:edoardo.alinovi@gmail.com" target="_blank">edoardo.alinovi@gmail.com</a>> wrote:<br>
> <br>
> Thank you very much Barry for the suggestion. <br>
> <br>
> Unfortunately, I am using Fortran and not C++ . Do you have an equivalent trick in this case? :)<br>
<br>
You would need to provide this function as a C function (in its own little .c file) and then call it from your Fortran code. <br></blockquote><div><br></div><div>I think you can also use:</div><div><br></div><div> <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPGetResidualHistory.html">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPGetResidualHistory.html</a></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">
Barry<br>
<br>
There is no way to access the data structure directly from Fortran.<br>
<br>
> ------<br>
> <br>
> Edoardo Alinovi, Ph.D.<br>
> <br>
> DICCA, Scuola Politecnica,<br>
> Universita' degli Studi di Genova,<br>
> 1, via Montallegro,<br>
> 16145 Genova, Italy<br>
> <br>
> Email: <a href="mailto:edoardo.alinovi@dicca.unige.it" target="_blank">edoardo.alinovi@dicca.unige.it</a><br>
> Tel: +39 010 353 2540<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> Il giorno dom 3 feb 2019 alle ore 20:03 Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> ha scritto:<br>
> <br>
> If you use the default KSP convergence tests (which almost everyone does) the initial residual norm is stored in ksp->rnorm0. Thus to access it you need to include the private header file that defines the KSP object kspimpl.h so something like <br>
> <br>
> #include <petsc/private/kspimpl.h> <br>
> <br>
> PetscErrorCode KSPGetInitialResidualNorm(KSP ksp,PetscReal *norm0)<br>
> {<br>
> *norm0 = ksp->rnorm0;<br>
> return 0;<br>
> }<br>
> <br>
> should work.<br>
> <br>
> Barry<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> > On Feb 3, 2019, at 8:27 AM, Edoardo alinovi via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<br>
> > <br>
> > Dear all,<br>
> > <br>
> > I have a very simple question for you. How can I get the initial residual from a ksp solver? I can easily extract the final (preconditioned) residual norm but when I try to use to do the same with the initial residual using:<br>
> > <br>
> > kspInitialResidual()<br>
> > <br>
> > PETSc tells me that this feature is not supported. I am actually doing it applying the definition of residual "by hand", but I am wondering if somenthing already built-in is available or not. <br>
> > <br>
> > Thank you very much! <br>
> > ------<br>
> > <br>
> > Edoardo Alinovi, Ph.D.<br>
> > <br>
> > DICCA, Scuola Politecnica,<br>
> > Universita' degli Studi di Genova,<br>
> > 1, via Montallegro,<br>
> > 16145 Genova, Italy<br>
> > <br>
> > Email: <a href="mailto:edoardo.alinovi@dicca.unige.it" target="_blank">edoardo.alinovi@dicca.unige.it</a><br>
> > Tel: +39 010 353 2540<br>
> > <br>
> > <br>
> > <br>
> <br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <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></div>