Actual source code: matdummy.c
1: #include <petsc/private/matimpl.h>
2: #include <../src/mat/impls/aij/seq/aij.h>
4: PetscErrorCode MatDestroySubMatrix_Dummy(Mat C)
5: {
6: Mat_SubSppt *submatj = (Mat_SubSppt *)C->data;
8: PetscFunctionBegin;
9: PetscCall(submatj->destroy(C));
10: PetscCall(MatDestroySubMatrix_Private(submatj));
11: PetscFunctionReturn(PETSC_SUCCESS);
12: }
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 */
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: }
31: /* memory is allocated even if n = 0 */
32: PetscCall(PetscFree(*mat));
33: PetscFunctionReturn(PETSC_SUCCESS);
34: }
36: static PetscErrorCode MatDestroy_Dummy(Mat A)
37: {
38: PetscFunctionBegin;
39: PetscCall(PetscObjectChangeTypeName((PetscObject)A, NULL));
40: PetscFunctionReturn(PETSC_SUCCESS);
41: }
43: /*MC
44: MATDUMMY - A matrix type to be used for reusing specific internal data structure.
46: Level: developer
48: .seealso: `Mat`
49: M*/
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;
59: /* special MATPREALLOCATOR functions */
60: PetscCall(PetscObjectChangeTypeName((PetscObject)A, MATDUMMY));
61: PetscFunctionReturn(PETSC_SUCCESS);
62: }