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(0); 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++) { 27 PetscCall(MatDestroy(&(*mat)[n+i])); 28 } 29 } 30 } 31 } 32 33 /* memory is allocated even if n = 0 */ 34 PetscCall(PetscFree(*mat)); 35 PetscFunctionReturn(0); 36 } 37 38 PetscErrorCode MatDestroy_Dummy(Mat A) 39 { 40 PetscFunctionBegin; 41 PetscCall(PetscObjectChangeTypeName((PetscObject)A,NULL)); 42 PetscFunctionReturn(0); 43 } 44 45 /*MC 46 MATDUMMY - A matrix type to be used for reusing specific internal data structure. 47 48 Level: developer 49 50 .seealso: Mat 51 52 M*/ 53 54 PETSC_EXTERN PetscErrorCode MatCreate_Dummy(Mat A) 55 { 56 PetscFunctionBegin; 57 /* matrix ops */ 58 PetscCall(PetscMemzero(A->ops,sizeof(struct _MatOps))); 59 A->ops->destroy = MatDestroy_Dummy; 60 A->ops->destroysubmatrices = MatDestroySubMatrices_Dummy; 61 62 /* special MATPREALLOCATOR functions */ 63 PetscCall(PetscObjectChangeTypeName((PetscObject)A,MATDUMMY)); 64 PetscFunctionReturn(0); 65 } 66