1: #include <petsc/private/matimpl.h>
2: #include <../src/mat/impls/aij/seq/aij.h>
4: PetscErrorCode MatDestroySubMatrices_SeqXAIJ(PetscInt n, Mat *mat[])
5: {
6: PetscFunctionBegin;
7: /* Destroy dummy submatrices (*mat)[n]...(*mat)[n+nstages-1] used for reuse struct Mat_SubSppt */
8: if ((*mat)[n]) {
9: PetscBool isdummy;
10: PetscCall(PetscObjectTypeCompare((PetscObject)(*mat)[n], MATDUMMY, &isdummy));
11: if (isdummy) {
12: Mat_SubSppt *smat = (Mat_SubSppt *)(*mat)[n]->data; /* singleis and nstages are saved in (*mat)[n]->data */
14: if (smat && !smat->singleis) n += smat->nstages;
15: }
16: }
18: PetscCall(MatDestroyMatrices(n, mat));
19: PetscFunctionReturn(PETSC_SUCCESS);
20: }
22: static PetscErrorCode MatDestroy_Dummy(Mat A)
23: {
24: PetscFunctionBegin;
25: PetscCall(MatDestroySubMatrix_Private((Mat_SubSppt *)A->data));
26: A->data = NULL;
27: PetscCall(PetscObjectChangeTypeName((PetscObject)A, NULL));
28: PetscFunctionReturn(PETSC_SUCCESS);
29: }
31: /*MC
32: MATDUMMY - A matrix type to be used for reusing specific internal data structure.
34: Level: developer
36: .seealso: `Mat`
37: M*/
39: PETSC_EXTERN PetscErrorCode MatCreate_Dummy(Mat A)
40: {
41: PetscFunctionBegin;
42: /* matrix ops */
43: PetscCall(PetscMemzero(A->ops, sizeof(struct _MatOps)));
44: A->ops->destroy = MatDestroy_Dummy;
45: A->ops->destroysubmatrices = MatDestroySubMatrices_SeqXAIJ;
47: /* special MATPREALLOCATOR functions */
48: PetscCall(PetscObjectChangeTypeName((PetscObject)A, MATDUMMY));
49: PetscFunctionReturn(PETSC_SUCCESS);
50: }