xref: /petsc/include/petsc/private/pcgamgimpl.h (revision dced61a5cfeeeda68dfa4ee3e53b34d3cfb8da9f)
1 #if !defined(__GAMG_IMPL)
2 #define __GAMG_IMPL
3 #include <petsc/private/pcimpl.h>
4 #include <petsc/private/pcmgimpl.h>                    /*I "petscksp.h" I*/
5 
6 struct _PCGAMGOps {
7   PetscErrorCode (*graph)(PC, Mat, Mat*);
8   PetscErrorCode (*coarsen)(PC, Mat*, PetscCoarsenData**);
9   PetscErrorCode (*prolongator)(PC, Mat, Mat, PetscCoarsenData*, Mat*);
10   PetscErrorCode (*optprolongator)(PC, Mat, Mat*);
11   PetscErrorCode (*createlevel)(PC, Mat, PetscInt, Mat *, Mat *, PetscMPIInt *, IS *);
12   PetscErrorCode (*createdefaultdata)(PC, Mat); /* for data methods that have a default (SA) */
13   PetscErrorCode (*setfromoptions)(PetscOptions*,PC);
14   PetscErrorCode (*destroy)(PC);
15   PetscErrorCode (*view)(PC,PetscViewer);
16 };
17 
18 /* Private context for the GAMG preconditioner */
19 typedef struct gamg_TAG {
20   PCGAMGType type;
21   PetscInt  Nlevels;
22   PetscInt  setup_count;
23   PetscBool repart;
24   PetscBool reuse_prol;
25   PetscBool use_aggs_in_gasm;
26   PetscInt  min_eq_proc;
27   PetscInt  coarse_eq_limit;
28   PetscReal threshold;      /* common quatity to many AMG methods so keep it up here */
29   PetscInt  current_level; /* stash construction state */
30 
31   /* these 4 are all related to the method data and should be in the subctx */
32   PetscInt  data_sz;      /* nloc*data_rows*data_cols */
33   PetscInt  data_cell_rows;
34   PetscInt  data_cell_cols;
35   PetscInt  orig_data_cell_rows;
36   PetscInt  orig_data_cell_cols;
37   PetscReal *data;          /* [data_sz] blocked vector of vertex data on fine grid (coordinates/nullspace) */
38   PetscReal *orig_data;          /* cache data */
39 
40   struct _PCGAMGOps *ops;
41   char *gamg_type_name;
42 
43   void *subctx;
44 } PC_GAMG;
45 
46 PetscErrorCode PCReset_MG(PC);
47 
48 /* hooks create derivied classes */
49 PetscErrorCode  PCCreateGAMG_GEO(PC);
50 PetscErrorCode  PCCreateGAMG_AGG(PC);
51 PetscErrorCode  PCCreateGAMG_Classical(PC);
52 
53 PetscErrorCode PCDestroy_GAMG(PC);
54 
55 /* helper methods */
56 PetscErrorCode PCGAMGCreateGraph(Mat, Mat*);
57 PetscErrorCode PCGAMGFilterGraph(Mat*, PetscReal, PetscBool);
58 PetscErrorCode PCGAMGGetDataWithGhosts(Mat, PetscInt, PetscReal[],PetscInt*, PetscReal **);
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 PETSC_INTERN PetscLogEvent petsc_gamg_setup_events[NUM_SET];
65 #endif
66 PETSC_INTERN PetscLogEvent PC_GAMGGraph_AGG;
67 PETSC_INTERN PetscLogEvent PC_GAMGGraph_GEO;
68 PETSC_INTERN PetscLogEvent PC_GAMGCoarsen_AGG;
69 PETSC_INTERN PetscLogEvent PC_GAMGCoarsen_GEO;
70 PETSC_INTERN PetscLogEvent PC_GAMGProlongator_AGG;
71 PETSC_INTERN PetscLogEvent PC_GAMGProlongator_GEO;
72 PETSC_INTERN PetscLogEvent PC_GAMGOptProlongator_AGG;
73 #endif
74 
75 typedef struct _GAMGHashTable {
76   PetscInt *table;
77   PetscInt *data;
78   PetscInt size;
79 } GAMGHashTable;
80 
81 
82 PETSC_EXTERN PetscErrorCode GAMGTableCreate(PetscInt, GAMGHashTable*);
83 PETSC_EXTERN PetscErrorCode GAMGTableDestroy(GAMGHashTable*);
84 PETSC_EXTERN PetscErrorCode GAMGTableAdd(GAMGHashTable*,PetscInt,PetscInt);
85 
86 #define GAMG_HASH(key) ((((PetscInt)7)*key)%a_tab->size)
87 #undef __FUNCT__
88 #define __FUNCT__ "GAMGTableFind"
89 PETSC_STATIC_INLINE PetscErrorCode GAMGTableFind(GAMGHashTable *a_tab, PetscInt a_key, PetscInt *a_data)
90 {
91   PetscInt kk,idx;
92 
93   PetscFunctionBegin;
94   if (a_key<0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"Negative key %d.",a_key);
95   for (kk = 0, idx = GAMG_HASH(a_key); kk < a_tab->size; kk++, idx = (idx==(a_tab->size-1)) ? 0 : idx + 1) {
96     if (a_tab->table[idx] == a_key) {
97       *a_data = a_tab->data[idx];
98       break;
99     } else if (a_tab->table[idx] == -1) {
100       /* not here */
101       *a_data = -1;
102       break;
103     }
104   }
105   if (kk==a_tab->size) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"key %d not found in table",a_key);
106   PetscFunctionReturn(0);
107 }
108 
109 #endif
110 
111