Actual source code: pcbddcstructsimpl.h

  1: #pragma once

  3: #include <petscksp.h>

  5: /* special marks for interface graph: they cannot be enums
  6:    since PCBDDCGRAPH_SPECIAL_MARK ranges from -4 to -max_int */
  7: #define PCBDDCGRAPH_NEUMANN_MARK        -1
  8: #define PCBDDCGRAPH_DIRICHLET_MARK      -2
  9: #define PCBDDCGRAPH_LOCAL_PERIODIC_MARK -3
 10: #define PCBDDCGRAPH_SPECIAL_MARK        -4

 12: /* Metadata information on node */
 13: typedef struct {
 14:   PetscBool touched;
 15:   PetscInt  subset;
 16:   PetscInt  which_dof;
 17:   PetscInt  special_dof;
 18:   PetscInt  local_sub;
 19:   PetscInt  count;
 20:   PetscInt *neighbours_set;
 21:   PetscBool shared;
 22:   PetscInt  local_groups_count;
 23:   PetscInt *local_groups;
 24: } PCBDDCGraphNode;

 26: /* Data structure for local graph partitioning */
 27: struct _PCBDDCGraph {
 28:   PetscBool setupcalled;
 29:   /* graph information */
 30:   ISLocalToGlobalMapping l2gmap;
 31:   PetscInt               nvtxs;
 32:   PetscInt               nvtxs_global;
 33:   PCBDDCGraphNode       *nodes;
 34:   PetscInt               custom_minimal_size;
 35:   PetscBool              twodim;
 36:   PetscBool              twodimset;
 37:   PetscBool              has_dirichlet;
 38:   PetscBool              multi_element;
 39:   IS                     dirdofs;
 40:   IS                     dirdofsB;
 41:   PetscBool              seq_graph;
 42:   PetscInt               maxcount;
 43:   /* data for connected components */
 44:   PetscInt  ncc;
 45:   PetscInt *cptr;
 46:   PetscInt *queue;
 47:   PetscBool queue_sorted;
 48:   /* data for interface subsets */
 49:   PetscInt   n_subsets;
 50:   PetscInt  *subset_size;
 51:   PetscInt **subset_idxs;
 52:   PetscInt  *subset_ncc;
 53:   PetscInt  *subset_ref_node;
 54:   PetscInt  *gsubset_size;
 55:   PetscInt  *interface_ref_rsize;
 56:   PetscSF    interface_ref_sf;
 57:   PetscSF    interface_subset_sf;
 58:   /* placeholders for connectivity relation between dofs */
 59:   PetscInt  nvtxs_csr;
 60:   PetscInt *xadj;
 61:   PetscInt *adjncy;
 62:   PetscBool freecsr;
 63:   /* data for local subdomains (if any have been detected)
 64:      these are not intended to be exposed */
 65:   PetscInt  n_local_subs;
 66:   PetscInt *local_subs;
 67:   /* coordinates (for corner detection) */
 68:   PetscBool  active_coords;
 69:   PetscBool  cloc;
 70:   PetscInt   cdim, cnloc;
 71:   PetscReal *coords;
 72: };
 73: typedef struct _PCBDDCGraph *PCBDDCGraph;

 75: struct _PCBDDCGraphCandidates {
 76:   PetscInt nfc, nec;
 77:   IS      *Faces, *Edges, Vertices;
 78: };
 79: typedef struct _PCBDDCGraphCandidates *PCBDDCGraphCandidates;

 81: /* Wrap to MatFactor solver in Schur complement mode. Provides
 82:    - standalone solver for interior variables
 83:    - forward and backward substitutions for correction solver
 84: */
 85: /* It assumes that interior variables are a contiguous set starting from 0 */
 86: struct _PCBDDCReuseSolvers {
 87:   /* the factored matrix obtained from MatGetFactor(...,solver_package,...) */
 88:   Mat F;
 89:   /* placeholders for the solution and rhs on the whole set of dofs of A (size local_dofs - local_vertices)*/
 90:   Vec sol;
 91:   Vec rhs;
 92:   /* */
 93:   PetscBool has_vertices;
 94:   /* shell PCs to handle interior/correction solvers */
 95:   PC interior_solver;
 96:   PC correction_solver;
 97:   IS is_R;
 98:   /* objects to handle Schur complement solution */
 99:   Vec        rhs_B;
100:   Vec        sol_B;
101:   IS         is_B;
102:   VecScatter correction_scatter_B;
103:   /* handle benign trick without change of basis on pressures */
104:   PetscInt     benign_n;
105:   IS          *benign_zerodiag_subs;
106:   PetscScalar *benign_save_vals;
107:   Mat          benign_csAIB;
108:   Mat          benign_AIIm1ones;
109:   Vec          benign_corr_work;
110:   Vec          benign_dummy_schur_vec;
111: };
112: typedef struct _PCBDDCReuseSolvers *PCBDDCReuseSolvers;

114: /* structure to handle Schur complements on subsets */
115: struct _PCBDDCSubSchurs {
116:   /* local Neumann matrix */
117:   Mat A;
118:   /* local Schur complement */
119:   Mat S;
120:   /* index sets */
121:   IS is_I;
122:   IS is_B;
123:   /* whether Schur complements are explicitly computed with or not */
124:   PetscBool schur_explicit;
125:   /* BDDC or GDSW */
126:   PetscBool gdsw;
127:   /* matrices contained explicit schur complements cat together */
128:   /* note that AIJ format is used but the values are inserted as in column major ordering */
129:   Mat S_Ej_all;
130:   Mat sum_S_Ej_all;
131:   Mat sum_S_Ej_inv_all;
132:   Mat sum_S_Ej_tilda_all;
133:   IS  is_Ej_all;
134:   IS  is_vertices;
135:   IS  is_dir;
136:   /* l2g maps */
137:   ISLocalToGlobalMapping l2gmap;
138:   ISLocalToGlobalMapping BtoNmap;
139:   /* number of local subproblems */
140:   PetscInt n_subs;
141:   /* connected components */
142:   IS     *is_subs;
143:   PetscBT is_edge;
144:   /* mat factor */
145:   char          mat_solver_type[64];
146:   MatFactorType mat_factor_type;
147:   PetscBool     is_symmetric;
148:   PetscBool     is_hermitian;
149:   PetscBool     is_posdef;
150:   /* data structure to reuse MatFactor with Schur solver */
151:   PCBDDCReuseSolvers reuse_solver;
152:   /* change of variables */
153:   KSP      *change;
154:   IS       *change_primal_sub;
155:   PetscBool change_with_qr;
156:   /* prefix */
157:   char *prefix;
158:   /* */
159:   PetscBool restrict_comm;
160:   /* debug */
161:   PetscBool debug;
162:   /* hook to PCBDDCGraph */
163:   PCBDDCGraph graph;
164: };
165: typedef struct _PCBDDCSubSchurs *PCBDDCSubSchurs;

167: /* Structure for deluxe scaling */
168: struct _PCBDDCDeluxeScaling {
169:   /* simple scaling on selected dofs (i.e. primal vertices and nodes on interface dirichlet boundaries) */
170:   PetscInt  n_simple;
171:   PetscInt *idx_simple_B;
172:   /* handle deluxe problems  */
173:   PetscInt     seq_n;
174:   PetscScalar *workspace;
175:   VecScatter  *seq_scctx;
176:   Vec         *seq_work1;
177:   Vec         *seq_work2;
178:   Mat         *seq_mat;
179:   Mat         *seq_mat_inv_sum;
180:   KSP         *change;
181:   PetscBool    change_with_qr;
182: };
183: typedef struct _PCBDDCDeluxeScaling *PCBDDCDeluxeScaling;

185: /* inexact solvers with nullspace correction */
186: struct _NullSpaceCorrection_ctx {
187:   Mat           basis_mat;
188:   Mat           inv_smat;
189:   PC            local_pc;
190:   Vec          *fw;
191:   Vec          *sw;
192:   PetscScalar   scale;
193:   PetscLogEvent evapply;
194:   PetscBool     symm;
195: };
196: typedef struct _NullSpaceCorrection_ctx *NullSpaceCorrection_ctx;

198: /* MatShell context for benign mat mults */
199: struct _PCBDDCBenignMatMult_ctx {
200:   Mat          A;
201:   PetscInt     benign_n;
202:   IS          *benign_zerodiag_subs;
203:   PetscScalar *work;
204:   PetscBool    apply_left;
205:   PetscBool    apply_right;
206:   PetscBool    apply_p0;
207:   PetscBool    free;
208: };
209: typedef struct _PCBDDCBenignMatMult_ctx *PCBDDCBenignMatMult_ctx;

211: /* feti-dp mat */
212: struct _FETIDPMat_ctx {
213:   PetscInt   n;        /* local number of rows */
214:   PetscInt   N;        /* global number of rows */
215:   PetscInt   n_lambda; /* global number of multipliers */
216:   Vec        lambda_local;
217:   Vec        temp_solution_B;
218:   Vec        temp_solution_D;
219:   Mat        B_delta;
220:   Mat        B_Ddelta;
221:   PetscBool  deluxe_nonred;
222:   VecScatter l2g_lambda;
223:   PC         pc;
224:   PetscBool  fully_redundant;
225:   /* saddle point */
226:   VecScatter l2g_lambda_only;
227:   Mat        B_BB;
228:   Mat        B_BI;
229:   Mat        Bt_BB;
230:   Mat        Bt_BI;
231:   Mat        C;
232:   VecScatter l2g_p;
233:   VecScatter g2g_p;
234:   Vec        vP;
235:   Vec        xPg;
236:   Vec        yPg;
237:   Vec        rhs_flip;
238:   IS         lP_I;
239:   IS         lP_B;
240:   IS         pressure;
241:   IS         lagrange;
242: };
243: typedef struct _FETIDPMat_ctx *FETIDPMat_ctx;

245: /* feti-dp preconditioner */
246: struct _FETIDPPC_ctx {
247:   Mat        S_j;
248:   Vec        lambda_local;
249:   Mat        B_Ddelta;
250:   VecScatter l2g_lambda;
251:   PC         pc;
252:   /* saddle point */
253:   Vec xPg;
254:   Vec yPg;
255: };
256: typedef struct _FETIDPPC_ctx *FETIDPPC_ctx;

258: struct _BDdelta_DN {
259:   Mat BD;
260:   KSP kBD;
261:   Vec work;
262: };
263: typedef struct _BDdelta_DN *BDdelta_DN;

265: /* Schur interface preconditioner */
266: struct _BDDCIPC_ctx {
267:   VecScatter g2l;
268:   PC         bddc;
269: };
270: typedef struct _BDDCIPC_ctx *BDDCIPC_ctx;