Actual source code: preonly.c

petsc-3.11.4 2019-09-28
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 stub method that applies ONLY the preconditioner.
 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:    Developer Notes:
 58:     Even though this method does not use any norms, the user is allowed to set the KSPNormType to any value.
 59:     This is so the users does not have to change KSPNormType options when they switch from other KSP methods to this one.

 61: .seealso:  KSPCreate(), KSPSetType(), KSPType (for list of available types), KSP

 63: M*/

 65: PETSC_EXTERN PetscErrorCode KSPCreate_PREONLY(KSP ksp)
 66: {

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

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