Date: 2022-03-31T04:46:59+00:00

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:   submatj->destroy(C);
      9:   MatDestroySubMatrix_Private(submatj);
     10:   return 0;
     11: }

     13: PetscErrorCode MatDestroySubMatrices_Dummy(PetscInt n, Mat *mat[])
     14: {
     15:   /* Destroy dummy submatrices (*mat)[n]...(*mat)[n+nstages-1] used for reuse struct Mat_SubSppt */
     16:   if ((*mat)[n]) {
     17:     PetscBool      isdummy;
     18:     PetscObjectTypeCompare((PetscObject)(*mat)[n],MATDUMMY,&isdummy);
     19:     if (isdummy) {
     20:       Mat_SubSppt* smat = (Mat_SubSppt*)((*mat)[n]->data); /* singleis and nstages are saved in (*mat)[n]->data */

     22:       if (smat && !smat->singleis) {
     23:         PetscInt i,nstages=smat->nstages;
     24:         for (i=0; i<nstages; i++) {
     25:           MatDestroy(&(*mat)[n+i]);
     26:         }
     27:       }
     28:     }
     29:   }

     31:   /* memory is allocated even if n = 0 */
     32:   PetscFree(*mat);
     33:   return 0;
     34: }

     36: PetscErrorCode MatDestroy_Dummy(Mat A)
     37: {
     38:   PetscObjectChangeTypeName((PetscObject)A,NULL);
     39:   return 0;
     40: }

     42: /*MC
     43:    MATDUMMY - A matrix type to be used for reusing specific internal data structure.

     45:   Level: developer

     47: .seealso: Mat

     49: M*/

     51: PETSC_EXTERN PetscErrorCode MatCreate_Dummy(Mat A)
     52: {
     53:   /* matrix ops */
     54:   PetscMemzero(A->ops,sizeof(struct _MatOps));
     55:   A->ops->destroy            = MatDestroy_Dummy;
     56:   A->ops->destroysubmatrices = MatDestroySubMatrices_Dummy;

     58:   /* special MATPREALLOCATOR functions */
     59:   PetscObjectChangeTypeName((PetscObject)A,MATDUMMY);
     60:   return 0;
     61: }