1 #include <petsc/private/matimpl.h> /*I "petscmat.h" I*/ 2 #include <../src/mat/impls/aij/seq/aij.h> 3 4 PetscErrorCode MatDestroySubMatrix_Dummy(Mat C) 5 { 6 Mat_SubSppt *submatj = (Mat_SubSppt *)C->data; 7 8 PetscFunctionBegin; 9 PetscCall(submatj->destroy(C)); 10 PetscCall(MatDestroySubMatrix_Private(submatj)); 11 PetscFunctionReturn(PETSC_SUCCESS); 12 } 13 14 PetscErrorCode MatDestroySubMatrices_Dummy(PetscInt n, Mat *mat[]) 15 { 16 PetscFunctionBegin; 17 /* Destroy dummy submatrices (*mat)[n]...(*mat)[n+nstages-1] used for reuse struct Mat_SubSppt */ 18 if ((*mat)[n]) { 19 PetscBool isdummy; 20 PetscCall(PetscObjectTypeCompare((PetscObject)(*mat)[n], MATDUMMY, &isdummy)); 21 if (isdummy) { 22 Mat_SubSppt *smat = (Mat_SubSppt *)((*mat)[n]->data); /* singleis and nstages are saved in (*mat)[n]->data */ 23 24 if (smat && !smat->singleis) { 25 PetscInt i, nstages = smat->nstages; 26 for (i = 0; i < nstages; i++) PetscCall(MatDestroy(&(*mat)[n + i])); 27 } 28 } 29 } 30 31 /* memory is allocated even if n = 0 */ 32 PetscCall(PetscFree(*mat)); 33 PetscFunctionReturn(PETSC_SUCCESS); 34 } 35 36 static PetscErrorCode MatDestroy_Dummy(Mat A) 37 { 38 PetscFunctionBegin; 39 PetscCall(PetscObjectChangeTypeName((PetscObject)A, NULL)); 40 PetscFunctionReturn(PETSC_SUCCESS); 41 } 42 43 /*MC 44 MATDUMMY - A matrix type to be used for reusing specific internal data structure. 45 46 Level: developer 47 48 .seealso: `Mat` 49 M*/ 50 51 PETSC_EXTERN PetscErrorCode MatCreate_Dummy(Mat A) 52 { 53 PetscFunctionBegin; 54 /* matrix ops */ 55 PetscCall(PetscMemzero(A->ops, sizeof(struct _MatOps))); 56 A->ops->destroy = MatDestroy_Dummy; 57 A->ops->destroysubmatrices = MatDestroySubMatrices_Dummy; 58 59 /* special MATPREALLOCATOR functions */ 60 PetscCall(PetscObjectChangeTypeName((PetscObject)A, MATDUMMY)); 61 PetscFunctionReturn(PETSC_SUCCESS); 62 } 63