Actual source code: preonly.c
petsc-3.10.5 2019-03-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:   PCGetSetUpFailedReason(ksp->pc,&pcreason);
     24:   if (pcreason) {
     25:     ksp->reason = KSP_DIVERGED_PCSETUP_FAILED;
     26:   } else {
     27:     ksp->its    = 1;
     28:     ksp->reason = KSP_CONVERGED_ITS;
     29:   }
     30:   return(0);
     31: }

     33: /*MC
     34:      KSPPREONLY - This implements a stub method that applies ONLY the preconditioner.
     35:                   This may be used in inner iterations, where it is desired to
     36:                   allow multiple iterations as well as the "0-iteration" case. It is
     37:                   commonly used with the direct solver preconditioners like PCLU and PCCHOLESKY

     39:    Options Database Keys:
     40: .   -ksp_type preonly

     42:    Level: beginner

     44:    Notes:
     45:     Since this does not involve an iteration the basic KSP parameters such as tolerances and iteration counts
     46:           do not apply

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

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

     54: M*/

     56: PETSC_EXTERN PetscErrorCode KSPCreate_PREONLY(KSP ksp)
     57: {

     61:   KSPSetSupportedNorm(ksp,KSP_NORM_NONE,PC_LEFT,3);
     62:   KSPSetSupportedNorm(ksp,KSP_NORM_NONE,PC_RIGHT,2);
     63:   KSPSetSupportedNorm(ksp,KSP_NORM_PRECONDITIONED,PC_LEFT,2);
     64:   KSPSetSupportedNorm(ksp,KSP_NORM_PRECONDITIONED,PC_RIGHT,2);
     65:   KSPSetSupportedNorm(ksp,KSP_NORM_UNPRECONDITIONED,PC_LEFT,2);
     66:   KSPSetSupportedNorm(ksp,KSP_NORM_UNPRECONDITIONED,PC_RIGHT,2);
     67:   KSPSetSupportedNorm(ksp,KSP_NORM_NATURAL,PC_LEFT,2);

     69:   ksp->data                = NULL;
     70:   ksp->ops->setup          = KSPSetUp_PREONLY;
     71:   ksp->ops->solve          = KSPSolve_PREONLY;
     72:   ksp->ops->destroy        = KSPDestroyDefault;
     73:   ksp->ops->buildsolution  = KSPBuildSolutionDefault;
     74:   ksp->ops->buildresidual  = KSPBuildResidualDefault;
     75:   ksp->ops->setfromoptions = 0;
     76:   ksp->ops->view           = 0;
     77:   return(0);
     78: }