xref: /petsc/src/ksp/pc/impls/gamg/gamg.h (revision 2205254efee3a00a594e5e2a3a70f74dcb40bc03)
1 #if !defined(__GAMG_IMPL)
2 #define __GAMG_IMPL
3 #include <petsc-private/pcimpl.h>   /*I "petscpc.h" I*/
4 #include <../src/ksp/pc/impls/mg/mgimpl.h>                    /*I "petscpcmg.h" I*/
5 #include <../src/mat/impls/aij/seq/aij.h>
6 #include <../src/mat/impls/aij/mpi/mpiaij.h>
7 #include <assert.h>
8 
9 /* Private context for the GAMG preconditioner */
10 typedef struct gamg_TAG {
11   PetscInt  Nlevels;
12   PetscInt  setup_count;
13   PetscBool repart;
14   PetscBool reuse_prol;
15   PetscBool use_aggs_in_gasm;
16   PetscInt  min_eq_proc;
17   PetscInt  coarse_eq_limit;
18   PetscReal threshold;      /* common quatity to many AMG methods so keep it up here */
19   PetscInt  verbose;
20   PetscInt  emax_id;      /* stashing places */
21 
22   /* these 4 are all related to the method data and should be in the subctx */
23   PetscInt  data_sz;      /* nloc*data_rows*data_cols */
24   PetscInt  data_cell_rows;
25   PetscInt  data_cell_cols;
26   PetscInt  orig_data_cell_rows;
27   PetscInt  orig_data_cell_cols;
28   PetscReal eigtarget[2];
29   PetscReal *data;          /* [data_sz] blocked vector of vertex data on fine grid (coordinates/nullspace) */
30   PetscReal *orig_data;          /* cache data */
31 
32   PetscErrorCode (*graph)(PC, const Mat, Mat*);
33   PetscErrorCode (*coarsen)(PC, Mat*, PetscCoarsenData**);
34   PetscErrorCode (*prolongator)(PC, const Mat, const Mat, PetscCoarsenData*, Mat*);
35   PetscErrorCode (*optprol)(PC, const Mat, Mat*);
36   PetscErrorCode (*formkktprol)(PC, const Mat, const Mat, Mat*);
37   PetscErrorCode (*createdefaultdata)(PC, Mat); /* for data methods that have a default (SA) */
38 
39   void *subctx;
40 } PC_GAMG;
41 
42 #define GAMGAGG "agg"
43 #define GAMGGEO "geo"
44 
45 PetscErrorCode PCSetFromOptions_MG(PC);
46 PetscErrorCode PCReset_MG(PC);
47 
48 /* hooks create derivied classes */
49 PetscErrorCode  PCCreateGAMG_GEO(PC pc);
50 PetscErrorCode  PCCreateGAMG_AGG(PC pc);
51 
52 PetscErrorCode PCSetFromOptions_GAMG(PC pc);
53 PetscErrorCode PCDestroy_GAMG(PC pc);
54 
55 /* helper methods */
56 PetscErrorCode PCGAMGCreateGraph(const Mat, Mat*);
57 PetscErrorCode PCGAMGFilterGraph(Mat*, const PetscReal, const PetscBool, const PetscInt);
58 PetscErrorCode PCGAMGGetDataWithGhosts(const Mat a_Gmat, const PetscInt a_data_sz, const PetscReal a_data_in[],PetscInt *a_stride, PetscReal **a_data_out);
59 
60 #if defined PETSC_USE_LOG
61 /* #define PETSC_GAMG_USE_LOG */
62 enum tag {SET1,SET2,GRAPH,GRAPH_MAT,GRAPH_FILTER,GRAPH_SQR,SET4,SET5,SET6,FIND_V,SET7,SET8,SET9,SET10,SET11,SET12,SET13,SET14,SET15,SET16,NUM_SET};
63 #if defined PETSC_GAMG_USE_LOG
64 extern PetscLogEvent petsc_gamg_setup_events[NUM_SET];
65 #endif
66 extern PetscLogEvent PC_GAMGGgraph_AGG;
67 extern PetscLogEvent PC_GAMGGgraph_GEO;
68 extern PetscLogEvent PC_GAMGCoarsen_AGG;
69 extern PetscLogEvent PC_GAMGCoarsen_GEO;
70 extern PetscLogEvent PC_GAMGProlongator_AGG;
71 extern PetscLogEvent PC_GAMGProlongator_GEO;
72 extern PetscLogEvent PC_GAMGOptprol_AGG;
73 extern PetscLogEvent PC_GAMGKKTProl_AGG;
74 #endif
75 
76 typedef struct _GAMGHashTable {
77   PetscInt *table;
78   PetscInt *data;
79   PetscInt size;
80 } GAMGHashTable;
81 
82 extern PetscErrorCode GAMGTableCreate(PetscInt a_size, GAMGHashTable *a_tab);
83 extern PetscErrorCode GAMGTableDestroy(GAMGHashTable*);
84 extern PetscErrorCode GAMGTableAdd(GAMGHashTable *a_tab, PetscInt a_key, PetscInt a_data);
85 extern PetscErrorCode GAMGTableFind(GAMGHashTable *a_tab, PetscInt a_key, PetscInt *a_data);
86 
87 #endif
88 
89