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: KSP ksp; /* KSP coupling the action of pc and P */
20: PC pc; /* inner fine-level PC, acting like a multigrid smoother */
21: HPDDM::Schwarz<PetscScalar> *P; /* coarse-level HPDDM solver */
22: Vec D; /* partition of unity */
23: PetscReal threshold; /* threshold for selecting local deflation vectors */
24: PetscInt nu; /* number of local deflation vectors */
25: const struct PC_HPDDM *parent; /* parent PC */
26: };
28: struct PC_HPDDM {
29: PC_HPDDM_Level **levels; /* array of shells */
30: Mat aux; /* local auxiliary matrix, or deflation matrix if the PetscBool deflation is PETSC_TRUE, defined at the finest level on PETSC_COMM_SELF */
31: Mat B; /* right-hand side matrix, defined at the finest level on PETSC_COMM_SELF */
32: Vec normal; /* temporary Vec when preconditioning the normal equations with KSPLSQR */
33: Vec scaling; /* user-supplied scaling in the ordering of the IS is, defined at the finest level on PETSC_COMM_SELF */
34: IS is; /* global numbering of the rows of the Mat aux and of the entries of the Vec scaling */
35: PetscInt N; /* number of levels */
36: PCHPDDMCoarseCorrectionType correction; /* type of coarse correction */
37: PetscBool3 Neumann; /* aux is the local Neumann matrix? */
38: PetscBool log_separate; /* separate events for each level? */
39: PetscBool share; /* shared subdomain KSP between SLEPc and PETSc? */
40: PetscBool deflation; /* aux is the local deflation space? */
41: PetscErrorCode (*setup)(Mat, PetscReal, Vec, Vec, PetscReal, IS, void *); /* setup function for the auxiliary matrix */
42: void *setup_ctx; /* context for setup */
43: };
45: struct KSPHPDDMConvergenceCtx {
46: PetscInt n;
47: PetscReal *norm;
48: PetscReal *init;
49: PetscReal *residual;
50: PetscBool *locked;
51: };
53: struct KSP_HPDDM {
54: HPDDM::PETScOperator *op;
55: PetscReal rcntl[1];
56: int icntl[2];
57: unsigned short scntl[2];
58: char cntl[5];
59: PetscPrecision precision;
60: KSPHPDDMConvergenceCtx convergence;
61: };
63: /* Context of the convergence test for multiple right-hand sides:
64: - KSPHPDDMConvergenceSetUp_Private() allocates the context buffers and initializes the right-hand side and initial residual norms (arrays norm and init in KSPHPDDMConvergenceCtx);
65: - KSPHPDDMConvergenceUpdate_Private() updates the context with the current residual norms and locks the right-hand sides that have converged (arrays residual and locked).
66: It outputs a read-only pointer to the locks stored in the context. */
67: PETSC_INTERN PetscErrorCode KSPHPDDMConvergenceSetUp_Private(KSP, PetscInt, const PetscReal[], const PetscReal[]);
68: PETSC_INTERN PetscErrorCode KSPHPDDMConvergenceUpdate_Private(KSP, PetscInt, const PetscReal[], const PetscBool **);
70: typedef struct _n_Harmonic *Harmonic;
71: struct _n_Harmonic {
72: KSP ksp;
73: Mat *A;
74: Vec v[2];
75: IS *is;
76: VecScatter scatter[2];
77: };
79: PETSC_EXTERN PetscLogEvent PC_HPDDM_PtAP;
80: PETSC_EXTERN PetscLogEvent PC_HPDDM_PtBP;
81: PETSC_EXTERN PetscLogEvent PC_HPDDM_Next;
82: PETSC_INTERN PetscErrorCode HPDDMLoadDL_Private(PetscBool *);
83: PETSC_INTERN const char HPDDMCitation[];
84: PETSC_INTERN PetscBool HPDDMCite;
85: #if PetscDefined(HAVE_CUDA) && PetscDefined(HAVE_HPDDM)
86: PETSC_INTERN PetscErrorCode KSPSolve_HPDDM_CUDA_Private(KSP_HPDDM *, const PetscScalar *, PetscScalar *, PetscInt, MPI_Comm);
87: #endif
89: #include <HPDDM.hpp>