void SolverLinearPetsc<T>::getResidualHistory( std::vector<double>& hist ) { int ierr = 0; int its = 0; // Fill the residual history vector with the residual norms // Note that GetResidualHistory() does not copy any values, it // simply sets the pointer p. Note that for some Krylov subspace // methods, the number of residuals returned in the history // vector may be different from what you are expecting. For // example, TFQMR returns two residual values per iteration step. double* p; ierr = KSPGetResidualHistory( M_ksp, &p, &its ); CHKERRABORT( this->worldComm().globalComm(),ierr ); // Check for early return if ( its == 0 ) return; // Create space to store the result hist.resize( its ); // Copy history into the vector provided by the user. for ( int i=0; i<its; ++i ) { hist[i] = *p; p++; } }
typename SolverLinearPetsc<T>::real_type SolverLinearPetsc<T>::getInitialResidual() { int ierr = 0; int its = 0; // Fill the residual history vector with the residual norms // Note that GetResidualHistory() does not copy any values, it // simply sets the pointer p. Note that for some Krylov subspace // methods, the number of residuals returned in the history // vector may be different from what you are expecting. For // example, TFQMR returns two residual values per iteration step. double* p; ierr = KSPGetResidualHistory( M_ksp, &p, &its ); CHKERRABORT( this->worldComm().globalComm(),ierr ); // Check no residual history if ( its == 0 ) { std::cerr << "No iterations have been performed, returning 0." << std::endl; return 0.; } // Otherwise, return the value pointed to by p. return *p; }
#include <petscksp.h> #include <petsc/private/f90impl.h> #if defined(PETSC_HAVE_FORTRAN_CAPS) #define kspgetresidualhistoryf90_ KSPGETRESIDUALHISTORYF90 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE) #define kspgetresidualhistoryf90_ kspgetresidualhistoryf90 #endif PETSC_EXTERN void PETSC_STDCALL kspgetresidualhistoryf90_(KSP *ksp,F90Array1d *indices,PetscInt *n,int *ierr PETSC_F90_2PTR_PROTO(ptrd)) { PetscReal *hist; *ierr = KSPGetResidualHistory(*ksp,&hist,n); if (*ierr) return; *ierr = F90Array1dCreate(hist,PETSC_DOUBLE,1,*n,indices PETSC_F90_2PTR_PARAM(ptrd)); }