Actual source code: pcgamgimpl.h
petsc-3.7.1 2016-05-15
Report Typos and Errors
3: #include <petsc/private/pcimpl.h> 4: #include <petsc/private/pcmgimpl.h> /*I "petscksp.h" I*/ 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)(PetscOptionItems*,PC); 14: PetscErrorCode (*destroy)(PC); 15: PetscErrorCode (*view)(PC,PetscViewer); 16: }; 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 */ 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 */ 40: struct _PCGAMGOps *ops; 41: char *gamg_type_name; 43: PetscRandom random; /* used to generate any random numbers needed by GAMG */ 44: void *subctx; 45: } PC_GAMG; 47: PetscErrorCode PCReset_MG(PC); 49: /* hooks create derivied classes */ 50: PetscErrorCode PCCreateGAMG_GEO(PC); 51: PetscErrorCode PCCreateGAMG_AGG(PC); 52: PetscErrorCode PCCreateGAMG_Classical(PC); 54: PetscErrorCode PCDestroy_GAMG(PC); 56: /* helper methods */ 57: PetscErrorCode PCGAMGCreateGraph(Mat, Mat*); 58: PetscErrorCode PCGAMGFilterGraph(Mat*, PetscReal, PetscBool); 59: PetscErrorCode PCGAMGGetDataWithGhosts(Mat, PetscInt, PetscReal[],PetscInt*, PetscReal **); 61: #if defined PETSC_USE_LOG 62: #define PETSC_GAMG_USE_LOG 63: 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}; 64: #if defined PETSC_GAMG_USE_LOG 65: PETSC_INTERN PetscLogEvent petsc_gamg_setup_events[NUM_SET]; 66: #endif 67: PETSC_INTERN PetscLogEvent PC_GAMGGraph_AGG; 68: PETSC_INTERN PetscLogEvent PC_GAMGGraph_GEO; 69: PETSC_INTERN PetscLogEvent PC_GAMGCoarsen_AGG; 70: PETSC_INTERN PetscLogEvent PC_GAMGCoarsen_GEO; 71: PETSC_INTERN PetscLogEvent PC_GAMGProlongator_AGG; 72: PETSC_INTERN PetscLogEvent PC_GAMGProlongator_GEO; 73: PETSC_INTERN PetscLogEvent PC_GAMGOptProlongator_AGG; 74: #endif 76: typedef struct _GAMGHashTable { 77: PetscInt *table; 78: PetscInt *data; 79: PetscInt size; 80: } GAMGHashTable; 83: PETSC_EXTERN PetscErrorCode GAMGTableCreate(PetscInt, GAMGHashTable*); 84: PETSC_EXTERN PetscErrorCode GAMGTableDestroy(GAMGHashTable*); 85: PETSC_EXTERN PetscErrorCode GAMGTableAdd(GAMGHashTable*,PetscInt,PetscInt); 87: #define GAMG_HASH(key) ((((PetscInt)7)*key)%a_tab->size) 90: PETSC_STATIC_INLINE PetscErrorCode GAMGTableFind(GAMGHashTable *a_tab, PetscInt a_key, PetscInt *a_data) 91: { 92: PetscInt kk,idx; 95: if (a_key<0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"Negative key %d.",a_key); 96: for (kk = 0, idx = GAMG_HASH(a_key); kk < a_tab->size; kk++, idx = (idx==(a_tab->size-1)) ? 0 : idx + 1) { 97: if (a_tab->table[idx] == a_key) { 98: *a_data = a_tab->data[idx]; 99: break; 100: } else if (a_tab->table[idx] == -1) { 101: /* not here */ 102: *a_data = -1; 103: break; 104: } 105: } 106: if (kk==a_tab->size) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"key %d not found in table",a_key); 107: return(0); 108: } 110: #endif