Actual source code: bddc.c

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

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

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

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

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

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

251: /*@
252:  PCBDDCSetDiscreteGradient - Sets the discrete gradient

254:    Collective on PC

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

264:    Level: advanced

266:    Notes: The discrete gradient matrix G is used to analyze the subdomain edges, and it should not contain any zero entry.
267:           For variable order spaces, the order should be set to zero.
268:           If global is true, the rows of G should be given in global ordering for the whole dofs;
269:           if false, the ordering should be global for the Nedelec field.
270:           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
271:           and geid the one for the Nedelec field.

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

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

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

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

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

313:    Collective on PC

315:    Input Parameters:
316: +  pc - the preconditioning context
317: .  divudotp - the matrix (must be of type MATIS)
318: .  trans - if trans if false (resp. true), then pressures are in the test (trial) space and velocities are in the trial (test) space.
319: -  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

321:    Level: advanced

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

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

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

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

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

359:    Collective on PC

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

366:    Level: intermediate

368:    Notes:

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

380:   if (pc->mat) {
381:     PetscInt rows_c,cols_c,rows,cols;
382:     MatGetSize(pc->mat,&rows,&cols);
383:     MatGetSize(change,&rows_c,&cols_c);
384:     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);
385:     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);
386:     MatGetLocalSize(pc->mat,&rows,&cols);
387:     MatGetLocalSize(change,&rows_c,&cols_c);
388:     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);
389:     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);
390:   }
391:   PetscTryMethod(pc,"PCBDDCSetChangeOfBasisMat_C",(PC,Mat,PetscBool),(pc,change,interior));
392:   return(0);
393: }

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

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

415:    Collective

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

421:    Level: intermediate

423:    Notes:
424:      Any process can list any global node

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

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

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

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

460:    Collective

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

466:    Level: intermediate

468:    Notes:

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

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

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

489:   pcbddc->coarsening_ratio = k;
490:   return(0);
491: }

493: /*@
494:  PCBDDCSetCoarseningRatio - Set coarsening ratio used in multilevel

496:    Logically collective on PC

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

502:    Options Database Keys:
503: .    -pc_bddc_coarsening_ratio

505:    Level: intermediate

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

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

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

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

529:   pcbddc->use_exact_dirichlet_trick = flg;
530:   return(0);
531: }

533: PetscErrorCode PCBDDCSetUseExactDirichlet(PC pc,PetscBool flg)
534: {

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

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

549:   pcbddc->current_level = level;
550:   return(0);
551: }

553: PetscErrorCode PCBDDCSetLevel(PC pc,PetscInt level)
554: {

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

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

569:   pcbddc->max_levels = levels;
570:   return(0);
571: }

573: /*@
574:  PCBDDCSetLevels - Sets the maximum number of levels for multilevel

576:    Logically collective on PC

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

582:    Options Database Keys:
583: .    -pc_bddc_levels

585:    Level: intermediate

587:    Notes:
588:      Default value is 0, i.e. traditional one-level BDDC

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

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

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

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

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

626:    Collective

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

632:    Level: intermediate

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

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

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

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

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

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

673:    Collective

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

679:    Level: intermediate

681:    Notes:

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

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

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

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

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

719:    Collective

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

725:    Level: intermediate

727:    Notes:
728:      Any process can list any global node

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

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

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

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

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

766:    Collective

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

772:    Level: intermediate

774:    Notes:

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

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

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

795:   *DirichletBoundaries = pcbddc->DirichletBoundaries;
796:   return(0);
797: }

799: /*@
800:  PCBDDCGetDirichletBoundaries - Get parallel IS for Dirichlet boundaries

802:    Collective

804:    Input Parameters:
805: .  pc - the preconditioning context

807:    Output Parameters:
808: .  DirichletBoundaries - index set defining the Dirichlet boundaries

810:    Level: intermediate

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

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

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

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

832:   *DirichletBoundaries = pcbddc->DirichletBoundariesLocal;
833:   return(0);
834: }

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

839:    Collective

841:    Input Parameters:
842: .  pc - the preconditioning context

844:    Output Parameters:
845: .  DirichletBoundaries - index set defining the subdomain part of Dirichlet boundaries

847:    Level: intermediate

849:    Notes:
850:      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).
851:           In the latter case, the IS will be available after PCSetUp.

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

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

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

870:   *NeumannBoundaries = pcbddc->NeumannBoundaries;
871:   return(0);
872: }

874: /*@
875:  PCBDDCGetNeumannBoundaries - Get parallel IS for Neumann boundaries

877:    Collective

879:    Input Parameters:
880: .  pc - the preconditioning context

882:    Output Parameters:
883: .  NeumannBoundaries - index set defining the Neumann boundaries

885:    Level: intermediate

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

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

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

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

907:   *NeumannBoundaries = pcbddc->NeumannBoundariesLocal;
908:   return(0);
909: }

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

914:    Collective

916:    Input Parameters:
917: .  pc - the preconditioning context

919:    Output Parameters:
920: .  NeumannBoundaries - index set defining the subdomain part of Neumann boundaries

922:    Level: intermediate

924:    Notes:
925:      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).
926:           In the latter case, the IS will be available after PCSetUp.

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

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

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

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

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

993:    Not collective

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

1001:    Level: intermediate

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

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

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

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

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

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

1074:    Collective

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

1081:    Level: intermediate

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

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

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

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

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

1147: /*@
1148:  PCBDDCSetDofsSplitting - Set index sets defining fields of the global matrix

1150:    Collective

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

1157:    Level: intermediate

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

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

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

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

1184:    Input Parameter:
1185: +  pc - the preconditioner contex

1187:    Application Interface Routine: PCPreSolve()

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

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

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

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

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

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

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

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

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

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

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

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

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

1383:    Input Parameter:
1384: +  pc - the preconditioner contex

1386:    Application Interface Routine: PCPostSolve()

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

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

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

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

1427:    Input Parameter:
1428: +  pc - the preconditioner context

1430:    Application Interface Routine: PCSetUp()

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

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

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

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

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

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

1496:   /* process topology information */
1497:   if (pcbddc->recompute_topography) {
1498:     PetscContainer   c;

1500:     PetscObjectQuery((PetscObject)pc->pmat,"_convert_nest_lfields",(PetscObject*)&c);
1501:     if (c) {
1502:       MatISLocalFields lf;
1503:       PetscContainerGetPointer(c,(void**)&lf);
1504:       PCBDDCSetDofsSplittingLocal(pc,lf->nr,lf->rf);
1505:     }
1506:     PCBDDCComputeLocalTopologyInfo(pc);
1507:     /* detect local disconnected subdomains if requested (use matis->A) */
1508:     if (pcbddc->detect_disconnected) {
1509:       PetscInt i;
1510:       for (i=0;i<pcbddc->n_local_subs;i++) {
1511:         ISDestroy(&pcbddc->local_subs[i]);
1512:       }
1513:       PetscFree(pcbddc->local_subs);
1514:       MatDetectDisconnectedComponents(matis->A,PETSC_FALSE,&pcbddc->n_local_subs,&pcbddc->local_subs);
1515:     }
1516:     if (pcbddc->discretegradient) {
1517:       PCBDDCNedelecSupport(pc);
1518:     }
1519:   }

1521:   /* change basis if requested by the user */
1522:   if (pcbddc->user_ChangeOfBasisMatrix) {
1523:     /* use_change_of_basis flag is used to automatically compute a change of basis from constraints */
1524:     pcbddc->use_change_of_basis = PETSC_FALSE;
1525:     PCBDDCComputeLocalMatrix(pc,pcbddc->user_ChangeOfBasisMatrix);
1526:   } else {
1527:     MatDestroy(&pcbddc->local_mat);
1528:     PetscObjectReference((PetscObject)matis->A);
1529:     pcbddc->local_mat = matis->A;
1530:   }

1532:   /*
1533:      Compute change of basis on local pressures (aka zerodiag dofs) with the benign trick
1534:      This should come earlier then PCISSetUp for extracting the correct subdomain matrices
1535:   */
1536:   PCBDDCBenignShellMat(pc,PETSC_TRUE);
1537:   if (pcbddc->benign_saddle_point) {
1538:     PC_IS* pcis = (PC_IS*)pc->data;

1540:     if (pcbddc->user_ChangeOfBasisMatrix || pcbddc->use_change_of_basis || !computesubschurs) pcbddc->benign_change_explicit = PETSC_TRUE;
1541:     /* detect local saddle point and change the basis in pcbddc->local_mat (TODO: reuse case) */
1542:     PCBDDCBenignDetectSaddlePoint(pc,&zerodiag);
1543:     /* pop B0 mat from local mat */
1544:     PCBDDCBenignPopOrPushB0(pc,PETSC_TRUE);
1545:     /* give pcis a hint to not reuse submatrices during PCISCreate */
1546:     if (pc->flag == SAME_NONZERO_PATTERN && pcis->reusesubmatrices == PETSC_TRUE) {
1547:       if (pcbddc->benign_n && (pcbddc->benign_change_explicit || pcbddc->dbg_flag)) {
1548:         pcis->reusesubmatrices = PETSC_FALSE;
1549:       } else {
1550:         pcis->reusesubmatrices = PETSC_TRUE;
1551:       }
1552:     } else {
1553:       pcis->reusesubmatrices = PETSC_FALSE;
1554:     }
1555:   }

1557:   /* propagate relevant information -> TODO remove*/
1558: #if !defined(PETSC_USE_COMPLEX) /* workaround for reals */
1559:   if (matis->A->symmetric_set) {
1560:     MatSetOption(pcbddc->local_mat,MAT_HERMITIAN,matis->A->symmetric);
1561:   }
1562: #endif
1563:   if (matis->A->symmetric_set) {
1564:     MatSetOption(pcbddc->local_mat,MAT_SYMMETRIC,matis->A->symmetric);
1565:   }
1566:   if (matis->A->spd_set) {
1567:     MatSetOption(pcbddc->local_mat,MAT_SPD,matis->A->spd);
1568:   }

1570:   /* Set up all the "iterative substructuring" common block without computing solvers */
1571:   {
1572:     Mat temp_mat;

1574:     temp_mat = matis->A;
1575:     matis->A = pcbddc->local_mat;
1576:     PCISSetUp(pc,PETSC_FALSE);
1577:     pcbddc->local_mat = matis->A;
1578:     matis->A = temp_mat;
1579:   }

1581:   /* Analyze interface */
1582:   if (!pcbddc->graphanalyzed) {
1583:     PCBDDCAnalyzeInterface(pc);
1584:     computeconstraintsmatrix = PETSC_TRUE;
1585:     if (pcbddc->adaptive_selection && !pcbddc->use_deluxe_scaling && !pcbddc->mat_graph->twodim) {
1586:       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot compute the adaptive primal space for a problem with 3D edges without deluxe scaling");
1587:     }
1588:     if (pcbddc->compute_nonetflux) {
1589:       MatNullSpace nnfnnsp;

1591:       PCBDDCComputeNoNetFlux(pc->pmat,pcbddc->divudotp,pcbddc->divudotp_trans,pcbddc->divudotp_vl2l,pcbddc->mat_graph,&nnfnnsp);
1592:       /* TODO what if a nearnullspace is already attached? */
1593:       MatSetNearNullSpace(pc->pmat,nnfnnsp);
1594:       MatNullSpaceDestroy(&nnfnnsp);
1595:     }
1596:   }

1598:   /* check existence of a divergence free extension, i.e.
1599:      b(v_I,p_0) = 0 for all v_I (raise error if not).
1600:      Also, check that PCBDDCBenignGetOrSetP0 works */
1601:   if (pcbddc->benign_saddle_point && pcbddc->dbg_flag > 1) {
1602:     PCBDDCBenignCheck(pc,zerodiag);
1603:   }
1604:   ISDestroy(&zerodiag);

1606:   /* Setup local dirichlet solver ksp_D and sub_schurs solvers */
1607:   if (computesubschurs && pcbddc->recompute_topography) {
1608:     PCBDDCInitSubSchurs(pc);
1609:   }
1610:   /* SetUp Scaling operator (scaling matrices could be needed in SubSchursSetUp)*/
1611:   if (!pcbddc->use_deluxe_scaling) {
1612:     PCBDDCScalingSetUp(pc);
1613:   }

1615:   /* finish setup solvers and do adaptive selection of constraints */
1616:   sub_schurs = pcbddc->sub_schurs;
1617:   if (sub_schurs && sub_schurs->schur_explicit) {
1618:     if (computesubschurs) {
1619:       PCBDDCSetUpSubSchurs(pc);
1620:     }
1621:     PCBDDCSetUpLocalSolvers(pc,PETSC_TRUE,PETSC_FALSE);
1622:   } else {
1623:     PCBDDCSetUpLocalSolvers(pc,PETSC_TRUE,PETSC_FALSE);
1624:     if (computesubschurs) {
1625:       PCBDDCSetUpSubSchurs(pc);
1626:     }
1627:   }
1628:   if (pcbddc->adaptive_selection) {
1629:     PCBDDCAdaptiveSelection(pc);
1630:     computeconstraintsmatrix = PETSC_TRUE;
1631:   }

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

1666:   /* Setup constraints and related work vectors */
1667:   /* reset primal space flags */
1668:   pcbddc->new_primal_space = PETSC_FALSE;
1669:   pcbddc->new_primal_space_local = PETSC_FALSE;
1670:   if (computeconstraintsmatrix || new_nearnullspace_provided) {
1671:     /* It also sets the primal space flags */
1672:     PCBDDCConstraintsSetUp(pc);
1673:   }
1674:   /* Allocate needed local vectors (which depends on quantities defined during ConstraintsSetUp) */
1675:   PCBDDCSetUpLocalWorkVectors(pc);

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

1680:     PCBDDCComputeLocalMatrix(pc,pcbddc->ChangeOfBasisMatrix);
1681:     if (pcbddc->benign_change) {
1682:       MatDestroy(&pcbddc->benign_B0);
1683:       /* pop B0 from pcbddc->local_mat */
1684:       PCBDDCBenignPopOrPushB0(pc,PETSC_TRUE);
1685:     }
1686:     /* get submatrices */
1687:     MatDestroy(&pcis->A_IB);
1688:     MatDestroy(&pcis->A_BI);
1689:     MatDestroy(&pcis->A_BB);
1690:     MatCreateSubMatrix(pcbddc->local_mat,pcis->is_B_local,pcis->is_B_local,MAT_INITIAL_MATRIX,&pcis->A_BB);
1691:     MatCreateSubMatrix(pcbddc->local_mat,pcis->is_I_local,pcis->is_B_local,MAT_INITIAL_MATRIX,&pcis->A_IB);
1692:     MatCreateSubMatrix(pcbddc->local_mat,pcis->is_B_local,pcis->is_I_local,MAT_INITIAL_MATRIX,&pcis->A_BI);
1693:     /* set flag in pcis to not reuse submatrices during PCISCreate */
1694:     pcis->reusesubmatrices = PETSC_FALSE;
1695:   } else if (!pcbddc->user_ChangeOfBasisMatrix && !pcbddc->benign_change) {
1696:     MatDestroy(&pcbddc->local_mat);
1697:     PetscObjectReference((PetscObject)matis->A);
1698:     pcbddc->local_mat = matis->A;
1699:   }

1701:   /* interface pressure block row for B_C */
1702:   PetscObjectQuery((PetscObject)pc,"__KSPFETIDP_lP" ,(PetscObject*)&lP);
1703:   PetscObjectQuery((PetscObject)pc,"__KSPFETIDP_lA" ,(PetscObject*)&lA);
1704:   if (lA && lP) {
1705:     PC_IS*    pcis = (PC_IS*)pc->data;
1706:     Mat       B_BI,B_BB,Bt_BI,Bt_BB;
1707:     PetscBool issym;
1708:     MatIsSymmetric(lA,PETSC_SMALL,&issym);
1709:     if (issym) {
1710:       MatCreateSubMatrix(lA,lP,pcis->is_I_local,MAT_INITIAL_MATRIX,&B_BI);
1711:       MatCreateSubMatrix(lA,lP,pcis->is_B_local,MAT_INITIAL_MATRIX,&B_BB);
1712:       MatCreateTranspose(B_BI,&Bt_BI);
1713:       MatCreateTranspose(B_BB,&Bt_BB);
1714:     } else {
1715:       MatCreateSubMatrix(lA,lP,pcis->is_I_local,MAT_INITIAL_MATRIX,&B_BI);
1716:       MatCreateSubMatrix(lA,lP,pcis->is_B_local,MAT_INITIAL_MATRIX,&B_BB);
1717:       MatCreateSubMatrix(lA,pcis->is_I_local,lP,MAT_INITIAL_MATRIX,&Bt_BI);
1718:       MatCreateSubMatrix(lA,pcis->is_B_local,lP,MAT_INITIAL_MATRIX,&Bt_BB);
1719:     }
1720:     PetscObjectCompose((PetscObject)pc,"__KSPFETIDP_B_BI",(PetscObject)B_BI);
1721:     PetscObjectCompose((PetscObject)pc,"__KSPFETIDP_B_BB",(PetscObject)B_BB);
1722:     PetscObjectCompose((PetscObject)pc,"__KSPFETIDP_Bt_BI",(PetscObject)Bt_BI);
1723:     PetscObjectCompose((PetscObject)pc,"__KSPFETIDP_Bt_BB",(PetscObject)Bt_BB);
1724:     MatDestroy(&B_BI);
1725:     MatDestroy(&B_BB);
1726:     MatDestroy(&Bt_BI);
1727:     MatDestroy(&Bt_BB);
1728:   }

1730:   /* SetUp coarse and local Neumann solvers */
1731:   PCBDDCSetUpSolvers(pc);
1732:   /* SetUp Scaling operator */
1733:   if (pcbddc->use_deluxe_scaling) {
1734:     PCBDDCScalingSetUp(pc);
1735:   }

1737:   /* mark topography as done */
1738:   pcbddc->recompute_topography = PETSC_FALSE;

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

1743:   if (pcbddc->dbg_flag) {
1744:     PetscViewerASCIISubtractTab(pcbddc->dbg_viewer,2*pcbddc->current_level);
1745:   }
1746:   return(0);
1747: }

1749: /*
1750:    PCApply_BDDC - Applies the BDDC operator to a vector.

1752:    Input Parameters:
1753: +  pc - the preconditioner context
1754: -  r - input vector (global)

1756:    Output Parameter:
1757: .  z - output vector (global)

1759:    Application Interface Routine: PCApply()
1760:  */
1761: PetscErrorCode PCApply_BDDC(PC pc,Vec r,Vec z)
1762: {
1763:   PC_IS             *pcis = (PC_IS*)(pc->data);
1764:   PC_BDDC           *pcbddc = (PC_BDDC*)(pc->data);
1765:   PetscInt          n_B = pcis->n_B, n_D = pcis->n - n_B;
1766:   PetscErrorCode    ierr;
1767:   const PetscScalar one = 1.0;
1768:   const PetscScalar m_one = -1.0;
1769:   const PetscScalar zero = 0.0;

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

1776:   PetscCitationsRegister(citation,&cited);
1777:   if (pcbddc->ChangeOfBasisMatrix) {
1778:     Vec swap;

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

1809:         VecSet(pcis->vec1_N,0.);
1810:         VecScatterBegin(pcis->N_to_D,pcis->vec2_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1811:         VecScatterEnd(pcis->N_to_D,pcis->vec2_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1812:         if (!pcbddc->switch_static_change) {
1813:           MatMult(matis->A,pcis->vec1_N,pcis->vec2_N);
1814:         } else {
1815:           MatMult(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1816:           MatMult(matis->A,pcis->vec2_N,pcis->vec1_N);
1817:           MatMultTranspose(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1818:         }
1819:         VecScatterBegin(pcis->N_to_D,pcis->vec2_N,pcis->vec1_D,ADD_VALUES,SCATTER_FORWARD);
1820:         VecScatterEnd(pcis->N_to_D,pcis->vec2_N,pcis->vec1_D,ADD_VALUES,SCATTER_FORWARD);
1821:         VecScatterBegin(pcis->N_to_B,pcis->vec2_N,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1822:         VecScatterEnd(pcis->N_to_B,pcis->vec2_N,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1823:       } else {
1824:         MatMult(pcis->A_BI,pcis->vec2_D,pcis->vec1_B);
1825:       }
1826:     } else {
1827:       VecSet(pcis->vec1_B,zero);
1828:     }
1829:     VecScatterBegin(pcis->global_to_B,pcis->vec1_B,z,ADD_VALUES,SCATTER_REVERSE);
1830:     VecScatterEnd(pcis->global_to_B,pcis->vec1_B,z,ADD_VALUES,SCATTER_REVERSE);
1831:     PCBDDCScalingRestriction(pc,z,pcis->vec1_B);
1832:   } else {
1833:     if (!pcbddc->benign_apply_coarse_only) {
1834:       PCBDDCScalingRestriction(pc,r,pcis->vec1_B);
1835:     }
1836:   }

1838:   /* Apply interface preconditioner
1839:      input/output vecs: pcis->vec1_B and pcis->vec1_D */
1840:   PCBDDCApplyInterfacePreconditioner(pc,PETSC_FALSE);

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

1845:   /* Second Dirichlet solve and assembling of output */
1846:   VecScatterBegin(pcis->global_to_B,z,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1847:   VecScatterEnd(pcis->global_to_B,z,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1848:   if (n_B) {
1849:     if (pcbddc->switch_static) {
1850:       Mat_IS *matis = (Mat_IS*)(pc->mat->data);

1852:       VecScatterBegin(pcis->N_to_D,pcis->vec1_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1853:       VecScatterEnd(pcis->N_to_D,pcis->vec1_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1854:       VecScatterBegin(pcis->N_to_B,pcis->vec1_B,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1855:       VecScatterEnd(pcis->N_to_B,pcis->vec1_B,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1856:       if (!pcbddc->switch_static_change) {
1857:         MatMult(matis->A,pcis->vec1_N,pcis->vec2_N);
1858:       } else {
1859:         MatMult(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1860:         MatMult(matis->A,pcis->vec2_N,pcis->vec1_N);
1861:         MatMultTranspose(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1862:       }
1863:       VecScatterBegin(pcis->N_to_D,pcis->vec2_N,pcis->vec3_D,INSERT_VALUES,SCATTER_FORWARD);
1864:       VecScatterEnd(pcis->N_to_D,pcis->vec2_N,pcis->vec3_D,INSERT_VALUES,SCATTER_FORWARD);
1865:     } else {
1866:       MatMult(pcis->A_IB,pcis->vec1_B,pcis->vec3_D);
1867:     }
1868:   } else if (pcbddc->switch_static) { /* n_B is zero */
1869:     Mat_IS *matis = (Mat_IS*)(pc->mat->data);

1871:     if (!pcbddc->switch_static_change) {
1872:       MatMult(matis->A,pcis->vec1_D,pcis->vec3_D);
1873:     } else {
1874:       MatMult(pcbddc->switch_static_change,pcis->vec1_D,pcis->vec1_N);
1875:       MatMult(matis->A,pcis->vec1_N,pcis->vec2_N);
1876:       MatMultTranspose(pcbddc->switch_static_change,pcis->vec2_N,pcis->vec3_D);
1877:     }
1878:   }
1879:   KSPSolve(pcbddc->ksp_D,pcis->vec3_D,pcis->vec4_D);

1881:   if (!pcbddc->exact_dirichlet_trick_app && !pcbddc->benign_apply_coarse_only) {
1882:     if (pcbddc->switch_static) {
1883:       VecAXPBYPCZ(pcis->vec2_D,m_one,one,m_one,pcis->vec4_D,pcis->vec1_D);
1884:     } else {
1885:       VecAXPBY(pcis->vec2_D,m_one,m_one,pcis->vec4_D);
1886:     }
1887:     VecScatterBegin(pcis->global_to_D,pcis->vec2_D,z,INSERT_VALUES,SCATTER_REVERSE);
1888:     VecScatterEnd(pcis->global_to_D,pcis->vec2_D,z,INSERT_VALUES,SCATTER_REVERSE);
1889:   } else {
1890:     if (pcbddc->switch_static) {
1891:       VecAXPBY(pcis->vec4_D,one,m_one,pcis->vec1_D);
1892:     } else {
1893:       VecScale(pcis->vec4_D,m_one);
1894:     }
1895:     VecScatterBegin(pcis->global_to_D,pcis->vec4_D,z,INSERT_VALUES,SCATTER_REVERSE);
1896:     VecScatterEnd(pcis->global_to_D,pcis->vec4_D,z,INSERT_VALUES,SCATTER_REVERSE);
1897:   }
1898:   if (pcbddc->benign_have_null) { /* set p0 (computed in PCBDDCApplyInterface) */
1899:     if (pcbddc->benign_apply_coarse_only) {
1900:       PetscMemzero(pcbddc->benign_p0,pcbddc->benign_n*sizeof(PetscScalar));
1901:     }
1902:     PCBDDCBenignGetOrSetP0(pc,z,PETSC_FALSE);
1903:   }

1905:   if (pcbddc->ChangeOfBasisMatrix) {
1906:     pcbddc->work_change = r;
1907:     VecCopy(z,pcbddc->work_change);
1908:     MatMult(pcbddc->ChangeOfBasisMatrix,pcbddc->work_change,z);
1909:   }
1910:   return(0);
1911: }

1913: /*
1914:    PCApplyTranspose_BDDC - Applies the transpose of the BDDC operator to a vector.

1916:    Input Parameters:
1917: +  pc - the preconditioner context
1918: -  r - input vector (global)

1920:    Output Parameter:
1921: .  z - output vector (global)

1923:    Application Interface Routine: PCApplyTranspose()
1924:  */
1925: PetscErrorCode PCApplyTranspose_BDDC(PC pc,Vec r,Vec z)
1926: {
1927:   PC_IS             *pcis = (PC_IS*)(pc->data);
1928:   PC_BDDC           *pcbddc = (PC_BDDC*)(pc->data);
1929:   PetscInt          n_B = pcis->n_B, n_D = pcis->n - n_B;
1930:   PetscErrorCode    ierr;
1931:   const PetscScalar one = 1.0;
1932:   const PetscScalar m_one = -1.0;
1933:   const PetscScalar zero = 0.0;

1936:   PetscCitationsRegister(citation,&cited);
1937:   if (pcbddc->ChangeOfBasisMatrix) {
1938:     Vec swap;

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

1969:         VecSet(pcis->vec1_N,0.);
1970:         VecScatterBegin(pcis->N_to_D,pcis->vec2_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1971:         VecScatterEnd(pcis->N_to_D,pcis->vec2_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
1972:         if (!pcbddc->switch_static_change) {
1973:           MatMultTranspose(matis->A,pcis->vec1_N,pcis->vec2_N);
1974:         } else {
1975:           MatMult(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1976:           MatMultTranspose(matis->A,pcis->vec2_N,pcis->vec1_N);
1977:           MatMultTranspose(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
1978:         }
1979:         VecScatterBegin(pcis->N_to_D,pcis->vec2_N,pcis->vec1_D,ADD_VALUES,SCATTER_FORWARD);
1980:         VecScatterEnd(pcis->N_to_D,pcis->vec2_N,pcis->vec1_D,ADD_VALUES,SCATTER_FORWARD);
1981:         VecScatterBegin(pcis->N_to_B,pcis->vec2_N,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1982:         VecScatterEnd(pcis->N_to_B,pcis->vec2_N,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
1983:       } else {
1984:         MatMultTranspose(pcis->A_IB,pcis->vec2_D,pcis->vec1_B);
1985:       }
1986:     } else {
1987:       VecSet(pcis->vec1_B,zero);
1988:     }
1989:     VecScatterBegin(pcis->global_to_B,pcis->vec1_B,z,ADD_VALUES,SCATTER_REVERSE);
1990:     VecScatterEnd(pcis->global_to_B,pcis->vec1_B,z,ADD_VALUES,SCATTER_REVERSE);
1991:     PCBDDCScalingRestriction(pc,z,pcis->vec1_B);
1992:   } else {
1993:     PCBDDCScalingRestriction(pc,r,pcis->vec1_B);
1994:   }

1996:   /* Apply interface preconditioner
1997:      input/output vecs: pcis->vec1_B and pcis->vec1_D */
1998:   PCBDDCApplyInterfacePreconditioner(pc,PETSC_TRUE);

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

2003:   /* Second Dirichlet solve and assembling of output */
2004:   VecScatterBegin(pcis->global_to_B,z,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
2005:   VecScatterEnd(pcis->global_to_B,z,pcis->vec1_B,INSERT_VALUES,SCATTER_FORWARD);
2006:   if (n_B) {
2007:     if (pcbddc->switch_static) {
2008:       Mat_IS *matis = (Mat_IS*)(pc->mat->data);

2010:       VecScatterBegin(pcis->N_to_D,pcis->vec1_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
2011:       VecScatterEnd(pcis->N_to_D,pcis->vec1_D,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
2012:       VecScatterBegin(pcis->N_to_B,pcis->vec1_B,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
2013:       VecScatterEnd(pcis->N_to_B,pcis->vec1_B,pcis->vec1_N,INSERT_VALUES,SCATTER_REVERSE);
2014:       if (!pcbddc->switch_static_change) {
2015:         MatMultTranspose(matis->A,pcis->vec1_N,pcis->vec2_N);
2016:       } else {
2017:         MatMult(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
2018:         MatMultTranspose(matis->A,pcis->vec2_N,pcis->vec1_N);
2019:         MatMultTranspose(pcbddc->switch_static_change,pcis->vec1_N,pcis->vec2_N);
2020:       }
2021:       VecScatterBegin(pcis->N_to_D,pcis->vec2_N,pcis->vec3_D,INSERT_VALUES,SCATTER_FORWARD);
2022:       VecScatterEnd(pcis->N_to_D,pcis->vec2_N,pcis->vec3_D,INSERT_VALUES,SCATTER_FORWARD);
2023:     } else {
2024:       MatMultTranspose(pcis->A_BI,pcis->vec1_B,pcis->vec3_D);
2025:     }
2026:   } else if (pcbddc->switch_static) { /* n_B is zero */
2027:     Mat_IS *matis = (Mat_IS*)(pc->mat->data);

2029:     if (!pcbddc->switch_static_change) {
2030:       MatMultTranspose(matis->A,pcis->vec1_D,pcis->vec3_D);
2031:     } else {
2032:       MatMult(pcbddc->switch_static_change,pcis->vec1_D,pcis->vec1_N);
2033:       MatMultTranspose(matis->A,pcis->vec1_N,pcis->vec2_N);
2034:       MatMultTranspose(pcbddc->switch_static_change,pcis->vec2_N,pcis->vec3_D);
2035:     }
2036:   }
2037:   KSPSolveTranspose(pcbddc->ksp_D,pcis->vec3_D,pcis->vec4_D);
2038:   if (!pcbddc->exact_dirichlet_trick_app && !pcbddc->benign_apply_coarse_only) {
2039:     if (pcbddc->switch_static) {
2040:       VecAXPBYPCZ(pcis->vec2_D,m_one,one,m_one,pcis->vec4_D,pcis->vec1_D);
2041:     } else {
2042:       VecAXPBY(pcis->vec2_D,m_one,m_one,pcis->vec4_D);
2043:     }
2044:     VecScatterBegin(pcis->global_to_D,pcis->vec2_D,z,INSERT_VALUES,SCATTER_REVERSE);
2045:     VecScatterEnd(pcis->global_to_D,pcis->vec2_D,z,INSERT_VALUES,SCATTER_REVERSE);
2046:   } else {
2047:     if (pcbddc->switch_static) {
2048:       VecAXPBY(pcis->vec4_D,one,m_one,pcis->vec1_D);
2049:     } else {
2050:       VecScale(pcis->vec4_D,m_one);
2051:     }
2052:     VecScatterBegin(pcis->global_to_D,pcis->vec4_D,z,INSERT_VALUES,SCATTER_REVERSE);
2053:     VecScatterEnd(pcis->global_to_D,pcis->vec4_D,z,INSERT_VALUES,SCATTER_REVERSE);
2054:   }
2055:   if (pcbddc->benign_have_null) { /* set p0 (computed in PCBDDCApplyInterface) */
2056:     PCBDDCBenignGetOrSetP0(pc,z,PETSC_FALSE);
2057:   }
2058:   if (pcbddc->ChangeOfBasisMatrix) {
2059:     pcbddc->work_change = r;
2060:     VecCopy(z,pcbddc->work_change);
2061:     MatMult(pcbddc->ChangeOfBasisMatrix,pcbddc->work_change,z);
2062:   }
2063:   return(0);
2064: }

2066: PetscErrorCode PCReset_BDDC(PC pc)
2067: {
2068:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;
2069:   PC_IS          *pcis = (PC_IS*)pc->data;
2070:   KSP            kspD,kspR,kspC;

2074:   /* free BDDC custom data  */
2075:   PCBDDCResetCustomization(pc);
2076:   /* destroy objects related to topography */
2077:   PCBDDCResetTopography(pc);
2078:   /* destroy objects for scaling operator */
2079:   PCBDDCScalingDestroy(pc);
2080:   /* free solvers stuff */
2081:   PCBDDCResetSolvers(pc);
2082:   /* free global vectors needed in presolve */
2083:   VecDestroy(&pcbddc->temp_solution);
2084:   VecDestroy(&pcbddc->original_rhs);
2085:   /* free data created by PCIS */
2086:   PCISDestroy(pc);

2088:   /* restore defaults */
2089:   kspD = pcbddc->ksp_D;
2090:   kspR = pcbddc->ksp_R;
2091:   kspC = pcbddc->coarse_ksp;
2092:   PetscMemzero(pc->data,sizeof(*pcbddc));
2093:   pcis->n_neigh                     = -1;
2094:   pcis->scaling_factor              = 1.0;
2095:   pcis->reusesubmatrices            = PETSC_TRUE;
2096:   pcbddc->use_local_adj             = PETSC_TRUE;
2097:   pcbddc->use_vertices              = PETSC_TRUE;
2098:   pcbddc->use_edges                 = PETSC_TRUE;
2099:   pcbddc->symmetric_primal          = PETSC_TRUE;
2100:   pcbddc->vertex_size               = 1;
2101:   pcbddc->recompute_topography      = PETSC_TRUE;
2102:   pcbddc->coarse_size               = -1;
2103:   pcbddc->use_exact_dirichlet_trick = PETSC_TRUE;
2104:   pcbddc->coarsening_ratio          = 8;
2105:   pcbddc->coarse_eqs_per_proc       = 1;
2106:   pcbddc->benign_compute_correction = PETSC_TRUE;
2107:   pcbddc->nedfield                  = -1;
2108:   pcbddc->nedglobal                 = PETSC_TRUE;
2109:   pcbddc->graphmaxcount             = PETSC_MAX_INT;
2110:   pcbddc->sub_schurs_layers         = -1;
2111:   pcbddc->ksp_D                     = kspD;
2112:   pcbddc->ksp_R                     = kspR;
2113:   pcbddc->coarse_ksp                = kspC;
2114:   return(0);
2115: }

2117: PetscErrorCode PCDestroy_BDDC(PC pc)
2118: {
2119:   PC_BDDC        *pcbddc = (PC_BDDC*)pc->data;

2123:   PCReset_BDDC(pc);
2124:   KSPDestroy(&pcbddc->ksp_D);
2125:   KSPDestroy(&pcbddc->ksp_R);
2126:   KSPDestroy(&pcbddc->coarse_ksp);
2127:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDiscreteGradient_C",NULL);
2128:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDivergenceMat_C",NULL);
2129:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetChangeOfBasisMat_C",NULL);
2130:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetPrimalVerticesLocalIS_C",NULL);
2131:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetPrimalVerticesIS_C",NULL);
2132:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetCoarseningRatio_C",NULL);
2133:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLevel_C",NULL);
2134:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetUseExactDirichlet_C",NULL);
2135:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLevels_C",NULL);
2136:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDirichletBoundaries_C",NULL);
2137:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDirichletBoundariesLocal_C",NULL);
2138:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetNeumannBoundaries_C",NULL);
2139:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetNeumannBoundariesLocal_C",NULL);
2140:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetDirichletBoundaries_C",NULL);
2141:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetDirichletBoundariesLocal_C",NULL);
2142:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetNeumannBoundaries_C",NULL);
2143:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetNeumannBoundariesLocal_C",NULL);
2144:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDofsSplitting_C",NULL);
2145:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDofsSplittingLocal_C",NULL);
2146:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLocalAdjacencyGraph_C",NULL);
2147:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCCreateFETIDPOperators_C",NULL);
2148:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCMatFETIDPGetRHS_C",NULL);
2149:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCMatFETIDPGetSolution_C",NULL);
2150:   PetscObjectComposeFunction((PetscObject)pc,"PCPreSolveChangeRHS_C",NULL);
2151:   PetscFree(pc->data);
2152:   return(0);
2153: }

2155: static PetscErrorCode PCPreSolveChangeRHS_BDDC(PC pc, PetscBool* change)
2156: {
2158:   *change = PETSC_TRUE;
2159:   return(0);
2160: }

2162: static PetscErrorCode PCBDDCMatFETIDPGetRHS_BDDC(Mat fetidp_mat, Vec standard_rhs, Vec fetidp_flux_rhs)
2163: {
2164:   FETIDPMat_ctx  mat_ctx;
2165:   Vec            work;
2166:   PC_IS*         pcis;
2167:   PC_BDDC*       pcbddc;

2171:   MatShellGetContext(fetidp_mat,&mat_ctx);
2172:   pcis = (PC_IS*)mat_ctx->pc->data;
2173:   pcbddc = (PC_BDDC*)mat_ctx->pc->data;

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

2239:   /* Application of B_delta and assembling of rhs for fetidp fluxes */
2240:   MatMult(mat_ctx->B_delta,pcis->vec1_B,mat_ctx->lambda_local);
2241:   VecScatterBegin(mat_ctx->l2g_lambda,mat_ctx->lambda_local,fetidp_flux_rhs,ADD_VALUES,SCATTER_FORWARD);
2242:   VecScatterEnd(mat_ctx->l2g_lambda,mat_ctx->lambda_local,fetidp_flux_rhs,ADD_VALUES,SCATTER_FORWARD);
2243:   /* Add contribution to interface pressures */
2244:   if (mat_ctx->l2g_p) {
2245:     MatMult(mat_ctx->B_BB,pcis->vec1_B,mat_ctx->vP);
2246:     if (pcbddc->switch_static) {
2247:       MatMultAdd(mat_ctx->B_BI,pcis->vec1_D,mat_ctx->vP,mat_ctx->vP);
2248:     }
2249:     VecScatterBegin(mat_ctx->l2g_p,mat_ctx->vP,fetidp_flux_rhs,ADD_VALUES,SCATTER_FORWARD);
2250:     VecScatterEnd(mat_ctx->l2g_p,mat_ctx->vP,fetidp_flux_rhs,ADD_VALUES,SCATTER_FORWARD);
2251:   }
2252:   return(0);
2253: }

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

2258:    Collective

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

2264:    Output Parameters:
2265: .  fetidp_flux_rhs - the right-hand side for the FETI-DP linear system

2267:    Level: developer

2269:    Notes:

2271: .seealso: PCBDDC, PCBDDCCreateFETIDPOperators, PCBDDCMatFETIDPGetSolution
2272: @*/
2273: PetscErrorCode PCBDDCMatFETIDPGetRHS(Mat fetidp_mat, Vec standard_rhs, Vec fetidp_flux_rhs)
2274: {
2275:   FETIDPMat_ctx  mat_ctx;

2282:   MatShellGetContext(fetidp_mat,&mat_ctx);
2283:   PetscUseMethod(mat_ctx->pc,"PCBDDCMatFETIDPGetRHS_C",(Mat,Vec,Vec),(fetidp_mat,standard_rhs,fetidp_flux_rhs));
2284:   return(0);
2285: }

2287: static PetscErrorCode PCBDDCMatFETIDPGetSolution_BDDC(Mat fetidp_mat, Vec fetidp_flux_sol, Vec standard_sol)
2288: {
2289:   FETIDPMat_ctx  mat_ctx;
2290:   PC_IS*         pcis;
2291:   PC_BDDC*       pcbddc;
2293:   Vec            work;

2296:   MatShellGetContext(fetidp_mat,&mat_ctx);
2297:   pcis = (PC_IS*)mat_ctx->pc->data;
2298:   pcbddc = (PC_BDDC*)mat_ctx->pc->data;

2300:   /* apply B_delta^T */
2301:   VecSet(pcis->vec1_B,0.);
2302:   VecScatterBegin(mat_ctx->l2g_lambda,fetidp_flux_sol,mat_ctx->lambda_local,INSERT_VALUES,SCATTER_REVERSE);
2303:   VecScatterEnd(mat_ctx->l2g_lambda,fetidp_flux_sol,mat_ctx->lambda_local,INSERT_VALUES,SCATTER_REVERSE);
2304:   MatMultTranspose(mat_ctx->B_delta,mat_ctx->lambda_local,pcis->vec1_B);
2305:   if (mat_ctx->l2g_p) {
2306:     VecScatterBegin(mat_ctx->l2g_p,fetidp_flux_sol,mat_ctx->vP,INSERT_VALUES,SCATTER_REVERSE);
2307:     VecScatterEnd(mat_ctx->l2g_p,fetidp_flux_sol,mat_ctx->vP,INSERT_VALUES,SCATTER_REVERSE);
2308:     MatMultAdd(mat_ctx->Bt_BB,mat_ctx->vP,pcis->vec1_B,pcis->vec1_B);
2309:   }

2311:   /* compute rhs for BDDC application */
2312:   VecAYPX(pcis->vec1_B,-1.0,mat_ctx->temp_solution_B);
2313:   if (pcbddc->switch_static) {
2314:     VecCopy(mat_ctx->temp_solution_D,pcis->vec1_D);
2315:     if (mat_ctx->l2g_p) {
2316:       VecScale(mat_ctx->vP,-1.);
2317:       MatMultAdd(mat_ctx->Bt_BI,mat_ctx->vP,pcis->vec1_D,pcis->vec1_D);
2318:     }
2319:   }

2321:   /* apply BDDC */
2322:   PetscMemzero(pcbddc->benign_p0,pcbddc->benign_n*sizeof(PetscScalar));
2323:   PCBDDCApplyInterfacePreconditioner(mat_ctx->pc,PETSC_FALSE);

2325:   /* put values into global vector */
2326:   if (pcbddc->ChangeOfBasisMatrix) work = pcbddc->work_change;
2327:   else work = standard_sol;
2328:   VecScatterBegin(pcis->global_to_B,pcis->vec1_B,work,INSERT_VALUES,SCATTER_REVERSE);
2329:   VecScatterEnd(pcis->global_to_B,pcis->vec1_B,work,INSERT_VALUES,SCATTER_REVERSE);
2330:   if (!pcbddc->switch_static) {
2331:     /* compute values into the interior if solved for the partially subassembled Schur complement */
2332:     MatMult(pcis->A_IB,pcis->vec1_B,pcis->vec1_D);
2333:     VecAYPX(pcis->vec1_D,-1.0,mat_ctx->temp_solution_D);
2334:     KSPSolve(pcbddc->ksp_D,pcis->vec1_D,pcis->vec1_D);
2335:   }

2337:   VecScatterBegin(pcis->global_to_D,pcis->vec1_D,work,INSERT_VALUES,SCATTER_REVERSE);
2338:   VecScatterEnd(pcis->global_to_D,pcis->vec1_D,work,INSERT_VALUES,SCATTER_REVERSE);
2339:   /* add p0 solution to final solution */
2340:   PCBDDCBenignGetOrSetP0(mat_ctx->pc,work,PETSC_FALSE);
2341:   if (pcbddc->ChangeOfBasisMatrix) {
2342:     MatMult(pcbddc->ChangeOfBasisMatrix,work,standard_sol);
2343:   }
2344:   PCPostSolve_BDDC(mat_ctx->pc,NULL,NULL,standard_sol);
2345:   if (mat_ctx->g2g_p) {
2346:     VecScatterBegin(mat_ctx->g2g_p,fetidp_flux_sol,standard_sol,INSERT_VALUES,SCATTER_REVERSE);
2347:     VecScatterEnd(mat_ctx->g2g_p,fetidp_flux_sol,standard_sol,INSERT_VALUES,SCATTER_REVERSE);
2348:   }
2349:   return(0);
2350: }

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

2355:    Collective

2357:    Input Parameters:
2358: +  fetidp_mat      - the FETI-DP matrix obtained by a call to PCBDDCCreateFETIDPOperators
2359: -  fetidp_flux_sol - the solution of the FETI-DP linear system

2361:    Output Parameters:
2362: .  standard_sol    - the solution defined on the physical domain

2364:    Level: developer

2366:    Notes:

2368: .seealso: PCBDDC, PCBDDCCreateFETIDPOperators, PCBDDCMatFETIDPGetRHS
2369: @*/
2370: PetscErrorCode PCBDDCMatFETIDPGetSolution(Mat fetidp_mat, Vec fetidp_flux_sol, Vec standard_sol)
2371: {
2372:   FETIDPMat_ctx  mat_ctx;

2379:   MatShellGetContext(fetidp_mat,&mat_ctx);
2380:   PetscUseMethod(mat_ctx->pc,"PCBDDCMatFETIDPGetSolution_C",(Mat,Vec,Vec),(fetidp_mat,fetidp_flux_sol,standard_sol));
2381:   return(0);
2382: }

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

2387:   FETIDPMat_ctx  fetidpmat_ctx;
2388:   Mat            newmat;
2389:   FETIDPPC_ctx   fetidppc_ctx;
2390:   PC             newpc;
2391:   MPI_Comm       comm;

2395:   PetscObjectGetComm((PetscObject)pc,&comm);
2396:   /* FETIDP linear matrix */
2397:   PCBDDCCreateFETIDPMatContext(pc,&fetidpmat_ctx);
2398:   fetidpmat_ctx->fully_redundant = fully_redundant;
2399:   PCBDDCSetupFETIDPMatContext(fetidpmat_ctx);
2400:   MatCreateShell(comm,fetidpmat_ctx->n,fetidpmat_ctx->n,fetidpmat_ctx->N,fetidpmat_ctx->N,fetidpmat_ctx,&newmat);
2401:   MatShellSetOperation(newmat,MATOP_MULT,(void (*)(void))FETIDPMatMult);
2402:   MatShellSetOperation(newmat,MATOP_MULT_TRANSPOSE,(void (*)(void))FETIDPMatMultTranspose);
2403:   MatShellSetOperation(newmat,MATOP_DESTROY,(void (*)(void))PCBDDCDestroyFETIDPMat);
2404:   MatSetOptionsPrefix(newmat,prefix);
2405:   MatAppendOptionsPrefix(newmat,"fetidp_");
2406:   MatSetUp(newmat);
2407:   /* FETIDP preconditioner */
2408:   PCBDDCCreateFETIDPPCContext(pc,&fetidppc_ctx);
2409:   PCBDDCSetupFETIDPPCContext(newmat,fetidppc_ctx);
2410:   PCCreate(comm,&newpc);
2411:   PCSetType(newpc,PCSHELL);
2412:   PCShellSetContext(newpc,fetidppc_ctx);
2413:   PCShellSetApply(newpc,FETIDPPCApply);
2414:   PCShellSetApplyTranspose(newpc,FETIDPPCApplyTranspose);
2415:   PCShellSetView(newpc,FETIDPPCView);
2416:   PCShellSetDestroy(newpc,PCBDDCDestroyFETIDPPC);
2417:   PCSetOperators(newpc,newmat,newmat);
2418:   PCSetOptionsPrefix(newpc,prefix);
2419:   PCAppendOptionsPrefix(newpc,"fetidp_");
2420:   /* return pointers for objects created */
2421:   *fetidp_mat = newmat;
2422:   *fetidp_pc = newpc;
2423:   return(0);
2424: }

2426: /*@
2427:  PCBDDCCreateFETIDPOperators - Create FETI-DP operators

2429:    Collective

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

2436:    Output Parameters:
2437: +  fetidp_mat - shell FETI-DP matrix object
2438: -  fetidp_pc  - shell Dirichlet preconditioner for FETI-DP matrix

2440:    Level: developer

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

2445: .seealso: PCBDDC, PCBDDCMatFETIDPGetRHS, PCBDDCMatFETIDPGetSolution
2446: @*/
2447: PetscErrorCode PCBDDCCreateFETIDPOperators(PC pc, PetscBool fully_redundant, const char *prefix, Mat *fetidp_mat, PC *fetidp_pc)
2448: {

2453:   if (pc->setupcalled) {
2454:     PetscUseMethod(pc,"PCBDDCCreateFETIDPOperators_C",(PC,PetscBool,const char*,Mat*,PC*),(pc,fully_redundant,prefix,fetidp_mat,fetidp_pc));
2455:   } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"You must call PCSetup_BDDC() first \n");
2456:   return(0);
2457: }
2458: /* -------------------------------------------------------------------------- */
2459: /*MC
2460:    PCBDDC - Balancing Domain Decomposition by Constraints.

2462:    An implementation of the BDDC preconditioner based on

2464: .vb
2465:    [1] C. R. Dohrmann. "An approximate BDDC preconditioner", Numerical Linear Algebra with Applications Volume 14, Issue 2, pages 149-168, March 2007
2466:    [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
2467:    [3] J. Mandel, B. Sousedik, C. R. Dohrmann. "Multispace and Multilevel BDDC", http://arxiv.org/abs/0712.3977
2468:    [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
2469: .ve

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

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

2475:    It also works with unsymmetric and indefinite problems.

2477:    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.

2479:    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).

2481:    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()
2482:    Additional information on dofs can be provided by using PCBDDCSetDofsSplitting(), PCBDDCSetDirichletBoundaries(), PCBDDCSetNeumannBoundaries(), and PCBDDCSetPrimalVerticesIS() and their local counterparts.

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

2486:    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.
2487:    User defined change of basis can be passed to PCBDDC by using PCBDDCSetChangeOfBasisMat()

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

2491:    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.

2493:    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.
2494:    Deluxe scaling is not supported yet for FETI-DP.

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

2498: .    -pc_bddc_use_vertices <true> - use or not vertices in primal space
2499: .    -pc_bddc_use_edges <true> - use or not edges in primal space
2500: .    -pc_bddc_use_faces <false> - use or not faces in primal space
2501: .    -pc_bddc_symmetric <true> - symmetric computation of primal basis functions. Specify false for unsymmetric problems
2502: .    -pc_bddc_use_change_of_basis <false> - use change of basis approach (on edges only)
2503: .    -pc_bddc_use_change_on_faces <false> - use change of basis approach on faces if change of basis has been requested
2504: .    -pc_bddc_switch_static <false> - switches from M_2 (default) to M_3 operator (see reference article [1])
2505: .    -pc_bddc_levels <0> - maximum number of levels for multilevel
2506: .    -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)
2507: .    -pc_bddc_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)
2508: .    -pc_bddc_use_deluxe_scaling <false> - use deluxe scaling
2509: .    -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)
2510: .    -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)
2511: -    -pc_bddc_check_level <0> - set verbosity level of debugging output

2513:    Options for Dirichlet, Neumann or coarse solver can be set with
2514: .vb
2515:       -pc_bddc_dirichlet_
2516:       -pc_bddc_neumann_
2517:       -pc_bddc_coarse_
2518: .ve
2519:    e.g -pc_bddc_dirichlet_ksp_type richardson -pc_bddc_dirichlet_pc_type gamg. PCBDDC uses by default KPSPREONLY and PCLU.

2521:    When using a multilevel approach, solvers' options at the N-th level (N > 1) can be specified as
2522: .vb
2523:       -pc_bddc_dirichlet_lN_
2524:       -pc_bddc_neumann_lN_
2525:       -pc_bddc_coarse_lN_
2526: .ve
2527:    Note that level number ranges from the finest (0) to the coarsest (N).
2528:    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.
2529: .vb
2530:      -pc_bddc_coarse_pc_bddc_adaptive_threshold 5 -pc_bddc_coarse_l1_pc_bddc_redistribute 3
2531: .ve
2532:    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

2534:    Level: intermediate

2536:    Developer notes:

2538:    Contributed by Stefano Zampini

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

2543: PETSC_EXTERN PetscErrorCode PCCreate_BDDC(PC pc)
2544: {
2545:   PetscErrorCode      ierr;
2546:   PC_BDDC             *pcbddc;

2549:   PetscNewLog(pc,&pcbddc);
2550:   pc->data = (void*)pcbddc;

2552:   /* create PCIS data structure */
2553:   PCISCreate(pc);

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

2558:   /* BDDC nonzero defaults */
2559:   pcbddc->use_local_adj             = PETSC_TRUE;
2560:   pcbddc->use_vertices              = PETSC_TRUE;
2561:   pcbddc->use_edges                 = PETSC_TRUE;
2562:   pcbddc->symmetric_primal          = PETSC_TRUE;
2563:   pcbddc->vertex_size               = 1;
2564:   pcbddc->recompute_topography      = PETSC_TRUE;
2565:   pcbddc->coarse_size               = -1;
2566:   pcbddc->use_exact_dirichlet_trick = PETSC_TRUE;
2567:   pcbddc->coarsening_ratio          = 8;
2568:   pcbddc->coarse_eqs_per_proc       = 1;
2569:   pcbddc->benign_compute_correction = PETSC_TRUE;
2570:   pcbddc->nedfield                  = -1;
2571:   pcbddc->nedglobal                 = PETSC_TRUE;
2572:   pcbddc->graphmaxcount             = PETSC_MAX_INT;
2573:   pcbddc->sub_schurs_layers         = -1;

2575:   /* function pointers */
2576:   pc->ops->apply               = PCApply_BDDC;
2577:   pc->ops->applytranspose      = PCApplyTranspose_BDDC;
2578:   pc->ops->setup               = PCSetUp_BDDC;
2579:   pc->ops->destroy             = PCDestroy_BDDC;
2580:   pc->ops->setfromoptions      = PCSetFromOptions_BDDC;
2581:   pc->ops->view                = PCView_BDDC;
2582:   pc->ops->applyrichardson     = 0;
2583:   pc->ops->applysymmetricleft  = 0;
2584:   pc->ops->applysymmetricright = 0;
2585:   pc->ops->presolve            = PCPreSolve_BDDC;
2586:   pc->ops->postsolve           = PCPostSolve_BDDC;
2587:   pc->ops->reset               = PCReset_BDDC;

2589:   /* composing function */
2590:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDiscreteGradient_C",PCBDDCSetDiscreteGradient_BDDC);
2591:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDivergenceMat_C",PCBDDCSetDivergenceMat_BDDC);
2592:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetChangeOfBasisMat_C",PCBDDCSetChangeOfBasisMat_BDDC);
2593:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetPrimalVerticesLocalIS_C",PCBDDCSetPrimalVerticesLocalIS_BDDC);
2594:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetPrimalVerticesIS_C",PCBDDCSetPrimalVerticesIS_BDDC);
2595:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetCoarseningRatio_C",PCBDDCSetCoarseningRatio_BDDC);
2596:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLevel_C",PCBDDCSetLevel_BDDC);
2597:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetUseExactDirichlet_C",PCBDDCSetUseExactDirichlet_BDDC);
2598:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLevels_C",PCBDDCSetLevels_BDDC);
2599:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDirichletBoundaries_C",PCBDDCSetDirichletBoundaries_BDDC);
2600:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDirichletBoundariesLocal_C",PCBDDCSetDirichletBoundariesLocal_BDDC);
2601:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetNeumannBoundaries_C",PCBDDCSetNeumannBoundaries_BDDC);
2602:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetNeumannBoundariesLocal_C",PCBDDCSetNeumannBoundariesLocal_BDDC);
2603:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetDirichletBoundaries_C",PCBDDCGetDirichletBoundaries_BDDC);
2604:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetDirichletBoundariesLocal_C",PCBDDCGetDirichletBoundariesLocal_BDDC);
2605:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetNeumannBoundaries_C",PCBDDCGetNeumannBoundaries_BDDC);
2606:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCGetNeumannBoundariesLocal_C",PCBDDCGetNeumannBoundariesLocal_BDDC);
2607:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDofsSplitting_C",PCBDDCSetDofsSplitting_BDDC);
2608:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetDofsSplittingLocal_C",PCBDDCSetDofsSplittingLocal_BDDC);
2609:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCSetLocalAdjacencyGraph_C",PCBDDCSetLocalAdjacencyGraph_BDDC);
2610:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCCreateFETIDPOperators_C",PCBDDCCreateFETIDPOperators_BDDC);
2611:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCMatFETIDPGetRHS_C",PCBDDCMatFETIDPGetRHS_BDDC);
2612:   PetscObjectComposeFunction((PetscObject)pc,"PCBDDCMatFETIDPGetSolution_C",PCBDDCMatFETIDPGetSolution_BDDC);
2613:   PetscObjectComposeFunction((PetscObject)pc,"PCPreSolveChangeRHS_C",PCPreSolveChangeRHS_BDDC);
2614:   return(0);
2615: }