[petsc-users] Ksp Initial residual norm

Smith, Barry F. bsmith at mcs.anl.gov
Sun Feb 3 16:06:37 CST 2019


  Oh yes. Better than my suggestion since it requires no coding.\

  Barry


> On Feb 3, 2019, at 3:40 PM, Matthew Knepley <knepley at gmail.com> wrote:
> 
> On Sun, Feb 3, 2019 at 2:24 PM Smith, Barry F. via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> 
> > On Feb 3, 2019, at 1:16 PM, Edoardo alinovi <edoardo.alinovi at gmail.com> wrote:
> > 
> > Thank you very much Barry for the suggestion. 
> > 
> > Unfortunately, I am using Fortran and not C++ . Do you have an equivalent trick in this case? :)
> 
>    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. 
> 
> I think you can also use:
> 
>   https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPGetResidualHistory.html
> 
>     Matt
>  
>    Barry
> 
>    There is no way to access the data structure directly from Fortran.
> 
> > ------
> > 
> > Edoardo Alinovi, Ph.D.
> > 
> > DICCA, Scuola Politecnica,
> > Universita' degli Studi di Genova,
> > 1, via Montallegro,
> > 16145 Genova, Italy
> > 
> > Email: edoardo.alinovi at dicca.unige.it
> > Tel: +39 010 353 2540
> > 
> > 
> > 
> > 
> > 
> > Il giorno dom 3 feb 2019 alle ore 20:03 Smith, Barry F. <bsmith at mcs.anl.gov> ha scritto:
> > 
> >    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 
> > 
> > #include <petsc/private/kspimpl.h> 
> > 
> >    PetscErrorCode KSPGetInitialResidualNorm(KSP ksp,PetscReal *norm0)
> >   {
> >    *norm0 = ksp->rnorm0;
> >    return 0;
> >   }
> > 
> > should work.
> > 
> >    Barry
> > 
> > 
> > 
> > 
> > 
> > 
> > > On Feb 3, 2019, at 8:27 AM, Edoardo alinovi via petsc-users <petsc-users at mcs.anl.gov> wrote:
> > > 
> > > Dear all,
> > > 
> > > 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:
> > > 
> > > kspInitialResidual()
> > > 
> > > 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. 
> > > 
> > > Thank you very much! 
> > > ------
> > > 
> > > Edoardo Alinovi, Ph.D.
> > > 
> > > DICCA, Scuola Politecnica,
> > > Universita' degli Studi di Genova,
> > > 1, via Montallegro,
> > > 16145 Genova, Italy
> > > 
> > > Email: edoardo.alinovi at dicca.unige.it
> > > Tel: +39 010 353 2540
> > > 
> > > 
> > > 
> > 
> 
> 
> 
> -- 
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
> -- Norbert Wiener
> 
> https://www.cse.buffalo.edu/~knepley/



More information about the petsc-users mailing list