xref: /petsc/src/binding/petsc4py/src/petsc4py/PETSc/petscpc.pxi (revision 834855d6effb0d027771461c8e947ee1ce5a1e17)
1cdef extern from * nogil:
2
3    ctypedef const char* PetscPCType "PCType"
4    PetscPCType PCNONE
5    PetscPCType PCJACOBI
6    PetscPCType PCSOR
7    PetscPCType PCLU
8    PetscPCType PCQR
9    PetscPCType PCSHELL
10    PetscPCType PCBJACOBI
11    PetscPCType PCMG
12    PetscPCType PCEISENSTAT
13    PetscPCType PCILU
14    PetscPCType PCICC
15    PetscPCType PCASM
16    PetscPCType PCGASM
17    PetscPCType PCKSP
18    PetscPCType PCCOMPOSITE
19    PetscPCType PCREDUNDANT
20    PetscPCType PCSPAI
21    PetscPCType PCNN
22    PetscPCType PCCHOLESKY
23    PetscPCType PCPBJACOBI
24    PetscPCType PCVPBJACOBI
25    PetscPCType PCMAT
26    PetscPCType PCHYPRE
27    PetscPCType PCPARMS
28    PetscPCType PCFIELDSPLIT
29    PetscPCType PCTFS
30    PetscPCType PCML
31    PetscPCType PCGALERKIN
32    PetscPCType PCEXOTIC
33    PetscPCType PCCP
34    PetscPCType PCLSC
35    PetscPCType PCPYTHON
36    PetscPCType PCPFMG
37    PetscPCType PCSYSPFMG
38    PetscPCType PCREDISTRIBUTE
39    PetscPCType PCSVD
40    PetscPCType PCGAMG
41    PetscPCType PCCHOWILUVIENNACL
42    PetscPCType PCROWSCALINGVIENNACL
43    PetscPCType PCSAVIENNACL
44    PetscPCType PCBDDC
45    PetscPCType PCKACZMARZ
46    PetscPCType PCTELESCOPE
47    PetscPCType PCPATCH
48    PetscPCType PCLMVM
49    PetscPCType PCHMG
50    PetscPCType PCDEFLATION
51    PetscPCType PCHPDDM
52    PetscPCType PCH2OPUS
53
54    ctypedef enum PetscPCSide "PCSide":
55        PC_SIDE_DEFAULT
56        PC_LEFT
57        PC_RIGHT
58        PC_SYMMETRIC
59
60    ctypedef enum PetscPCASMType "PCASMType":
61        PC_ASM_BASIC
62        PC_ASM_RESTRICT
63        PC_ASM_INTERPOLATE
64        PC_ASM_NONE
65
66    ctypedef enum PetscPCGASMType "PCGASMType":
67        PC_GASM_BASIC
68        PC_GASM_RESTRICT
69        PC_GASM_INTERPOLATE
70        PC_GASM_NONE
71
72    ctypedef enum PetscPCMGType "PCMGType":
73        PC_MG_MULTIPLICATIVE
74        PC_MG_ADDITIVE
75        PC_MG_FULL
76        PC_MG_KASKADE
77
78    ctypedef enum PetscPCMGCycleType "PCMGCycleType":
79        PC_MG_CYCLE_V
80        PC_MG_CYCLE_W
81
82    ctypedef const char* PetscPCGAMGType "PCGAMGType"
83    PetscPCGAMGType PCGAMGAGG
84    PetscPCGAMGType PCGAMGGEO
85    PetscPCGAMGType PCGAMGCLASSICAL
86
87    ctypedef const char* PetscPCHYPREType "const char*"
88
89    ctypedef enum PetscPCCompositeType "PCCompositeType":
90        PC_COMPOSITE_ADDITIVE
91        PC_COMPOSITE_MULTIPLICATIVE
92        PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE
93        PC_COMPOSITE_SPECIAL
94        PC_COMPOSITE_SCHUR
95
96    ctypedef enum PetscPCFieldSplitSchurPreType "PCFieldSplitSchurPreType":
97        PC_FIELDSPLIT_SCHUR_PRE_SELF
98        PC_FIELDSPLIT_SCHUR_PRE_SELFP
99        PC_FIELDSPLIT_SCHUR_PRE_A11
100        PC_FIELDSPLIT_SCHUR_PRE_USER
101        PC_FIELDSPLIT_SCHUR_PRE_FULL
102
103    ctypedef enum PetscPCFieldSplitSchurFactType "PCFieldSplitSchurFactType":
104        PC_FIELDSPLIT_SCHUR_FACT_DIAG
105        PC_FIELDSPLIT_SCHUR_FACT_LOWER
106        PC_FIELDSPLIT_SCHUR_FACT_UPPER
107        PC_FIELDSPLIT_SCHUR_FACT_FULL
108
109    ctypedef enum PetscPCPatchConstructType "PCPatchConstructType":
110        PC_PATCH_STAR
111        PC_PATCH_VANKA
112        PC_PATCH_PARDECOMP
113        PC_PATCH_USER
114        PC_PATCH_PYTHON
115
116    ctypedef enum PetscPCHPDDMCoarseCorrectionType "PCHPDDMCoarseCorrectionType":
117        PC_HPDDM_COARSE_CORRECTION_DEFLATED
118        PC_HPDDM_COARSE_CORRECTION_ADDITIVE
119        PC_HPDDM_COARSE_CORRECTION_BALANCED
120        PC_HPDDM_COARSE_CORRECTION_NONE
121
122    ctypedef enum PetscPCDeflationSpaceType "PCDeflationSpaceType":
123        PC_DEFLATION_SPACE_HAAR
124        PC_DEFLATION_SPACE_DB2
125        PC_DEFLATION_SPACE_DB4
126        PC_DEFLATION_SPACE_DB8
127        PC_DEFLATION_SPACE_DB16
128        PC_DEFLATION_SPACE_BIORTH22
129        PC_DEFLATION_SPACE_MEYER
130        PC_DEFLATION_SPACE_AGGREGATION
131        PC_DEFLATION_SPACE_USER
132
133    ctypedef enum PetscPCFailedReason "PCFailedReason":
134        PC_SETUP_ERROR
135        PC_NOERROR
136        PC_FACTOR_STRUCT_ZEROPIVOT
137        PC_FACTOR_NUMERIC_ZEROPIVOT
138        PC_FACTOR_OUTMEMORY
139        PC_FACTOR_OTHER
140        PC_SUBPC_ERROR
141
142    PetscErrorCode PCCreate(MPI_Comm, PetscPC*)
143    PetscErrorCode PCDestroy(PetscPC*)
144    PetscErrorCode PCView(PetscPC, PetscViewer)
145
146    PetscErrorCode PCSetType(PetscPC, PetscPCType)
147    PetscErrorCode PCGetType(PetscPC, PetscPCType*)
148
149    PetscErrorCode PCSetOptionsPrefix(PetscPC, char[])
150    PetscErrorCode PCAppendOptionsPrefix(PetscPC, char[])
151    PetscErrorCode PCGetOptionsPrefix(PetscPC, char*[])
152    PetscErrorCode PCSetFromOptions(PetscPC)
153
154    PetscErrorCode PCSetFailedReason(PetscPC, PetscPCFailedReason)
155    PetscErrorCode PCGetFailedReason(PetscPC, PetscPCFailedReason*)
156
157    PetscErrorCode PCSetUp(PetscPC)
158    PetscErrorCode PCReset(PetscPC)
159    PetscErrorCode PCSetUpOnBlocks(PetscPC)
160
161    PetscErrorCode PCApply(PetscPC, PetscVec, PetscVec)
162    PetscErrorCode PCMatApply(PetscPC, PetscMat, PetscMat)
163    PetscErrorCode PCApplyTranspose(PetscPC, PetscVec, PetscVec)
164    PetscErrorCode PCMatApplyTranspose(PetscPC, PetscMat, PetscMat)
165    PetscErrorCode PCApplySymmetricLeft(PetscPC, PetscVec, PetscVec)
166    PetscErrorCode PCApplySymmetricRight(PetscPC, PetscVec, PetscVec)
167    PetscErrorCode PCApplyRichardson(PetscPC, PetscVec, PetscVec, PetscVec, PetscReal, PetscReal, PetscReal, PetscInt)
168    PetscErrorCode PCApplyBAorAB(PetscPC, PetscPCSide, PetscVec, PetscVec, PetscVec)
169    PetscErrorCode PCApplyBAorABTranspose(PetscPC, PetscPCSide, PetscVec, PetscVec, PetscVec)
170
171    PetscErrorCode PCGetDM(PetscPC, PetscDM*)
172    PetscErrorCode PCSetDM(PetscPC, PetscDM)
173
174    PetscErrorCode PCSetOperators(PetscPC, PetscMat, PetscMat)
175    PetscErrorCode PCGetOperators(PetscPC, PetscMat*, PetscMat*)
176    PetscErrorCode PCGetOperatorsSet(PetscPC, PetscBool*, PetscBool*)
177    PetscErrorCode PCSetCoordinates(PetscPC, PetscInt, PetscInt, PetscReal[])
178    PetscErrorCode PCSetUseAmat(PetscPC, PetscBool)
179    PetscErrorCode PCGetUseAmat(PetscPC, PetscBool*)
180
181    PetscErrorCode PCComputeExplicitOperator(PetscPC, PetscMat*)
182
183    PetscErrorCode PCDiagonalScale(PetscPC, PetscBool*)
184    PetscErrorCode PCDiagonalScaleLeft(PetscPC, PetscVec, PetscVec)
185    PetscErrorCode PCDiagonalScaleRight(PetscPC, PetscVec, PetscVec)
186    PetscErrorCode PCDiagonalScaleSet(PetscPC, PetscVec)
187
188    PetscErrorCode PCBJacobiGetSubKSP(PetscPC, PetscInt*, PetscInt*, PetscKSP*[])
189
190    PetscErrorCode PCASMSetType(PetscPC, PetscPCASMType)
191    PetscErrorCode PCASMSetOverlap(PetscPC, PetscInt)
192    PetscErrorCode PCASMSetLocalSubdomains(PetscPC, PetscInt, PetscIS[], PetscIS[])
193    PetscErrorCode PCASMSetTotalSubdomains(PetscPC, PetscInt, PetscIS[], PetscIS[])
194    PetscErrorCode PCASMGetSubKSP(PetscPC, PetscInt*, PetscInt*, PetscKSP*[])
195    PetscErrorCode PCASMSetSortIndices(PetscPC, PetscBool)
196
197    PetscErrorCode PCGASMSetType(PetscPC, PetscPCGASMType)
198    PetscErrorCode PCGASMSetOverlap(PetscPC, PetscInt)
199
200    PetscErrorCode PCGAMGSetType(PetscPC, PetscPCGAMGType)
201    PetscErrorCode PCGAMGSetNlevels(PetscPC, PetscInt)
202    PetscErrorCode PCGAMGSetNSmooths(PetscPC, PetscInt)
203
204    PetscErrorCode PCHYPREGetType(PetscPC, PetscPCHYPREType*)
205    PetscErrorCode PCHYPRESetType(PetscPC, PetscPCHYPREType)
206    PetscErrorCode PCHYPRESetDiscreteCurl(PetscPC, PetscMat)
207    PetscErrorCode PCHYPRESetDiscreteGradient(PetscPC, PetscMat)
208    PetscErrorCode PCHYPRESetAlphaPoissonMatrix(PetscPC, PetscMat)
209    PetscErrorCode PCHYPRESetBetaPoissonMatrix(PetscPC, PetscMat)
210    PetscErrorCode PCHYPRESetEdgeConstantVectors(PetscPC, PetscVec, PetscVec, PetscVec)
211    PetscErrorCode PCHYPRESetInterpolations(PetscPC, PetscInt, PetscMat, PetscMat[], PetscMat, PetscMat[])
212    PetscErrorCode PCHYPREAMSSetInteriorNodes(PetscPC, PetscVec)
213
214    PetscErrorCode PCFactorGetMatrix(PetscPC, PetscMat*)
215    PetscErrorCode PCFactorSetZeroPivot(PetscPC, PetscReal)
216    PetscErrorCode PCFactorSetShiftType(PetscPC, PetscMatFactorShiftType)
217    PetscErrorCode PCFactorSetShiftAmount(PetscPC, PetscReal)
218    PetscErrorCode PCFactorSetMatSolverType(PetscPC, PetscMatSolverType)
219    PetscErrorCode PCFactorGetMatSolverType(PetscPC, PetscMatSolverType*)
220    PetscErrorCode PCFactorSetUpMatSolverType(PetscPC)
221    PetscErrorCode PCFactorSetFill(PetscPC, PetscReal)
222    PetscErrorCode PCFactorSetColumnPivot(PetscPC, PetscReal)
223    PetscErrorCode PCFactorReorderForNonzeroDiagonal(PetscPC, PetscReal)
224    PetscErrorCode PCFactorSetMatOrderingType(PetscPC, PetscMatOrderingType)
225    PetscErrorCode PCFactorSetReuseOrdering(PetscPC, PetscBool)
226    PetscErrorCode PCFactorSetReuseFill(PetscPC, PetscBool)
227    PetscErrorCode PCFactorSetUseInPlace(PetscPC)
228    PetscErrorCode PCFactorSetAllowDiagonalFill(PetscPC)
229    PetscErrorCode PCFactorSetPivotInBlocks(PetscPC, PetscBool)
230    PetscErrorCode PCFactorSetLevels(PetscPC, PetscInt)
231    PetscErrorCode PCFactorSetDropTolerance(PetscPC, PetscReal, PetscReal, PetscInt)
232
233    PetscErrorCode PCFieldSplitSetType(PetscPC, PetscPCCompositeType)
234    PetscErrorCode PCFieldSplitSetBlockSize(PetscPC, PetscInt)
235    PetscErrorCode PCFieldSplitSetFields(PetscPC, char[], PetscInt, PetscInt*, PetscInt*)
236    PetscErrorCode PCFieldSplitSetIS(PetscPC, char[], PetscIS)
237    PetscErrorCode PCFieldSplitGetSubKSP(PetscPC, PetscInt*, PetscKSP*[])
238    PetscErrorCode PCFieldSplitGetIS(PetscPC, char[], PetscIS*)
239    PetscErrorCode PCFieldSplitSchurGetSubKSP(PetscPC, PetscInt*, PetscKSP*[])
240    PetscErrorCode PCFieldSplitSetSchurPre(PetscPC, PetscPCFieldSplitSchurPreType, PetscMat)
241    PetscErrorCode PCFieldSplitSetSchurFactType(PetscPC, PetscPCFieldSplitSchurFactType)
242
243    PetscErrorCode PCCompositeSetType(PetscPC, PetscPCCompositeType)
244    PetscErrorCode PCCompositeGetPC(PetscPC, PetscInt, PetscPC*)
245    PetscErrorCode PCCompositeAddPCType(PetscPC, PetscPCType)
246    PetscErrorCode PCCompositeAddPC(PetscPC, PetscPC)
247
248    PetscErrorCode PCKSPGetKSP(PetscPC, PetscKSP*)
249
250    PetscErrorCode PCSetReusePreconditioner(PetscPC, PetscBool)
251
252    # --- MG ---
253    PetscErrorCode PCMGSetType(PetscPC, PetscPCMGType)
254    PetscErrorCode PCMGGetType(PetscPC, PetscPCMGType*)
255    PetscErrorCode PCMGSetInterpolation(PetscPC, PetscInt, PetscMat)
256    PetscErrorCode PCMGGetInterpolation(PetscPC, PetscInt, PetscMat*)
257    PetscErrorCode PCMGSetRestriction(PetscPC, PetscInt, PetscMat)
258    PetscErrorCode PCMGGetRestriction(PetscPC, PetscInt, PetscMat*)
259    PetscErrorCode PCMGSetRScale(PetscPC, PetscInt, PetscVec)
260    PetscErrorCode PCMGGetRScale(PetscPC, PetscInt, PetscVec*)
261    PetscErrorCode PCMGGetSmoother(PetscPC, PetscInt, PetscKSP*)
262    PetscErrorCode PCMGGetSmootherUp(PetscPC, PetscInt, PetscKSP*)
263    PetscErrorCode PCMGGetSmootherDown(PetscPC, PetscInt, PetscKSP*)
264    PetscErrorCode PCMGGetCoarseSolve(PetscPC, PetscKSP*)
265    PetscErrorCode PCMGSetRhs(PetscPC, PetscInt, PetscVec)
266    PetscErrorCode PCMGSetX(PetscPC, PetscInt, PetscVec)
267    PetscErrorCode PCMGSetR(PetscPC, PetscInt, PetscVec)
268    PetscErrorCode PCMGSetLevels(PetscPC, PetscInt, MPI_Comm*)
269    PetscErrorCode PCMGGetLevels(PetscPC, PetscInt*)
270    PetscErrorCode PCMGSetCycleType(PetscPC, PetscPCMGCycleType)
271    PetscErrorCode PCMGSetCycleTypeOnLevel(PetscPC, PetscInt, PetscPCMGCycleType)
272
273    # --- BDDC ---
274    PetscErrorCode PCBDDCSetDiscreteGradient(PetscPC, PetscMat, PetscInt, PetscInt, PetscBool, PetscBool)
275    PetscErrorCode PCBDDCSetDivergenceMat(PetscPC, PetscMat, PetscBool, PetscIS)
276    PetscErrorCode PCBDDCSetChangeOfBasisMat(PetscPC, PetscMat, PetscBool)
277    PetscErrorCode PCBDDCSetPrimalVerticesIS(PetscPC, PetscIS)
278    PetscErrorCode PCBDDCSetPrimalVerticesLocalIS(PetscPC, PetscIS)
279    PetscErrorCode PCBDDCSetCoarseningRatio(PetscPC, PetscInt)
280    PetscErrorCode PCBDDCSetLevels(PetscPC, PetscInt)
281    PetscErrorCode PCBDDCSetDirichletBoundaries(PetscPC, PetscIS)
282    PetscErrorCode PCBDDCSetDirichletBoundariesLocal(PetscPC, PetscIS)
283    PetscErrorCode PCBDDCSetNeumannBoundaries(PetscPC, PetscIS)
284    PetscErrorCode PCBDDCSetNeumannBoundariesLocal(PetscPC, PetscIS)
285    PetscErrorCode PCBDDCSetDofsSplitting(PetscPC, PetscInt, PetscIS[])
286    PetscErrorCode PCBDDCSetDofsSplittingLocal(PetscPC, PetscInt, PetscIS[])
287    PetscErrorCode PCBDDCSetLocalAdjacencyGraph(PetscPC, PetscInt, const PetscInt*, const PetscInt*, PetscCopyMode)
288
289    # --- Patch ---
290    ctypedef PetscErrorCode (*PetscPCPatchComputeOperator)(PetscPC,
291                                                           PetscInt,
292                                                           PetscVec,
293                                                           PetscMat,
294                                                           PetscIS,
295                                                           PetscInt,
296                                                           const PetscInt*,
297                                                           const PetscInt*,
298                                                           void*) except PETSC_ERR_PYTHON
299    ctypedef PetscErrorCode (*PetscPCPatchComputeFunction)(PetscPC,
300                                                           PetscInt,
301                                                           PetscVec,
302                                                           PetscVec,
303                                                           PetscIS,
304                                                           PetscInt,
305                                                           const PetscInt*,
306                                                           const PetscInt*,
307                                                           void*) except PETSC_ERR_PYTHON
308    ctypedef PetscErrorCode (*PetscPCPatchConstructOperator)(PetscPC,
309                                                             PetscInt*,
310                                                             PetscIS**,
311                                                             PetscIS*,
312                                                             void*) except PETSC_ERR_PYTHON
313    PetscErrorCode PCPatchGetSubKSP(PetscPC, PetscInt*, PetscKSP*[])
314    PetscErrorCode PCPatchSetCellNumbering(PetscPC, PetscSection)
315    PetscErrorCode PCPatchSetDiscretisationInfo(PetscPC, PetscInt, PetscDM*, PetscInt*, PetscInt*, const PetscInt**, const PetscInt*, PetscInt, const PetscInt*, PetscInt, const PetscInt*)
316    PetscErrorCode PCPatchSetComputeOperator(PetscPC, PetscPCPatchComputeOperator, void*)
317    PetscErrorCode PCPatchSetComputeOperatorInteriorFacets(PetscPC, PetscPCPatchComputeOperator, void*)
318    PetscErrorCode PCPatchSetComputeFunction(PetscPC, PetscPCPatchComputeFunction, void*)
319    PetscErrorCode PCPatchSetComputeFunctionInteriorFacets(PetscPC, PetscPCPatchComputeFunction, void*)
320    PetscErrorCode PCPatchSetConstructType(PetscPC, PetscPCPatchConstructType, PetscPCPatchConstructOperator, void*)
321
322    # --- HPDDM ---
323    ctypedef PetscErrorCode (*PetscPCHPDDMAuxiliaryMat)(PetscMat,
324                                                        PetscReal,
325                                                        PetscVec,
326                                                        PetscVec,
327                                                        PetscReal,
328                                                        PetscIS,
329                                                        void*) except PETSC_ERR_PYTHON
330    PetscErrorCode PCHPDDMSetAuxiliaryMat(PetscPC, PetscIS, PetscMat, PetscPCHPDDMAuxiliaryMat, void*)
331    PetscErrorCode PCHPDDMSetRHSMat(PetscPC, PetscMat)
332    PetscErrorCode PCHPDDMGetComplexities(PetscPC, PetscReal*, PetscReal*)
333    PetscErrorCode PCHPDDMHasNeumannMat(PetscPC, PetscBool)
334    PetscErrorCode PCHPDDMSetCoarseCorrectionType(PetscPC, PetscPCHPDDMCoarseCorrectionType)
335    PetscErrorCode PCHPDDMGetCoarseCorrectionType(PetscPC, PetscPCHPDDMCoarseCorrectionType*)
336    PetscErrorCode PCHPDDMGetSTShareSubKSP(PetscPC, PetscBool*)
337    PetscErrorCode PCHPDDMSetDeflationMat(PetscPC, PetscIS, PetscMat)
338
339    # --- SPAI ---
340    PetscErrorCode PCSPAISetEpsilon(PetscPC, PetscReal)
341    PetscErrorCode PCSPAISetNBSteps(PetscPC, PetscInt)
342    PetscErrorCode PCSPAISetMax(PetscPC, PetscInt)
343    PetscErrorCode PCSPAISetMaxNew(PetscPC, PetscInt)
344    PetscErrorCode PCSPAISetBlockSize(PetscPC, PetscInt)
345    PetscErrorCode PCSPAISetCacheSize(PetscPC, PetscInt)
346    PetscErrorCode PCSPAISetVerbose(PetscPC, PetscInt)
347    PetscErrorCode PCSPAISetSp(PetscPC, PetscInt)
348
349    # --- DEFLATION ---
350    PetscErrorCode PCDeflationSetInitOnly(PetscPC, PetscBool)
351    PetscErrorCode PCDeflationSetLevels(PetscPC, PetscInt)
352    PetscErrorCode PCDeflationSetReductionFactor(PetscPC, PetscInt)
353    PetscErrorCode PCDeflationSetCorrectionFactor(PetscPC, PetscScalar)
354    PetscErrorCode PCDeflationSetSpaceToCompute(PetscPC, PetscPCDeflationSpaceType, PetscInt)
355    PetscErrorCode PCDeflationSetSpace(PetscPC, PetscMat, PetscBool)
356    PetscErrorCode PCDeflationSetProjectionNullSpaceMat(PetscPC, PetscMat)
357    PetscErrorCode PCDeflationSetCoarseMat(PetscPC, PetscMat)
358    PetscErrorCode PCDeflationGetCoarseKSP(PetscPC, PetscKSP*)
359    PetscErrorCode PCDeflationGetPC(PetscPC, PetscPC*)
360
361    # --- PYTHON ---
362    PetscErrorCode PCPythonSetType(PetscPC, char[])
363    PetscErrorCode PCPythonGetType(PetscPC, char*[])
364
365# --------------------------------------------------------------------
366
367cdef inline PC ref_PC(PetscPC pc):
368    cdef PC ob = <PC> PC()
369    ob.pc = pc
370    CHKERR(PetscINCREF(ob.obj))
371    return ob
372
373cdef PetscErrorCode PCPatch_ComputeOperator(
374    PetscPC pc,
375    PetscInt point,
376    PetscVec vec,
377    PetscMat mat,
378    PetscIS cells,
379    PetscInt ndof,
380    const PetscInt *dofmap,
381    const PetscInt *dofmapWithAll,
382    void *ctx) except PETSC_ERR_PYTHON with gil:
383    cdef Vec Vec = ref_Vec(vec)
384    cdef Mat Mat = ref_Mat(mat)
385    cdef PC Pc = ref_PC(pc)
386    cdef IS Is = ref_IS(cells)
387    cdef object context = Pc.get_attr("__patch_compute_operator__")
388    if context is None and ctx != NULL: context = <object>ctx
389    assert context is not None and type(context) is tuple
390    (op, args, kargs) = context
391    cdef PetscInt[:] pydofs = <PetscInt[:ndof]>dofmap
392    cdef PetscInt[:] pydofsWithAll
393    if dofmapWithAll != NULL:
394        pydofsWithAll = <PetscInt[:ndof]>dofmapWithAll
395        dofsall = asarray(pydofsWithAll)
396    else:
397        dofsall = None
398    op(Pc, toInt(point), Vec, Mat, Is, asarray(pydofs), dofsall, *args, **kargs)
399    return PETSC_SUCCESS
400
401cdef PetscErrorCode PCPatch_ComputeFunction(
402    PetscPC pc,
403    PetscInt point,
404    PetscVec vec,
405    PetscVec out,
406    PetscIS cells,
407    PetscInt ndof,
408    const PetscInt *dofmap,
409    const PetscInt *dofmapWithAll,
410    void *ctx) except PETSC_ERR_PYTHON with gil:
411    cdef Vec Out = ref_Vec(out)
412    cdef Vec Vec = ref_Vec(vec)
413    cdef PC Pc = ref_PC(pc)
414    cdef IS Is = ref_IS(cells)
415    cdef object context = Pc.get_attr("__patch_compute_function__")
416    if context is None and ctx != NULL: context = <object>ctx
417    assert context is not None and type(context) is tuple
418    (op, args, kargs) = context
419    cdef PetscInt[:] pydofs = <PetscInt[:ndof]>dofmap
420    cdef PetscInt[:] pydofsWithAll = <PetscInt[:ndof]>dofmapWithAll
421    op(Pc, toInt(point), Vec, Out, Is, asarray(pydofs), asarray(pydofsWithAll), *args, **kargs)
422    return PETSC_SUCCESS
423
424cdef PetscErrorCode PCPatch_ComputeOperatorInteriorFacets(
425    PetscPC pc,
426    PetscInt point,
427    PetscVec vec,
428    PetscMat mat,
429    PetscIS facets,
430    PetscInt ndof,
431    const PetscInt *dofmap,
432    const PetscInt *dofmapWithAll,
433    void *ctx) except PETSC_ERR_PYTHON with gil:
434    cdef Vec Vec = ref_Vec(vec)
435    cdef Mat Mat = ref_Mat(mat)
436    cdef PC Pc = ref_PC(pc)
437    cdef IS Is = ref_IS(facets)
438    cdef object context = Pc.get_attr("__patch_compute_operator_interior_facets__")
439    if context is None and ctx != NULL: context = <object>ctx
440    assert context is not None and type(context) is tuple
441    (op, args, kargs) = context
442    cdef PetscInt[:] pydofs = <PetscInt[:ndof]>dofmap
443    cdef PetscInt[:] pydofsWithAll
444    if dofmapWithAll != NULL:
445        pydofsWithAll = <PetscInt[:ndof]>dofmapWithAll
446        dofsall = asarray(pydofsWithAll)
447    else:
448        dofsall = None
449    op(Pc, toInt(point), Vec, Mat, Is, asarray(pydofs), dofsall, *args, **kargs)
450    return PETSC_SUCCESS
451
452cdef PetscErrorCode PCPatch_ComputeFunctionInteriorFacets(
453    PetscPC pc,
454    PetscInt point,
455    PetscVec vec,
456    PetscVec out,
457    PetscIS facets,
458    PetscInt ndof,
459    const PetscInt *dofmap,
460    const PetscInt *dofmapWithAll,
461    void *ctx) except PETSC_ERR_PYTHON with gil:
462    cdef Vec Out = ref_Vec(out)
463    cdef Vec Vec = ref_Vec(vec)
464    cdef PC Pc = ref_PC(pc)
465    cdef IS Is = ref_IS(facets)
466    cdef object context = Pc.get_attr("__patch_compute_function_interior_facets__")
467    if context is None and ctx != NULL: context = <object>ctx
468    assert context is not None and type(context) is tuple
469    (op, args, kargs) = context
470    cdef PetscInt[:] pydofs = <PetscInt[:ndof]>dofmap
471    cdef PetscInt[:] pydofsWithAll = <PetscInt[:ndof]>dofmapWithAll
472    op(Pc, toInt(point), Vec, Out, Is, asarray(pydofs), asarray(pydofsWithAll), *args, **kargs)
473    return PETSC_SUCCESS
474
475cdef PetscErrorCode PCPatch_UserConstructOperator(
476    PetscPC pc,
477    PetscInt *n,
478    PetscIS **userIS,
479    PetscIS *userIterationSet,
480    void *ctx) except PETSC_ERR_PYTHON with gil:
481    cdef PC Pc = ref_PC(pc)
482    cdef PetscInt i
483    cdef object context = Pc.get_attr("__patch_construction_operator__")
484    if context is None and ctx != NULL: context = <object>ctx
485    assert context is not None and type(context) is tuple
486    (op, args, kargs) = context
487    (patches, iterationSet) = op(Pc, *args, **kargs)
488    n[0] = <PetscInt>len(patches)
489    CHKERR(PetscMalloc(<size_t>n[0]*sizeof(PetscIS), userIS))
490    for i in range(n[0]):
491        userIS[0][i] = (<IS?>patches[i]).iset
492        CHKERR(PetscINCREF(<PetscObject*>&userIS[0][i]))
493    userIterationSet[0] = (<IS?>iterationSet).iset
494    CHKERR(PetscINCREF(<PetscObject*>&userIterationSet[0]))
495    return PETSC_SUCCESS
496