xref: /petsc/include/petsc/private/pcgamgimpl.h (revision f61fa1bf5c611e7ec88fe6b5dab8a7d00ec7cf33) !
1 #pragma once
2 #include <petscksp.h>
3 #include <petsc/private/pcimpl.h>
4 #include <petsc/private/pcmgimpl.h> /*I "petscksp.h" I*/
5 #include <petscmatcoarsen.h>        /*I "petscmatcoarsen.h" I*/
6 #include <petsc/private/matimpl.h>
7 
8 struct _PCGAMGOps {
9   PetscErrorCode (*creategraph)(PC, Mat, Mat *);
10   PetscErrorCode (*coarsen)(PC, Mat *, PetscCoarsenData **);
11   PetscErrorCode (*prolongator)(PC, Mat, PetscCoarsenData *, Mat *);
12   PetscErrorCode (*optprolongator)(PC, Mat, Mat *);
13   PetscErrorCode (*createlevel)(PC, Mat, PetscInt, Mat *, Mat *, PetscMPIInt *, IS *, PetscBool);
14   PetscErrorCode (*createdefaultdata)(PC, Mat); /* for data methods that have a default (SA) */
15   PetscErrorCode (*setfromoptions)(PC, PetscOptionItems);
16   PetscErrorCode (*destroy)(PC);
17   PetscErrorCode (*view)(PC, PetscViewer);
18 };
19 /* Private context for the GAMG preconditioner */
20 typedef struct gamg_TAG {
21   PCGAMGType       type;
22   PetscInt         Nlevels;
23   PetscBool        repart;
24   PetscBool        reuse_prol;
25   PetscBool        use_aggs_in_asm;
26   PetscBool        use_parallel_coarse_grid_solver;
27   PCGAMGLayoutType layout_type;
28   PetscBool        cpu_pin_coarse_grids;
29   PetscInt         min_eq_proc;
30   PetscInt         asm_hem_aggs;
31   MatCoarsen       asm_crs; /* used to generate ASM aggregates */
32   PetscInt         coarse_eq_limit;
33   PetscReal        threshold_scale;
34   PetscReal        threshold[PETSC_MG_MAXLEVELS]; /* common quantity to many AMG methods so keep it up here */
35   PetscInt         level_reduction_factors[PETSC_MG_MAXLEVELS];
36   PetscInt         current_level; /* stash construction state */
37   /* these 4 are all related to the method data and should be in the subctx */
38   PetscInt   data_sz; /* nloc*data_rows*data_cols */
39   PetscInt   data_cell_rows;
40   PetscInt   data_cell_cols;
41   PetscInt   orig_data_cell_rows;
42   PetscInt   orig_data_cell_cols;
43   PetscReal *data;      /* [data_sz] blocked vector of vertex data on fine grid (coordinates/nullspace) */
44   PetscReal *orig_data; /* cache data */
45 
46   struct _PCGAMGOps *ops;
47   char              *gamg_type_name;
48 
49   void *subctx;
50 
51   PetscBool use_sa_esteig;
52   PetscReal emin, emax;
53   PetscBool recompute_esteig;
54   PetscInt  injection_index_size;
55   PetscInt  injection_index[MAT_COARSEN_STRENGTH_INDEX_SIZE];
56 } PC_GAMG;
57 
58 /* hooks create derivied classes */
59 PetscErrorCode PCCreateGAMG_GEO(PC);
60 PetscErrorCode PCCreateGAMG_AGG(PC);
61 PetscErrorCode PCCreateGAMG_Classical(PC);
62 
63 PetscErrorCode PCDestroy_GAMG(PC);
64 
65 /* helper methods */
66 PetscErrorCode PCGAMGGetDataWithGhosts(Mat, PetscInt, PetscReal[], PetscInt *, PetscReal **);
67 
68 enum tag {
69   GAMG_SETUP = 0,
70   GAMG_MESH,
71   GAMG_MATRIX,
72   GAMG_GRAPH,
73   GAMG_COARSEN,
74   GAMG_SQUARE,
75   GAMG_MIS,
76   GAMG_PROL,
77   GAMG_PROLA,
78   GAMG_PROLB,
79   GAMG_OPT,
80   GAMG_OPTSM,
81   GAMG_LEVEL,
82   GAMG_PTAP,
83   GAMG_REDUCE,
84   GAMG_REPART,
85   SET13,
86   SET14,
87   SET15,
88   GAMG_NUM_SET
89 };
90 PETSC_EXTERN PetscLogEvent petsc_gamg_setup_events[GAMG_NUM_SET];
91 PETSC_EXTERN PetscLogEvent petsc_gamg_setup_matmat_events[PETSC_MG_MAXLEVELS][3];
92