Actual source code: pcmgimpl.h

  1: /*
  2:       Data structure used for Multigrid preconditioner.
  3: */
  4: #ifndef PETSC_PCMGIMPL_H
  5: #define PETSC_PCMGIMPL_H

  7: #include <petsc/private/pcimpl.h>
  8: #include <petscksp.h>
  9: #include <petscpctypes.h>
 10: #define PETSC_MG_MAXLEVELS 10
 11: /*
 12:      Each level has its own copy of this data.
 13:      Level (0) is always the coarsest level and Level (levels-1) is the finest.
 14: */
 15: typedef struct {
 16:   PetscInt cycles; /* Type of cycle to run: 1 V 2 W */
 17:   PetscInt level;  /* level = 0 coarsest level */
 18:   PetscInt levels; /* number of active levels used */
 19:   Vec      b;      /* Right hand side */
 20:   Vec      x;      /* Solution */
 21:   Vec      r;      /* Residual */
 22:   Mat      B;
 23:   Mat      X;
 24:   Mat      R;
 25:   Mat      coarseSpace; /* A vector space which should be accurately captured by the next coarser mesh,
 26:                                                   and thus accurately interpolated. The columns of this dense matrix
 27:                                                   correspond to the same function discretized in
 28:                                                   the sequence of spaces. */

 30:   PetscErrorCode (*residual)(Mat, Vec, Vec, Vec);
 31:   PetscErrorCode (*residualtranspose)(Mat, Vec, Vec, Vec);
 32:   PetscErrorCode (*matresidual)(Mat, Mat, Mat, Mat);
 33:   PetscErrorCode (*matresidualtranspose)(Mat, Mat, Mat, Mat);

 35:   Mat           A;       /* matrix used in forming residual*/
 36:   KSP           smoothd; /* pre smoother */
 37:   KSP           smoothu; /* post smoother */
 38:   KSP           cr;      /* post compatible relaxation (cr) */
 39:   Vec           crx;     /* cr solution */
 40:   Vec           crb;     /* cr rhs */
 41:   Mat           interpolate;
 42:   Mat           restrct;          /* restrict is a reserved word in C99 and on Cray */
 43:   Mat           inject;           /* Used for moving state if provided. */
 44:   Vec           rscale;           /* scaling of restriction matrix */
 45:   PetscLogEvent eventsmoothsetup; /* if logging times for each level */
 46:   PetscLogEvent eventsmoothsolve;
 47:   PetscLogEvent eventresidual;
 48:   PetscLogEvent eventinterprestrict;
 49: } PC_MG_Levels;

 51: /*
 52:     This data structure is shared by all the levels.
 53: */
 54: typedef struct {
 55:   PCMGType         am;                     /* Multiplicative, additive or full */
 56:   PetscInt         cyclesperpcapply;       /* Number of cycles to use in each PCApply(), multiplicative only*/
 57:   PetscInt         maxlevels;              /* total number of levels allocated */
 58:   PCMGGalerkinType galerkin;               /* use Galerkin process to compute coarser matrices */
 59:   PetscBool        usedmfornumberoflevels; /* sets the number of levels by getting this information out of the DM */

 61:   PetscBool           adaptInterpolation; /* flag to adapt the interpolator based upon the coarseSpace */
 62:   PCMGCoarseSpaceType coarseSpaceType;    /* Type of coarse space: polynomials, harmonics, eigenvectors, ... */
 63:   PetscInt            Nc;                 /* The number of vectors in coarseSpace */
 64:   PetscInt            eigenvalue;         /* Key for storing the eigenvalue as a scalar in the eigenvector Vec */
 65:   PetscBool           mespMonitor;        /* flag to monitor the multilevel eigensolver */

 67:   PetscBool compatibleRelaxation; /* flag to monitor the coarse space quality using an auxiliary solve with compatible relaxation */

 69:   PetscInt       nlevels;
 70:   PC_MG_Levels **levels;
 71:   PetscInt       default_smoothu;          /* number of smooths per level if not over-ridden */
 72:   PetscInt       default_smoothd;          /*  with calls to KSPSetTolerances() */
 73:   PetscReal      rtol, abstol, dtol, ttol; /* tolerances for when running with PCApplyRichardson_MG */

 75:   void         *innerctx; /* optional data for preconditioner, like PCEXOTIC that inherits off of PCMG */
 76:   PetscLogStage stageApply;
 77:   PetscErrorCode (*view)(PC, PetscViewer); /* GAMG and other objects that use PCMG can set their own viewer here */
 78:   PetscReal min_eigen_DinvA[PETSC_MG_MAXLEVELS];
 79:   PetscReal max_eigen_DinvA[PETSC_MG_MAXLEVELS];
 80: } PC_MG;

 82: PETSC_INTERN PetscErrorCode PCSetUp_MG(PC);
 83: PETSC_INTERN PetscErrorCode PCDestroy_MG(PC);
 84: PETSC_INTERN PetscErrorCode PCSetFromOptions_MG(PC, PetscOptionItems *PetscOptionsObject);
 85: PETSC_INTERN PetscErrorCode PCView_MG(PC, PetscViewer);
 86: PETSC_INTERN PetscErrorCode PCMGGetLevels_MG(PC, PetscInt *);
 87: PETSC_INTERN PetscErrorCode PCMGSetLevels_MG(PC, PetscInt, MPI_Comm *);
 88: PETSC_DEPRECATED_FUNCTION("Use PCMGResidualDefault() (since version 3.5)") static inline PetscErrorCode PCMGResidual_Default(Mat A, Vec b, Vec x, Vec r)
 89: {
 90:   return PCMGResidualDefault(A, b, x, r);
 91: }

 93: PETSC_INTERN PetscErrorCode DMSetBasisFunction_Internal(PetscInt, PetscBool, PetscInt, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *));
 94: PETSC_INTERN PetscErrorCode PCMGComputeCoarseSpace_Internal(PC, PetscInt, PCMGCoarseSpaceType, PetscInt, Mat, Mat *);
 95: PETSC_INTERN PetscErrorCode PCMGAdaptInterpolator_Internal(PC, PetscInt, KSP, KSP, Mat, Mat);
 96: PETSC_INTERN PetscErrorCode PCMGRecomputeLevelOperators_Internal(PC, PetscInt);
 97: PETSC_INTERN PetscErrorCode PCMGACycle_Private(PC, PC_MG_Levels **, PetscBool, PetscBool);
 98: PETSC_INTERN PetscErrorCode PCMGFCycle_Private(PC, PC_MG_Levels **, PetscBool, PetscBool);
 99: PETSC_INTERN PetscErrorCode PCMGKCycle_Private(PC, PC_MG_Levels **, PetscBool, PetscBool);
100: PETSC_INTERN PetscErrorCode PCMGMCycle_Private(PC, PC_MG_Levels **, PetscBool, PetscBool, PCRichardsonConvergedReason *);

102: PETSC_INTERN PetscErrorCode PCMGGDSWCreateCoarseSpace_Private(PC, PetscInt, DM, KSP, PetscInt, Mat, Mat *);
103: #endif // PETSC_PCMGIMPL_H