Actual source code: preonly.c
petsc-3.13.6 2020-09-29
Report Typos and Errors

      2:  #include <petsc/private/kspimpl.h>

      4: static PetscErrorCode KSPSetUp_PREONLY(KSP ksp)
      5: {
      7:   return(0);
      8: }

     10: static PetscErrorCode  KSPSolve_PREONLY(KSP ksp)
     11: {
     13:   PetscBool      diagonalscale;
     14:   PCFailedReason pcreason;

     17:   PCGetDiagonalScale(ksp->pc,&diagonalscale);
     18:   if (diagonalscale) SETERRQ1(PetscObjectComm((PetscObject)ksp),PETSC_ERR_SUP,"Krylov method %s does not support diagonal scaling",((PetscObject)ksp)->type_name);
     19:   if (!ksp->guess_zero) SETERRQ(PetscObjectComm((PetscObject)ksp),PETSC_ERR_USER,"Running KSP of preonly doesn't make sense with nonzero initial guess\n\
     20:                you probably want a KSP type of Richardson");
     21:   ksp->its = 0;
     22:   KSP_PCApply(ksp,ksp->vec_rhs,ksp->vec_sol);
     23:   PCGetFailedReason(ksp->pc,&pcreason);
     24:   if (pcreason) {
     25:     ksp->reason = KSP_DIVERGED_PC_FAILED;
     26:   } else {
     27:     ksp->its    = 1;
     28:     ksp->reason = KSP_CONVERGED_ITS;
     29: #if defined(PETSC_USE_DEBUG)
     30:     {
     31:       PetscReal norm;
     32:       VecNorm(ksp->vec_sol,NORM_2,&norm);
     33:       if (PetscIsInfOrNanReal(norm)) {
     34:         ksp->reason = KSP_DIVERGED_NANORINF;
     35:       }
     36:     }
     37: #endif
     38:   }
     39:   return(0);
     40: }

     42: /*MC
     43:      KSPPREONLY - This implements a method that applies ONLY the preconditioner exactly once.
     44:                   This may be used in inner iterations, where it is desired to
     45:                   allow multiple iterations as well as the "0-iteration" case. It is
     46:                   commonly used with the direct solver preconditioners like PCLU and PCCHOLESKY

     48:    Options Database Keys:
     49: .   -ksp_type preonly

     51:    Level: beginner

     53:    Notes:
     54:     Since this does not involve an iteration the basic KSP parameters such as tolerances and iteration counts
     55:           do not apply

     57:     To apply multiple preconditioners in a simple iteration use KSPRICHARDSON

     59:    Developer Notes:
     60:     Even though this method does not use any norms, the user is allowed to set the KSPNormType to any value.
     61:     This is so the users does not have to change KSPNormType options when they switch from other KSP methods to this one.

     63: .seealso:  KSPCreate(), KSPSetType(), KSPType, KSP, KSPRICHARDSON, KSPCHEBYSHEV

     65: M*/

     67: PETSC_EXTERN PetscErrorCode KSPCreate_PREONLY(KSP ksp)
     68: {

     72:   KSPSetSupportedNorm(ksp,KSP_NORM_NONE,PC_LEFT,3);
     73:   KSPSetSupportedNorm(ksp,KSP_NORM_NONE,PC_RIGHT,2);
     74:   KSPSetSupportedNorm(ksp,KSP_NORM_PRECONDITIONED,PC_LEFT,2);
     75:   KSPSetSupportedNorm(ksp,KSP_NORM_PRECONDITIONED,PC_RIGHT,2);
     76:   KSPSetSupportedNorm(ksp,KSP_NORM_UNPRECONDITIONED,PC_LEFT,2);
     77:   KSPSetSupportedNorm(ksp,KSP_NORM_UNPRECONDITIONED,PC_RIGHT,2);
     78:   KSPSetSupportedNorm(ksp,KSP_NORM_NATURAL,PC_LEFT,2);

     80:   ksp->data                = NULL;
     81:   ksp->ops->setup          = KSPSetUp_PREONLY;
     82:   ksp->ops->solve          = KSPSolve_PREONLY;
     83:   ksp->ops->destroy        = KSPDestroyDefault;
     84:   ksp->ops->buildsolution  = KSPBuildSolutionDefault;
     85:   ksp->ops->buildresidual  = KSPBuildResidualDefault;
     86:   ksp->ops->setfromoptions = 0;
     87:   ksp->ops->view           = 0;
     88:   return(0);
     89: }