Actual source code: bddc.c

petsc-3.8.4 2018-03-24
Report Typos and Errors
  1: /* TODOLIST

  3:    Solvers
  4:    - Add support for cholesky for coarse solver (similar to local solvers)
  5:    - Propagate ksp prefixes for solvers to mat objects?

  7:    User interface
  8:    - ** DM attached to pc?

 10:    Debugging output
 11:    - * Better management of verbosity levels of debugging output

 13:    Extra
 14:    - *** Is it possible to work with PCBDDCGraph on boundary indices only (less memory consumed)?
 15:    - BDDC with MG framework?

 17:    MATIS related operations contained in BDDC code
 18:    - Provide general case for subassembling

 20: */

 22:  #include <../src/ksp/pc/impls/bddc/bddc.h>
 23:  #include <../src/ksp/pc/impls/bddc/bddcprivate.h>
 24:  #include <petscblaslapack.h>

 26: static PetscBool  cited = PETSC_FALSE;
 27: static const char citation[] =
 28: "@article{ZampiniPCBDDC,\n"
 29: "author = {Stefano Zampini},\n"
 30: "title = {{PCBDDC}: A Class of Robust Dual-Primal Methods in {PETS}c},\n"
 31: "journal = {SIAM Journal on Scientific Computing},\n"
 32: "volume = {38},\n"
 33: "number = {5},\n"
 34: "pages = {S282-S306},\n"
 35: "year = {2016},\n"
 36: "doi = {10.1137/15M1025785},\n"
 37: "URL = {http://dx.doi.org/10.1137/15M1025785},\n"
 38: "eprint = {http://dx.doi.org/10.1137/15M1025785}\n"
 39: "}\n";

 41: /* temporarily declare it */
 42: PetscErrorCode PCApply_BDDC(PC,Vec,Vec);

 44: PetscErrorCode PCSetFromOptions_BDDC(PetscOptionItems *PetscOptionsObject,PC pc)
 45: {
 46:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;

 50:   PetscOptionsHead(PetscOptionsObject,"BDDC options");
 51:   /* Verbose debugging */
 52:   PetscOptionsInt("-pc_bddc_check_level","Verbose output for PCBDDC (intended for debug)","none",pcbddc->dbg_flag,&pcbddc->dbg_flag,NULL);
 53:   /* Approximate solvers */
 54:   PetscOptionsBool("-pc_bddc_dirichlet_approximate","Inform PCBDDC that we are using approximate Dirichlet solvers","none",pcbddc->NullSpace_corr[0],&pcbddc->NullSpace_corr[0],NULL);
 55:   PetscOptionsBool("-pc_bddc_dirichlet_approximate_scale","Inform PCBDDC that we need to scale the Dirichlet solve","none",pcbddc->NullSpace_corr[1],&pcbddc->NullSpace_corr[1],NULL);
 56:   PetscOptionsBool("-pc_bddc_neumann_approximate","Inform PCBDDC that we are using approximate Neumann solvers","none",pcbddc->NullSpace_corr[2],&pcbddc->NullSpace_corr[2],NULL);
 57:   PetscOptionsBool("-pc_bddc_neumann_approximate_scale","Inform PCBDDC that we need to scale the Neumann solve","none",pcbddc->NullSpace_corr[3],&pcbddc->NullSpace_corr[3],NULL);
 58:   /* Primal space customization */
 59:   PetscOptionsBool("-pc_bddc_use_local_mat_graph","Use or not adjacency graph of local mat for interface analysis","none",pcbddc->use_local_adj,&pcbddc->use_local_adj,NULL);
 60:   PetscOptionsInt("-pc_bddc_graph_maxcount","Maximum number of shared subdomains for a connected component","none",pcbddc->graphmaxcount,&pcbddc->graphmaxcount,NULL);
 61:   PetscOptionsBool("-pc_bddc_use_vertices","Use or not corner dofs in coarse space","none",pcbddc->use_vertices,&pcbddc->use_vertices,NULL);
 62:   PetscOptionsBool("-pc_bddc_use_edges","Use or not edge constraints in coarse space","none",pcbddc->use_edges,&pcbddc->use_edges,NULL);
 63:   PetscOptionsBool("-pc_bddc_use_faces","Use or not face constraints in coarse space","none",pcbddc->use_faces,&pcbddc->use_faces,NULL);
 64:   PetscOptionsInt("-pc_bddc_vertex_size","Connected components smaller or equal to vertex size will be considered as primal vertices","none",pcbddc->vertex_size,&pcbddc->vertex_size,NULL);
 65:   PetscOptionsBool("-pc_bddc_use_true_nnsp","Use near null space attached to the matrix without modifications","none",pcbddc->use_nnsp_true,&pcbddc->use_nnsp_true,NULL);
 66:   PetscOptionsBool("-pc_bddc_use_qr_single","Use QR factorization for single constraints on cc (QR is always used when multiple constraints are present)","none",pcbddc->use_qr_single,&pcbddc->use_qr_single,NULL);
 67:   /* Change of basis */
 68:   PetscOptionsBool("-pc_bddc_use_change_of_basis","Use or not internal change of basis on local edge nodes","none",pcbddc->use_change_of_basis,&pcbddc->use_change_of_basis,NULL);
 69:   PetscOptionsBool("-pc_bddc_use_change_on_faces","Use or not internal change of basis on local face nodes","none",pcbddc->use_change_on_faces,&pcbddc->use_change_on_faces,NULL);
 70:   if (!pcbddc->use_change_of_basis) {
 71:     pcbddc->use_change_on_faces = PETSC_FALSE;
 72:   }
 73:   /* Switch between M_2 (default) and M_3 preconditioners (as defined by C. Dohrmann in the ref. article) */
 74:   PetscOptionsBool("-pc_bddc_switch_static","Switch on static condensation ops around the interface preconditioner","none",pcbddc->switch_static,&pcbddc->switch_static,NULL);
 75:   PetscOptionsInt("-pc_bddc_coarse_eqs_per_proc","Number of equations per process for coarse problem redistribution (significant only at the coarsest level)","none",pcbddc->coarse_eqs_per_proc,&pcbddc->coarse_eqs_per_proc,NULL);
 76:   PetscOptionsInt("-pc_bddc_coarsening_ratio","Set coarsening ratio used in multilevel coarsening","none",pcbddc->coarsening_ratio,&pcbddc->coarsening_ratio,NULL);
 77:   PetscOptionsInt("-pc_bddc_levels","Set maximum number of levels for multilevel","none",pcbddc->max_levels,&pcbddc->max_levels,NULL);
 78:   PetscOptionsBool("-pc_bddc_use_coarse_estimates","Use estimated eigenvalues for coarse problem","none",pcbddc->use_coarse_estimates,&pcbddc->use_coarse_estimates,NULL);
 79:   PetscOptionsBool("-pc_bddc_use_deluxe_scaling","Use deluxe scaling for BDDC","none",pcbddc->use_deluxe_scaling,&pcbddc->use_deluxe_scaling,NULL);
 80:   PetscOptionsBool("-pc_bddc_schur_rebuild","Whether or not the interface graph for Schur principal minors has to be rebuilt (i.e. define the interface without any adjacency)","none",pcbddc->sub_schurs_rebuild,&pcbddc->sub_schurs_rebuild,NULL);
 81:   PetscOptionsInt("-pc_bddc_schur_layers","Number of dofs' layers for the computation of principal minors (i.e. -1 uses all dofs)","none",pcbddc->sub_schurs_layers,&pcbddc->sub_schurs_layers,NULL);
 82:   PetscOptionsBool("-pc_bddc_schur_use_useradj","Whether or not the CSR graph specified by the user should be used for computing successive layers (default is to use adj of local mat)","none",pcbddc->sub_schurs_use_useradj,&pcbddc->sub_schurs_use_useradj,NULL);
 83:   PetscOptionsBool("-pc_bddc_schur_exact","Whether or not to use the exact Schur complement instead of the reduced one (which excludes size 1 cc)","none",pcbddc->sub_schurs_exact_schur,&pcbddc->sub_schurs_exact_schur,NULL);
 84:   PetscOptionsBool("-pc_bddc_deluxe_zerorows","Zero rows and columns of deluxe operators associated with primal dofs","none",pcbddc->deluxe_zerorows,&pcbddc->deluxe_zerorows,NULL);
 85:   PetscOptionsBool("-pc_bddc_deluxe_singlemat","Collapse deluxe operators","none",pcbddc->deluxe_singlemat,&pcbddc->deluxe_singlemat,NULL);
 86:   PetscOptionsBool("-pc_bddc_adaptive_userdefined","Use user-defined constraints (should be attached via MatSetNearNullSpace to pmat) in addition to those adaptively generated","none",pcbddc->adaptive_userdefined,&pcbddc->adaptive_userdefined,NULL);
 87:   PetscOptionsReal("-pc_bddc_adaptive_threshold","Threshold to be used for adaptive selection of constraints","none",pcbddc->adaptive_threshold,&pcbddc->adaptive_threshold,NULL);
 88:   PetscOptionsInt("-pc_bddc_adaptive_nmin","Minimum number of constraints per connected components","none",pcbddc->adaptive_nmin,&pcbddc->adaptive_nmin,NULL);
 89:   PetscOptionsInt("-pc_bddc_adaptive_nmax","Maximum number of constraints per connected components","none",pcbddc->adaptive_nmax,&pcbddc->adaptive_nmax,NULL);
 90:   PetscOptionsBool("-pc_bddc_symmetric","Symmetric computation of primal basis functions","none",pcbddc->symmetric_primal,&pcbddc->symmetric_primal,NULL);
 91:   PetscOptionsInt("-pc_bddc_coarse_adj","Number of processors where to map the coarse adjacency list","none",pcbddc->coarse_adj_red,&pcbddc->coarse_adj_red,NULL);
 92:   PetscOptionsBool("-pc_bddc_benign_trick","Apply the benign subspace trick to saddle point problems with discontinuous pressures","none",pcbddc->benign_saddle_point,&pcbddc->benign_saddle_point,NULL);
 93:   PetscOptionsBool("-pc_bddc_benign_change","Compute the pressure change of basis explicitly","none",pcbddc->benign_change_explicit,&pcbddc->benign_change_explicit,NULL);
 94:   PetscOptionsBool("-pc_bddc_benign_compute_correction","Compute the benign correction during PreSolve","none",pcbddc->benign_compute_correction,&pcbddc->benign_compute_correction,NULL);
 95:   PetscOptionsBool("-pc_bddc_nonetflux","Automatic computation of no-net-flux quadrature weights","none",pcbddc->compute_nonetflux,&pcbddc->compute_nonetflux,NULL);
 96:   PetscOptionsBool("-pc_bddc_detect_disconnected","Detects disconnected subdomains","none",pcbddc->detect_disconnected,&pcbddc->detect_disconnected,NULL);
 97:   PetscOptionsBool("-pc_bddc_eliminate_dirichlet","Whether or not we want to eliminate dirichlet dofs during presolve","none",pcbddc->eliminate_dirdofs,&pcbddc->eliminate_dirdofs,NULL);
 98:   PetscOptionsTail();
 99:   return(0);
100: }

102: static PetscErrorCode PCView_BDDC(PC pc,PetscViewer viewer)
103: {
104:   PC_BDDC              *pcbddc = (PC_BDDC*)pc->data;
105:   PC_IS                *pcis = (PC_IS*)pc->data;
106:   PetscErrorCode       ierr;
107:   PetscBool            isascii,isstring;
108:   PetscSubcomm         subcomm;
109:   PetscViewer          subviewer;

112:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
113:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);
114:   /* Nothing printed for the String viewer */
115:   /* ASCII viewer */
116:   if (isascii) {
117:     PetscMPIInt   color,rank,size;
118:     PetscInt64    loc[7],gsum[6],gmax[6],gmin[6],totbenign;
119:     PetscScalar   interface_size;
120:     PetscReal     ratio1=0.,ratio2=0.;
121:     Vec           counter;

123:     if (!pc->setupcalled) {
124:       PetscViewerASCIIPrintf(viewer,"  Partial information available: preconditioner has not been setup yet\n");
125:     }
126:     PetscViewerASCIIPrintf(viewer,"  Use verbose output: %D\n",pcbddc->dbg_flag);
127:     PetscViewerASCIIPrintf(viewer,"  Use user-defined CSR: %D\n",!!pcbddc->mat_graph->nvtxs_csr);
128:     PetscViewerASCIIPrintf(viewer,"  Use local mat graph: %D\n",pcbddc->use_local_adj && !pcbddc->mat_graph->nvtxs_csr);
129:     if (pcbddc->mat_graph->twodim) {
130:       PetscViewerASCIIPrintf(viewer,"  Connectivity graph topological dimension: 2\n");
131:     } else {
132:       PetscViewerASCIIPrintf(viewer,"  Connectivity graph topological dimension: 3\n");
133:     }
134:     if (pcbddc->graphmaxcount != PETSC_MAX_INT) {
135:       PetscViewerASCIIPrintf(viewer,"  Graph max count: %D\n",pcbddc->graphmaxcount);
136:     }
137:     PetscViewerASCIIPrintf(viewer,"  Use vertices: %d (vertex size %d)\n",pcbddc->use_vertices,pcbddc->vertex_size);
138:     PetscViewerASCIIPrintf(viewer,"  Use edges: %d\n",pcbddc->use_edges);
139:     PetscViewerASCIIPrintf(viewer,"  Use faces: %d\n",pcbddc->use_faces);
140:     PetscViewerASCIIPrintf(viewer,"  Use true near null space: %d\n",pcbddc->use_nnsp_true);
141:     PetscViewerASCIIPrintf(viewer,"  Use QR for single constraints on cc: %d\n",pcbddc->use_qr_single);
142:     PetscViewerASCIIPrintf(viewer,"  Use change of basis on local edge nodes: %d\n",pcbddc->use_change_of_basis);
143:     PetscViewerASCIIPrintf(viewer,"  Use change of basis on local face nodes: %d\n",pcbddc->use_change_on_faces);
144:     PetscViewerASCIIPrintf(viewer,"  User defined change of basis matrix: %d\n",!!pcbddc->user_ChangeOfBasisMatrix);
145:     PetscViewerASCIIPrintf(viewer,"  Has change of basis matrix: %d\n",!!pcbddc->ChangeOfBasisMatrix);
146:     PetscViewerASCIIPrintf(viewer,"  Eliminate dirichlet boundary dofs: %d\n",pcbddc->eliminate_dirdofs);
147:     PetscViewerASCIIPrintf(viewer,"  Switch on static condensation ops around the interface preconditioner: %d\n",pcbddc->switch_static);
148:     PetscViewerASCIIPrintf(viewer,"  Use exact dirichlet trick: %d\n",pcbddc->use_exact_dirichlet_trick);
149:     PetscViewerASCIIPrintf(viewer,"  Multilevel max levels: %d\n",pcbddc->max_levels);
150:     PetscViewerASCIIPrintf(viewer,"  Multilevel coarsening ratio: %d\n",pcbddc->coarsening_ratio);
151:     PetscViewerASCIIPrintf(viewer,"  Use estimated eigs for coarse problem: %d\n",pcbddc->use_coarse_estimates);
152:     PetscViewerASCIIPrintf(viewer,"  Use deluxe scaling: %d\n",pcbddc->use_deluxe_scaling);
153:     PetscViewerASCIIPrintf(viewer,"  Use deluxe zerorows: %d\n",pcbddc->deluxe_zerorows);
154:     PetscViewerASCIIPrintf(viewer,"  Use deluxe singlemat: %d\n",pcbddc->deluxe_singlemat);
155:     PetscViewerASCIIPrintf(viewer,"  Rebuild interface graph for Schur principal minors: %d\n",pcbddc->sub_schurs_rebuild);
156:     PetscViewerASCIIPrintf(viewer,"  Number of dofs' layers for the computation of principal minors: %d\n",pcbddc->sub_schurs_layers);
157:     PetscViewerASCIIPrintf(viewer,"  Use user CSR graph to compute successive layers: %d\n",pcbddc->sub_schurs_use_useradj);
158:     PetscViewerASCIIPrintf(viewer,"  Adaptive constraint selection threshold (active %d, userdefined %d): %g\n",pcbddc->adaptive_selection,pcbddc->adaptive_userdefined,pcbddc->adaptive_threshold);
159:     PetscViewerASCIIPrintf(viewer,"  Min constraints / connected component: %d\n",pcbddc->adaptive_nmin);
160:     PetscViewerASCIIPrintf(viewer,"  Max constraints / connected component: %d\n",pcbddc->adaptive_nmax);
161:     PetscViewerASCIIPrintf(viewer,"  Invert exact Schur complement for adaptive selection: %d\n",pcbddc->sub_schurs_exact_schur);
162:     PetscViewerASCIIPrintf(viewer,"  Symmetric computation of primal basis functions: %d\n",pcbddc->symmetric_primal);
163:     PetscViewerASCIIPrintf(viewer,"  Num. Procs. to map coarse adjacency list: %d\n",pcbddc->coarse_adj_red);
164:     PetscViewerASCIIPrintf(viewer,"  Coarse eqs per proc (significant at the coarsest level): %d\n",pcbddc->coarse_eqs_per_proc);
165:     PetscViewerASCIIPrintf(viewer,"  Detect disconnected: %d\n",pcbddc->detect_disconnected);
166:     PetscViewerASCIIPrintf(viewer,"  Benign subspace trick: %d (change explicit %d)\n",pcbddc->benign_saddle_point,pcbddc->benign_change_explicit);
167:     PetscViewerASCIIPrintf(viewer,"  Benign subspace trick is active: %d\n",pcbddc->benign_have_null);
168:     PetscViewerASCIIPrintf(viewer,"  Algebraic computation of no-net-flux %d\n",pcbddc->compute_nonetflux);
169:     if (!pc->setupcalled) return(0);

171:     /* compute interface size */
172:     VecSet(pcis->vec1_B,1.0);
173:     MatCreateVecs(pc->pmat,&counter,0);
174:     VecSet(counter,0.0);
175:     VecScatterBegin(pcis->global_to_B,pcis->vec1_B,counter,INSERT_VALUES,SCATTER_REVERSE);
176:     VecScatterEnd(pcis->global_to_B,pcis->vec1_B,counter,INSERT_VALUES,SCATTER_REVERSE);
177:     VecSum(counter,&interface_size);
178:     VecDestroy(&counter);

180:     /* compute some statistics on the domain decomposition */
181:     gsum[0] = 1;
182:     gsum[1] = gsum[2] = gsum[3] = gsum[4] = gsum[5] = 0;
183:     loc[0]  = !!pcis->n;
184:     loc[1]  = pcis->n - pcis->n_B;
185:     loc[2]  = pcis->n_B;
186:     loc[3]  = pcbddc->local_primal_size;
187:     loc[4]  = pcis->n;
188:     loc[5]  = pcbddc->n_local_subs > 0 ? pcbddc->n_local_subs : (pcis->n ? 1 : 0);
189:     loc[6]  = pcbddc->benign_n;
190:     MPI_Reduce(loc,gsum,6,MPIU_INT64,MPI_SUM,0,PetscObjectComm((PetscObject)pc));
191:     if (!loc[0]) loc[1] = loc[2] = loc[3] = loc[4] = loc[5] = -1;
192:     MPI_Reduce(loc,gmax,6,MPIU_INT64,MPI_MAX,0,PetscObjectComm((PetscObject)pc));
193:     if (!loc[0]) loc[1] = loc[2] = loc[3] = loc[4] = loc[5] = PETSC_MAX_INT;
194:     MPI_Reduce(loc,gmin,6,MPIU_INT64,MPI_MIN,0,PetscObjectComm((PetscObject)pc));
195:     MPI_Reduce(&loc[6],&totbenign,1,MPIU_INT64,MPI_SUM,0,PetscObjectComm((PetscObject)pc));
196:     if (pcbddc->coarse_size) {
197:       ratio1 = pc->pmat->rmap->N/(1.*pcbddc->coarse_size);
198:       ratio2 = PetscRealPart(interface_size)/pcbddc->coarse_size;
199:     }
200:     PetscViewerASCIIPrintf(viewer,"  ********************************** STATISTICS AT LEVEL %d **********************************\n",pcbddc->current_level);
201:     PetscViewerASCIIPrintf(viewer,"  Global dofs sizes: all %d interface %d coarse %d\n",pc->pmat->rmap->N,(PetscInt)PetscRealPart(interface_size),pcbddc->coarse_size);
202:     PetscViewerASCIIPrintf(viewer,"  Coarsening ratios: all/coarse %d interface/coarse %d\n",(PetscInt)ratio1,(PetscInt)ratio2);
203:     PetscViewerASCIIPrintf(viewer,"  Active processes : %d\n",(PetscInt)gsum[0]);
204:     PetscViewerASCIIPrintf(viewer,"  Total subdomains : %d\n",(PetscInt)gsum[5]);
205:     if (pcbddc->benign_have_null) {
206:       PetscViewerASCIIPrintf(viewer,"  Benign subs      : %d\n",(PetscInt)totbenign);
207:     }
208:     PetscViewerASCIIPrintf(viewer,"  Dofs type        :\tMIN\tMAX\tMEAN\n",(PetscInt)gmin[1],(PetscInt)gmax[1],(PetscInt)(gsum[1]/gsum[0]));
209:     PetscViewerASCIIPrintf(viewer,"  Interior  dofs   :\t%d\t%d\t%d\n",(PetscInt)gmin[1],(PetscInt)gmax[1],(PetscInt)(gsum[1]/gsum[0]));
210:     PetscViewerASCIIPrintf(viewer,"  Interface dofs   :\t%d\t%d\t%d\n",(PetscInt)gmin[2],(PetscInt)gmax[2],(PetscInt)(gsum[2]/gsum[0]));
211:     PetscViewerASCIIPrintf(viewer,"  Primal    dofs   :\t%d\t%d\t%d\n",(PetscInt)gmin[3],(PetscInt)gmax[3],(PetscInt)(gsum[3]/gsum[0]));
212:     PetscViewerASCIIPrintf(viewer,"  Local     dofs   :\t%d\t%d\t%d\n",(PetscInt)gmin[4],(PetscInt)gmax[4],(PetscInt)(gsum[4]/gsum[0]));
213:     PetscViewerASCIIPrintf(viewer,"  Local     subs   :\t%d\t%d\n",(PetscInt)gmin[5],(PetscInt)gmax[5]);
214:     PetscViewerASCIIPrintf(viewer,"  ********************************** COARSE PROBLEM DETAILS *********************************\n",pcbddc->current_level);
215:     PetscViewerFlush(viewer);

217:     /* the coarse problem can be handled by a different communicator */
218:     if (pcbddc->coarse_ksp) color = 1;
219:     else color = 0;
220:     MPI_Comm_rank(PetscObjectComm((PetscObject)pc),&rank);
221:     MPI_Comm_size(PetscObjectComm((PetscObject)pc),&size);
222:     PetscSubcommCreate(PetscObjectComm((PetscObject)pc),&subcomm);
223:     PetscSubcommSetNumber(subcomm,PetscMin(size,2));
224:     PetscSubcommSetTypeGeneral(subcomm,color,rank);
225:     PetscViewerGetSubViewer(viewer,PetscSubcommChild(subcomm),&subviewer);
226:     if (color == 1) {
227:       KSPView(pcbddc->coarse_ksp,subviewer);
228:       PetscViewerFlush(subviewer);
229:     }
230:     PetscViewerRestoreSubViewer(viewer,PetscSubcommChild(subcomm),&subviewer);
231:     PetscSubcommDestroy(&subcomm);
232:     PetscViewerFlush(viewer);
233:   }
234:   return(0);
235: }

237: static PetscErrorCode PCBDDCSetDiscreteGradient_BDDC(PC pc, Mat G, PetscInt order, PetscInt field, PetscBool global, PetscBool conforming)
238: {
239:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;

243:   PetscObjectReference((PetscObject)G);
244:   MatDestroy(&pcbddc->discretegradient);
245:   pcbddc->discretegradient = G;
246:   pcbddc->nedorder         = order > 0 ? order : -order;
247:   pcbddc->nedfield         = field;
248:   pcbddc->nedglobal        = global;
249:   pcbddc->conforming       = conforming;
250:   return(0);
251: }

253: /*@
254:  PCBDDCSetDiscreteGradient - Sets the discrete gradient

256:    Collective on PC

258:    Input Parameters:
259: +  pc         - the preconditioning context
260: .  G          - the discrete gradient matrix (should be in AIJ format)
261: .  order      - the order of the Nedelec space (1 for the lowest order)
262: .  field      - the field id of the Nedelec dofs (not used if the fields have not been specified)
263: .  global     - the type of global ordering for the rows of G
264: -  conforming - whether the mesh is conforming or not

266:    Level: advanced

268:    Notes: The discrete gradient matrix G is used to analyze the subdomain edges, and it should not contain any zero entry.
269:           For variable order spaces, the order should be set to zero.
270:           If global is true, the rows of G should be given in global ordering for the whole dofs;
271:           if false, the ordering should be global for the Nedelec field.
272:           In the latter case, it should hold gid[i] < gid[j] iff geid[i] < geid[j], with gid the global orderding for all the dofs
273:           and geid the one for the Nedelec field.

275: .seealso: PCBDDC,PCBDDCSetDofsSplitting(),PCBDDCSetDofsSplittingLocal()
276: @*/
277: PetscErrorCode PCBDDCSetDiscreteGradient(PC pc, Mat G, PetscInt order, PetscInt field, PetscBool global, PetscBool conforming)
278: {

289:   PetscTryMethod(pc,"PCBDDCSetDiscreteGradient_C",(PC,Mat,PetscInt,PetscInt,PetscBool,PetscBool),(pc,G,order,field,global,conforming));
290:   return(0);
291: }

293: static PetscErrorCode PCBDDCSetDivergenceMat_BDDC(PC pc, Mat divudotp, PetscBool trans, IS vl2l)
294: {
295:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;

299:   PetscObjectReference((PetscObject)divudotp);
300:   MatDestroy(&pcbddc->divudotp);
301:   pcbddc->divudotp = divudotp;
302:   pcbddc->divudotp_trans = trans;
303:   pcbddc->compute_nonetflux = PETSC_TRUE;
304:   if (vl2l) {
305:     PetscObjectReference((PetscObject)vl2l);
306:     ISDestroy(&pcbddc->divudotp_vl2l);
307:     pcbddc->divudotp_vl2l = vl2l;
308:   }
309:   return(0);
310: }

312: /*@
313:  PCBDDCSetDivergenceMat - Sets the linear operator representing \int_\Omega \div {\bf u} \cdot p dx

315:    Collective on PC

317:    Input Parameters:
318: +  pc - the preconditioning context
319: .  divudotp - the matrix (must be of type MATIS)
320: .  trans - if trans if false (resp. true), then pressures are in the test (trial) space and velocities are in the trial (test) space.
321: -  vl2l - optional IS describing the local (wrt the local mat in divudotp) to local (wrt the local mat in pc->pmat) map for the velocities

323:    Level: advanced

325:    Notes: This auxiliary matrix is used to compute quadrature weights representing the net-flux across subdomain boundaries

327: .seealso: PCBDDC
328: @*/
329: PetscErrorCode PCBDDCSetDivergenceMat(PC pc, Mat divudotp, PetscBool trans, IS vl2l)
330: {
331:   PetscBool      ismatis;

340:   PetscObjectTypeCompare((PetscObject)divudotp,MATIS,&ismatis);
341:   if (!ismatis) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_WRONG,"Divergence matrix needs to be of type MATIS");
342:   PetscTryMethod(pc,"PCBDDCSetDivergenceMat_C",(PC,Mat,PetscBool,IS),(pc,divudotp,trans,vl2l));
343:   return(0);
344: }

346: static PetscErrorCode PCBDDCSetChangeOfBasisMat_BDDC(PC pc, Mat change, PetscBool interior)
347: {
348:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;

352:   PetscObjectReference((PetscObject)change);
353:   MatDestroy(&pcbddc->user_ChangeOfBasisMatrix);
354:   pcbddc->user_ChangeOfBasisMatrix = change;
355:   pcbddc->change_interior = interior;
356:   return(0);
357: }
358: /*@
359:  PCBDDCSetChangeOfBasisMat - Set user defined change of basis for dofs

361:    Collective on PC

363:    Input Parameters:
364: +  pc - the preconditioning context
365: .  change - the change of basis matrix
366: -  interior - whether or not the change of basis modifies interior dofs

368:    Level: intermediate

370:    Notes:

372: .seealso: PCBDDC
373: @*/
374: PetscErrorCode PCBDDCSetChangeOfBasisMat(PC pc, Mat change, PetscBool interior)
375: {

382:   if (pc->mat) {
383:     PetscInt rows_c,cols_c,rows,cols;
384:     MatGetSize(pc->mat,&rows,&cols);
385:     MatGetSize(change,&rows_c,&cols_c);
386:     if (rows_c != rows) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Invalid number of rows for change of basis matrix! %D != %D",rows_c,rows);
387:     if (cols_c != cols) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Invalid number of columns for change of basis matrix! %D != %D",cols_c,cols);
388:     MatGetLocalSize(pc->mat,&rows,&cols);
389:     MatGetLocalSize(change,&rows_c,&cols_c);
390:     if (rows_c != rows) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Invalid number of local rows for change of basis matrix! %D != %D",rows_c,rows);
391:     if (cols_c != cols) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Invalid number of local columns for change of basis matrix! %D != %D",cols_c,cols);
392:   }
393:   PetscTryMethod(pc,"PCBDDCSetChangeOfBasisMat_C",(PC,Mat,PetscBool),(pc,change,interior));
394:   return(0);
395: }

397: static PetscErrorCode PCBDDCSetPrimalVerticesIS_BDDC(PC pc, IS PrimalVertices)
398: {
399:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
400:   PetscBool      isequal = PETSC_FALSE;

404:   PetscObjectReference((PetscObject)PrimalVertices);
405:   if (pcbddc->user_primal_vertices) {
406:     ISEqual(PrimalVertices,pcbddc->user_primal_vertices,&isequal);
407:   }
408:   ISDestroy(&pcbddc->user_primal_vertices);
409:   ISDestroy(&pcbddc->user_primal_vertices_local);
410:   pcbddc->user_primal_vertices = PrimalVertices;
411:   if (!isequal) pcbddc->recompute_topography = PETSC_TRUE;
412:   return(0);
413: }
414: /*@
415:  PCBDDCSetPrimalVerticesIS - Set additional user defined primal vertices in PCBDDC

417:    Collective

419:    Input Parameters:
420: +  pc - the preconditioning context
421: -  PrimalVertices - index set of primal vertices in global numbering (can be empty)

423:    Level: intermediate

425:    Notes:
426:      Any process can list any global node

428: .seealso: PCBDDC
429: @*/
430: PetscErrorCode PCBDDCSetPrimalVerticesIS(PC pc, IS PrimalVertices)
431: {

438:   PetscTryMethod(pc,"PCBDDCSetPrimalVerticesIS_C",(PC,IS),(pc,PrimalVertices));
439:   return(0);
440: }

442: static PetscErrorCode PCBDDCSetPrimalVerticesLocalIS_BDDC(PC pc, IS PrimalVertices)
443: {
444:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
445:   PetscBool      isequal = PETSC_FALSE;

449:   PetscObjectReference((PetscObject)PrimalVertices);
450:   if (pcbddc->user_primal_vertices_local) {
451:     ISEqual(PrimalVertices,pcbddc->user_primal_vertices_local,&isequal);
452:   }
453:   ISDestroy(&pcbddc->user_primal_vertices);
454:   ISDestroy(&pcbddc->user_primal_vertices_local);
455:   pcbddc->user_primal_vertices_local = PrimalVertices;
456:   if (!isequal) pcbddc->recompute_topography = PETSC_TRUE;
457:   return(0);
458: }
459: /*@
460:  PCBDDCSetPrimalVerticesLocalIS - Set additional user defined primal vertices in PCBDDC

462:    Collective

464:    Input Parameters:
465: +  pc - the preconditioning context
466: -  PrimalVertices - index set of primal vertices in local numbering (can be empty)

468:    Level: intermediate

470:    Notes:

472: .seealso: PCBDDC
473: @*/
474: PetscErrorCode PCBDDCSetPrimalVerticesLocalIS(PC pc, IS PrimalVertices)
475: {

482:   PetscTryMethod(pc,"PCBDDCSetPrimalVerticesLocalIS_C",(PC,IS),(pc,PrimalVertices));
483:   return(0);
484: }

486: static PetscErrorCode PCBDDCSetCoarseningRatio_BDDC(PC pc,PetscInt k)
487: {
488:   PC_BDDC  *pcbddc = (PC_BDDC*)pc->data;

491:   pcbddc->coarsening_ratio = k;
492:   return(0);
493: }

495: /*@
496:  PCBDDCSetCoarseningRatio - Set coarsening ratio used in multilevel

498:    Logically collective on PC

500:    Input Parameters:
501: +  pc - the preconditioning context
502: -  k - coarsening ratio (H/h at the coarser level)

504:    Options Database Keys:
505: .    -pc_bddc_coarsening_ratio

507:    Level: intermediate

509:    Notes:
510:      Approximatively k subdomains at the finer level will be aggregated into a single subdomain at the coarser level

512: .seealso: PCBDDC, PCBDDCSetLevels()
513: @*/
514: PetscErrorCode PCBDDCSetCoarseningRatio(PC pc,PetscInt k)
515: {

521:   PetscTryMethod(pc,"PCBDDCSetCoarseningRatio_C",(PC,PetscInt),(pc,k));
522:   return(0);
523: }

525: /* The following functions (PCBDDCSetUseExactDirichlet PCBDDCSetLevel) are not public */
526: static PetscErrorCode PCBDDCSetUseExactDirichlet_BDDC(PC pc,PetscBool flg)
527: {
528:   PC_BDDC  *pcbddc = (PC_BDDC*)pc->data;

531:   pcbddc->use_exact_dirichlet_trick = flg;
532:   return(0);
533: }

535: PetscErrorCode PCBDDCSetUseExactDirichlet(PC pc,PetscBool flg)
536: {

542:   PetscTryMethod(pc,"PCBDDCSetUseExactDirichlet_C",(PC,PetscBool),(pc,flg));
543:   return(0);
544: }

546: static PetscErrorCode PCBDDCSetLevel_BDDC(PC pc,PetscInt level)
547: {
548:   PC_BDDC  *pcbddc = (PC_BDDC*)pc->data;

551:   pcbddc->current_level = level;
552:   return(0);
553: }

555: PetscErrorCode PCBDDCSetLevel(PC pc,PetscInt level)
556: {

562:   PetscTryMethod(pc,"PCBDDCSetLevel_C",(PC,PetscInt),(pc,level));
563:   return(0);
564: }

566: static PetscErrorCode PCBDDCSetLevels_BDDC(PC pc,PetscInt levels)
567: {
568:   PC_BDDC  *pcbddc = (PC_BDDC*)pc->data;

571:   pcbddc->max_levels = levels;
572:   return(0);
573: }

575: /*@
576:  PCBDDCSetLevels - Sets the maximum number of levels for multilevel

578:    Logically collective on PC

580:    Input Parameters:
581: +  pc - the preconditioning context
582: -  levels - the maximum number of levels (max 9)

584:    Options Database Keys:
585: .    -pc_bddc_levels

587:    Level: intermediate

589:    Notes:
590:      Default value is 0, i.e. traditional one-level BDDC

592: .seealso: PCBDDC, PCBDDCSetCoarseningRatio()
593: @*/
594: PetscErrorCode PCBDDCSetLevels(PC pc,PetscInt levels)
595: {

601:   if (levels > 99) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Maximum number of levels for bddc is 99\n");
602:   PetscTryMethod(pc,"PCBDDCSetLevels_C",(PC,PetscInt),(pc,levels));
603:   return(0);
604: }

606: static PetscErrorCode PCBDDCSetDirichletBoundaries_BDDC(PC pc,IS DirichletBoundaries)
607: {
608:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
609:   PetscBool      isequal = PETSC_FALSE;

613:   PetscObjectReference((PetscObject)DirichletBoundaries);
614:   if (pcbddc->DirichletBoundaries) {
615:     ISEqual(DirichletBoundaries,pcbddc->DirichletBoundaries,&isequal);
616:   }
617:   /* last user setting takes precendence -> destroy any other customization */
618:   ISDestroy(&pcbddc->DirichletBoundariesLocal);
619:   ISDestroy(&pcbddc->DirichletBoundaries);
620:   pcbddc->DirichletBoundaries = DirichletBoundaries;
621:   if (!isequal) pcbddc->recompute_topography = PETSC_TRUE;
622:   return(0);
623: }

625: /*@
626:  PCBDDCSetDirichletBoundaries - Set IS defining Dirichlet boundaries for the global problem.

628:    Collective

630:    Input Parameters:
631: +  pc - the preconditioning context
632: -  DirichletBoundaries - parallel IS defining the Dirichlet boundaries

634:    Level: intermediate

636:    Notes:
637:      Provide the information if you used MatZeroRows/Columns routines. Any process can list any global node

639: .seealso: PCBDDC, PCBDDCSetDirichletBoundariesLocal(), MatZeroRows(), MatZeroRowsColumns()
640: @*/
641: PetscErrorCode PCBDDCSetDirichletBoundaries(PC pc,IS DirichletBoundaries)
642: {

649:   PetscTryMethod(pc,"PCBDDCSetDirichletBoundaries_C",(PC,IS),(pc,DirichletBoundaries));
650:   return(0);
651: }

653: static PetscErrorCode PCBDDCSetDirichletBoundariesLocal_BDDC(PC pc,IS DirichletBoundaries)
654: {
655:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
656:   PetscBool      isequal = PETSC_FALSE;

660:   PetscObjectReference((PetscObject)DirichletBoundaries);
661:   if (pcbddc->DirichletBoundariesLocal) {
662:     ISEqual(DirichletBoundaries,pcbddc->DirichletBoundariesLocal,&isequal);
663:   }
664:   /* last user setting takes precendence -> destroy any other customization */
665:   ISDestroy(&pcbddc->DirichletBoundariesLocal);
666:   ISDestroy(&pcbddc->DirichletBoundaries);
667:   pcbddc->DirichletBoundariesLocal = DirichletBoundaries;
668:   if (!isequal) pcbddc->recompute_topography = PETSC_TRUE;
669:   return(0);
670: }

672: /*@
673:  PCBDDCSetDirichletBoundariesLocal - Set IS defining Dirichlet boundaries for the global problem in local ordering.

675:    Collective

677:    Input Parameters:
678: +  pc - the preconditioning context
679: -  DirichletBoundaries - parallel IS defining the Dirichlet boundaries (in local ordering)

681:    Level: intermediate

683:    Notes:

685: .seealso: PCBDDC, PCBDDCSetDirichletBoundaries(), MatZeroRows(), MatZeroRowsColumns()
686: @*/
687: PetscErrorCode PCBDDCSetDirichletBoundariesLocal(PC pc,IS DirichletBoundaries)
688: {

695:   PetscTryMethod(pc,"PCBDDCSetDirichletBoundariesLocal_C",(PC,IS),(pc,DirichletBoundaries));
696:   return(0);
697: }

699: static PetscErrorCode PCBDDCSetNeumannBoundaries_BDDC(PC pc,IS NeumannBoundaries)
700: {
701:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
702:   PetscBool      isequal = PETSC_FALSE;

706:   PetscObjectReference((PetscObject)NeumannBoundaries);
707:   if (pcbddc->NeumannBoundaries) {
708:     ISEqual(NeumannBoundaries,pcbddc->NeumannBoundaries,&isequal);
709:   }
710:   /* last user setting takes precendence -> destroy any other customization */
711:   ISDestroy(&pcbddc->NeumannBoundariesLocal);
712:   ISDestroy(&pcbddc->NeumannBoundaries);
713:   pcbddc->NeumannBoundaries = NeumannBoundaries;
714:   if (!isequal) pcbddc->recompute_topography = PETSC_TRUE;
715:   return(0);
716: }

718: /*@
719:  PCBDDCSetNeumannBoundaries - Set IS defining Neumann boundaries for the global problem.

721:    Collective

723:    Input Parameters:
724: +  pc - the preconditioning context
725: -  NeumannBoundaries - parallel IS defining the Neumann boundaries

727:    Level: intermediate

729:    Notes:
730:      Any process can list any global node

732: .seealso: PCBDDC, PCBDDCSetNeumannBoundariesLocal()
733: @*/
734: PetscErrorCode PCBDDCSetNeumannBoundaries(PC pc,IS NeumannBoundaries)
735: {

742:   PetscTryMethod(pc,"PCBDDCSetNeumannBoundaries_C",(PC,IS),(pc,NeumannBoundaries));
743:   return(0);
744: }

746: static PetscErrorCode PCBDDCSetNeumannBoundariesLocal_BDDC(PC pc,IS NeumannBoundaries)
747: {
748:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
749:   PetscBool      isequal = PETSC_FALSE;

753:   PetscObjectReference((PetscObject)NeumannBoundaries);
754:   if (pcbddc->NeumannBoundariesLocal) {
755:     ISEqual(NeumannBoundaries,pcbddc->NeumannBoundariesLocal,&isequal);
756:   }
757:   /* last user setting takes precendence -> destroy any other customization */
758:   ISDestroy(&pcbddc->NeumannBoundariesLocal);
759:   ISDestroy(&pcbddc->NeumannBoundaries);
760:   pcbddc->NeumannBoundariesLocal = NeumannBoundaries;
761:   if (!isequal) pcbddc->recompute_topography = PETSC_TRUE;
762:   return(0);
763: }

765: /*@
766:  PCBDDCSetNeumannBoundariesLocal - Set IS defining Neumann boundaries for the global problem in local ordering.

768:    Collective

770:    Input Parameters:
771: +  pc - the preconditioning context
772: -  NeumannBoundaries - parallel IS defining the subdomain part of Neumann boundaries (in local ordering)

774:    Level: intermediate

776:    Notes:

778: .seealso: PCBDDC, PCBDDCSetNeumannBoundaries()
779: @*/
780: PetscErrorCode PCBDDCSetNeumannBoundariesLocal(PC pc,IS NeumannBoundaries)
781: {

788:   PetscTryMethod(pc,"PCBDDCSetNeumannBoundariesLocal_C",(PC,IS),(pc,NeumannBoundaries));
789:   return(0);
790: }

792: static PetscErrorCode PCBDDCGetDirichletBoundaries_BDDC(PC pc,IS *DirichletBoundaries)
793: {
794:   PC_BDDC  *pcbddc = (PC_BDDC*)pc->data;

797:   *DirichletBoundaries = pcbddc->DirichletBoundaries;
798:   return(0);
799: }

801: /*@
802:  PCBDDCGetDirichletBoundaries - Get parallel IS for Dirichlet boundaries

804:    Collective

806:    Input Parameters:
807: .  pc - the preconditioning context

809:    Output Parameters:
810: .  DirichletBoundaries - index set defining the Dirichlet boundaries

812:    Level: intermediate

814:    Notes:
815:      The IS returned (if any) is the same passed in earlier by the user with PCBDDCSetDirichletBoundaries

817: .seealso: PCBDDC
818: @*/
819: PetscErrorCode PCBDDCGetDirichletBoundaries(PC pc,IS *DirichletBoundaries)
820: {

825:   PetscUseMethod(pc,"PCBDDCGetDirichletBoundaries_C",(PC,IS*),(pc,DirichletBoundaries));
826:   return(0);
827: }

829: static PetscErrorCode PCBDDCGetDirichletBoundariesLocal_BDDC(PC pc,IS *DirichletBoundaries)
830: {
831:   PC_BDDC  *pcbddc = (PC_BDDC*)pc->data;

834:   *DirichletBoundaries = pcbddc->DirichletBoundariesLocal;
835:   return(0);
836: }

838: /*@
839:  PCBDDCGetDirichletBoundariesLocal - Get parallel IS for Dirichlet boundaries (in local ordering)

841:    Collective

843:    Input Parameters:
844: .  pc - the preconditioning context

846:    Output Parameters:
847: .  DirichletBoundaries - index set defining the subdomain part of Dirichlet boundaries

849:    Level: intermediate

851:    Notes:
852:      The IS returned could be the same passed in earlier by the user (if provided with PCBDDCSetDirichletBoundariesLocal) or a global-to-local map of the global IS (if provided with PCBDDCSetDirichletBoundaries).
853:           In the latter case, the IS will be available after PCSetUp.

855: .seealso: PCBDDC
856: @*/
857: PetscErrorCode PCBDDCGetDirichletBoundariesLocal(PC pc,IS *DirichletBoundaries)
858: {

863:   PetscUseMethod(pc,"PCBDDCGetDirichletBoundariesLocal_C",(PC,IS*),(pc,DirichletBoundaries));
864:   return(0);
865: }

867: static PetscErrorCode PCBDDCGetNeumannBoundaries_BDDC(PC pc,IS *NeumannBoundaries)
868: {
869:   PC_BDDC  *pcbddc = (PC_BDDC*)pc->data;

872:   *NeumannBoundaries = pcbddc->NeumannBoundaries;
873:   return(0);
874: }

876: /*@
877:  PCBDDCGetNeumannBoundaries - Get parallel IS for Neumann boundaries

879:    Collective

881:    Input Parameters:
882: .  pc - the preconditioning context

884:    Output Parameters:
885: .  NeumannBoundaries - index set defining the Neumann boundaries

887:    Level: intermediate

889:    Notes:
890:      The IS returned (if any) is the same passed in earlier by the user with PCBDDCSetNeumannBoundaries

892: .seealso: PCBDDC
893: @*/
894: PetscErrorCode PCBDDCGetNeumannBoundaries(PC pc,IS *NeumannBoundaries)
895: {

900:   PetscUseMethod(pc,"PCBDDCGetNeumannBoundaries_C",(PC,IS*),(pc,NeumannBoundaries));
901:   return(0);
902: }

904: static PetscErrorCode PCBDDCGetNeumannBoundariesLocal_BDDC(PC pc,IS *NeumannBoundaries)
905: {
906:   PC_BDDC  *pcbddc = (PC_BDDC*)pc->data;

909:   *NeumannBoundaries = pcbddc->NeumannBoundariesLocal;
910:   return(0);
911: }

913: /*@
914:  PCBDDCGetNeumannBoundariesLocal - Get parallel IS for Neumann boundaries (in local ordering)

916:    Collective

918:    Input Parameters:
919: .  pc - the preconditioning context

921:    Output Parameters:
922: .  NeumannBoundaries - index set defining the subdomain part of Neumann boundaries

924:    Level: intermediate

926:    Notes:
927:      The IS returned could be the same passed in earlier by the user (if provided with PCBDDCSetNeumannBoundariesLocal) or a global-to-local map of the global IS (if provided with PCBDDCSetNeumannBoundaries).
928:           In the latter case, the IS will be available after PCSetUp.

930: .seealso: PCBDDC
931: @*/
932: PetscErrorCode PCBDDCGetNeumannBoundariesLocal(PC pc,IS *NeumannBoundaries)
933: {

938:   PetscUseMethod(pc,"PCBDDCGetNeumannBoundariesLocal_C",(PC,IS*),(pc,NeumannBoundaries));
939:   return(0);
940: }

942: static PetscErrorCode PCBDDCSetLocalAdjacencyGraph_BDDC(PC pc, PetscInt nvtxs,const PetscInt xadj[],const PetscInt adjncy[], PetscCopyMode copymode)
943: {
944:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
945:   PCBDDCGraph    mat_graph = pcbddc->mat_graph;
946:   PetscBool      same_data = PETSC_FALSE;

950:   if (!nvtxs) {
951:     if (copymode == PETSC_OWN_POINTER) {
952:       PetscFree(xadj);
953:       PetscFree(adjncy);
954:     }
955:     PCBDDCGraphResetCSR(mat_graph);
956:     return(0);
957:   }
958:   if (mat_graph->nvtxs == nvtxs && mat_graph->freecsr) { /* we own the data */
959:     if (mat_graph->xadj == xadj && mat_graph->adjncy == adjncy) same_data = PETSC_TRUE;
960:     if (!same_data && mat_graph->xadj[nvtxs] == xadj[nvtxs]) {
961:       PetscMemcmp(xadj,mat_graph->xadj,(nvtxs+1)*sizeof(PetscInt),&same_data);
962:       if (same_data) {
963:         PetscMemcmp(adjncy,mat_graph->adjncy,xadj[nvtxs]*sizeof(PetscInt),&same_data);
964:       }
965:     }
966:   }
967:   if (!same_data) {
968:     /* free old CSR */
969:     PCBDDCGraphResetCSR(mat_graph);
970:     /* get CSR into graph structure */
971:     if (copymode == PETSC_COPY_VALUES) {
972:       PetscMalloc1(nvtxs+1,&mat_graph->xadj);
973:       PetscMalloc1(xadj[nvtxs],&mat_graph->adjncy);
974:       PetscMemcpy(mat_graph->xadj,xadj,(nvtxs+1)*sizeof(PetscInt));
975:       PetscMemcpy(mat_graph->adjncy,adjncy,xadj[nvtxs]*sizeof(PetscInt));
976:       mat_graph->freecsr = PETSC_TRUE;
977:     } else if (copymode == PETSC_OWN_POINTER) {
978:       mat_graph->xadj    = (PetscInt*)xadj;
979:       mat_graph->adjncy  = (PetscInt*)adjncy;
980:       mat_graph->freecsr = PETSC_TRUE;
981:     } else if (copymode == PETSC_USE_POINTER) {
982:       mat_graph->xadj    = (PetscInt*)xadj;
983:       mat_graph->adjncy  = (PetscInt*)adjncy;
984:       mat_graph->freecsr = PETSC_FALSE;
985:     } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unsupported copy mode %D",copymode);
986:     mat_graph->nvtxs_csr = nvtxs;
987:     pcbddc->recompute_topography = PETSC_TRUE;
988:   }
989:   return(0);
990: }

992: /*@
993:  PCBDDCSetLocalAdjacencyGraph - Set adjacency structure (CSR graph) of the local degrees of freedom.

995:    Not collective

997:    Input Parameters:
998: +  pc - the preconditioning context.
999: .  nvtxs - number of local vertices of the graph (i.e., the number of local dofs).
1000: .  xadj, adjncy - the connectivity of the dofs in CSR format.
1001: -  copymode - supported modes are PETSC_COPY_VALUES, PETSC_USE_POINTER or PETSC_OWN_POINTER.

1003:    Level: intermediate

1005:    Notes: A dof is considered connected with all local dofs if xadj[dof+1]-xadj[dof] == 1 and adjncy[xadj[dof]] is negative.

1007: .seealso: PCBDDC,PetscCopyMode
1008: @*/
1009: PetscErrorCode PCBDDCSetLocalAdjacencyGraph(PC pc,PetscInt nvtxs,const PetscInt xadj[],const PetscInt adjncy[], PetscCopyMode copymode)
1010: {
1011:   void (*f)(void) = 0;

1016:   if (nvtxs) {
1019:   }
1020:   PetscTryMethod(pc,"PCBDDCSetLocalAdjacencyGraph_C",(PC,PetscInt,const PetscInt[],const PetscInt[],PetscCopyMode),(pc,nvtxs,xadj,adjncy,copymode));
1021:   /* free arrays if PCBDDC is not the PC type */
1022:   PetscObjectQueryFunction((PetscObject)pc,"PCBDDCSetLocalAdjacencyGraph_C",&f);
1023:   if (!f && copymode == PETSC_OWN_POINTER) {
1024:     PetscFree(xadj);
1025:     PetscFree(adjncy);
1026:   }
1027:   return(0);
1028: }

1030: static PetscErrorCode PCBDDCSetDofsSplittingLocal_BDDC(PC pc,PetscInt n_is, IS ISForDofs[])
1031: {
1032:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
1033:   PetscInt       i;
1034:   PetscBool      isequal = PETSC_FALSE;

1038:   if (pcbddc->n_ISForDofsLocal == n_is) {
1039:     for (i=0;i<n_is;i++) {
1040:       PetscBool isequalt;
1041:       ISEqual(ISForDofs[i],pcbddc->ISForDofsLocal[i],&isequalt);
1042:       if (!isequalt) break;
1043:     }
1044:     if (i == n_is) isequal = PETSC_TRUE;
1045:   }
1046:   for (i=0;i<n_is;i++) {
1047:     PetscObjectReference((PetscObject)ISForDofs[i]);
1048:   }
1049:   /* Destroy ISes if they were already set */
1050:   for (i=0;i<pcbddc->n_ISForDofsLocal;i++) {
1051:     ISDestroy(&pcbddc->ISForDofsLocal[i]);
1052:   }
1053:   PetscFree(pcbddc->ISForDofsLocal);
1054:   /* last user setting takes precendence -> destroy any other customization */
1055:   for (i=0;i<pcbddc->n_ISForDofs;i++) {
1056:     ISDestroy(&pcbddc->ISForDofs[i]);
1057:   }
1058:   PetscFree(pcbddc->ISForDofs);
1059:   pcbddc->n_ISForDofs = 0;
1060:   /* allocate space then set */
1061:   if (n_is) {
1062:     PetscMalloc1(n_is,&pcbddc->ISForDofsLocal);
1063:   }
1064:   for (i=0;i<n_is;i++) {
1065:     pcbddc->ISForDofsLocal[i] = ISForDofs[i];
1066:   }
1067:   pcbddc->n_ISForDofsLocal = n_is;
1068:   if (n_is) pcbddc->user_provided_isfordofs = PETSC_TRUE;
1069:   if (!isequal) pcbddc->recompute_topography = PETSC_TRUE;
1070:   return(0);
1071: }

1073: /*@
1074:  PCBDDCSetDofsSplittingLocal - Set index sets defining fields of the local subdomain matrix

1076:    Collective

1078:    Input Parameters:
1079: +  pc - the preconditioning context
1080: .  n_is - number of index sets defining the fields
1081: -  ISForDofs - array of IS describing the fields in local ordering

1083:    Level: intermediate

1085:    Notes:
1086:      n_is should be the same among processes. Not all nodes need to be listed: unlisted nodes will belong to the complement field.

1088: .seealso: PCBDDC
1089: @*/
1090: PetscErrorCode PCBDDCSetDofsSplittingLocal(PC pc,PetscInt n_is, IS ISForDofs[])
1091: {
1092:   PetscInt       i;

1098:   for (i=0;i<n_is;i++) {
1101:   }
1102:   PetscTryMethod(pc,"PCBDDCSetDofsSplittingLocal_C",(PC,PetscInt,IS[]),(pc,n_is,ISForDofs));
1103:   return(0);
1104: }

1106: static PetscErrorCode PCBDDCSetDofsSplitting_BDDC(PC pc,PetscInt n_is, IS ISForDofs[])
1107: {
1108:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
1109:   PetscInt       i;
1110:   PetscBool      isequal = PETSC_FALSE;

1114:   if (pcbddc->n_ISForDofs == n_is) {
1115:     for (i=0;i<n_is;i++) {
1116:       PetscBool isequalt;
1117:       ISEqual(ISForDofs[i],pcbddc->ISForDofs[i],&isequalt);
1118:       if (!isequalt) break;
1119:     }
1120:     if (i == n_is) isequal = PETSC_TRUE;
1121:   }
1122:   for (i=0;i<n_is;i++) {
1123:     PetscObjectReference((PetscObject)ISForDofs[i]);
1124:   }
1125:   /* Destroy ISes if they were already set */
1126:   for (i=0;i<pcbddc->n_ISForDofs;i++) {
1127:     ISDestroy(&pcbddc->ISForDofs[i]);
1128:   }
1129:   PetscFree(pcbddc->ISForDofs);
1130:   /* last user setting takes precendence -> destroy any other customization */
1131:   for (i=0;i<pcbddc->n_ISForDofsLocal;i++) {
1132:     ISDestroy(&pcbddc->ISForDofsLocal[i]);
1133:   }
1134:   PetscFree(pcbddc->ISForDofsLocal);
1135:   pcbddc->n_ISForDofsLocal = 0;
1136:   /* allocate space then set */
1137:   if (n_is) {
1138:     PetscMalloc1(n_is,&pcbddc->ISForDofs);
1139:   }
1140:   for (i=0;i<n_is;i++) {
1141:     pcbddc->ISForDofs[i] = ISForDofs[i];
1142:   }
1143:   pcbddc->n_ISForDofs = n_is;
1144:   if (n_is) pcbddc->user_provided_isfordofs = PETSC_TRUE;
1145:   if (!isequal) pcbddc->recompute_topography = PETSC_TRUE;
1146:   return(0);
1147: }

1149: /*@
1150:  PCBDDCSetDofsSplitting - Set index sets defining fields of the global matrix

1152:    Collective

1154:    Input Parameters:
1155: +  pc - the preconditioning context
1156: .  n_is - number of index sets defining the fields
1157: -  ISForDofs - array of IS describing the fields in global ordering

1159:    Level: intermediate

1161:    Notes:
1162:      Any process can list any global node. Not all nodes need to be listed: unlisted nodes will belong to the complement field.

1164: .seealso: PCBDDC
1165: @*/
1166: PetscErrorCode PCBDDCSetDofsSplitting(PC pc,PetscInt n_is, IS ISForDofs[])
1167: {
1168:   PetscInt       i;

1174:   for (i=0;i<n_is;i++) {
1177:   }
1178:   PetscTryMethod(pc,"PCBDDCSetDofsSplitting_C",(PC,PetscInt,IS[]),(pc,n_is,ISForDofs));
1179:   return(0);
1180: }

1182: /*
1183:    PCPreSolve_BDDC - Changes the right hand side and (if necessary) the initial
1184:                      guess if a transformation of basis approach has been selected.

1186:    Input Parameter:
1187: +  pc - the preconditioner contex

1189:    Application Interface Routine: PCPreSolve()

1191:    Notes:
1192:      The interface routine PCPreSolve() is not usually called directly by
1193:    the user, but instead is called by KSPSolve().
1194: */
1195: static PetscErrorCode PCPreSolve_BDDC(PC pc, KSP ksp, Vec rhs, Vec x)
1196: {
1198:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
1199:   PC_IS          *pcis = (PC_IS*)(pc->data);
1200:   Vec            used_vec;
1201:   PetscBool      save_rhs = PETSC_TRUE, benign_correction_computed;

1204:   /* if we are working with CG, one dirichlet solve can be avoided during Krylov iterations */
1205:   if (ksp) {
1206:     PetscBool iscg, isgroppcg, ispipecg, ispipecgrr;
1207:     PetscObjectTypeCompare((PetscObject)ksp,KSPCG,&iscg);
1208:     PetscObjectTypeCompare((PetscObject)ksp,KSPGROPPCG,&isgroppcg);
1209:     PetscObjectTypeCompare((PetscObject)ksp,KSPPIPECG,&ispipecg);
1210:     PetscObjectTypeCompare((PetscObject)ksp,KSPPIPECGRR,&ispipecgrr);
1211:     if (pcbddc->benign_apply_coarse_only || pcbddc->switch_static || (!iscg && !isgroppcg && !ispipecg && !ispipecgrr)) {
1212:       PCBDDCSetUseExactDirichlet(pc,PETSC_FALSE);
1213:     }
1214:   }
1215:   if (pcbddc->benign_apply_coarse_only || pcbddc->switch_static) {
1216:     PCBDDCSetUseExactDirichlet(pc,PETSC_FALSE);
1217:   }

1219:   /* Creates parallel work vectors used in presolve */
1220:   if (!pcbddc->original_rhs) {
1221:     VecDuplicate(pcis->vec1_global,&pcbddc->original_rhs);
1222:   }
1223:   if (!pcbddc->temp_solution) {
1224:     VecDuplicate(pcis->vec1_global,&pcbddc->temp_solution);
1225:   }

1227:   pcbddc->temp_solution_used = PETSC_FALSE;
1228:   if (x) {
1229:     PetscObjectReference((PetscObject)x);
1230:     used_vec = x;
1231:   } else { /* it can only happen when calling PCBDDCMatFETIDPGetRHS */
1232:     PetscObjectReference((PetscObject)pcbddc->temp_solution);
1233:     used_vec = pcbddc->temp_solution;
1234:     VecSet(used_vec,0.0);
1235:     pcbddc->temp_solution_used = PETSC_TRUE;
1236:     VecCopy(rhs,pcbddc->original_rhs);
1237:     save_rhs = PETSC_FALSE;
1238:     pcbddc->eliminate_dirdofs = PETSC_TRUE;
1239:   }

1241:   /* hack into ksp data structure since PCPreSolve comes earlier than setting to zero the guess in src/ksp/ksp/interface/itfunc.c */
1242:   if (ksp) {
1243:     /* store the flag for the initial guess since it will be restored back during PCPostSolve_BDDC */
1244:     KSPGetInitialGuessNonzero(ksp,&pcbddc->ksp_guess_nonzero);
1245:     if (!pcbddc->ksp_guess_nonzero) {
1246:       VecSet(used_vec,0.0);
1247:     }
1248:   }

1250:   pcbddc->rhs_change = PETSC_FALSE;
1251:   /* Take into account zeroed rows -> change rhs and store solution removed */
1252:   if (rhs && pcbddc->eliminate_dirdofs) {
1253:     IS dirIS = NULL;

1255:     /* DirichletBoundariesLocal may not be consistent among neighbours; gets a dirichlet dofs IS from graph (may be cached) */
1256:     PCBDDCGraphGetDirichletDofs(pcbddc->mat_graph,&dirIS);
1257:     if (dirIS) {
1258:       Mat_IS            *matis = (Mat_IS*)pc->pmat->data;
1259:       PetscInt          dirsize,i,*is_indices;
1260:       PetscScalar       *array_x;
1261:       const PetscScalar *array_diagonal;

1263:       MatGetDiagonal(pc->pmat,pcis->vec1_global);
1264:       VecPointwiseDivide(pcis->vec1_global,rhs,pcis->vec1_global);
1265:       VecScatterBegin(matis->rctx,pcis->vec1_global,pcis->vec2_N,INSERT_VALUES,SCATTER_FORWARD);
1266:       VecScatterEnd(matis->rctx,pcis->vec1_global,pcis->vec2_N,INSERT_VALUES,SCATTER_FORWARD);
1267:       VecScatterBegin(matis->rctx,used_vec,pcis->vec1_N,INSERT_VALUES,SCATTER_FORWARD);
1268:       VecScatterEnd(matis->rctx,used_vec,pcis->vec1_N,INSERT_VALUES,SCATTER_FORWARD);
1269:       ISGetLocalSize(dirIS,&dirsize);
1270:       VecGetArray(pcis->vec1_N,&array_x);
1271:       VecGetArrayRead(pcis->vec2_N,&array_diagonal);
1272:       ISGetIndices(dirIS,(const PetscInt**)&is_indices);
1273:       for (i=0; i<dirsize; i++) array_x[is_indices[i]] = array_diagonal[is_indices[i]];
1274:       ISRestoreIndices(dirIS,(const PetscInt**)&is_indices);
1275:       VecRestoreArrayRead(pcis->vec2_N,&array_diagonal);
1276:       VecRestoreArray(pcis->vec1_N,&array_x);
1277:       VecScatterBegin(matis->rctx,pcis->vec1_N,used_vec,INSERT_VALUES,SCATTER_REVERSE);
1278:       VecScatterEnd(matis->rctx,pcis->vec1_N,used_vec,INSERT_VALUES,SCATTER_REVERSE);
1279:       pcbddc->rhs_change = PETSC_TRUE;
1280:       ISDestroy(&dirIS);
1281:     }
1282:   }

1284:   /* remove the computed solution or the initial guess from the rhs */
1285:   if (pcbddc->rhs_change || (ksp && pcbddc->ksp_guess_nonzero) ) {
1286:     /* save the original rhs */
1287:     if (save_rhs) {
1288:       VecSwap(rhs,pcbddc->original_rhs);
1289:       save_rhs = PETSC_FALSE;
1290:     }
1291:     pcbddc->rhs_change = PETSC_TRUE;
1292:     VecScale(used_vec,-1.0);
1293:     MatMultAdd(pc->mat,used_vec,pcbddc->original_rhs,rhs);
1294:     VecScale(used_vec,-1.0);
1295:     VecCopy(used_vec,pcbddc->temp_solution);
1296:     pcbddc->temp_solution_used = PETSC_TRUE;
1297:     if (ksp) {
1298:       KSPSetInitialGuessNonzero(ksp,PETSC_FALSE);
1299:     }
1300:   }
1301:   VecDestroy(&used_vec);

1303:   /* compute initial vector in benign space if needed
1304:      and remove non-benign solution from the rhs */
1305:   benign_correction_computed = PETSC_FALSE;
1306:   if (rhs && pcbddc->benign_compute_correction && pcbddc->benign_have_null) {
1307:     /* compute u^*_h using ideas similar to those in Xuemin Tu's PhD thesis (see Section 4.8.1)
1308:        Recursively apply BDDC in the multilevel case */
1309:     if (!pcbddc->benign_vec) {
1310:       VecDuplicate(rhs,&pcbddc->benign_vec);
1311:     }
1312:     pcbddc->benign_apply_coarse_only = PETSC_TRUE;
1313:     if (!pcbddc->benign_skip_correction) {
1314:       PCApply_BDDC(pc,rhs,pcbddc->benign_vec);
1315:       benign_correction_computed = PETSC_TRUE;
1316:       if (pcbddc->temp_solution_used) {
1317:         VecAXPY(pcbddc->temp_solution,1.0,pcbddc->benign_vec);
1318:       }
1319:       VecScale(pcbddc->benign_vec,-1.0);
1320:       /* store the original rhs if not done earlier */
1321:       if (save_rhs) {
1322:         VecSwap(rhs,pcbddc->original_rhs);
1323:       }
1324:       if (pcbddc->rhs_change) {
1325:         MatMultAdd(pc->mat,pcbddc->benign_vec,rhs,rhs);
1326:       } else {
1327:         MatMultAdd(pc->mat,pcbddc->benign_vec,pcbddc->original_rhs,rhs);
1328:       }
1329:       pcbddc->rhs_change = PETSC_TRUE;
1330:     }
1331:     pcbddc->benign_apply_coarse_only = PETSC_FALSE;
1332:   }

1334:   /* dbg output */
1335:   if (pcbddc->dbg_flag && benign_correction_computed) {
1336:     Vec v;
1337:     VecDuplicate(pcis->vec1_global,&v);
1338:     MatMultTranspose(pcbddc->ChangeOfBasisMatrix,rhs,v);
1339:     PCBDDCBenignGetOrSetP0(pc,v,PETSC_TRUE);
1340:     PetscViewerASCIIPrintf(pcbddc->dbg_viewer,"LEVEL %D: is the correction benign?\n",pcbddc->current_level);
1341:     PetscScalarView(pcbddc->benign_n,pcbddc->benign_p0,PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)pc)));
1342:     VecDestroy(&v);
1343:   }

1345:   /* set initial guess if using PCG */
1346:   pcbddc->exact_dirichlet_trick_app = PETSC_FALSE;
1347:   if (x && pcbddc->use_exact_dirichlet_trick) {
1348:     VecSet(x,0.0);
1349:     if (pcbddc->ChangeOfBasisMatrix && pcbddc->change_interior) {
1350:       if (benign_correction_computed) { /* we have already saved the changed rhs */
1351:         VecLockPop(pcis->vec1_global);
1352:       } else {
1353:         MatMultTranspose(pcbddc->ChangeOfBasisMatrix,rhs,pcis->vec1_global);
1354:       }
1355:       VecScatterBegin(pcis->global_to_D,pcis->vec1_global,pcis->vec1_D,INSERT_VALUES,SCATTER_FORWARD);
1356:       VecScatterEnd(pcis->global_to_D,pcis->vec1_global,pcis->vec1_D,INSERT_VALUES,SCATTER_FORWARD);
1357:     } else {
1358:       VecScatterBegin(pcis->global_to_D,rhs,pcis->vec1_D,INSERT_VALUES,SCATTER_FORWARD);
1359:       VecScatterEnd(pcis->global_to_D,rhs,pcis->vec1_D,INSERT_VALUES,SCATTER_FORWARD);
1360:     }
1361:     KSPSolve(pcbddc->ksp_D,pcis->vec1_D,pcis->vec2_D);
1362:     if (pcbddc->ChangeOfBasisMatrix && pcbddc->change_interior) {
1363:       VecSet(pcis->vec1_global,0.);
1364:       VecScatterBegin(pcis->global_to_D,pcis->vec2_D,pcis->vec1_global,INSERT_VALUES,SCATTER_REVERSE);
1365:       VecScatterEnd(pcis->global_to_D,pcis->vec2_D,pcis->vec1_global,INSERT_VALUES,SCATTER_REVERSE);
1366:       MatMult(pcbddc->ChangeOfBasisMatrix,pcis->vec1_global,x);
1367:     } else {
1368:       VecScatterBegin(pcis->global_to_D,pcis->vec2_D,x,INSERT_VALUES,SCATTER_REVERSE);
1369:       VecScatterEnd(pcis->global_to_D,pcis->vec2_D,x,INSERT_VALUES,SCATTER_REVERSE);
1370:     }
1371:     if (ksp) {
1372:       KSPSetInitialGuessNonzero(ksp,PETSC_TRUE);
1373:     }
1374:     pcbddc->exact_dirichlet_trick_app = PETSC_TRUE;
1375:   } else if (pcbddc->ChangeOfBasisMatrix && pcbddc->change_interior && benign_correction_computed && pcbddc->use_exact_dirichlet_trick) {
1376:     VecLockPop(pcis->vec1_global);
1377:   }
1378:   return(0);
1379: }

1381: /*
1382:    PCPostSolve_BDDC - Changes the computed solution if a transformation of basis
1383:                      approach has been selected. Also, restores rhs to its original state.

1385:    Input Parameter:
1386: +  pc - the preconditioner contex

1388:    Application Interface Routine: PCPostSolve()

1390:    Notes:
1391:      The interface routine PCPostSolve() is not usually called directly by
1392:      the user, but instead is called by KSPSolve().
1393: */
1394: static PetscErrorCode PCPostSolve_BDDC(PC pc, KSP ksp, Vec rhs, Vec x)
1395: {
1397:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;

1400:   /* add solution removed in presolve */
1401:   if (x && pcbddc->rhs_change) {
1402:     if (pcbddc->temp_solution_used) {
1403:       VecAXPY(x,1.0,pcbddc->temp_solution);
1404:     } else if (pcbddc->benign_compute_correction && pcbddc->benign_vec) {
1405:       VecAXPY(x,-1.0,pcbddc->benign_vec);
1406:     }
1407:     /* restore to original state (not for FETI-DP) */
1408:     if (ksp) pcbddc->temp_solution_used = PETSC_FALSE;
1409:   }

1411:   /* restore rhs to its original state (not needed for FETI-DP) */
1412:   if (rhs && pcbddc->rhs_change) {
1413:     VecSwap(rhs,pcbddc->original_rhs);
1414:     pcbddc->rhs_change = PETSC_FALSE;
1415:   }
1416:   /* restore ksp guess state */
1417:   if (ksp) {
1418:     KSPSetInitialGuessNonzero(ksp,pcbddc->ksp_guess_nonzero);
1419:     /* reset flag for exact dirichlet trick */
1420:     pcbddc->exact_dirichlet_trick_app = PETSC_FALSE;
1421:   }
1422:   return(0);
1423: }

1425: /*
1426:    PCSetUp_BDDC - Prepares for the use of the BDDC preconditioner
1427:                   by setting data structures and options.

1429:    Input Parameter:
1430: +  pc - the preconditioner context

1432:    Application Interface Routine: PCSetUp()

1434:    Notes:
1435:      The interface routine PCSetUp() is not usually called directly by
1436:      the user, but instead is called by PCApply() if necessary.
1437: */
1438: PetscErrorCode PCSetUp_BDDC(PC pc)
1439: {
1440:   PC_BDDC*        pcbddc = (PC_BDDC*)pc->data;
1441:   PCBDDCSubSchurs sub_schurs;
1442:   Mat_IS*         matis;
1443:   MatNullSpace    nearnullspace;
1444:   Mat             lA;
1445:   IS              lP,zerodiag = NULL;
1446:   PetscInt        nrows,ncols;
1447:   PetscBool       computesubschurs;
1448:   PetscBool       computeconstraintsmatrix;
1449:   PetscBool       new_nearnullspace_provided,ismatis;
1450:   PetscErrorCode  ierr;

1453:   PetscObjectTypeCompare((PetscObject)pc->pmat,MATIS,&ismatis);
1454:   if (!ismatis) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_WRONG,"PCBDDC preconditioner requires matrix of type MATIS");
1455:   MatGetSize(pc->pmat,&nrows,&ncols);
1456:   if (nrows != ncols) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"PCBDDC preconditioner requires a square preconditioning matrix");
1457:   matis = (Mat_IS*)pc->pmat->data;
1458:   /* the following lines of code should be replaced by a better logic between PCIS, PCNN, PCBDDC and other future nonoverlapping preconditioners */
1459:   /* For BDDC we need to define a local "Neumann" problem different to that defined in PCISSetup
1460:      Also, BDDC builds its own KSP for the Dirichlet problem */
1461:   if (!pc->setupcalled || pc->flag == DIFFERENT_NONZERO_PATTERN) pcbddc->recompute_topography = PETSC_TRUE;
1462:   if (pcbddc->recompute_topography) {
1463:     pcbddc->graphanalyzed    = PETSC_FALSE;
1464:     computeconstraintsmatrix = PETSC_TRUE;
1465:   } else {
1466:     computeconstraintsmatrix = PETSC_FALSE;
1467:   }

1469:   /* check parameters' compatibility */
1470:   if (!pcbddc->use_deluxe_scaling) pcbddc->deluxe_zerorows = PETSC_FALSE;
1471:   pcbddc->adaptive_selection = (PetscBool)(pcbddc->adaptive_threshold > 0.0);
1472:   pcbddc->adaptive_userdefined = (PetscBool)(pcbddc->adaptive_selection && pcbddc->adaptive_userdefined);
1473:   if (pcbddc->adaptive_selection) pcbddc->use_faces = PETSC_TRUE;

1475:   computesubschurs = (PetscBool)(pcbddc->adaptive_selection || pcbddc->use_deluxe_scaling);
1476:   if (pcbddc->switch_static) {
1477:     PetscBool ismatis;
1478:     PetscObjectTypeCompare((PetscObject)pc->mat,MATIS,&ismatis);
1479:     if (!ismatis) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"When the static switch is one, the iteration matrix should be of type MATIS");
1480:   }

1482:   /* activate all connected components if the netflux has been requested */
1483:   if (pcbddc->compute_nonetflux) {
1484:     pcbddc->use_vertices = PETSC_TRUE;
1485:     pcbddc->use_edges = PETSC_TRUE;
1486:     pcbddc->use_faces = PETSC_TRUE;
1487:   }

1489:   /* Get stdout for dbg */
1490:   if (pcbddc->dbg_flag) {
1491:     if (!pcbddc->dbg_viewer) {
1492:       pcbddc->dbg_viewer = PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)pc));
1493:       PetscViewerASCIIPushSynchronized(pcbddc->dbg_viewer);
1494:     }
1495:     PetscViewerASCIIAddTab(pcbddc->dbg_viewer,2*pcbddc->current_level);
1496:   }

1498:   /* process topology information */
1499:   if (pcbddc->recompute_topography) {
1500:     PCBDDCComputeLocalTopologyInfo(pc);
1501:     /* detect local disconnected subdomains if requested (use matis->A) */
1502:     if (pcbddc->detect_disconnected) {
1503:       IS       primalv;
1504:       PetscInt i;

1506:       for (i=0;i<pcbddc->n_local_subs;i++) {
1507:         ISDestroy(&pcbddc->local_subs[i]);
1508:       }
1509:       PetscFree(pcbddc->local_subs);
1510:       PCBDDCDetectDisconnectedComponents(pc,&pcbddc->n_local_subs,&pcbddc->local_subs,&primalv);
1511:       if (primalv) {
1512:         if (pcbddc->user_primal_vertices_local) {
1513:           IS list[2], newp;

1515:           list[0] = primalv;
1516:           list[1] = pcbddc->user_primal_vertices_local;
1517:           ISConcatenate(PetscObjectComm((PetscObject)pc),2,list,&newp);
1518:           ISDestroy(&list[0]);
1519:           ISDestroy(&list[1]);
1520:           pcbddc->user_primal_vertices_local = newp;
1521:         } else {
1522:           pcbddc->user_primal_vertices_local = primalv;
1523:         }
1524:       }
1525:     }
1526:     if (pcbddc->discretegradient) {
1527:       PCBDDCNedelecSupport(pc);
1528:     }
1529:   }

1531:   /* change basis if requested by the user */
1532:   if (pcbddc->user_ChangeOfBasisMatrix) {
1533:     /* use_change_of_basis flag is used to automatically compute a change of basis from constraints */
1534:     pcbddc->use_change_of_basis = PETSC_FALSE;
1535:     PCBDDCComputeLocalMatrix(pc,pcbddc->user_ChangeOfBasisMatrix);
1536:   } else {
1537:     MatDestroy(&pcbddc->local_mat);
1538:     PetscObjectReference((PetscObject)matis->A);
1539:     pcbddc->local_mat = matis->A;
1540:   }

1542:   /*
1543:      Compute change of basis on local pressures (aka zerodiag dofs) with the benign trick
1544:      This should come earlier then PCISSetUp for extracting the correct subdomain matrices
1545:   */
1546:   PCBDDCBenignShellMat(pc,PETSC_TRUE);
1547:   if (pcbddc->benign_saddle_point) {
1548:     PC_IS* pcis = (PC_IS*)pc->data;

1550:     if (pcbddc->user_ChangeOfBasisMatrix || pcbddc->use_change_of_basis || !computesubschurs) pcbddc->benign_change_explicit = PETSC_TRUE;
1551:     /* detect local saddle point and change the basis in pcbddc->local_mat (TODO: reuse case) */
1552:     PCBDDCBenignDetectSaddlePoint(pc,&zerodiag);
1553:     /* pop B0 mat from local mat */
1554:     PCBDDCBenignPopOrPushB0(pc,PETSC_TRUE);
1555:     /* give pcis a hint to not reuse submatrices during PCISCreate */
1556:     if (pc->flag == SAME_NONZERO_PATTERN && pcis->reusesubmatrices == PETSC_TRUE) {
1557:       if (pcbddc->benign_n && (pcbddc->benign_change_explicit || pcbddc->dbg_flag)) {
1558:         pcis->reusesubmatrices = PETSC_FALSE;
1559:       } else {
1560:         pcis->reusesubmatrices = PETSC_TRUE;
1561:       }
1562:     } else {
1563:       pcis->reusesubmatrices = PETSC_FALSE;
1564:     }
1565:   }

1567:   /* propagate relevant information -> TODO remove*/
1568: #if !defined(PETSC_USE_COMPLEX) /* workaround for reals */
1569:   if (matis->A->symmetric_set) {
1570:     MatSetOption(pcbddc->local_mat,MAT_HERMITIAN,matis->A->symmetric);
1571:   }
1572: #endif
1573:   if (matis->A->symmetric_set) {
1574:     MatSetOption(pcbddc->local_mat,MAT_SYMMETRIC,matis->A->symmetric);
1575:   }
1576:   if (matis->A->spd_set) {
1577:     MatSetOption(pcbddc->local_mat,MAT_SPD,matis->A->spd);
1578:   }

1580:   /* Set up all the "iterative substructuring" common block without computing solvers */
1581:   {
1582:     Mat temp_mat;

1584:     temp_mat = matis->A;
1585:     matis->A = pcbddc->local_mat;
1586:     PCISSetUp(pc,PETSC_FALSE);
1587:     pcbddc->local_mat = matis->A;
1588:     matis->A = temp_mat;
1589:   }

1591:   /* Analyze interface */
1592:   if (!pcbddc->graphanalyzed) {
1593:     PCBDDCAnalyzeInterface(pc);
1594:     computeconstraintsmatrix = PETSC_TRUE;
1595:     if (pcbddc->adaptive_selection && !pcbddc->use_deluxe_scaling && !pcbddc->mat_graph->twodim) {
1596:       SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Cannot compute the adaptive primal space for a problem with 3D edges without deluxe scaling");
1597:     }
1598:     if (pcbddc->compute_nonetflux) {
1599:       MatNullSpace nnfnnsp;

1601:       if (!pcbddc->divudotp) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Missing divudotp operator");
1602:       PCBDDCComputeNoNetFlux(pc->pmat,pcbddc->divudotp,pcbddc->divudotp_trans,pcbddc->divudotp_vl2l,pcbddc->mat_graph,&nnfnnsp);
1603:       /* TODO what if a nearnullspace is already attached? */
1604:       MatSetNearNullSpace(pc->pmat,nnfnnsp);
1605:       MatNullSpaceDestroy(&nnfnnsp);
1606:     }
1607:   }

1609:   /* check existence of a divergence free extension, i.e.
1610:      b(v_I,p_0) = 0 for all v_I (raise error if not).
1611:      Also, check that PCBDDCBenignGetOrSetP0 works */
1612:   if (pcbddc->benign_saddle_point && pcbddc->dbg_flag > 1) {
1613:     PCBDDCBenignCheck(pc,zerodiag);
1614:   }
1615:   ISDestroy(&zerodiag);

1617:   /* Setup local dirichlet solver ksp_D and sub_schurs solvers */
1618:   if (computesubschurs && pcbddc->recompute_topography) {
1619:     PCBDDCInitSubSchurs(pc);
1620:   }
1621:   /* SetUp Scaling operator (scaling matrices could be needed in SubSchursSetUp)*/
1622:   if (!pcbddc->use_deluxe_scaling) {
1623:     PCBDDCScalingSetUp(pc);
1624:   }

1626:   /* finish setup solvers and do adaptive selection of constraints */
1627:   sub_schurs = pcbddc->sub_schurs;
1628:   if (sub_schurs && sub_schurs->schur_explicit) {
1629:     if (computesubschurs) {
1630:       PCBDDCSetUpSubSchurs(pc);
1631:     }
1632:     PCBDDCSetUpLocalSolvers(pc,PETSC_TRUE,PETSC_FALSE);
1633:   } else {
1634:     PCBDDCSetUpLocalSolvers(pc,PETSC_TRUE,PETSC_FALSE);
1635:     if (computesubschurs) {
1636:       PCBDDCSetUpSubSchurs(pc);
1637:     }
1638:   }
1639:   if (pcbddc->adaptive_selection) {
1640:     PCBDDCAdaptiveSelection(pc);
1641:     computeconstraintsmatrix = PETSC_TRUE;
1642:   }

1644:   /* infer if NullSpace object attached to Mat via MatSetNearNullSpace has changed */
1645:   new_nearnullspace_provided = PETSC_FALSE;
1646:   MatGetNearNullSpace(pc->pmat,&nearnullspace);
1647:   if (pcbddc->onearnullspace) { /* already used nearnullspace */
1648:     if (!nearnullspace) { /* near null space attached to mat has been destroyed */
1649:       new_nearnullspace_provided = PETSC_TRUE;
1650:     } else {
1651:       /* determine if the two nullspaces are different (should be lightweight) */
1652:       if (nearnullspace != pcbddc->onearnullspace) {
1653:         new_nearnullspace_provided = PETSC_TRUE;
1654:       } else { /* maybe the user has changed the content of the nearnullspace so check vectors ObjectStateId */
1655:         PetscInt         i;
1656:         const Vec        *nearnullvecs;
1657:         PetscObjectState state;
1658:         PetscInt         nnsp_size;
1659:         MatNullSpaceGetVecs(nearnullspace,NULL,&nnsp_size,&nearnullvecs);
1660:         for (i=0;i<nnsp_size;i++) {
1661:           PetscObjectStateGet((PetscObject)nearnullvecs[i],&state);
1662:           if (pcbddc->onearnullvecs_state[i] != state) {
1663:             new_nearnullspace_provided = PETSC_TRUE;
1664:             break;
1665:           }
1666:         }
1667:       }
1668:     }
1669:   } else {
1670:     if (!nearnullspace) { /* both nearnullspaces are null */
1671:       new_nearnullspace_provided = PETSC_FALSE;
1672:     } else { /* nearnullspace attached later */
1673:       new_nearnullspace_provided = PETSC_TRUE;
1674:     }
1675:   }

1677:   /* Setup constraints and related work vectors */
1678:   /* reset primal space flags */
1679:   pcbddc->new_primal_space = PETSC_FALSE;
1680:   pcbddc->new_primal_space_local = PETSC_FALSE;
1681:   if (computeconstraintsmatrix || new_nearnullspace_provided) {
1682:     /* It also sets the primal space flags */
1683:     PCBDDCConstraintsSetUp(pc);
1684:   }
1685:   /* Allocate needed local vectors (which depends on quantities defined during ConstraintsSetUp) */
1686:   PCBDDCSetUpLocalWorkVectors(pc);

1688:   if (pcbddc->use_change_of_basis) {
1689:     PC_IS *pcis = (PC_IS*)(pc->data);

1691:     PCBDDCComputeLocalMatrix(pc,pcbddc->ChangeOfBasisMatrix);
1692:     if (pcbddc->benign_change) {
1693:       MatDestroy(&pcbddc->benign_B0);
1694:       /* pop B0 from pcbddc->local_mat */
1695:       PCBDDCBenignPopOrPushB0(pc,PETSC_TRUE);
1696:     }
1697:     /* get submatrices */
1698:     MatDestroy(&pcis->A_IB);
1699:     MatDestroy(&pcis->A_BI);
1700:     MatDestroy(&pcis->A_BB);
1701:     MatCreateSubMatrix(pcbddc->local_mat,pcis->is_B_local,pcis->is_B_local,MAT_INITIAL_MATRIX,&pcis->A_BB);
1702:     MatCreateSubMatrix(pcbddc->local_mat,pcis->is_I_local,pcis->is_B_local,MAT_INITIAL_MATRIX,&pcis->A_IB);
1703:     MatCreateSubMatrix(pcbddc->local_mat,pcis->is_B_local,pcis->is_I_local,MAT_INITIAL_MATRIX,&pcis->A_BI);
1704:     /* set flag in pcis to not reuse submatrices during PCISCreate */
1705:     pcis->reusesubmatrices = PETSC_FALSE;
1706:   } else if (!pcbddc->user_ChangeOfBasisMatrix && !pcbddc->benign_change) {
1707:     MatDestroy(&pcbddc->local_mat);
1708:     PetscObjectReference((PetscObject)matis->A);
1709:     pcbddc->local_mat = matis->A;
1710:   }

1712:   /* interface pressure block row for B_C */
1713:   PetscObjectQuery((PetscObject)pc,"__KSPFETIDP_lP" ,(PetscObject*)&lP);
1714:   PetscObjectQuery((PetscObject)pc,"__KSPFETIDP_lA" ,(PetscObject*)&lA);
1715:   if (lA && lP) {
1716:     PC_IS*    pcis = (PC_IS*)pc->data;
1717:     Mat       B_BI,B_BB,Bt_BI,Bt_BB;
1718:     PetscBool issym;
1719:     MatIsSymmetric(lA,PETSC_SMALL,&issym);
1720:     if (issym) {
1721:       MatCreateSubMatrix(lA,lP,pcis->is_I_local,MAT_INITIAL_MATRIX,&B_BI);
1722:       MatCreateSubMatrix(lA,lP,pcis->is_B_local,MAT_INITIAL_MATRIX,&B_BB);
1723:       MatCreateTranspose(B_BI,&Bt_BI);
1724:       MatCreateTranspose(B_BB,&Bt_BB);
1725:     } else {
1726:       MatCreateSubMatrix(lA,lP,pcis->is_I_local,MAT_INITIAL_MATRIX,&B_BI);
1727:       MatCreateSubMatrix(lA,lP,pcis->is_B_local,MAT_INITIAL_MATRIX,&B_BB);
1728:       MatCreateSubMatrix(lA,pcis->is_I_local,lP,MAT_INITIAL_MATRIX,&Bt_BI);
1729:       MatCreateSubMatrix(lA,pcis->is_B_local,lP,MAT_INITIAL_MATRIX,&Bt_BB);
1730:     }
1731:     PetscObjectCompose((PetscObject)pc,"__KSPFETIDP_B_BI",(PetscObject)B_BI);
1732:     PetscObjectCompose((PetscObject)pc,"__KSPFETIDP_B_BB",(PetscObject)B_BB);
1733:     PetscObjectCompose((PetscObject)pc,"__KSPFETIDP_Bt_BI",(PetscObject)Bt_BI);
1734:     PetscObjectCompose((PetscObject)pc,"__KSPFETIDP_Bt_BB",(PetscObject)Bt_BB);
1735:     MatDestroy(&B_BI);
1736:     MatDestroy(&B_BB);
1737:     MatDestroy(&Bt_BI);
1738:     MatDestroy(&Bt_BB);
1739:   }

1741:   /* SetUp coarse and local Neumann solvers */
1742:   PCBDDCSetUpSolvers(pc);
1743:   /* SetUp Scaling operator */
1744:   if (pcbddc->use_deluxe_scaling) {
1745:     PCBDDCScalingSetUp(pc);
1746:   }

1748:   /* mark topography as done */
1749:   pcbddc->recompute_topography = PETSC_FALSE;

1751:   /* wrap pcis->A_IB and pcis->A_BI if we did not change explicitly the variables on the pressures */
1752:   PCBDDCBenignShellMat(pc,PETSC_FALSE);

1754:   if (pcbddc->dbg_flag) {
1755:     PetscViewerASCIISubtractTab(pcbddc->dbg_viewer,2*pcbddc->current_level);
1756:   }
1757:   return(0);
1758: }

1760: /*
1761:    PCApply_BDDC - Applies the BDDC operator to a vector.

1763:    Input Parameters:
1764: +  pc - the preconditioner context
1765: -  r - input vector (global)

1767:    Output Parameter:
1768: .  z - output vector (global)

1770:    Application Interface Routine: PCApply()
1771:  */
1772: PetscErrorCode PCApply_BDDC(PC pc,Vec r,Vec z)
1773: {
1774:   PC_IS             *pcis = (PC_IS*)(pc->data);
1775:   PC_BDDC           *pcbddc = (PC_BDDC*)(pc->data);
1776:   PetscInt          n_B = pcis->n_B, n_D = pcis->n - n_B;
1777:   PetscErrorCode    ierr;
1778:   const PetscScalar one = 1.0;
1779:   const PetscScalar m_one = -1.0;
1780:   const PetscScalar zero = 0.0;

1782: /* This code is similar to that provided in nn.c for PCNN
1783:    NN interface preconditioner changed to BDDC
1784:    Added support for M_3 preconditioner in the reference article (code is active if pcbddc->switch_static == PETSC_TRUE) */

1787:   PetscCitationsRegister(citation,&cited);
1788:   if (pcbddc->ChangeOfBasisMatrix) {
1789:     Vec swap;

1791:     MatMultTranspose(pcbddc->ChangeOfBasisMatrix,r,pcbddc->work_change);
1792:     swap = pcbddc->work_change;
1793:     pcbddc->work_change = r;
1794:     r = swap;
1795:     /* save rhs so that we don't need to apply the change of basis for the exact dirichlet trick in PreSolve */
1796:     if (pcbddc->benign_apply_coarse_only && pcbddc->use_exact_dirichlet_trick && pcbddc->change_interior) {
1797:       VecCopy(r,pcis->vec1_global);
1798:       VecLockPush(pcis->vec1_global);
1799:     }
1800:   }
1801:   if (pcbddc->benign_have_null) { /* get p0 from r */
1802:     PCBDDCBenignGetOrSetP0(pc,r,PETSC_TRUE);
1803:   }
1804:   if (!pcbddc->exact_dirichlet_trick_app && !pcbddc->benign_apply_coarse_only) {
1805:     VecCopy(r,z);
1806:     /* First Dirichlet solve */
1807:     VecScatterBegin(pcis->global_to_D,r,pcis->vec1_D,INSERT_VALUES,SCATTER_FORWARD);
1808:     VecScatterEnd(pcis->global_to_D,r,pcis->vec1_D,INSERT_VALUES,SCATTER_FORWARD);
1809:     /*
1810:       Assembling right hand side for BDDC operator
1811:       - pcis->vec1_D for the Dirichlet part (if needed, i.e. pcbddc->switch_static == PETSC_TRUE)
1812:       - pcis->vec1_B the interface part of the global vector z
1813:     */
1814:     if (n_D) {
1815:       KSPSolve(pcbddc->ksp_D,pcis->vec1_D,pcis->vec2_D);
1816:       VecScale(pcis->vec2_D,m_one);
1817:       if (pcbddc->switch_static) {
1818:         Mat_IS *matis = (Mat_IS*)(pc->mat->data);

1820:         VecSet(pcis->vec1_N,0.);
1821:         VecScatterBegin(pcis->N_to_D,pcis->vec2_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1822:         VecScatterEnd(pcis->N_to_D,pcis->vec2_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1823:         if (!pcbddc->switch_static_change) {
1824:           MatMult(matis->A,pcis->vec1_N,pcis->vec2_N);
1825:         } else {
1826:           MatMult(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1827:           MatMult(matis->A,pcis->vec2_N,pcis->vec1_N);
1828:           MatMultTranspose(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1829:         }
1830:         VecScatterBegin(pcis->N_to_D,pcis->vec2_N,pcis->vec1_D,ADD_VALUES,SCATTER_FORWARD);
1831:         VecScatterEnd(pcis->N_to_D,pcis->vec2_N,pcis->vec1_D,ADD_VALUES,SCATTER_FORWARD);
1832:         VecScatterBegin(pcis->N_to_B,pcis->vec2_N,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1833:         VecScatterEnd(pcis->N_to_B,pcis->vec2_N,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1834:       } else {
1835:         MatMult(pcis->A_BI,pcis->vec2_D,pcis->vec1_B);
1836:       }
1837:     } else {
1838:       VecSet(pcis->vec1_B,zero);
1839:     }
1840:     VecScatterBegin(pcis->global_to_B,pcis->vec1_B,z,ADD_VALUES,SCATTER_REVERSE);
1841:     VecScatterEnd(pcis->global_to_B,pcis->vec1_B,z,ADD_VALUES,SCATTER_REVERSE);
1842:     PCBDDCScalingRestriction(pc,z,pcis->vec1_B);
1843:   } else {
1844:     if (!pcbddc->benign_apply_coarse_only) {
1845:       PCBDDCScalingRestriction(pc,r,pcis->vec1_B);
1846:     }
1847:   }

1849:   /* Apply interface preconditioner
1850:      input/output vecs: pcis->vec1_B and pcis->vec1_D */
1851:   PCBDDCApplyInterfacePreconditioner(pc,PETSC_FALSE);

1853:   /* Apply transpose of partition of unity operator */
1854:   PCBDDCScalingExtension(pc,pcis->vec1_B,z);

1856:   /* Second Dirichlet solve and assembling of output */
1857:   VecScatterBegin(pcis->global_to_B,z,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1858:   VecScatterEnd(pcis->global_to_B,z,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1859:   if (n_B) {
1860:     if (pcbddc->switch_static) {
1861:       Mat_IS *matis = (Mat_IS*)(pc->mat->data);

1863:       VecScatterBegin(pcis->N_to_D,pcis->vec1_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1864:       VecScatterEnd(pcis->N_to_D,pcis->vec1_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1865:       VecScatterBegin(pcis->N_to_B,pcis->vec1_B,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1866:       VecScatterEnd(pcis->N_to_B,pcis->vec1_B,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1867:       if (!pcbddc->switch_static_change) {
1868:         MatMult(matis->A,pcis->vec1_N,pcis->vec2_N);
1869:       } else {
1870:         MatMult(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1871:         MatMult(matis->A,pcis->vec2_N,pcis->vec1_N);
1872:         MatMultTranspose(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1873:       }
1874:       VecScatterBegin(pcis->N_to_D,pcis->vec2_N,pcis->vec3_D,INSERT_VALUES,SCATTER_FORWARD);
1875:       VecScatterEnd(pcis->N_to_D,pcis->vec2_N,pcis->vec3_D,INSERT_VALUES,SCATTER_FORWARD);
1876:     } else {
1877:       MatMult(pcis->A_IB,pcis->vec1_B,pcis->vec3_D);
1878:     }
1879:   } else if (pcbddc->switch_static) { /* n_B is zero */
1880:     Mat_IS *matis = (Mat_IS*)(pc->mat->data);

1882:     if (!pcbddc->switch_static_change) {
1883:       MatMult(matis->A,pcis->vec1_D,pcis->vec3_D);
1884:     } else {
1885:       MatMult(pcbddc->switch_static_change,pcis->vec1_D,pcis->vec1_N);
1886:       MatMult(matis->A,pcis->vec1_N,pcis->vec2_N);
1887:       MatMultTranspose(pcbddc->switch_static_change,pcis->vec2_N,pcis->vec3_D);
1888:     }
1889:   }
1890:   KSPSolve(pcbddc->ksp_D,pcis->vec3_D,pcis->vec4_D);

1892:   if (!pcbddc->exact_dirichlet_trick_app && !pcbddc->benign_apply_coarse_only) {
1893:     if (pcbddc->switch_static) {
1894:       VecAXPBYPCZ(pcis->vec2_D,m_one,one,m_one,pcis->vec4_D,pcis->vec1_D);
1895:     } else {
1896:       VecAXPBY(pcis->vec2_D,m_one,m_one,pcis->vec4_D);
1897:     }
1898:     VecScatterBegin(pcis->global_to_D,pcis->vec2_D,z,INSERT_VALUES,SCATTER_REVERSE);
1899:     VecScatterEnd(pcis->global_to_D,pcis->vec2_D,z,INSERT_VALUES,SCATTER_REVERSE);
1900:   } else {
1901:     if (pcbddc->switch_static) {
1902:       VecAXPBY(pcis->vec4_D,one,m_one,pcis->vec1_D);
1903:     } else {
1904:       VecScale(pcis->vec4_D,m_one);
1905:     }
1906:     VecScatterBegin(pcis->global_to_D,pcis->vec4_D,z,INSERT_VALUES,SCATTER_REVERSE);
1907:     VecScatterEnd(pcis->global_to_D,pcis->vec4_D,z,INSERT_VALUES,SCATTER_REVERSE);
1908:   }
1909:   if (pcbddc->benign_have_null) { /* set p0 (computed in PCBDDCApplyInterface) */
1910:     if (pcbddc->benign_apply_coarse_only) {
1911:       PetscMemzero(pcbddc->benign_p0,pcbddc->benign_n*sizeof(PetscScalar));
1912:     }
1913:     PCBDDCBenignGetOrSetP0(pc,z,PETSC_FALSE);
1914:   }

1916:   if (pcbddc->ChangeOfBasisMatrix) {
1917:     pcbddc->work_change = r;
1918:     VecCopy(z,pcbddc->work_change);
1919:     MatMult(pcbddc->ChangeOfBasisMatrix,pcbddc->work_change,z);
1920:   }
1921:   return(0);
1922: }

1924: /*
1925:    PCApplyTranspose_BDDC - Applies the transpose of the BDDC operator to a vector.

1927:    Input Parameters:
1928: +  pc - the preconditioner context
1929: -  r - input vector (global)

1931:    Output Parameter:
1932: .  z - output vector (global)

1934:    Application Interface Routine: PCApplyTranspose()
1935:  */
1936: PetscErrorCode PCApplyTranspose_BDDC(PC pc,Vec r,Vec z)
1937: {
1938:   PC_IS             *pcis = (PC_IS*)(pc->data);
1939:   PC_BDDC           *pcbddc = (PC_BDDC*)(pc->data);
1940:   PetscInt          n_B = pcis->n_B, n_D = pcis->n - n_B;
1941:   PetscErrorCode    ierr;
1942:   const PetscScalar one = 1.0;
1943:   const PetscScalar m_one = -1.0;
1944:   const PetscScalar zero = 0.0;

1947:   PetscCitationsRegister(citation,&cited);
1948:   if (pcbddc->ChangeOfBasisMatrix) {
1949:     Vec swap;

1951:     MatMultTranspose(pcbddc->ChangeOfBasisMatrix,r,pcbddc->work_change);
1952:     swap = pcbddc->work_change;
1953:     pcbddc->work_change = r;
1954:     r = swap;
1955:     /* save rhs so that we don't need to apply the change of basis for the exact dirichlet trick in PreSolve */
1956:     if (pcbddc->benign_apply_coarse_only && pcbddc->exact_dirichlet_trick_app && pcbddc->change_interior) {
1957:       VecCopy(r,pcis->vec1_global);
1958:       VecLockPush(pcis->vec1_global);
1959:     }
1960:   }
1961:   if (pcbddc->benign_have_null) { /* get p0 from r */
1962:     PCBDDCBenignGetOrSetP0(pc,r,PETSC_TRUE);
1963:   }
1964:   if (!pcbddc->exact_dirichlet_trick_app && !pcbddc->benign_apply_coarse_only) {
1965:     VecCopy(r,z);
1966:     /* First Dirichlet solve */
1967:     VecScatterBegin(pcis->global_to_D,r,pcis->vec1_D,INSERT_VALUES,SCATTER_FORWARD);
1968:     VecScatterEnd(pcis->global_to_D,r,pcis->vec1_D,INSERT_VALUES,SCATTER_FORWARD);
1969:     /*
1970:       Assembling right hand side for BDDC operator
1971:       - pcis->vec1_D for the Dirichlet part (if needed, i.e. pcbddc->switch_static == PETSC_TRUE)
1972:       - pcis->vec1_B the interface part of the global vector z
1973:     */
1974:     if (n_D) {
1975:       KSPSolveTranspose(pcbddc->ksp_D,pcis->vec1_D,pcis->vec2_D);
1976:       VecScale(pcis->vec2_D,m_one);
1977:       if (pcbddc->switch_static) {
1978:         Mat_IS *matis = (Mat_IS*)(pc->mat->data);

1980:         VecSet(pcis->vec1_N,0.);
1981:         VecScatterBegin(pcis->N_to_D,pcis->vec2_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1982:         VecScatterEnd(pcis->N_to_D,pcis->vec2_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1983:         if (!pcbddc->switch_static_change) {
1984:           MatMultTranspose(matis->A,pcis->vec1_N,pcis->vec2_N);
1985:         } else {
1986:           MatMult(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1987:           MatMultTranspose(matis->A,pcis->vec2_N,pcis->vec1_N);
1988:           MatMultTranspose(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1989:         }
1990:         VecScatterBegin(pcis->N_to_D,pcis->vec2_N,pcis->vec1_D,ADD_VALUES,SCATTER_FORWARD);
1991:         VecScatterEnd(pcis->N_to_D,pcis->vec2_N,pcis->vec1_D,ADD_VALUES,SCATTER_FORWARD);
1992:         VecScatterBegin(pcis->N_to_B,pcis->vec2_N,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1993:         VecScatterEnd(pcis->N_to_B,pcis->vec2_N,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1994:       } else {
1995:         MatMultTranspose(pcis->A_IB,pcis->vec2_D,pcis->vec1_B);
1996:       }
1997:     } else {
1998:       VecSet(pcis->vec1_B,zero);
1999:     }
2000:     VecScatterBegin(pcis->global_to_B,pcis->vec1_B,z,ADD_VALUES,SCATTER_REVERSE);
2001:     VecScatterEnd(pcis->global_to_B,pcis->vec1_B,z,ADD_VALUES,SCATTER_REVERSE);
2002:     PCBDDCScalingRestriction(pc,z,pcis->vec1_B);
2003:   } else {
2004:     PCBDDCScalingRestriction(pc,r,pcis->vec1_B);
2005:   }

2007:   /* Apply interface preconditioner
2008:      input/output vecs: pcis->vec1_B and pcis->vec1_D */
2009:   PCBDDCApplyInterfacePreconditioner(pc,PETSC_TRUE);

2011:   /* Apply transpose of partition of unity operator */
2012:   PCBDDCScalingExtension(pc,pcis->vec1_B,z);

2014:   /* Second Dirichlet solve and assembling of output */
2015:   VecScatterBegin(pcis->global_to_B,z,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
2016:   VecScatterEnd(pcis->global_to_B,z,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
2017:   if (n_B) {
2018:     if (pcbddc->switch_static) {
2019:       Mat_IS *matis = (Mat_IS*)(pc->mat->data);

2021:       VecScatterBegin(pcis->N_to_D,pcis->vec1_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
2022:       VecScatterEnd(pcis->N_to_D,pcis->vec1_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
2023:       VecScatterBegin(pcis->N_to_B,pcis->vec1_B,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
2024:       VecScatterEnd(pcis->N_to_B,pcis->vec1_B,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
2025:       if (!pcbddc->switch_static_change) {
2026:         MatMultTranspose(matis->A,pcis->vec1_N,pcis->vec2_N);
2027:       } else {
2028:         MatMult(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
2029:         MatMultTranspose(matis->A,pcis->vec2_N,pcis->vec1_N);
2030:         MatMultTranspose(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
2031:       }
2032:       VecScatterBegin(pcis->N_to_D,pcis->vec2_N,pcis->vec3_D,INSERT_VALUES,SCATTER_FORWARD);
2033:       VecScatterEnd(pcis->N_to_D,pcis->vec2_N,pcis->vec3_D,INSERT_VALUES,SCATTER_FORWARD);
2034:     } else {
2035:       MatMultTranspose(pcis->A_BI,pcis->vec1_B,pcis->vec3_D);
2036:     }
2037:   } else if (pcbddc->switch_static) { /* n_B is zero */
2038:     Mat_IS *matis = (Mat_IS*)(pc->mat->data);

2040:     if (!pcbddc->switch_static_change) {
2041:       MatMultTranspose(matis->A,pcis->vec1_D,pcis->vec3_D);
2042:     } else {
2043:       MatMult(pcbddc->switch_static_change,pcis->vec1_D,pcis->vec1_N);
2044:       MatMultTranspose(matis->A,pcis->vec1_N,pcis->vec2_N);
2045:       MatMultTranspose(pcbddc->switch_static_change,pcis->vec2_N,pcis->vec3_D);
2046:     }
2047:   }
2048:   KSPSolveTranspose(pcbddc->ksp_D,pcis->vec3_D,pcis->vec4_D);
2049:   if (!pcbddc->exact_dirichlet_trick_app && !pcbddc->benign_apply_coarse_only) {
2050:     if (pcbddc->switch_static) {
2051:       VecAXPBYPCZ(pcis->vec2_D,m_one,one,m_one,pcis->vec4_D,pcis->vec1_D);
2052:     } else {
2053:       VecAXPBY(pcis->vec2_D,m_one,m_one,pcis->vec4_D);
2054:     }
2055:     VecScatterBegin(pcis->global_to_D,pcis->vec2_D,z,INSERT_VALUES,SCATTER_REVERSE);
2056:     VecScatterEnd(pcis->global_to_D,pcis->vec2_D,z,INSERT_VALUES,SCATTER_REVERSE);
2057:   } else {
2058:     if (pcbddc->switch_static) {
2059:       VecAXPBY(pcis->vec4_D,one,m_one,pcis->vec1_D);
2060:     } else {
2061:       VecScale(pcis->vec4_D,m_one);
2062:     }
2063:     VecScatterBegin(pcis->global_to_D,pcis->vec4_D,z,INSERT_VALUES,SCATTER_REVERSE);
2064:     VecScatterEnd(pcis->global_to_D,pcis->vec4_D,z,INSERT_VALUES,SCATTER_REVERSE);
2065:   }
2066:   if (pcbddc->benign_have_null) { /* set p0 (computed in PCBDDCApplyInterface) */
2067:     PCBDDCBenignGetOrSetP0(pc,z,PETSC_FALSE);
2068:   }
2069:   if (pcbddc->ChangeOfBasisMatrix) {
2070:     pcbddc->work_change = r;
2071:     VecCopy(z,pcbddc->work_change);
2072:     MatMult(pcbddc->ChangeOfBasisMatrix,pcbddc->work_change,z);
2073:   }
2074:   return(0);
2075: }

2077: PetscErrorCode PCReset_BDDC(PC pc)
2078: {
2079:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
2080:   PC_IS          *pcis = (PC_IS*)pc->data;
2081:   KSP            kspD,kspR,kspC;

2085:   /* free BDDC custom data  */
2086:   PCBDDCResetCustomization(pc);
2087:   /* destroy objects related to topography */
2088:   PCBDDCResetTopography(pc);
2089:   /* destroy objects for scaling operator */
2090:   PCBDDCScalingDestroy(pc);
2091:   /* free solvers stuff */
2092:   PCBDDCResetSolvers(pc);
2093:   /* free global vectors needed in presolve */
2094:   VecDestroy(&pcbddc->temp_solution);
2095:   VecDestroy(&pcbddc->original_rhs);
2096:   /* free data created by PCIS */
2097:   PCISDestroy(pc);

2099:   /* restore defaults */
2100:   kspD = pcbddc->ksp_D;
2101:   kspR = pcbddc->ksp_R;
2102:   kspC = pcbddc->coarse_ksp;
2103:   PetscMemzero(pc->data,sizeof(*pcbddc));
2104:   pcis->n_neigh                     = -1;
2105:   pcis->scaling_factor              = 1.0;
2106:   pcis->reusesubmatrices            = PETSC_TRUE;
2107:   pcbddc->use_local_adj             = PETSC_TRUE;
2108:   pcbddc->use_vertices              = PETSC_TRUE;
2109:   pcbddc->use_edges                 = PETSC_TRUE;
2110:   pcbddc->symmetric_primal          = PETSC_TRUE;
2111:   pcbddc->vertex_size               = 1;
2112:   pcbddc->recompute_topography      = PETSC_TRUE;
2113:   pcbddc->coarse_size               = -1;
2114:   pcbddc->use_exact_dirichlet_trick = PETSC_TRUE;
2115:   pcbddc->coarsening_ratio          = 8;
2116:   pcbddc->coarse_eqs_per_proc       = 1;
2117:   pcbddc->benign_compute_correction = PETSC_TRUE;
2118:   pcbddc->nedfield                  = -1;
2119:   pcbddc->nedglobal                 = PETSC_TRUE;
2120:   pcbddc->graphmaxcount             = PETSC_MAX_INT;
2121:   pcbddc->sub_schurs_layers         = -1;
2122:   pcbddc->ksp_D                     = kspD;
2123:   pcbddc->ksp_R                     = kspR;
2124:   pcbddc->coarse_ksp                = kspC;
2125:   return(0);
2126: }

2128: PetscErrorCode PCDestroy_BDDC(PC pc)
2129: {
2130:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;

2134:   PCReset_BDDC(pc);
2135:   KSPDestroy(&pcbddc->ksp_D);
2136:   KSPDestroy(&pcbddc->ksp_R);
2137:   KSPDestroy(&pcbddc->coarse_ksp);
2138:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDiscreteGradient_C",NULL);
2139:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDivergenceMat_C",NULL);
2140:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetChangeOfBasisMat_C",NULL);
2141:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetPrimalVerticesLocalIS_C",NULL);
2142:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetPrimalVerticesIS_C",NULL);
2143:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetCoarseningRatio_C",NULL);
2144:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLevel_C",NULL);
2145:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetUseExactDirichlet_C",NULL);
2146:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLevels_C",NULL);
2147:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDirichletBoundaries_C",NULL);
2148:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDirichletBoundariesLocal_C",NULL);
2149:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetNeumannBoundaries_C",NULL);
2150:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetNeumannBoundariesLocal_C",NULL);
2151:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetDirichletBoundaries_C",NULL);
2152:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetDirichletBoundariesLocal_C",NULL);
2153:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetNeumannBoundaries_C",NULL);
2154:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetNeumannBoundariesLocal_C",NULL);
2155:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDofsSplitting_C",NULL);
2156:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDofsSplittingLocal_C",NULL);
2157:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLocalAdjacencyGraph_C",NULL);
2158:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCCreateFETIDPOperators_C",NULL);
2159:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCMatFETIDPGetRHS_C",NULL);
2160:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCMatFETIDPGetSolution_C",NULL);
2161:   PetscObjectComposeFunction((PetscObject)pc,"PCPreSolveChangeRHS_C",NULL);
2162:   PetscFree(pc->data);
2163:   return(0);
2164: }

2166: static PetscErrorCode PCPreSolveChangeRHS_BDDC(PC pc, PetscBool* change)
2167: {
2169:   *change = PETSC_TRUE;
2170:   return(0);
2171: }

2173: static PetscErrorCode PCBDDCMatFETIDPGetRHS_BDDC(Mat fetidp_mat, Vec standard_rhs, Vec fetidp_flux_rhs)
2174: {
2175:   FETIDPMat_ctx  mat_ctx;
2176:   Vec            work;
2177:   PC_IS*         pcis;
2178:   PC_BDDC*       pcbddc;

2182:   MatShellGetContext(fetidp_mat,&mat_ctx);
2183:   pcis = (PC_IS*)mat_ctx->pc->data;
2184:   pcbddc = (PC_BDDC*)mat_ctx->pc->data;

2186:   VecSet(fetidp_flux_rhs,0.0);
2187:   /* copy rhs since we may change it during PCPreSolve_BDDC */
2188:   if (!pcbddc->original_rhs) {
2189:     VecDuplicate(pcis->vec1_global,&pcbddc->original_rhs);
2190:   }
2191:   if (mat_ctx->rhs_flip) {
2192:     VecPointwiseMult(pcbddc->original_rhs,standard_rhs,mat_ctx->rhs_flip);
2193:   } else {
2194:     VecCopy(standard_rhs,pcbddc->original_rhs);
2195:   }
2196:   if (mat_ctx->g2g_p) {
2197:     /* interface pressure rhs */
2198:     VecScatterBegin(mat_ctx->g2g_p,fetidp_flux_rhs,pcbddc->original_rhs,INSERT_VALUES,SCATTER_REVERSE);
2199:     VecScatterEnd(mat_ctx->g2g_p,fetidp_flux_rhs,pcbddc->original_rhs,INSERT_VALUES,SCATTER_REVERSE);
2200:     VecScatterBegin(mat_ctx->g2g_p,standard_rhs,fetidp_flux_rhs,INSERT_VALUES,SCATTER_FORWARD);
2201:     VecScatterEnd(mat_ctx->g2g_p,standard_rhs,fetidp_flux_rhs,INSERT_VALUES,SCATTER_FORWARD);
2202:     if (!mat_ctx->rhs_flip) {
2203:       VecScale(fetidp_flux_rhs,-1.);
2204:     }
2205:   }
2206:   /*
2207:      change of basis for physical rhs if needed
2208:      It also changes the rhs in case of dirichlet boundaries
2209:   */
2210:   PCPreSolve_BDDC(mat_ctx->pc,NULL,pcbddc->original_rhs,NULL);
2211:   if (pcbddc->ChangeOfBasisMatrix) {
2212:     MatMultTranspose(pcbddc->ChangeOfBasisMatrix,pcbddc->original_rhs,pcbddc->work_change);
2213:     work = pcbddc->work_change;
2214:    } else {
2215:     work = pcbddc->original_rhs;
2216:   }
2217:   /* store vectors for computation of fetidp final solution */
2218:   VecScatterBegin(pcis->global_to_D,work,mat_ctx->temp_solution_D,INSERT_VALUES,SCATTER_FORWARD);
2219:   VecScatterEnd(pcis->global_to_D,work,mat_ctx->temp_solution_D,INSERT_VALUES,SCATTER_FORWARD);
2220:   /* scale rhs since it should be unassembled */
2221:   /* TODO use counter scaling? (also below) */
2222:   VecScatterBegin(pcis->global_to_B,work,mat_ctx->temp_solution_B,INSERT_VALUES,SCATTER_FORWARD);
2223:   VecScatterEnd(pcis->global_to_B,work,mat_ctx->temp_solution_B,INSERT_VALUES,SCATTER_FORWARD);
2224:   /* Apply partition of unity */
2225:   VecPointwiseMult(mat_ctx->temp_solution_B,pcis->D,mat_ctx->temp_solution_B);
2226:   /* PCBDDCScalingRestriction(mat_ctx->pc,work,mat_ctx->temp_solution_B); */
2227:   if (!pcbddc->switch_static) {
2228:     /* compute partially subassembled Schur complement right-hand side */
2229:     KSPSolve(pcbddc->ksp_D,mat_ctx->temp_solution_D,pcis->vec1_D);
2230:     MatMult(pcis->A_BI,pcis->vec1_D,pcis->vec1_B);
2231:     VecAXPY(mat_ctx->temp_solution_B,-1.0,pcis->vec1_B);
2232:     VecSet(work,0.0);
2233:     VecScatterBegin(pcis->global_to_B,mat_ctx->temp_solution_B,work,ADD_VALUES,SCATTER_REVERSE);
2234:     VecScatterEnd(pcis->global_to_B,mat_ctx->temp_solution_B,work,ADD_VALUES,SCATTER_REVERSE);
2235:     /* PCBDDCScalingRestriction(mat_ctx->pc,work,mat_ctx->temp_solution_B); */
2236:     VecScatterBegin(pcis->global_to_B,work,mat_ctx->temp_solution_B,INSERT_VALUES,SCATTER_FORWARD);
2237:     VecScatterEnd(pcis->global_to_B,work,mat_ctx->temp_solution_B,INSERT_VALUES,SCATTER_FORWARD);
2238:     VecPointwiseMult(mat_ctx->temp_solution_B,pcis->D,mat_ctx->temp_solution_B);
2239:   }
2240:   /* BDDC rhs */
2241:   VecCopy(mat_ctx->temp_solution_B,pcis->vec1_B);
2242:   if (pcbddc->switch_static) {
2243:     VecCopy(mat_ctx->temp_solution_D,pcis->vec1_D);
2244:   }
2245:   /* apply BDDC */
2246:   PetscMemzero(pcbddc->benign_p0,pcbddc->benign_n*sizeof(PetscScalar));
2247:   PCBDDCApplyInterfacePreconditioner(mat_ctx->pc,PETSC_FALSE);
2248:   PetscMemzero(pcbddc->benign_p0,pcbddc->benign_n*sizeof(PetscScalar));

2250:   /* Application of B_delta and assembling of rhs for fetidp fluxes */
2251:   MatMult(mat_ctx->B_delta,pcis->vec1_B,mat_ctx->lambda_local);
2252:   VecScatterBegin(mat_ctx->l2g_lambda,mat_ctx->lambda_local,fetidp_flux_rhs,ADD_VALUES,SCATTER_FORWARD);
2253:   VecScatterEnd(mat_ctx->l2g_lambda,mat_ctx->lambda_local,fetidp_flux_rhs,ADD_VALUES,SCATTER_FORWARD);
2254:   /* Add contribution to interface pressures */
2255:   if (mat_ctx->l2g_p) {
2256:     MatMult(mat_ctx->B_BB,pcis->vec1_B,mat_ctx->vP);
2257:     if (pcbddc->switch_static) {
2258:       MatMultAdd(mat_ctx->B_BI,pcis->vec1_D,mat_ctx->vP,mat_ctx->vP);
2259:     }
2260:     VecScatterBegin(mat_ctx->l2g_p,mat_ctx->vP,fetidp_flux_rhs,ADD_VALUES,SCATTER_FORWARD);
2261:     VecScatterEnd(mat_ctx->l2g_p,mat_ctx->vP,fetidp_flux_rhs,ADD_VALUES,SCATTER_FORWARD);
2262:   }
2263:   return(0);
2264: }

2266: /*@
2267:  PCBDDCMatFETIDPGetRHS - Compute the right-hand side for FETI-DP linear system using the physical right-hand side

2269:    Collective

2271:    Input Parameters:
2272: +  fetidp_mat      - the FETI-DP matrix object obtained by a call to PCBDDCCreateFETIDPOperators
2273: -  standard_rhs    - the right-hand side of the original linear system

2275:    Output Parameters:
2276: .  fetidp_flux_rhs - the right-hand side for the FETI-DP linear system

2278:    Level: developer

2280:    Notes:

2282: .seealso: PCBDDC, PCBDDCCreateFETIDPOperators, PCBDDCMatFETIDPGetSolution
2283: @*/
2284: PetscErrorCode PCBDDCMatFETIDPGetRHS(Mat fetidp_mat, Vec standard_rhs, Vec fetidp_flux_rhs)
2285: {
2286:   FETIDPMat_ctx  mat_ctx;

2293:   MatShellGetContext(fetidp_mat,&mat_ctx);
2294:   PetscUseMethod(mat_ctx->pc,"PCBDDCMatFETIDPGetRHS_C",(Mat,Vec,Vec),(fetidp_mat,standard_rhs,fetidp_flux_rhs));
2295:   return(0);
2296: }

2298: static PetscErrorCode PCBDDCMatFETIDPGetSolution_BDDC(Mat fetidp_mat, Vec fetidp_flux_sol, Vec standard_sol)
2299: {
2300:   FETIDPMat_ctx  mat_ctx;
2301:   PC_IS*         pcis;
2302:   PC_BDDC*       pcbddc;
2304:   Vec            work;

2307:   MatShellGetContext(fetidp_mat,&mat_ctx);
2308:   pcis = (PC_IS*)mat_ctx->pc->data;
2309:   pcbddc = (PC_BDDC*)mat_ctx->pc->data;

2311:   /* apply B_delta^T */
2312:   VecSet(pcis->vec1_B,0.);
2313:   VecScatterBegin(mat_ctx->l2g_lambda,fetidp_flux_sol,mat_ctx->lambda_local,INSERT_VALUES,SCATTER_REVERSE);
2314:   VecScatterEnd(mat_ctx->l2g_lambda,fetidp_flux_sol,mat_ctx->lambda_local,INSERT_VALUES,SCATTER_REVERSE);
2315:   MatMultTranspose(mat_ctx->B_delta,mat_ctx->lambda_local,pcis->vec1_B);
2316:   if (mat_ctx->l2g_p) {
2317:     VecScatterBegin(mat_ctx->l2g_p,fetidp_flux_sol,mat_ctx->vP,INSERT_VALUES,SCATTER_REVERSE);
2318:     VecScatterEnd(mat_ctx->l2g_p,fetidp_flux_sol,mat_ctx->vP,INSERT_VALUES,SCATTER_REVERSE);
2319:     MatMultAdd(mat_ctx->Bt_BB,mat_ctx->vP,pcis->vec1_B,pcis->vec1_B);
2320:   }

2322:   /* compute rhs for BDDC application */
2323:   VecAYPX(pcis->vec1_B,-1.0,mat_ctx->temp_solution_B);
2324:   if (pcbddc->switch_static) {
2325:     VecCopy(mat_ctx->temp_solution_D,pcis->vec1_D);
2326:     if (mat_ctx->l2g_p) {
2327:       VecScale(mat_ctx->vP,-1.);
2328:       MatMultAdd(mat_ctx->Bt_BI,mat_ctx->vP,pcis->vec1_D,pcis->vec1_D);
2329:     }
2330:   }

2332:   /* apply BDDC */
2333:   PetscMemzero(pcbddc->benign_p0,pcbddc->benign_n*sizeof(PetscScalar));
2334:   PCBDDCApplyInterfacePreconditioner(mat_ctx->pc,PETSC_FALSE);

2336:   /* put values into global vector */
2337:   if (pcbddc->ChangeOfBasisMatrix) work = pcbddc->work_change;
2338:   else work = standard_sol;
2339:   VecScatterBegin(pcis->global_to_B,pcis->vec1_B,work,INSERT_VALUES,SCATTER_REVERSE);
2340:   VecScatterEnd(pcis->global_to_B,pcis->vec1_B,work,INSERT_VALUES,SCATTER_REVERSE);
2341:   if (!pcbddc->switch_static) {
2342:     /* compute values into the interior if solved for the partially subassembled Schur complement */
2343:     MatMult(pcis->A_IB,pcis->vec1_B,pcis->vec1_D);
2344:     VecAYPX(pcis->vec1_D,-1.0,mat_ctx->temp_solution_D);
2345:     KSPSolve(pcbddc->ksp_D,pcis->vec1_D,pcis->vec1_D);
2346:   }

2348:   VecScatterBegin(pcis->global_to_D,pcis->vec1_D,work,INSERT_VALUES,SCATTER_REVERSE);
2349:   VecScatterEnd(pcis->global_to_D,pcis->vec1_D,work,INSERT_VALUES,SCATTER_REVERSE);
2350:   /* add p0 solution to final solution */
2351:   PCBDDCBenignGetOrSetP0(mat_ctx->pc,work,PETSC_FALSE);
2352:   if (pcbddc->ChangeOfBasisMatrix) {
2353:     MatMult(pcbddc->ChangeOfBasisMatrix,work,standard_sol);
2354:   }
2355:   PCPostSolve_BDDC(mat_ctx->pc,NULL,NULL,standard_sol);
2356:   if (mat_ctx->g2g_p) {
2357:     VecScatterBegin(mat_ctx->g2g_p,fetidp_flux_sol,standard_sol,INSERT_VALUES,SCATTER_REVERSE);
2358:     VecScatterEnd(mat_ctx->g2g_p,fetidp_flux_sol,standard_sol,INSERT_VALUES,SCATTER_REVERSE);
2359:   }
2360:   return(0);
2361: }

2363: /*@
2364:  PCBDDCMatFETIDPGetSolution - Compute the physical solution using the solution of the FETI-DP linear system

2366:    Collective

2368:    Input Parameters:
2369: +  fetidp_mat      - the FETI-DP matrix obtained by a call to PCBDDCCreateFETIDPOperators
2370: -  fetidp_flux_sol - the solution of the FETI-DP linear system

2372:    Output Parameters:
2373: .  standard_sol    - the solution defined on the physical domain

2375:    Level: developer

2377:    Notes:

2379: .seealso: PCBDDC, PCBDDCCreateFETIDPOperators, PCBDDCMatFETIDPGetRHS
2380: @*/
2381: PetscErrorCode PCBDDCMatFETIDPGetSolution(Mat fetidp_mat, Vec fetidp_flux_sol, Vec standard_sol)
2382: {
2383:   FETIDPMat_ctx  mat_ctx;

2390:   MatShellGetContext(fetidp_mat,&mat_ctx);
2391:   PetscUseMethod(mat_ctx->pc,"PCBDDCMatFETIDPGetSolution_C",(Mat,Vec,Vec),(fetidp_mat,fetidp_flux_sol,standard_sol));
2392:   return(0);
2393: }

2395: static PetscErrorCode PCBDDCCreateFETIDPOperators_BDDC(PC pc, PetscBool fully_redundant, const char* prefix, Mat *fetidp_mat, PC *fetidp_pc)
2396: {

2398:   FETIDPMat_ctx  fetidpmat_ctx;
2399:   Mat            newmat;
2400:   FETIDPPC_ctx   fetidppc_ctx;
2401:   PC             newpc;
2402:   MPI_Comm       comm;

2406:   PetscObjectGetComm((PetscObject)pc,&comm);
2407:   /* FETIDP linear matrix */
2408:   PCBDDCCreateFETIDPMatContext(pc,&fetidpmat_ctx);
2409:   fetidpmat_ctx->fully_redundant = fully_redundant;
2410:   PCBDDCSetupFETIDPMatContext(fetidpmat_ctx);
2411:   MatCreateShell(comm,fetidpmat_ctx->n,fetidpmat_ctx->n,fetidpmat_ctx->N,fetidpmat_ctx->N,fetidpmat_ctx,&newmat);
2412:   MatShellSetOperation(newmat,MATOP_MULT,(void (*)(void))FETIDPMatMult);
2413:   MatShellSetOperation(newmat,MATOP_MULT_TRANSPOSE,(void (*)(void))FETIDPMatMultTranspose);
2414:   MatShellSetOperation(newmat,MATOP_DESTROY,(void (*)(void))PCBDDCDestroyFETIDPMat);
2415:   MatSetOptionsPrefix(newmat,prefix);
2416:   MatAppendOptionsPrefix(newmat,"fetidp_");
2417:   MatSetUp(newmat);
2418:   /* FETIDP preconditioner */
2419:   PCBDDCCreateFETIDPPCContext(pc,&fetidppc_ctx);
2420:   PCBDDCSetupFETIDPPCContext(newmat,fetidppc_ctx);
2421:   PCCreate(comm,&newpc);
2422:   PCSetOperators(newpc,newmat,newmat);
2423:   PCSetOptionsPrefix(newpc,prefix);
2424:   PCAppendOptionsPrefix(newpc,"fetidp_");
2425:   if (!fetidpmat_ctx->l2g_lambda_only) {
2426:     PCSetType(newpc,PCSHELL);
2427:     PCShellSetContext(newpc,fetidppc_ctx);
2428:     PCShellSetApply(newpc,FETIDPPCApply);
2429:     PCShellSetApplyTranspose(newpc,FETIDPPCApplyTranspose);
2430:     PCShellSetView(newpc,FETIDPPCView);
2431:     PCShellSetDestroy(newpc,PCBDDCDestroyFETIDPPC);
2432:   } else {
2433:     KSP      *ksps;
2434:     PC       lagpc;
2435:     Mat      M,AM,PM;
2436:     PetscInt nn;

2438:     PetscObjectQuery((PetscObject)pc,"__KSPFETIDP_PPmat",(PetscObject*)&M);
2439:     PCSetType(newpc,PCFIELDSPLIT);
2440:     PCFieldSplitSetIS(newpc,"lag",fetidpmat_ctx->lagrange);
2441:     PCFieldSplitSetIS(newpc,"p",fetidpmat_ctx->pressure);
2442:     PCFieldSplitSetType(newpc,PC_COMPOSITE_SCHUR);
2443:     PCFieldSplitSetSchurFactType(newpc,PC_FIELDSPLIT_SCHUR_FACT_DIAG);
2444:     PCFieldSplitSetSchurPre(newpc,PC_FIELDSPLIT_SCHUR_PRE_USER,M);
2445:     PCFieldSplitSetSchurScale(newpc,1.0);
2446:     PCSetFromOptions(newpc);
2447:     PCSetUp(newpc);

2449:     /* set the solver for the (0,0) block */
2450:     PCFieldSplitGetSubKSP(newpc,&nn,&ksps);
2451:     PCCreate(comm,&lagpc);
2452:     PCSetType(lagpc,PCSHELL);
2453:     KSPGetOperators(ksps[0],&AM,&PM);
2454:     PCSetOperators(lagpc,AM,PM);
2455:     PCShellSetContext(lagpc,fetidppc_ctx);
2456:     PCShellSetApply(lagpc,FETIDPPCApply);
2457:     PCShellSetApplyTranspose(lagpc,FETIDPPCApplyTranspose);
2458:     PCShellSetView(lagpc,FETIDPPCView);
2459:     PCShellSetDestroy(lagpc,PCBDDCDestroyFETIDPPC);
2460:     KSPSetPC(ksps[0],lagpc);
2461:     PCDestroy(&lagpc);
2462:     PetscFree(ksps);
2463:   }
2464:   /* return pointers for objects created */
2465:   *fetidp_mat = newmat;
2466:   *fetidp_pc = newpc;
2467:   return(0);
2468: }

2470: /*@C
2471:  PCBDDCCreateFETIDPOperators - Create FETI-DP operators

2473:    Collective

2475:    Input Parameters:
2476: +  pc - the BDDC preconditioning context (setup should have been called before)
2477: .  fully_redundant - true for a fully redundant set of Lagrange multipliers
2478: -  prefix - optional options database prefix for the objects to be created (can be NULL)

2480:    Output Parameters:
2481: +  fetidp_mat - shell FETI-DP matrix object
2482: -  fetidp_pc  - shell Dirichlet preconditioner for FETI-DP matrix

2484:    Level: developer

2486:    Notes:
2487:      Currently the only operations provided for FETI-DP matrix are MatMult and MatMultTranspose

2489: .seealso: PCBDDC, PCBDDCMatFETIDPGetRHS, PCBDDCMatFETIDPGetSolution
2490: @*/
2491: PetscErrorCode PCBDDCCreateFETIDPOperators(PC pc, PetscBool fully_redundant, const char *prefix, Mat *fetidp_mat, PC *fetidp_pc)
2492: {

2497:   if (pc->setupcalled) {
2498:     PetscUseMethod(pc,"PCBDDCCreateFETIDPOperators_C",(PC,PetscBool,const char*,Mat*,PC*),(pc,fully_redundant,prefix,fetidp_mat,fetidp_pc));
2499:   } else SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"You must call PCSetup_BDDC() first \n");
2500:   return(0);
2501: }
2502: /* -------------------------------------------------------------------------- */
2503: /*MC
2504:    PCBDDC - Balancing Domain Decomposition by Constraints.

2506:    An implementation of the BDDC preconditioner based on

2508: .vb
2509:    [1] C. R. Dohrmann. "An approximate BDDC preconditioner", Numerical Linear Algebra with Applications Volume 14, Issue 2, pages 149-168, March 2007
2510:    [2] A. Klawonn and O. B. Widlund. "Dual-Primal FETI Methods for Linear Elasticity", http://cs.nyu.edu/csweb/Research/TechReports/TR2004-855/TR2004-855.pdf
2511:    [3] J. Mandel, B. Sousedik, C. R. Dohrmann. "Multispace and Multilevel BDDC", http://arxiv.org/abs/0712.3977
2512:    [4] C. Pechstein and C. R. Dohrmann. "Modern domain decomposition methods BDDC, deluxe scaling, and an algebraic approach", Seminar talk, Linz, December 2013, http://people.ricam.oeaw.ac.at/c.pechstein/pechstein-bddc2013.pdf
2513: .ve

2515:    The matrix to be preconditioned (Pmat) must be of type MATIS.

2517:    Currently works with MATIS matrices with local matrices of type MATSEQAIJ, MATSEQBAIJ or MATSEQSBAIJ, either with real or complex numbers.

2519:    It also works with unsymmetric and indefinite problems.

2521:    Unlike 'conventional' interface preconditioners, PCBDDC iterates over all degrees of freedom, not just those on the interface. This allows the use of approximate solvers on the subdomains.

2523:    Approximate local solvers are automatically adapted (see [1]) if the user has attached a nullspace object to the subdomain matrices, and informed BDDC of using approximate solvers (via the command line).

2525:    Boundary nodes are split in vertices, edges and faces classes using information from the local to global mapping of dofs and the local connectivity graph of nodes. The latter can be customized by using PCBDDCSetLocalAdjacencyGraph()
2526:    Additional information on dofs can be provided by using PCBDDCSetDofsSplitting(), PCBDDCSetDirichletBoundaries(), PCBDDCSetNeumannBoundaries(), and PCBDDCSetPrimalVerticesIS() and their local counterparts.

2528:    Constraints can be customized by attaching a MatNullSpace object to the MATIS matrix via MatSetNearNullSpace(). Non-singular modes are retained via SVD.

2530:    Change of basis is performed similarly to [2] when requested. When more than one constraint is present on a single connected component (i.e. an edge or a face), a robust method based on local QR factorizations is used.
2531:    User defined change of basis can be passed to PCBDDC by using PCBDDCSetChangeOfBasisMat()

2533:    The PETSc implementation also supports multilevel BDDC [3]. Coarse grids are partitioned using a MatPartitioning object.

2535:    Adaptive selection of primal constraints [4] is supported for SPD systems with high-contrast in the coefficients if MUMPS or MKL_PARDISO are present. Future versions of the code will also consider using PASTIX.

2537:    An experimental interface to the FETI-DP method is available. FETI-DP operators could be created using PCBDDCCreateFETIDPOperators(). A stand-alone class for the FETI-DP method will be provided in the next releases.
2538:    Deluxe scaling is not supported yet for FETI-DP.

2540:    Options Database Keys (some of them, run with -h for a complete list):

2542: .    -pc_bddc_use_vertices <true> - use or not vertices in primal space
2543: .    -pc_bddc_use_edges <true> - use or not edges in primal space
2544: .    -pc_bddc_use_faces <false> - use or not faces in primal space
2545: .    -pc_bddc_symmetric <true> - symmetric computation of primal basis functions. Specify false for unsymmetric problems
2546: .    -pc_bddc_use_change_of_basis <false> - use change of basis approach (on edges only)
2547: .    -pc_bddc_use_change_on_faces <false> - use change of basis approach on faces if change of basis has been requested
2548: .    -pc_bddc_switch_static <false> - switches from M_2 (default) to M_3 operator (see reference article [1])
2549: .    -pc_bddc_levels <0> - maximum number of levels for multilevel
2550: .    -pc_bddc_coarsening_ratio <8> - number of subdomains which will be aggregated together at the coarser level (e.g. H/h ratio at the coarser level, significative only in the multilevel case)
2551: .    -pc_bddc_coarse_redistribute <0> - size of a subset of processors where the coarse problem will be remapped (the value is ignored if not at the coarsest level)
2552: .    -pc_bddc_use_deluxe_scaling <false> - use deluxe scaling
2553: .    -pc_bddc_schur_layers <-1> - select the economic version of deluxe scaling by specifying the number of layers (-1 corresponds to the original deluxe scaling)
2554: .    -pc_bddc_adaptive_threshold <0.0> - when a value greater than one is specified, adaptive selection of constraints is performed on edges and faces (requires deluxe scaling and MUMPS or MKL_PARDISO installed)
2555: -    -pc_bddc_check_level <0> - set verbosity level of debugging output

2557:    Options for Dirichlet, Neumann or coarse solver can be set with
2558: .vb
2559:       -pc_bddc_dirichlet_
2560:       -pc_bddc_neumann_
2561:       -pc_bddc_coarse_
2562: .ve
2563:    e.g -pc_bddc_dirichlet_ksp_type richardson -pc_bddc_dirichlet_pc_type gamg. PCBDDC uses by default KPSPREONLY and PCLU.

2565:    When using a multilevel approach, solvers' options at the N-th level (N > 1) can be specified as
2566: .vb
2567:       -pc_bddc_dirichlet_lN_
2568:       -pc_bddc_neumann_lN_
2569:       -pc_bddc_coarse_lN_
2570: .ve
2571:    Note that level number ranges from the finest (0) to the coarsest (N).
2572:    In order to specify options for the BDDC operators at the coarser levels (and not for the solvers), prepend -pc_bddc_coarse_ or -pc_bddc_coarse_l to the option, e.g.
2573: .vb
2574:      -pc_bddc_coarse_pc_bddc_adaptive_threshold 5 -pc_bddc_coarse_l1_pc_bddc_redistribute 3
2575: .ve
2576:    will use a threshold of 5 for constraints' selection at the first coarse level and will redistribute the coarse problem of the first coarse level on 3 processors

2578:    Level: intermediate

2580:    Developer notes:

2582:    Contributed by Stefano Zampini

2584: .seealso:  PCCreate(), PCSetType(), PCType (for list of available types), PC,  MATIS
2585: M*/

2587: PETSC_EXTERN PetscErrorCode PCCreate_BDDC(PC pc)
2588: {
2589:   PetscErrorCode      ierr;
2590:   PC_BDDC             *pcbddc;

2593:   PetscNewLog(pc,&pcbddc);
2594:   pc->data = (void*)pcbddc;

2596:   /* create PCIS data structure */
2597:   PCISCreate(pc);

2599:   /* create local graph structure */
2600:   PCBDDCGraphCreate(&pcbddc->mat_graph);

2602:   /* BDDC nonzero defaults */
2603:   pcbddc->use_local_adj             = PETSC_TRUE;
2604:   pcbddc->use_vertices              = PETSC_TRUE;
2605:   pcbddc->use_edges                 = PETSC_TRUE;
2606:   pcbddc->symmetric_primal          = PETSC_TRUE;
2607:   pcbddc->vertex_size               = 1;
2608:   pcbddc->recompute_topography      = PETSC_TRUE;
2609:   pcbddc->coarse_size               = -1;
2610:   pcbddc->use_exact_dirichlet_trick = PETSC_TRUE;
2611:   pcbddc->coarsening_ratio          = 8;
2612:   pcbddc->coarse_eqs_per_proc       = 1;
2613:   pcbddc->benign_compute_correction = PETSC_TRUE;
2614:   pcbddc->nedfield                  = -1;
2615:   pcbddc->nedglobal                 = PETSC_TRUE;
2616:   pcbddc->graphmaxcount             = PETSC_MAX_INT;
2617:   pcbddc->sub_schurs_layers         = -1;

2619:   /* function pointers */
2620:   pc->ops->apply               = PCApply_BDDC;
2621:   pc->ops->applytranspose      = PCApplyTranspose_BDDC;
2622:   pc->ops->setup               = PCSetUp_BDDC;
2623:   pc->ops->destroy             = PCDestroy_BDDC;
2624:   pc->ops->setfromoptions      = PCSetFromOptions_BDDC;
2625:   pc->ops->view                = PCView_BDDC;
2626:   pc->ops->applyrichardson     = 0;
2627:   pc->ops->applysymmetricleft  = 0;
2628:   pc->ops->applysymmetricright = 0;
2629:   pc->ops->presolve            = PCPreSolve_BDDC;
2630:   pc->ops->postsolve           = PCPostSolve_BDDC;
2631:   pc->ops->reset               = PCReset_BDDC;

2633:   /* composing function */
2634:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDiscreteGradient_C",PCBDDCSetDiscreteGradient_BDDC);
2635:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDivergenceMat_C",PCBDDCSetDivergenceMat_BDDC);
2636:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetChangeOfBasisMat_C",PCBDDCSetChangeOfBasisMat_BDDC);
2637:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetPrimalVerticesLocalIS_C",PCBDDCSetPrimalVerticesLocalIS_BDDC);
2638:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetPrimalVerticesIS_C",PCBDDCSetPrimalVerticesIS_BDDC);
2639:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetCoarseningRatio_C",PCBDDCSetCoarseningRatio_BDDC);
2640:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLevel_C",PCBDDCSetLevel_BDDC);
2641:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetUseExactDirichlet_C",PCBDDCSetUseExactDirichlet_BDDC);
2642:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLevels_C",PCBDDCSetLevels_BDDC);
2643:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDirichletBoundaries_C",PCBDDCSetDirichletBoundaries_BDDC);
2644:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDirichletBoundariesLocal_C",PCBDDCSetDirichletBoundariesLocal_BDDC);
2645:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetNeumannBoundaries_C",PCBDDCSetNeumannBoundaries_BDDC);
2646:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetNeumannBoundariesLocal_C",PCBDDCSetNeumannBoundariesLocal_BDDC);
2647:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetDirichletBoundaries_C",PCBDDCGetDirichletBoundaries_BDDC);
2648:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetDirichletBoundariesLocal_C",PCBDDCGetDirichletBoundariesLocal_BDDC);
2649:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetNeumannBoundaries_C",PCBDDCGetNeumannBoundaries_BDDC);
2650:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetNeumannBoundariesLocal_C",PCBDDCGetNeumannBoundariesLocal_BDDC);
2651:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDofsSplitting_C",PCBDDCSetDofsSplitting_BDDC);
2652:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDofsSplittingLocal_C",PCBDDCSetDofsSplittingLocal_BDDC);
2653:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLocalAdjacencyGraph_C",PCBDDCSetLocalAdjacencyGraph_BDDC);
2654:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCCreateFETIDPOperators_C",PCBDDCCreateFETIDPOperators_BDDC);
2655:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCMatFETIDPGetRHS_C",PCBDDCMatFETIDPGetRHS_BDDC);
2656:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCMatFETIDPGetSolution_C",PCBDDCMatFETIDPGetSolution_BDDC);
2657:   PetscObjectComposeFunction((PetscObject)pc,"PCPreSolveChangeRHS_C",PCPreSolveChangeRHS_BDDC);
2658:   return(0);
2659: }