4: #include <petscksp.h> 5: #include <petscbt.h> 7: /* special marks for interface graph: they cannot be enums 8: since PCBDDCGRAPH_SPECIAL_MARK ranges from -4 to -max_int */ 9: #define PCBDDCGRAPH_NEUMANN_MARK -1 10: #define PCBDDCGRAPH_DIRICHLET_MARK -2 11: #define PCBDDCGRAPH_LOCAL_PERIODIC_MARK -3 12: #define PCBDDCGRAPH_SPECIAL_MARK -4 14: /* Structure for local graph partitioning */ 15: struct _PCBDDCGraph { 16: PetscBool setupcalled; 17: /* graph information */ 18: ISLocalToGlobalMapping l2gmap; 19: PetscInt nvtxs; 20: PetscInt nvtxs_global; 21: PetscBT touched; 22: PetscInt *count; 23: PetscInt **neighbours_set; 24: PetscInt *subset; 25: PetscInt *which_dof; 26: PetscInt *special_dof; 27: PetscInt custom_minimal_size; 28: PetscBool twodim; 29: PetscBool twodimset; 30: PetscBool has_dirichlet; 31: IS dirdofs; 32: IS dirdofsB; 33: PetscInt commsizelimit; 34: PetscInt maxcount; 35: /* data for connected components */ 36: PetscInt ncc; 37: PetscInt *cptr; 38: PetscInt *queue; 39: PetscBool queue_sorted; 40: /* data for interface subsets */ 41: PetscInt n_subsets; 42: PetscInt *subset_size; 43: PetscInt **subset_idxs; 44: PetscInt *subset_ncc; 45: PetscInt *subset_ref_node; 46: /* data for periodic dofs */ 47: PetscInt *mirrors; 48: PetscInt **mirrors_set; 49: /* placeholders for connectivity relation between dofs */ 50: PetscInt nvtxs_csr; 51: PetscInt *xadj; 52: PetscInt *adjncy; 53: PetscBool freecsr; 54: /* data for local subdomains (if any have been detected) 55: these are not intended to be exposed */ 56: PetscInt n_local_subs; 57: PetscInt *local_subs; 58: /* coordinates (for corner detection) */ 59: PetscBool active_coords; 60: PetscBool cloc; 61: PetscInt cdim,cnloc; 62: PetscReal* coords; 64: }; 65: typedef struct _PCBDDCGraph *PCBDDCGraph; 67: /* Wrap to MatFactor solver in Schur complement mode. Provides 68: - standalone solver for interior variables 69: - forward and backward substitutions for correction solver 70: */ 71: /* It assumes that interior variables are a contiguous set starting from 0 */ 72: struct _PCBDDCReuseSolvers { 73: /* the factored matrix obtained from MatGetFactor(...,solver_package,...) */ 74: Mat F; 75: /* placeholders for the solution and rhs on the whole set of dofs of A (size local_dofs - local_vertices)*/ 76: Vec sol; 77: Vec rhs; 78: /* */ 79: PetscBool has_vertices; 80: /* shell PCs to handle interior/correction solvers */ 81: PC interior_solver; 82: PC correction_solver; 83: IS is_R; 84: /* objects to handle Schur complement solution */ 85: Vec rhs_B; 86: Vec sol_B; 87: IS is_B; 88: VecScatter correction_scatter_B; 89: /* handle benign trick without change of basis on pressures */ 90: PetscInt benign_n; 91: IS *benign_zerodiag_subs; 92: PetscScalar *benign_save_vals; 93: Mat benign_csAIB; 94: Mat benign_AIIm1ones; 95: Vec benign_corr_work; 96: Vec benign_dummy_schur_vec; 97: }; 98: typedef struct _PCBDDCReuseSolvers *PCBDDCReuseSolvers; 100: /* structure to handle Schur complements on subsets */ 101: struct _PCBDDCSubSchurs { 102: /* local Neumann matrix */ 103: Mat A; 104: /* local Schur complement */ 105: Mat S; 106: /* index sets */ 107: IS is_I; 108: IS is_B; 109: /* whether Schur complements are explicitly computed with or not */ 110: char mat_solver_type[64]; 111: PetscBool schur_explicit; 112: /* matrices cointained explicit schur complements cat together */ 113: /* note that AIJ format is used but the values are inserted as in column major ordering */ 114: Mat S_Ej_all; 115: Mat sum_S_Ej_all; 116: Mat sum_S_Ej_inv_all; 117: Mat sum_S_Ej_tilda_all; 118: IS is_Ej_all; 119: IS is_vertices; 120: IS is_dir; 121: /* l2g maps */ 122: ISLocalToGlobalMapping l2gmap; 123: ISLocalToGlobalMapping BtoNmap; 124: /* number of local subproblems */ 125: PetscInt n_subs; 126: /* connected components */ 127: IS* is_subs; 128: PetscBT is_edge; 129: /* mat flags */ 130: PetscBool is_symmetric; 131: PetscBool is_hermitian; 132: PetscBool is_posdef; 133: /* data structure to reuse MatFactor with Schur solver */ 134: PCBDDCReuseSolvers reuse_solver; 135: /* change of variables */ 136: KSP *change; 137: IS *change_primal_sub; 138: PetscBool change_with_qr; 139: /* prefix */ 140: char *prefix; 141: /* */ 142: PetscBool restrict_comm; 143: /* debug */ 144: PetscBool debug; 145: }; 146: typedef struct _PCBDDCSubSchurs *PCBDDCSubSchurs; 148: /* Structure for deluxe scaling */ 149: struct _PCBDDCDeluxeScaling { 150: /* simple scaling on selected dofs (i.e. primal vertices and nodes on interface dirichlet boundaries) */ 151: PetscInt n_simple; 152: PetscInt* idx_simple_B; 153: /* handle deluxe problems */ 154: PetscInt seq_n; 155: PetscScalar *workspace; 156: VecScatter *seq_scctx; 157: Vec *seq_work1; 158: Vec *seq_work2; 159: Mat *seq_mat; 160: Mat *seq_mat_inv_sum; 161: KSP *change; 162: PetscBool change_with_qr; 163: }; 164: typedef struct _PCBDDCDeluxeScaling *PCBDDCDeluxeScaling; 166: /* inexact solvers with nullspace correction */ 167: struct _NullSpaceCorrection_ctx { 168: Mat basis_mat; 169: Mat inv_smat; 170: PC local_pc; 171: Vec *fw; 172: Vec *sw; 173: PetscScalar scale; 174: PetscLogEvent evapply; 175: PetscBool symm; 176: }; 177: typedef struct _NullSpaceCorrection_ctx *NullSpaceCorrection_ctx; 179: /* MatShell context for benign mat mults */ 180: struct _PCBDDCBenignMatMult_ctx { 181: Mat A; 182: PetscInt benign_n; 183: IS *benign_zerodiag_subs; 184: PetscScalar *work; 185: PetscBool apply_left; 186: PetscBool apply_right; 187: PetscBool apply_p0; 188: PetscBool free; 189: }; 190: typedef struct _PCBDDCBenignMatMult_ctx *PCBDDCBenignMatMult_ctx; 192: /* feti-dp mat */ 193: struct _FETIDPMat_ctx { 194: PetscInt n; /* local number of rows */ 195: PetscInt N; /* global number of rows */ 196: PetscInt n_lambda; /* global number of multipliers */ 197: Vec lambda_local; 198: Vec temp_solution_B; 199: Vec temp_solution_D; 200: Mat B_delta; 201: Mat B_Ddelta; 202: PetscBool deluxe_nonred; 203: VecScatter l2g_lambda; 204: PC pc; 205: PetscBool fully_redundant; 206: /* saddle point */ 207: VecScatter l2g_lambda_only; 208: Mat B_BB; 209: Mat B_BI; 210: Mat Bt_BB; 211: Mat Bt_BI; 212: Mat C; 213: VecScatter l2g_p; 214: VecScatter g2g_p; 215: Vec vP; 216: Vec xPg; 217: Vec yPg; 218: Vec rhs_flip; 219: IS pressure; 220: IS lagrange; 221: }; 222: typedef struct _FETIDPMat_ctx *FETIDPMat_ctx; 224: /* feti-dp preconditioner */ 225: struct _FETIDPPC_ctx { 226: Mat S_j; 227: Vec lambda_local; 228: Mat B_Ddelta; 229: VecScatter l2g_lambda; 230: PC pc; 231: /* saddle point */ 232: Vec xPg; 233: Vec yPg; 234: }; 235: typedef struct _FETIDPPC_ctx *FETIDPPC_ctx; 237: struct _BDdelta_DN { 238: Mat BD; 239: KSP kBD; 240: Vec work; 241: }; 242: typedef struct _BDdelta_DN *BDdelta_DN; 244: /* Schur interface preconditioner */ 245: struct _BDDCIPC_ctx { 246: VecScatter g2l; 247: PC bddc; 248: }; 249: typedef struct _BDDCIPC_ctx *BDDCIPC_ctx; 251: #endif