diff --git a/firedrake/cython/dmcommon.pyx b/firedrake/cython/dmcommon.pyx index db194b04b7..999d08f82e 100644 --- a/firedrake/cython/dmcommon.pyx +++ b/firedrake/cython/dmcommon.pyx @@ -3480,7 +3480,7 @@ cdef int DMPlexGetAdjacency_Facet_Support(PETSc.PetscDM dm, numAdj += 1 # Too many adjacent points for the provided output array. if numAdj > maxAdjSize: - SETERR(77) + CHKERR(PETSC_ERR_LIB) CHKERR(DMPlexRestoreTransitiveClosure(dm, point, PETSC_TRUE, &closureSize, &closure)) adjSize[0] = numAdj return 0 @@ -3565,7 +3565,7 @@ cdef int DMPlexGetAdjacency_Closure_Star_Ridge( numAdj += 1 # Too many adjacent points for the provided output array. if numAdj > maxAdjSize: - SETERR(77) + CHKERR(PETSC_ERR_LIB) CHKERR(DMPlexRestoreTransitiveClosure(dm, point, PETSC_TRUE, &closureSize, &closure)) CHKERR(DMPlexRestoreTransitiveClosure(dm, p, PETSC_FALSE, &starSize, &star)) adjSize[0] = numAdj diff --git a/firedrake/cython/extrusion_numbering.pyx b/firedrake/cython/extrusion_numbering.pyx index 86167ed20b..e2a989de1e 100644 --- a/firedrake/cython/extrusion_numbering.pyx +++ b/firedrake/cython/extrusion_numbering.pyx @@ -291,7 +291,7 @@ def layer_extents(PETSc.DM dm, PETSc.Section cell_numbering, tmp = numpy.copy(layer_extents) # To get owned points correct, we do a reduction over the SF. - CHKERR(MPI_Op_create(extents_reduce, 4, &EXTENTS_REDUCER)) + CHKERRMPI(MPI_Op_create(extents_reduce, 4, &EXTENTS_REDUCER)) CHKERR(PetscSFReduceBegin(sf.sf, contig.ob_mpi, layer_extents.data, tmp.data, @@ -300,7 +300,7 @@ def layer_extents(PETSc.DM dm, PETSc.Section cell_numbering, layer_extents.data, tmp.data, EXTENTS_REDUCER)) - CHKERR(MPI_Op_free(&EXTENTS_REDUCER)) + CHKERRMPI(MPI_Op_free(&EXTENTS_REDUCER)) layer_extents[:] = tmp[:] # OK, now we have the correct extents for owned points, but # potentially incorrect extents for ghost points, so do a SF Bcast diff --git a/firedrake/cython/petschdr.pxi b/firedrake/cython/petschdr.pxi index a94de11e56..fa9d10c300 100644 --- a/firedrake/cython/petschdr.pxi +++ b/firedrake/cython/petschdr.pxi @@ -1,4 +1,5 @@ cimport petsc4py.PETSc as PETSc +from petsc4py.PETSc cimport CHKERR, CHKERRMPI cimport mpi4py.MPI as MPI cimport numpy as np @@ -21,13 +22,16 @@ cdef extern from "petsc.h": PETSC_SCALAR, PETSC_COMPLEX, PETSC_DATATYPE_UNKNOWN + ctypedef enum PetscErrorCode: + PETSC_SUCCESS + PETSC_ERR_LIB cdef extern from "petscsys.h" nogil: - int PetscMalloc1(PetscInt,void*) - int PetscMalloc2(PetscInt,void*,PetscInt,void*) - int PetscFree(void*) - int PetscFree2(void*,void*) - int PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]) + PetscErrorCode PetscMalloc1(PetscInt,void*) + PetscErrorCode PetscMalloc2(PetscInt,void*,PetscInt,void*) + PetscErrorCode PetscFree(void*) + PetscErrorCode PetscFree2(void*,void*) + PetscErrorCode PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]) cdef extern from "petscdmtypes.h" nogil: ctypedef enum PetscDMPolytopeType "DMPolytopeType": @@ -51,90 +55,90 @@ cdef extern from "petscdmtypes.h" nogil: DM_NUM_POLYTOPES cdef extern from "petscdmplex.h" nogil: - int DMPlexGetHeightStratum(PETSc.PetscDM,PetscInt,PetscInt*,PetscInt*) - int DMPlexGetDepthStratum(PETSc.PetscDM,PetscInt,PetscInt*,PetscInt*) - int DMPlexGetPointHeight(PETSc.PetscDM,PetscInt,PetscInt*) - int DMPlexGetPointDepth(PETSc.PetscDM,PetscInt,PetscInt*) - - int DMPlexGetChart(PETSc.PetscDM,PetscInt*,PetscInt*) - int DMPlexGetConeSize(PETSc.PetscDM,PetscInt,PetscInt*) - int DMPlexGetCone(PETSc.PetscDM,PetscInt,PetscInt*[]) - int DMPlexGetConeOrientation(PETSc.PetscDM,PetscInt,PetscInt*[]) - int DMPlexGetSupportSize(PETSc.PetscDM,PetscInt,PetscInt*) - int DMPlexGetSupport(PETSc.PetscDM,PetscInt,PetscInt*[]) - int DMPlexGetMaxSizes(PETSc.PetscDM,PetscInt*,PetscInt*) - - int DMPlexGetTransitiveClosure(PETSc.PetscDM,PetscInt,PetscBool,PetscInt *,PetscInt *[]) - int DMPlexRestoreTransitiveClosure(PETSc.PetscDM,PetscInt,PetscBool,PetscInt *,PetscInt *[]) - int DMPlexDistributeData(PETSc.PetscDM,PETSc.PetscSF,PETSc.PetscSection,MPI.MPI_Datatype,void*,PETSc.PetscSection,void**) - int DMPlexSetAdjacencyUser(PETSc.PetscDM,int(*)(PETSc.PetscDM,PetscInt,PetscInt*,PetscInt[],void*),void*) - int DMPlexCreatePointNumbering(PETSc.PetscDM,PETSc.PetscIS*) - int DMPlexLabelComplete(PETSc.PetscDM, PETSc.PetscDMLabel) - int DMPlexDistributeOverlap(PETSc.PetscDM,PetscInt,PETSc.PetscSF*,PETSc.PetscDM*) - - int DMPlexFilter(PETSc.PetscDM,PETSc.PetscDMLabel,PetscInt,PetscBool,PetscBool,PETSc.PetscSF*,PETSc.PetscDM*) - int DMPlexGetSubpointIS(PETSc.PetscDM,PETSc.PetscIS*) - int DMPlexGetSubpointMap(PETSc.PetscDM,PETSc.PetscDMLabel*) - int DMPlexSetSubpointMap(PETSc.PetscDM,PETSc.PetscDMLabel) - - int DMPlexSetCellType(PETSc.PetscDM,PetscInt,PetscDMPolytopeType) - int DMPlexGetCellType(PETSc.PetscDM,PetscInt,PetscDMPolytopeType*) + PetscErrorCode DMPlexGetHeightStratum(PETSc.PetscDM,PetscInt,PetscInt*,PetscInt*) + PetscErrorCode DMPlexGetDepthStratum(PETSc.PetscDM,PetscInt,PetscInt*,PetscInt*) + PetscErrorCode DMPlexGetPointHeight(PETSc.PetscDM,PetscInt,PetscInt*) + PetscErrorCode DMPlexGetPointDepth(PETSc.PetscDM,PetscInt,PetscInt*) + + PetscErrorCode DMPlexGetChart(PETSc.PetscDM,PetscInt*,PetscInt*) + PetscErrorCode DMPlexGetConeSize(PETSc.PetscDM,PetscInt,PetscInt*) + PetscErrorCode DMPlexGetCone(PETSc.PetscDM,PetscInt,PetscInt*[]) + PetscErrorCode DMPlexGetConeOrientation(PETSc.PetscDM,PetscInt,PetscInt*[]) + PetscErrorCode DMPlexGetSupportSize(PETSc.PetscDM,PetscInt,PetscInt*) + PetscErrorCode DMPlexGetSupport(PETSc.PetscDM,PetscInt,PetscInt*[]) + PetscErrorCode DMPlexGetMaxSizes(PETSc.PetscDM,PetscInt*,PetscInt*) + + PetscErrorCode DMPlexGetTransitiveClosure(PETSc.PetscDM,PetscInt,PetscBool,PetscInt *,PetscInt *[]) + PetscErrorCode DMPlexRestoreTransitiveClosure(PETSc.PetscDM,PetscInt,PetscBool,PetscInt *,PetscInt *[]) + PetscErrorCode DMPlexDistributeData(PETSc.PetscDM,PETSc.PetscSF,PETSc.PetscSection,MPI.MPI_Datatype,void*,PETSc.PetscSection,void**) + PetscErrorCode DMPlexSetAdjacencyUser(PETSc.PetscDM,int(*)(PETSc.PetscDM,PetscInt,PetscInt*,PetscInt[],void*),void*) + PetscErrorCode DMPlexCreatePointNumbering(PETSc.PetscDM,PETSc.PetscIS*) + PetscErrorCode DMPlexLabelComplete(PETSc.PetscDM, PETSc.PetscDMLabel) + PetscErrorCode DMPlexDistributeOverlap(PETSc.PetscDM,PetscInt,PETSc.PetscSF*,PETSc.PetscDM*) + + PetscErrorCode DMPlexFilter(PETSc.PetscDM,PETSc.PetscDMLabel,PetscInt,PetscBool,PetscBool,PETSc.PetscSF*,PETSc.PetscDM*) + PetscErrorCode DMPlexGetSubpointIS(PETSc.PetscDM,PETSc.PetscIS*) + PetscErrorCode DMPlexGetSubpointMap(PETSc.PetscDM,PETSc.PetscDMLabel*) + PetscErrorCode DMPlexSetSubpointMap(PETSc.PetscDM,PETSc.PetscDMLabel) + + PetscErrorCode DMPlexSetCellType(PETSc.PetscDM,PetscInt,PetscDMPolytopeType) + PetscErrorCode DMPlexGetCellType(PETSc.PetscDM,PetscInt,PetscDMPolytopeType*) cdef extern from "petscdmlabel.h" nogil: struct _n_DMLabel ctypedef _n_DMLabel* DMLabel "DMLabel" - int DMLabelCreateIndex(DMLabel, PetscInt, PetscInt) - int DMLabelDestroyIndex(DMLabel) - int DMLabelDestroy(DMLabel*) - int DMLabelHasPoint(DMLabel, PetscInt, PetscBool*) - int DMLabelSetValue(DMLabel, PetscInt, PetscInt) - int DMLabelGetValue(DMLabel, PetscInt, PetscInt*) - int DMLabelClearValue(DMLabel, PetscInt, PetscInt) - int DMLabelGetStratumSize(DMLabel, PetscInt, PetscInt*) - int DMLabelGetStratumIS(DMLabel, PetscInt, PETSc.PetscIS*) + PetscErrorCode DMLabelCreateIndex(DMLabel, PetscInt, PetscInt) + PetscErrorCode DMLabelDestroyIndex(DMLabel) + PetscErrorCode DMLabelDestroy(DMLabel*) + PetscErrorCode DMLabelHasPoint(DMLabel, PetscInt, PetscBool*) + PetscErrorCode DMLabelSetValue(DMLabel, PetscInt, PetscInt) + PetscErrorCode DMLabelGetValue(DMLabel, PetscInt, PetscInt*) + PetscErrorCode DMLabelClearValue(DMLabel, PetscInt, PetscInt) + PetscErrorCode DMLabelGetStratumSize(DMLabel, PetscInt, PetscInt*) + PetscErrorCode DMLabelGetStratumIS(DMLabel, PetscInt, PETSc.PetscIS*) cdef extern from "petscdm.h" nogil: - int DMCreateLabel(PETSc.PetscDM,char[]) - int DMGetLabel(PETSc.PetscDM,char[],DMLabel*) - int DMGetPointSF(PETSc.PetscDM,PETSc.PetscSF*) - int DMSetLabelValue(PETSc.PetscDM,char[],PetscInt,PetscInt) - int DMGetLabelValue(PETSc.PetscDM,char[],PetscInt,PetscInt*) + PetscErrorCode DMCreateLabel(PETSc.PetscDM,char[]) + PetscErrorCode DMGetLabel(PETSc.PetscDM,char[],DMLabel*) + PetscErrorCode DMGetPointSF(PETSc.PetscDM,PETSc.PetscSF*) + PetscErrorCode DMSetLabelValue(PETSc.PetscDM,char[],PetscInt,PetscInt) + PetscErrorCode DMGetLabelValue(PETSc.PetscDM,char[],PetscInt,PetscInt*) cdef extern from "petscdmswarm.h" nogil: - int DMSwarmGetLocalSize(PETSc.PetscDM,PetscInt*) - int DMSwarmGetCellDM(PETSc.PetscDM, PETSc.PetscDM*) - int DMSwarmGetCellDMActive(PETSc.PetscDM, PETSc.PetscDMSwarmCellDM*) - int DMSwarmCellDMGetCellID(PETSc.PetscDMSwarmCellDM, const char *[]) - int DMSwarmGetField(PETSc.PetscDM,const char[],PetscInt*,PetscDataType*,void**) - int DMSwarmRestoreField(PETSc.PetscDM,const char[],PetscInt*,PetscDataType*,void**) + PetscErrorCode DMSwarmGetLocalSize(PETSc.PetscDM,PetscInt*) + PetscErrorCode DMSwarmGetCellDM(PETSc.PetscDM, PETSc.PetscDM*) + PetscErrorCode DMSwarmGetCellDMActive(PETSc.PetscDM, PETSc.PetscDMSwarmCellDM*) + PetscErrorCode DMSwarmCellDMGetCellID(PETSc.PetscDMSwarmCellDM, const char *[]) + PetscErrorCode DMSwarmGetField(PETSc.PetscDM,const char[],PetscInt*,PetscDataType*,void**) + PetscErrorCode DMSwarmRestoreField(PETSc.PetscDM,const char[],PetscInt*,PetscDataType*,void**) cdef extern from "petscvec.h" nogil: - int VecGetArray(PETSc.PetscVec,PetscScalar**) - int VecRestoreArray(PETSc.PetscVec,PetscScalar**) - int VecGetArrayRead(PETSc.PetscVec,const PetscScalar**) - int VecRestoreArrayRead(PETSc.PetscVec,const PetscScalar**) + PetscErrorCode VecGetArray(PETSc.PetscVec,PetscScalar**) + PetscErrorCode VecRestoreArray(PETSc.PetscVec,PetscScalar**) + PetscErrorCode VecGetArrayRead(PETSc.PetscVec,const PetscScalar**) + PetscErrorCode VecRestoreArrayRead(PETSc.PetscVec,const PetscScalar**) cdef extern from "petscis.h" nogil: - int PetscSectionGetOffset(PETSc.PetscSection,PetscInt,PetscInt*) - int PetscSectionGetDof(PETSc.PetscSection,PetscInt,PetscInt*) - int PetscSectionSetDof(PETSc.PetscSection,PetscInt,PetscInt) - int PetscSectionSetFieldDof(PETSc.PetscSection,PetscInt,PetscInt,PetscInt) - int PetscSectionGetFieldDof(PETSc.PetscSection,PetscInt,PetscInt,PetscInt*) - int PetscSectionGetConstraintDof(PETSc.PetscSection,PetscInt,PetscInt*) - int PetscSectionSetConstraintDof(PETSc.PetscSection,PetscInt,PetscInt) - int PetscSectionSetConstraintIndices(PETSc.PetscSection,PetscInt, PetscInt[]) - int PetscSectionGetConstraintIndices(PETSc.PetscSection,PetscInt, const PetscInt**) - int PetscSectionGetMaxDof(PETSc.PetscSection,PetscInt*) - int PetscSectionSetPermutation(PETSc.PetscSection,PETSc.PetscIS) - int ISGetIndices(PETSc.PetscIS,PetscInt*[]) - int ISGetSize(PETSc.PetscIS,PetscInt*) - int ISRestoreIndices(PETSc.PetscIS,PetscInt*[]) - int ISGeneralSetIndices(PETSc.PetscIS,PetscInt,PetscInt[],PetscCopyMode) - int ISLocalToGlobalMappingCreateIS(PETSc.PetscIS,PETSc.PetscLGMap*) - int ISLocalToGlobalMappingGetSize(PETSc.PetscLGMap,PetscInt*) - int ISLocalToGlobalMappingGetBlockIndices(PETSc.PetscLGMap, const PetscInt**) - int ISLocalToGlobalMappingRestoreBlockIndices(PETSc.PetscLGMap, const PetscInt**) - int ISDestroy(PETSc.PetscIS*) + PetscErrorCode PetscSectionGetOffset(PETSc.PetscSection,PetscInt,PetscInt*) + PetscErrorCode PetscSectionGetDof(PETSc.PetscSection,PetscInt,PetscInt*) + PetscErrorCode PetscSectionSetDof(PETSc.PetscSection,PetscInt,PetscInt) + PetscErrorCode PetscSectionSetFieldDof(PETSc.PetscSection,PetscInt,PetscInt,PetscInt) + PetscErrorCode PetscSectionGetFieldDof(PETSc.PetscSection,PetscInt,PetscInt,PetscInt*) + PetscErrorCode PetscSectionGetConstraintDof(PETSc.PetscSection,PetscInt,PetscInt*) + PetscErrorCode PetscSectionSetConstraintDof(PETSc.PetscSection,PetscInt,PetscInt) + PetscErrorCode PetscSectionSetConstraintIndices(PETSc.PetscSection,PetscInt, PetscInt[]) + PetscErrorCode PetscSectionGetConstraintIndices(PETSc.PetscSection,PetscInt, const PetscInt**) + PetscErrorCode PetscSectionGetMaxDof(PETSc.PetscSection,PetscInt*) + PetscErrorCode PetscSectionSetPermutation(PETSc.PetscSection,PETSc.PetscIS) + PetscErrorCode ISGetIndices(PETSc.PetscIS,PetscInt*[]) + PetscErrorCode ISGetSize(PETSc.PetscIS,PetscInt*) + PetscErrorCode ISRestoreIndices(PETSc.PetscIS,PetscInt*[]) + PetscErrorCode ISGeneralSetIndices(PETSc.PetscIS,PetscInt,PetscInt[],PetscCopyMode) + PetscErrorCode ISLocalToGlobalMappingCreateIS(PETSc.PetscIS,PETSc.PetscLGMap*) + PetscErrorCode ISLocalToGlobalMappingGetSize(PETSc.PetscLGMap,PetscInt*) + PetscErrorCode ISLocalToGlobalMappingGetBlockIndices(PETSc.PetscLGMap, const PetscInt**) + PetscErrorCode ISLocalToGlobalMappingRestoreBlockIndices(PETSc.PetscLGMap, const PetscInt**) + PetscErrorCode ISDestroy(PETSc.PetscIS*) cdef extern from "petscsf.h" nogil: struct PetscSFNode_: @@ -142,14 +146,14 @@ cdef extern from "petscsf.h" nogil: PetscInt index ctypedef PetscSFNode_ PetscSFNode "PetscSFNode" - int PetscSFGetGraph(PETSc.PetscSF,PetscInt*,PetscInt*,PetscInt**,PetscSFNode**) - int PetscSFSetGraph(PETSc.PetscSF,PetscInt,PetscInt,PetscInt*,PetscCopyMode,PetscSFNode*,PetscCopyMode) - int PetscSFBcastBegin(PETSc.PetscSF,MPI.MPI_Datatype,const void*, void*,) - int PetscSFBcastEnd(PETSc.PetscSF,MPI.MPI_Datatype,const void*, void*) - int PetscSFReduceBegin(PETSc.PetscSF,MPI.MPI_Datatype,const void*, void*,MPI.MPI_Op) - int PetscSFReduceEnd(PETSc.PetscSF,MPI.MPI_Datatype,const void*, void*,MPI.MPI_Op) + PetscErrorCode PetscSFGetGraph(PETSc.PetscSF,PetscInt*,PetscInt*,PetscInt**,PetscSFNode**) + PetscErrorCode PetscSFSetGraph(PETSc.PetscSF,PetscInt,PetscInt,PetscInt*,PetscCopyMode,PetscSFNode*,PetscCopyMode) + PetscErrorCode PetscSFBcastBegin(PETSc.PetscSF,MPI.MPI_Datatype,const void*, void*,) + PetscErrorCode PetscSFBcastEnd(PETSc.PetscSF,MPI.MPI_Datatype,const void*, void*) + PetscErrorCode PetscSFReduceBegin(PETSc.PetscSF,MPI.MPI_Datatype,const void*, void*,MPI.MPI_Op) + PetscErrorCode PetscSFReduceEnd(PETSc.PetscSF,MPI.MPI_Datatype,const void*, void*,MPI.MPI_Op) -ctypedef int (*PetscPCPatchComputeFunction)(PETSc.PetscPC, +ctypedef PetscErrorCode (*PetscPCPatchComputeFunction)(PETSc.PetscPC, PetscInt, PETSc.PetscVec, PETSc.PetscVec, @@ -158,7 +162,7 @@ ctypedef int (*PetscPCPatchComputeFunction)(PETSc.PetscPC, const PetscInt*, const PetscInt*, void*) -ctypedef int (*PetscPCPatchComputeOperator)(PETSc.PetscPC, +ctypedef PetscErrorCode (*PetscPCPatchComputeOperator)(PETSc.PetscPC, PetscInt, PETSc.PetscVec, PETSc.PetscMat, @@ -168,52 +172,28 @@ ctypedef int (*PetscPCPatchComputeOperator)(PETSc.PetscPC, const PetscInt*, void*) cdef extern from "petscsnes.h" nogil: - int SNESPatchSetComputeFunction(PETSc.PetscSNES, PetscPCPatchComputeFunction, void *) - int SNESPatchSetComputeOperator(PETSc.PetscSNES, PetscPCPatchComputeOperator, void *) + PetscErrorCode SNESPatchSetComputeFunction(PETSc.PetscSNES, PetscPCPatchComputeFunction, void *) + PetscErrorCode SNESPatchSetComputeOperator(PETSc.PetscSNES, PetscPCPatchComputeOperator, void *) cdef extern from "petscpc.h" nogil: - int PCPatchSetComputeFunction(PETSc.PetscPC, PetscPCPatchComputeFunction, void *) - int PCPatchSetComputeFunctionInteriorFacets(PETSc.PetscPC, PetscPCPatchComputeFunction, void *) - int PCPatchSetComputeOperator(PETSc.PetscPC, PetscPCPatchComputeOperator, void *) - int PCPatchSetComputeOperatorInteriorFacets(PETSc.PetscPC, PetscPCPatchComputeOperator, void *) + PetscErrorCode PCPatchSetComputeFunction(PETSc.PetscPC, PetscPCPatchComputeFunction, void *) + PetscErrorCode PCPatchSetComputeFunctionInteriorFacets(PETSc.PetscPC, PetscPCPatchComputeFunction, void *) + PetscErrorCode PCPatchSetComputeOperator(PETSc.PetscPC, PetscPCPatchComputeOperator, void *) + PetscErrorCode PCPatchSetComputeOperatorInteriorFacets(PETSc.PetscPC, PetscPCPatchComputeOperator, void *) cdef extern from "petscbt.h" nogil: ctypedef char * PetscBT - int PetscBTCreate(PetscInt,PetscBT*) - int PetscBTDestroy(PetscBT*) + PetscErrorCode PetscBTCreate(PetscInt,PetscBT*) + PetscErrorCode PetscBTDestroy(PetscBT*) char PetscBTLookup(PetscBT,PetscInt) - int PetscBTSet(PetscBT,PetscInt) + PetscErrorCode PetscBTSet(PetscBT,PetscInt) cdef extern from "petscmat.h" nogil: - int MatSetValuesLocal(PETSc.PetscMat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], + PetscErrorCode MatSetValuesLocal(PETSc.PetscMat, PetscInt, const PetscInt[], PetscInt, const PetscInt[], const PetscScalar[], PetscInt) - int MatAssemblyBegin(PETSc.PetscMat, PetscInt) - int MatAssemblyEnd(PETSc.PetscMat, PetscInt) + PetscErrorCode MatAssemblyBegin(PETSc.PetscMat, PetscInt) + PetscErrorCode MatAssemblyEnd(PETSc.PetscMat, PetscInt) PetscInt MAT_FINAL_ASSEMBLY = 0 cdef extern from * nogil: - int PetscObjectTypeCompare(PETSc.PetscObject, char[], PetscBool*) - -# --- Error handling taken from petsc4py (src/PETSc.pyx) ------------- - -cdef extern from *: - void PyErr_SetObject(object, object) - void *PyExc_RuntimeError - -cdef object PetscError = PyExc_RuntimeError - -cdef inline int SETERR(int ierr) with gil: - if (PetscError) != NULL: - PyErr_SetObject(PetscError, ierr) - else: - PyErr_SetObject(PyExc_RuntimeError, ierr) - return ierr - -cdef inline int CHKERR(int ierr) except -1 nogil: - if ierr == 0: - return 0 # no error - else: - SETERR(ierr) - return -1 - -# -------------------------------------------------------------------- + PetscErrorCode PetscObjectTypeCompare(PETSc.PetscObject, char[], PetscBool*) diff --git a/pyop2/sparsity.pyx b/pyop2/sparsity.pyx index d6411fecac..5914bacc86 100644 --- a/pyop2/sparsity.pyx +++ b/pyop2/sparsity.pyx @@ -37,6 +37,7 @@ import numpy as np cimport numpy as np import cython cimport petsc4py.PETSc as PETSc +from petsc4py.PETSc cimport CHKERR from petsc4py import PETSc from pyop2.datatypes import IntType @@ -49,18 +50,21 @@ cdef extern from "petsc.h": PETSC_TRUE, PETSC_FALSE ctypedef enum PetscInsertMode "InsertMode": PETSC_INSERT_VALUES "INSERT_VALUES" - int PetscCalloc1(size_t, void*) - int PetscMalloc1(size_t, void*) - int PetscMalloc2(size_t, void*, size_t, void*) - int PetscFree(void*) - int PetscFree2(void*,void*) - int MatSetValuesBlockedLocal(PETSc.PetscMat, PetscInt, PetscInt*, PetscInt, PetscInt*, - PetscScalar*, PetscInsertMode) - int MatSetValuesLocal(PETSc.PetscMat, PetscInt, PetscInt*, PetscInt, PetscInt*, - PetscScalar*, PetscInsertMode) - int MatPreallocatorPreallocate(PETSc.PetscMat, PetscBool, PETSc.PetscMat) - int MatXAIJSetPreallocation(PETSc.PetscMat, PetscInt, const PetscInt[], const PetscInt[], - const PetscInt[], const PetscInt[]) + ctypedef enum PetscErrorCode: + PETSC_SUCCESS + + PetscErrorCode PetscCalloc1(size_t, void*) + PetscErrorCode PetscMalloc1(size_t, void*) + PetscErrorCode PetscMalloc2(size_t, void*, size_t, void*) + PetscErrorCode PetscFree(void*) + PetscErrorCode PetscFree2(void*,void*) + PetscErrorCode MatSetValuesBlockedLocal(PETSc.PetscMat, PetscInt, PetscInt*, PetscInt, PetscInt*, + PetscScalar*, PetscInsertMode) + PetscErrorCode MatSetValuesLocal(PETSc.PetscMat, PetscInt, PetscInt*, PetscInt, PetscInt*, + PetscScalar*, PetscInsertMode) + PetscErrorCode MatPreallocatorPreallocate(PETSc.PetscMat, PetscBool, PETSc.PetscMat) + PetscErrorCode MatXAIJSetPreallocation(PETSc.PetscMat, PetscInt, const PetscInt[], const PetscInt[], + const PetscInt[], const PetscInt[]) cdef extern from "petsc/private/matimpl.h": struct _p_Mat: @@ -71,26 +75,6 @@ ctypedef struct Mat_Preallocator: PetscInt *dnz PetscInt *onz -cdef extern from *: - void PyErr_SetObject(object, object) - void *PyExc_RuntimeError - -cdef object PetscError = PyExc_RuntimeError - -cdef inline int SETERR(int ierr) with gil: - if (PetscError) != NULL: - PyErr_SetObject(PetscError, ierr) - else: - PyErr_SetObject(PyExc_RuntimeError, ierr) - return ierr - -cdef inline int CHKERR(int ierr) nogil except -1: - if ierr == 0: - return 0 # no error - else: - SETERR(ierr) - return -1 - cdef object set_writeable(map): flag = map.values_with_halo.flags['WRITEABLE'] map.values_with_halo.setflags(write=True) diff --git a/tests/firedrake/regression/test_nullspace.py b/tests/firedrake/regression/test_nullspace.py index 5b3538c41e..e7ba515579 100644 --- a/tests/firedrake/regression/test_nullspace.py +++ b/tests/firedrake/regression/test_nullspace.py @@ -1,5 +1,4 @@ from firedrake import * -from firedrake.petsc import PETSc import pytest import numpy as np @@ -236,7 +235,6 @@ def test_nullspace_mixed_multiple_components(): F_stokes += inner(g * rho * khat, N) * dx F_stokes += -inner(u, grad(M)) * dx - PETSc.Sys.popErrorHandler() solver_parameters = { 'mat_type': 'matfree', 'snes_type': 'ksponly', @@ -295,7 +293,6 @@ def test_near_nullspace_mixed(aux_pc, rhs): # test nullspace and nearnullspace for a mixed Stokes system # this is tested on the SINKER case of May and Moresi https://doi.org/10.1016/j.pepi.2008.07.036 # fails in parallel if nullspace is copied to fieldsplit_1_Mp_ksp solve (see PR #3488) - PETSc.Sys.popErrorHandler() n = 64 mesh = UnitSquareMesh(n, n) V = VectorFunctionSpace(mesh, "CG", 2) diff --git a/tests/pyop2/test_matrices.py b/tests/pyop2/test_matrices.py index f3c354d49f..96b25cd689 100644 --- a/tests/pyop2/test_matrices.py +++ b/tests/pyop2/test_matrices.py @@ -609,14 +609,7 @@ def test_mat_always_has_diagonal_space(self): d2 = op2.Set(3) m2 = op2.Map(s, d2, 1, [1]) sparsity = op2.Sparsity((d ** 1, d2 ** 1), [(m, m2, None)]) - - from petsc4py import PETSc - # petsc4py default error handler swallows SETERRQ, so just - # install the abort handler to notice an error. - PETSc.Sys.pushErrorHandler("abort") mat = op2.Mat(sparsity) - PETSc.Sys.popErrorHandler() - assert np.allclose(mat.handle.getDiagonal().array, 0.0) def test_minimal_zero_mat(self):