xref: /petsc/include/petscpc.h (revision dce485f07e72743cf7fcd46e5ac18384fae07f70)
1 /*
2       Preconditioner module.
3 */
4 #if !defined(__PETSCPC_H)
5 #define __PETSCPC_H
6 #include "petscmat.h"
7 #include "petscdm.h"
8 PETSC_EXTERN_CXX_BEGIN
9 
10 extern PetscErrorCode   PCInitializePackage(const char[]);
11 
12 /*
13     PCList contains the list of preconditioners currently registered
14    These are added with the PCRegisterDynamic() macro
15 */
16 extern PetscFList PCList;
17 
18 /*S
19      PC - Abstract PETSc object that manages all preconditioners
20 
21    Level: beginner
22 
23   Concepts: preconditioners
24 
25 .seealso:  PCCreate(), PCSetType(), PCType (for list of available types)
26 S*/
27 typedef struct _p_PC* PC;
28 
29 /*E
30     PCType - String with the name of a PETSc preconditioner method or the creation function
31        with an optional dynamic library name, for example
32        http://www.mcs.anl.gov/petsc/lib.a:mypccreate()
33 
34    Level: beginner
35 
36    Notes: Click on the links below to see details on a particular solver
37 
38 .seealso: PCSetType(), PC, PCCreate()
39 E*/
40 #define PCType char*
41 #define PCNONE            "none"
42 #define PCJACOBI          "jacobi"
43 #define PCSOR             "sor"
44 #define PCLU              "lu"
45 #define PCSHELL           "shell"
46 #define PCBJACOBI         "bjacobi"
47 #define PCMG              "mg"
48 #define PCEISENSTAT       "eisenstat"
49 #define PCILU             "ilu"
50 #define PCICC             "icc"
51 #define PCASM             "asm"
52 #define PCGASM            "gasm"
53 #define PCKSP             "ksp"
54 #define PCCOMPOSITE       "composite"
55 #define PCREDUNDANT       "redundant"
56 #define PCSPAI            "spai"
57 #define PCNN              "nn"
58 #define PCCHOLESKY        "cholesky"
59 #define PCPBJACOBI        "pbjacobi"
60 #define PCMAT             "mat"
61 #define PCHYPRE           "hypre"
62 #define PCFIELDSPLIT      "fieldsplit"
63 #define PCTFS             "tfs"
64 #define PCML              "ml"
65 #define PCPROMETHEUS      "prometheus"
66 #define PCGALERKIN        "galerkin"
67 #define PCEXOTIC          "exotic"
68 #define PCOPENMP          "openmp"
69 #define PCSUPPORTGRAPH    "supportgraph"
70 #define PCASA             "asa"
71 #define PCCP              "cp"
72 #define PCBFBT            "bfbt"
73 #define PCLSC             "lsc"
74 #define PCPYTHON          "python"
75 #define PCPFMG            "pfmg"
76 #define PCSYSPFMG         "syspfmg"
77 #define PCREDISTRIBUTE    "redistribute"
78 #define PCSACUSP          "sacusp"
79 #define PCBICGSTABCUSP    "bicgstabcusp"
80 #define PCSVD             "svd"
81 
82 /* Logging support */
83 extern PetscClassId  PC_CLASSID;
84 
85 /*E
86     PCSide - If the preconditioner is to be applied to the left, right
87      or symmetrically around the operator.
88 
89    Level: beginner
90 
91 .seealso:
92 E*/
93 typedef enum { PC_LEFT,PC_RIGHT,PC_SYMMETRIC } PCSide;
94 extern const char *PCSides[];
95 
96 extern PetscErrorCode  PCCreate(MPI_Comm,PC*);
97 extern PetscErrorCode  PCSetType(PC,const PCType);
98 extern PetscErrorCode  PCSetUp(PC);
99 extern PetscErrorCode  PCSetUpOnBlocks(PC);
100 extern PetscErrorCode  PCApply(PC,Vec,Vec);
101 extern PetscErrorCode  PCApplySymmetricLeft(PC,Vec,Vec);
102 extern PetscErrorCode  PCApplySymmetricRight(PC,Vec,Vec);
103 extern PetscErrorCode  PCApplyBAorAB(PC,PCSide,Vec,Vec,Vec);
104 extern PetscErrorCode  PCApplyTranspose(PC,Vec,Vec);
105 extern PetscErrorCode  PCApplyTransposeExists(PC,PetscBool *);
106 extern PetscErrorCode  PCApplyBAorABTranspose(PC,PCSide,Vec,Vec,Vec);
107 
108 /*E
109     PCRichardsonConvergedReason - reason a PCApplyRichardson method terminates
110 
111    Level: advanced
112 
113    Notes: this must match finclude/petscpc.h and the KSPConvergedReason values in petscksp.h
114 
115 .seealso: PCApplyRichardson()
116 E*/
117 typedef enum {
118               PCRICHARDSON_CONVERGED_RTOL               =  2,
119               PCRICHARDSON_CONVERGED_ATOL               =  3,
120               PCRICHARDSON_CONVERGED_ITS                =  4,
121               PCRICHARDSON_DIVERGED_DTOL                = -4} PCRichardsonConvergedReason;
122 
123 extern PetscErrorCode  PCApplyRichardson(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool ,PetscInt*,PCRichardsonConvergedReason*);
124 extern PetscErrorCode  PCApplyRichardsonExists(PC,PetscBool *);
125 extern PetscErrorCode  PCSetInitialGuessNonzero(PC,PetscBool );
126 
127 extern PetscErrorCode  PCRegisterDestroy(void);
128 extern PetscErrorCode  PCRegisterAll(const char[]);
129 extern PetscBool  PCRegisterAllCalled;
130 
131 extern PetscErrorCode  PCRegister(const char[],const char[],const char[],PetscErrorCode(*)(PC));
132 
133 /*MC
134    PCRegisterDynamic - Adds a method to the preconditioner package.
135 
136    Synopsis:
137    PetscErrorCode PCRegisterDynamic(const char *name_solver,const char *path,const char *name_create,PetscErrorCode (*routine_create)(PC))
138 
139    Not collective
140 
141    Input Parameters:
142 +  name_solver - name of a new user-defined solver
143 .  path - path (either absolute or relative) the library containing this solver
144 .  name_create - name of routine to create method context
145 -  routine_create - routine to create method context
146 
147    Notes:
148    PCRegisterDynamic() may be called multiple times to add several user-defined preconditioners.
149 
150    If dynamic libraries are used, then the fourth input argument (routine_create)
151    is ignored.
152 
153    Sample usage:
154 .vb
155    PCRegisterDynamic("my_solver","/home/username/my_lib/lib/libO/solaris/mylib",
156               "MySolverCreate",MySolverCreate);
157 .ve
158 
159    Then, your solver can be chosen with the procedural interface via
160 $     PCSetType(pc,"my_solver")
161    or at runtime via the option
162 $     -pc_type my_solver
163 
164    Level: advanced
165 
166    Notes: ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},  or ${any environmental variable}
167            occuring in pathname will be replaced with appropriate values.
168          If your function is not being put into a shared library then use PCRegister() instead
169 
170 .keywords: PC, register
171 
172 .seealso: PCRegisterAll(), PCRegisterDestroy()
173 M*/
174 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
175 #define PCRegisterDynamic(a,b,c,d) PCRegister(a,b,c,0)
176 #else
177 #define PCRegisterDynamic(a,b,c,d) PCRegister(a,b,c,d)
178 #endif
179 
180 extern PetscErrorCode  PCReset(PC);
181 extern PetscErrorCode  PCDestroy(PC);
182 extern PetscErrorCode  PCSetFromOptions(PC);
183 extern PetscErrorCode  PCGetType(PC,const PCType*);
184 
185 extern PetscErrorCode  PCFactorGetMatrix(PC,Mat*);
186 extern PetscErrorCode  PCSetModifySubMatrices(PC,PetscErrorCode(*)(PC,PetscInt,const IS[],const IS[],Mat[],void*),void*);
187 extern PetscErrorCode  PCModifySubMatrices(PC,PetscInt,const IS[],const IS[],Mat[],void*);
188 
189 extern PetscErrorCode  PCSetOperators(PC,Mat,Mat,MatStructure);
190 extern PetscErrorCode  PCGetOperators(PC,Mat*,Mat*,MatStructure*);
191 extern PetscErrorCode  PCGetOperatorsSet(PC,PetscBool *,PetscBool *);
192 
193 extern PetscErrorCode  PCView(PC,PetscViewer);
194 
195 extern PetscErrorCode  PCSetOptionsPrefix(PC,const char[]);
196 extern PetscErrorCode  PCAppendOptionsPrefix(PC,const char[]);
197 extern PetscErrorCode  PCGetOptionsPrefix(PC,const char*[]);
198 
199 extern PetscErrorCode  PCComputeExplicitOperator(PC,Mat*);
200 
201 /*
202       These are used to provide extra scaling of preconditioned
203    operator for time-stepping schemes like in SUNDIALS
204 */
205 extern PetscErrorCode  PCGetDiagonalScale(PC,PetscBool *);
206 extern PetscErrorCode  PCDiagonalScaleLeft(PC,Vec,Vec);
207 extern PetscErrorCode  PCDiagonalScaleRight(PC,Vec,Vec);
208 extern PetscErrorCode  PCSetDiagonalScale(PC,Vec);
209 
210 /* ------------- options specific to particular preconditioners --------- */
211 
212 extern PetscErrorCode  PCJacobiSetUseRowMax(PC);
213 extern PetscErrorCode  PCJacobiSetUseRowSum(PC);
214 extern PetscErrorCode  PCJacobiSetUseAbs(PC);
215 extern PetscErrorCode  PCSORSetSymmetric(PC,MatSORType);
216 extern PetscErrorCode  PCSORSetOmega(PC,PetscReal);
217 extern PetscErrorCode  PCSORSetIterations(PC,PetscInt,PetscInt);
218 
219 extern PetscErrorCode  PCEisenstatSetOmega(PC,PetscReal);
220 extern PetscErrorCode  PCEisenstatNoDiagonalScaling(PC);
221 
222 #define USE_PRECONDITIONER_MATRIX 0
223 #define USE_TRUE_MATRIX           1
224 extern PetscErrorCode  PCBJacobiSetUseTrueLocal(PC);
225 extern PetscErrorCode  PCBJacobiSetTotalBlocks(PC,PetscInt,const PetscInt[]);
226 extern PetscErrorCode  PCBJacobiSetLocalBlocks(PC,PetscInt,const PetscInt[]);
227 
228 extern PetscErrorCode  PCKSPSetUseTrue(PC);
229 
230 extern PetscErrorCode  PCShellSetApply(PC,PetscErrorCode (*)(PC,Vec,Vec));
231 extern PetscErrorCode  PCShellSetApplyBA(PC,PetscErrorCode (*)(PC,PCSide,Vec,Vec,Vec));
232 extern PetscErrorCode  PCShellSetApplyTranspose(PC,PetscErrorCode (*)(PC,Vec,Vec));
233 extern PetscErrorCode  PCShellSetSetUp(PC,PetscErrorCode (*)(PC));
234 extern PetscErrorCode  PCShellSetApplyRichardson(PC,PetscErrorCode (*)(PC,Vec,Vec,Vec,PetscReal,PetscReal,PetscReal,PetscInt,PetscBool ,PetscInt*,PCRichardsonConvergedReason*));
235 extern PetscErrorCode  PCShellSetView(PC,PetscErrorCode (*)(PC,PetscViewer));
236 extern PetscErrorCode  PCShellSetDestroy(PC,PetscErrorCode (*)(PC));
237 extern PetscErrorCode  PCShellGetContext(PC,void**);
238 extern PetscErrorCode  PCShellSetContext(PC,void*);
239 extern PetscErrorCode  PCShellSetName(PC,const char[]);
240 extern PetscErrorCode  PCShellGetName(PC,char*[]);
241 
242 extern PetscErrorCode  PCFactorSetZeroPivot(PC,PetscReal);
243 
244 extern PetscErrorCode  PCFactorSetShiftType(PC,MatFactorShiftType);
245 extern PetscErrorCode  PCFactorSetShiftAmount(PC,PetscReal);
246 
247 extern PetscErrorCode  PCFactorSetMatSolverPackage(PC,const MatSolverPackage);
248 extern PetscErrorCode  PCFactorGetMatSolverPackage(PC,const MatSolverPackage*);
249 extern PetscErrorCode  PCFactorSetUpMatSolverPackage(PC);
250 
251 extern PetscErrorCode  PCFactorSetFill(PC,PetscReal);
252 extern PetscErrorCode  PCFactorSetColumnPivot(PC,PetscReal);
253 extern PetscErrorCode  PCFactorReorderForNonzeroDiagonal(PC,PetscReal);
254 
255 extern PetscErrorCode  PCFactorSetMatOrderingType(PC,const MatOrderingType);
256 extern PetscErrorCode  PCFactorSetReuseOrdering(PC,PetscBool );
257 extern PetscErrorCode  PCFactorSetReuseFill(PC,PetscBool );
258 extern PetscErrorCode  PCFactorSetUseInPlace(PC);
259 extern PetscErrorCode  PCFactorSetAllowDiagonalFill(PC);
260 extern PetscErrorCode  PCFactorSetPivotInBlocks(PC,PetscBool );
261 
262 extern PetscErrorCode  PCFactorSetLevels(PC,PetscInt);
263 extern PetscErrorCode  PCFactorSetDropTolerance(PC,PetscReal,PetscReal,PetscInt);
264 
265 extern PetscErrorCode  PCASMSetLocalSubdomains(PC,PetscInt,IS[],IS[]);
266 extern PetscErrorCode  PCASMSetTotalSubdomains(PC,PetscInt,IS[],IS[]);
267 extern PetscErrorCode  PCASMSetOverlap(PC,PetscInt);
268 extern PetscErrorCode  PCASMSetSortIndices(PC,PetscBool );
269 
270 /*E
271     PCASMType - Type of additive Schwarz method to use
272 
273 $  PC_ASM_BASIC - symmetric version where residuals from the ghost points are used
274 $                 and computed values in ghost regions are added together. Classical
275 $                 standard additive Schwarz
276 $  PC_ASM_RESTRICT - residuals from ghost points are used but computed values in ghost
277 $                    region are discarded. Default
278 $  PC_ASM_INTERPOLATE - residuals from ghost points are not used, computed values in ghost
279 $                       region are added back in
280 $  PC_ASM_NONE - ghost point residuals are not used, computed ghost values are discarded
281 $                not very good.
282 
283    Level: beginner
284 
285 .seealso: PCASMSetType()
286 E*/
287 typedef enum {PC_ASM_BASIC = 3,PC_ASM_RESTRICT = 1,PC_ASM_INTERPOLATE = 2,PC_ASM_NONE = 0} PCASMType;
288 extern const char *PCASMTypes[];
289 
290 extern PetscErrorCode  PCASMSetType(PC,PCASMType);
291 extern PetscErrorCode  PCASMCreateSubdomains(Mat,PetscInt,IS*[]);
292 extern PetscErrorCode  PCASMDestroySubdomains(PetscInt,IS[],IS[]);
293 extern PetscErrorCode  PCASMCreateSubdomains2D(PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt*,IS**,IS**);
294 extern PetscErrorCode  PCASMGetLocalSubdomains(PC,PetscInt*,IS*[],IS*[]);
295 extern PetscErrorCode  PCASMGetLocalSubmatrices(PC,PetscInt*,Mat*[]);
296 
297 /*E
298     PCGASMType - Type of generalized additive Schwarz method to use (differs from ASM in allowing multiple processors per domain)
299 
300 $  PC_GASM_BASIC - symmetric version where residuals from the ghost points are used
301 $                 and computed values in ghost regions are added together. Classical
302 $                 standard additive Schwarz
303 $  PC_GASM_RESTRICT - residuals from ghost points are used but computed values in ghost
304 $                    region are discarded. Default
305 $  PC_GASM_INTERPOLATE - residuals from ghost points are not used, computed values in ghost
306 $                       region are added back in
307 $  PC_GASM_NONE - ghost point residuals are not used, computed ghost values are discarded
308 $                not very good.
309 
310    Level: beginner
311 
312 .seealso: PCGASMSetType()
313 E*/
314 typedef enum {PC_GASM_BASIC = 3,PC_GASM_RESTRICT = 1,PC_GASM_INTERPOLATE = 2,PC_GASM_NONE = 0} PCGASMType;
315 extern const char *PCGASMTypes[];
316 
317 extern PetscErrorCode  PCGASMSetLocalSubdomains(PC,PetscInt,IS[],IS[]);
318 extern PetscErrorCode  PCGASMSetTotalSubdomains(PC,PetscInt);
319 extern PetscErrorCode  PCGASMSetOverlap(PC,PetscInt);
320 extern PetscErrorCode  PCGASMSetSortIndices(PC,PetscBool );
321 
322 extern PetscErrorCode  PCGASMSetType(PC,PCGASMType);
323 extern PetscErrorCode  PCGASMCreateSubdomains(Mat,PetscInt,IS*[]);
324 extern PetscErrorCode  PCGASMDestroySubdomains(PetscInt,IS[],IS[]);
325 extern PetscErrorCode  PCGASMCreateSubdomains2D(PC,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt*,IS**,IS**);
326 extern PetscErrorCode  PCGASMGetLocalSubdomains(PC,PetscInt*,IS*[],IS*[]);
327 extern PetscErrorCode  PCGASMGetLocalSubmatrices(PC,PetscInt*,Mat*[]);
328 
329 /*E
330     PCCompositeType - Determines how two or more preconditioner are composed
331 
332 $  PC_COMPOSITE_ADDITIVE - results from application of all preconditioners are added together
333 $  PC_COMPOSITE_MULTIPLICATIVE - preconditioners are applied sequentially to the residual freshly
334 $                                computed after the previous preconditioner application
335 $  PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE - preconditioners are applied sequentially to the residual freshly
336 $                                computed from first preconditioner to last and then back (Use only for symmetric matrices and preconditions)
337 $  PC_COMPOSITE_SPECIAL - This is very special for a matrix of the form alpha I + R + S
338 $                         where first preconditioner is built from alpha I + S and second from
339 $                         alpha I + R
340 
341    Level: beginner
342 
343 .seealso: PCCompositeSetType()
344 E*/
345 typedef enum {PC_COMPOSITE_ADDITIVE,PC_COMPOSITE_MULTIPLICATIVE,PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE,PC_COMPOSITE_SPECIAL,PC_COMPOSITE_SCHUR} PCCompositeType;
346 extern const char *PCCompositeTypes[];
347 
348 extern PetscErrorCode  PCCompositeSetUseTrue(PC);
349 extern PetscErrorCode  PCCompositeSetType(PC,PCCompositeType);
350 extern PetscErrorCode  PCCompositeAddPC(PC,PCType);
351 extern PetscErrorCode  PCCompositeGetPC(PC,PetscInt,PC *);
352 extern PetscErrorCode  PCCompositeSpecialSetAlpha(PC,PetscScalar);
353 
354 extern PetscErrorCode  PCRedundantSetNumber(PC,PetscInt);
355 extern PetscErrorCode  PCRedundantSetScatter(PC,VecScatter,VecScatter);
356 extern PetscErrorCode  PCRedundantGetOperators(PC,Mat*,Mat*);
357 
358 extern PetscErrorCode  PCSPAISetEpsilon(PC,double);
359 extern PetscErrorCode  PCSPAISetNBSteps(PC,PetscInt);
360 extern PetscErrorCode  PCSPAISetMax(PC,PetscInt);
361 extern PetscErrorCode  PCSPAISetMaxNew(PC,PetscInt);
362 extern PetscErrorCode  PCSPAISetBlockSize(PC,PetscInt);
363 extern PetscErrorCode  PCSPAISetCacheSize(PC,PetscInt);
364 extern PetscErrorCode  PCSPAISetVerbose(PC,PetscInt);
365 extern PetscErrorCode  PCSPAISetSp(PC,PetscInt);
366 
367 extern PetscErrorCode  PCHYPRESetType(PC,const char[]);
368 extern PetscErrorCode  PCHYPREGetType(PC,const char*[]);
369 extern PetscErrorCode  PCBJacobiGetLocalBlocks(PC,PetscInt*,const PetscInt*[]);
370 extern PetscErrorCode  PCBJacobiGetTotalBlocks(PC,PetscInt*,const PetscInt*[]);
371 
372 extern PetscErrorCode  PCFieldSplitSetFields(PC,const char[],PetscInt,const PetscInt*);
373 extern PetscErrorCode  PCFieldSplitSetType(PC,PCCompositeType);
374 extern PetscErrorCode  PCFieldSplitSetBlockSize(PC,PetscInt);
375 extern PetscErrorCode  PCFieldSplitSetIS(PC,const char[],IS);
376 
377 /*E
378     PCFieldSplitSchurPreType - Determines how to precondition Schur complement
379 
380     Level: intermediate
381 
382 .seealso: PCFieldSplitSchurPrecondition()
383 E*/
384 typedef enum {PC_FIELDSPLIT_SCHUR_PRE_SELF,PC_FIELDSPLIT_SCHUR_PRE_DIAG,PC_FIELDSPLIT_SCHUR_PRE_USER} PCFieldSplitSchurPreType;
385 extern const char *const PCFieldSplitSchurPreTypes[];
386 
387 extern PetscErrorCode  PCFieldSplitSchurPrecondition(PC,PCFieldSplitSchurPreType,Mat);
388 extern PetscErrorCode  PCFieldSplitGetSchurBlocks(PC,Mat*,Mat*,Mat*,Mat*);
389 
390 extern PetscErrorCode  PCGalerkinSetRestriction(PC,Mat);
391 extern PetscErrorCode  PCGalerkinSetInterpolation(PC,Mat);
392 
393 extern PetscErrorCode  PCSetCoordinates(PC,PetscInt,PetscReal*);
394 extern PetscErrorCode  PCSASetVectors(PC,PetscInt,PetscReal *);
395 
396 extern PetscErrorCode  PCPythonSetType(PC,const char[]);
397 
398 extern PetscErrorCode  PCSetDM(PC,DM);
399 extern PetscErrorCode  PCGetDM(PC,DM*);
400 
401 extern PetscErrorCode  PCBiCGStabCUSPSetTolerance(PC,PetscReal);
402 extern PetscErrorCode  PCBiCGStabCUSPSetIterations(PC,PetscInt);
403 extern PetscErrorCode  PCBiCGStabCUSPSetUseVerboseMonitor(PC,PetscBool);
404 
405 PETSC_EXTERN_CXX_END
406 
407 #endif /* __PETSCPC_H */
408