Actual source code: matreg.c

  1: /*
  2:      Mechanism for register PETSc matrix types
  3: */
 4:  #include src/mat/matimpl.h
 5:  #include petscsys.h

  7: PetscTruth MatRegisterAllCalled = PETSC_FALSE;

  9: /*
 10:    Contains the list of registered Mat routines
 11: */
 12: PetscFList MatList = 0;

 16: /*@C
 17:    MatSetType - Builds matrix object for a particular matrix type

 19:    Collective on Mat

 21:    Input Parameters:
 22: +  mat      - the matrix object
 23: -  matype   - matrix type

 25:    Options Database Key:
 26: .  -mat_type  <method> - Sets the type; use -help for a list 
 27:     of available methods (for instance, seqaij)

 29:    Notes:  
 30:    See "${PETSC_DIR}/include/petscmat.h" for available methods

 32:   Level: intermediate

 34: .keywords: Mat, MatType, set, method

 36: .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat
 37: @*/
 38: PetscErrorCode MatSetType(Mat mat,const MatType matype)
 39: {
 40:   PetscErrorCode ierr,(*r)(Mat);
 41:   PetscTruth sametype;


 46:   PetscTypeCompare((PetscObject)mat,matype,&sametype);
 47:   if (!sametype) {
 48:     /* Get the function pointers for the matrix requested */
 49:     if (!MatRegisterAllCalled) {MatRegisterAll(PETSC_NULL);}
 50:      PetscFListFind(mat->comm,MatList,matype,(void(**)(void))&r);
 51:     if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown Mat type given: %s",matype);

 53:     /* free the old data structure if it existed */
 54:     if (mat->ops->destroy) {
 55:       MatPreallocated(mat);
 56:       (*mat->ops->destroy)(mat);
 57:       mat->ops->destroy = PETSC_NULL;
 58:       mat->preallocated = PETSC_FALSE;
 59:     }

 61:     if (mat->rmap) {
 62:       PetscMapDestroy(mat->rmap);
 63:       mat->rmap = 0;
 64:     }
 65:     if (mat->cmap) {
 66:       PetscMapDestroy(mat->cmap);
 67:       mat->cmap = 0;
 68:     }
 69:     /* create the new data structure */
 70:     (*r)(mat);
 71:     PetscObjectChangeTypeName((PetscObject)mat,matype);
 72:   }
 73:   PetscPublishAll(mat);
 74:   return(0);
 75: }


 80: /*@C
 81:    MatRegisterDestroy - Frees the list of matrix types that were
 82:    registered by MatRegister()/MatRegisterDynamic().

 84:    Not Collective

 86:    Level: advanced

 88: .keywords: Mat, register, destroy

 90: .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic()
 91: @*/
 92: PetscErrorCode MatRegisterDestroy(void)
 93: {

 97:   if (MatList) {
 98:     PetscFListDestroy(&MatList);
 99:     MatList = 0;
100:   }
101:   MatRegisterAllCalled = PETSC_FALSE;
102:   return(0);
103: }

107: /*@C
108:    MatGetType - Gets the matrix type as a string from the matrix object.

110:    Not Collective

112:    Input Parameter:
113: .  mat - the matrix

115:    Output Parameter:
116: .  name - name of matrix type

118:    Level: intermediate

120: .keywords: Mat, MatType, get, method, name

122: .seealso: MatSetType()
123: @*/
124: PetscErrorCode MatGetType(Mat mat,MatType *type)
125: {
127:   *type = mat->type_name;
128:   return(0);
129: }


134: /*@C
135:   MatRegister - See MatRegisterDynamic()

137:   Level: advanced
138: @*/
139: PetscErrorCode MatRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(Mat))
140: {
142:   char fullname[PETSC_MAX_PATH_LEN];

145:   PetscFListConcat(path,name,fullname);
146:   PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);
147:   return(0);
148: }