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 use_aggs_in_gasm; 15 PetscInt min_eq_proc; 16 PetscInt coarse_eq_limit; 17 PetscReal threshold; /* common quatity to many AMG methods so keep it up here */ 18 PetscInt verbose; 19 PetscInt emax_id; /* stashing places */ 20 /* these 4 are all related to the method data and should be in the subctx */ 21 PetscInt data_sz; /* nloc*data_rows*data_cols */ 22 PetscInt data_cell_rows; 23 PetscInt data_cell_cols; 24 PetscReal eigtarget[2]; 25 PetscReal *data; /* [data_sz] blocked vector of vertex data on fine grid (coordinates/nullspace) */ 26 PetscErrorCode (*graph)( PC, const Mat, Mat * ); 27 PetscErrorCode (*coarsen)( PC, Mat *, PetscCoarsenData** ); 28 PetscErrorCode (*prolongator)( PC, const Mat, const Mat, PetscCoarsenData *, Mat* ); 29 PetscErrorCode (*optprol)( PC, const Mat, Mat* ); 30 PetscErrorCode (*formkktprol)( PC, const Mat, const Mat, Mat* ); 31 PetscErrorCode (*createdefaultdata)( PC, Mat ); /* for data methods that have a default (SA) */ 32 void *subctx; 33 } PC_GAMG; 34 35 #define GAMGAGG "agg" 36 #define GAMGGEO "geo" 37 38 PetscErrorCode PCSetFromOptions_MG( PC ); 39 PetscErrorCode PCReset_MG( PC ); 40 41 /* hooks create derivied classes */ 42 PetscErrorCode PCCreateGAMG_GEO( PC pc ); 43 PetscErrorCode PCCreateGAMG_AGG( PC pc ); 44 45 PetscErrorCode PCSetFromOptions_GAMG( PC pc ); 46 PetscErrorCode PCDestroy_GAMG(PC pc); 47 48 /* helper methods */ 49 PetscErrorCode PCGAMGCreateGraph( const Mat, Mat * ); 50 PetscErrorCode PCGAMGFilterGraph( Mat *, const PetscReal, const PetscBool, const PetscInt ); 51 PetscErrorCode PCGAMGGetDataWithGhosts( const Mat a_Gmat, const PetscInt a_data_sz, const PetscReal a_data_in[], 52 PetscInt *a_stride, PetscReal **a_data_out ); 53 54 #if defined PETSC_USE_LOG 55 /* #define PETSC_GAMG_USE_LOG */ 56 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}; 57 #if defined PETSC_GAMG_USE_LOG 58 extern PetscLogEvent petsc_gamg_setup_events[NUM_SET]; 59 #endif 60 extern PetscLogEvent PC_GAMGGgraph_AGG; 61 extern PetscLogEvent PC_GAMGGgraph_GEO; 62 extern PetscLogEvent PC_GAMGCoarsen_AGG; 63 extern PetscLogEvent PC_GAMGCoarsen_GEO; 64 extern PetscLogEvent PC_GAMGProlongator_AGG; 65 extern PetscLogEvent PC_GAMGProlongator_GEO; 66 extern PetscLogEvent PC_GAMGOptprol_AGG; 67 extern PetscLogEvent PC_GAMGKKTProl_AGG; 68 #endif 69 70 typedef struct _GAMGHashTable{ 71 PetscInt *table; 72 PetscInt *data; 73 PetscInt size; 74 }GAMGHashTable; 75 76 extern PetscErrorCode GAMGTableCreate( PetscInt a_size, GAMGHashTable *a_tab ); 77 extern PetscErrorCode GAMGTableDestroy( GAMGHashTable * ); 78 extern PetscErrorCode GAMGTableAdd( GAMGHashTable *a_tab, PetscInt a_key, PetscInt a_data ); 79 extern PetscErrorCode GAMGTableFind( GAMGHashTable *a_tab, PetscInt a_key, PetscInt *a_data ); 80 81 #endif 82 83