Actual source code: petschpddm.h

  1: #pragma once

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

  5: #define PETSC_PCHPDDM_MAXLEVELS 9

  7: #define PETSC_KSPHPDDM_DEFAULT_PRECISION PETSC_DEPRECATED_MACRO(3, 25, 0, "PETSC_SCALAR_PRECISION", ) PETSC_SCALAR_PRECISION

  9: namespace HPDDM
 10: {
 11: template <class>
 12: class Schwarz; /* forward definitions of two needed HPDDM classes */
 13: class PETScOperator;
 14: } // namespace HPDDM

 16: struct PC_HPDDM_Level {
 17:   VecScatter                   scatter;   /* scattering from PETSc nonoverlapping numbering to HPDDM overlapping */
 18:   Vec                         *v[2];      /* working vectors */
 19:   Mat                          V[3];      /* working matrices */
 20:   KSP                          ksp;       /* KSP coupling the action of pc and P */
 21:   PC                           pc;        /* inner fine-level PC, acting like a multigrid smoother */
 22:   HPDDM::Schwarz<PetscScalar> *P;         /* coarse-level HPDDM solver */
 23:   Vec                          D;         /* partition of unity */
 24:   PetscReal                    threshold; /* threshold for selecting local deflation vectors */
 25:   PetscInt                     nu;        /* number of local deflation vectors */
 26:   const struct PC_HPDDM       *parent;    /* parent PC */
 27: };

 29: struct PC_HPDDM {
 30:   PC_HPDDM_Level            **levels;                                       /* array of shells */
 31:   Mat                         aux;                                          /* local auxiliary matrix, or deflation matrix if the PetscBool deflation is PETSC_TRUE, defined at the finest level on PETSC_COMM_SELF */
 32:   Mat                         B;                                            /* right-hand side matrix, defined at the finest level on PETSC_COMM_SELF */
 33:   Vec                         normal;                                       /* temporary Vec when preconditioning the normal equations with KSPLSQR */
 34:   Vec                         scaling;                                      /* user-supplied scaling in the ordering of the IS is, defined at the finest level on PETSC_COMM_SELF */
 35:   IS                          is;                                           /* global numbering of the rows of the Mat aux and of the entries of the Vec scaling */
 36:   PetscInt                    N;                                            /* number of levels */
 37:   PCHPDDMCoarseCorrectionType correction;                                   /* type of coarse correction */
 38:   PetscBool3                  Neumann;                                      /* aux is the local Neumann matrix? */
 39:   PetscBool                   log_separate;                                 /* separate events for each level? */
 40:   PetscBool                   share;                                        /* shared subdomain KSP between SLEPc and PETSc? */
 41:   PetscBool                   deflation;                                    /* aux is the local deflation space? */
 42:   PetscErrorCode (*setup)(Mat, PetscReal, Vec, Vec, PetscReal, IS, void *); /* setup function for the auxiliary matrix */
 43:   void *setup_ctx;                                                          /* context for setup */
 44: };

 46: struct KSPHPDDMConvergenceCtx {
 47:   PetscInt   n;
 48:   PetscReal *norm;
 49:   PetscReal *init;
 50:   PetscReal *residual;
 51:   PetscBool *locked;
 52: };

 54: struct KSP_HPDDM {
 55:   HPDDM::PETScOperator  *op;
 56:   PetscReal              rcntl[1];
 57:   int                    icntl[2];
 58:   unsigned short         scntl[2];
 59:   char                   cntl[5];
 60:   PetscPrecision         precision;
 61:   KSPHPDDMConvergenceCtx convergence;
 62: };

 64: /* Context of the convergence test for multiple right-hand sides:
 65:      - KSPHPDDMConvergenceSetUp_Private() allocates the context buffers and initializes the right-hand side and initial residual norms (arrays norm and init in KSPHPDDMConvergenceCtx);
 66:      - KSPHPDDMConvergenceUpdate_Private() updates the context with the current residual norms and locks the right-hand sides that have converged (arrays residual and locked).
 67:    It outputs a read-only pointer to the locks stored in the context. */
 68: PETSC_INTERN PetscErrorCode KSPHPDDMConvergenceSetUp_Private(KSP, PetscInt, const PetscReal[], const PetscReal[]);
 69: PETSC_INTERN PetscErrorCode KSPHPDDMConvergenceUpdate_Private(KSP, PetscInt, const PetscReal[], const PetscBool **);

 71: typedef struct _n_Harmonic *Harmonic;
 72: struct _n_Harmonic {
 73:   KSP        ksp;
 74:   Mat       *A;
 75:   Vec        v[2];
 76:   IS        *is;
 77:   VecScatter scatter[2];
 78: };

 80: PETSC_EXTERN PetscLogEvent  PC_HPDDM_PtAP;
 81: PETSC_EXTERN PetscLogEvent  PC_HPDDM_PtBP;
 82: PETSC_EXTERN PetscLogEvent  PC_HPDDM_Next;
 83: PETSC_INTERN PetscErrorCode HPDDMLoadDL_Private(PetscBool *);
 84: PETSC_INTERN const char     HPDDMCitation[];
 85: PETSC_INTERN PetscBool      HPDDMCite;
 86: #if PetscDefined(HAVE_CUDA) && PetscDefined(HAVE_HPDDM)
 87: PETSC_INTERN PetscErrorCode KSPSolve_HPDDM_CUDA_Private(KSP_HPDDM *, const PetscScalar *, PetscScalar *, PetscInt, MPI_Comm);
 88: #endif

 90: #include <HPDDM.hpp>