Actual source code: matreg.c

  1: #ifdef PETSC_RCS_HEADER
  2: static char vcid[] = "$Id: matreg.c,v 1.18 2001/07/20 21:19:21 bsmith Exp $";
  3: #endif
  4: /*
  5:      Mechanism for register PETSc matrix types
  6: */
 7:  #include src/mat/matimpl.h
 8:  #include petscsys.h

 10: PetscTruth MatRegisterAllCalled = PETSC_FALSE;

 12: /*
 13:    Contains the list of registered Mat routines
 14: */
 15: PetscFList MatList = 0;

 19: /*@C
 20:    MatSetType - Builds matrix object for a particular matrix type

 22:    Collective on Mat

 24:    Input Parameters:
 25: +  mat      - the matrix object
 26: -  matype   - matrix type

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

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

 35:   Level: intermediate

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

 39: .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat
 40: @*/
 41: int MatSetType(Mat mat,const MatType matype)
 42: {
 43:   int        ierr,(*r)(Mat);
 44:   PetscTruth sametype;


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

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

 64:     if (mat->rmap) {
 65:       PetscMapDestroy(mat->rmap);
 66:       mat->rmap = 0;
 67:     }
 68:     if (mat->cmap) {
 69:       PetscMapDestroy(mat->cmap);
 70:       mat->cmap = 0;
 71:     }
 72:     if (mat->qlist) {
 73:       PetscFListDestroy(&mat->qlist);
 74:       mat->qlist = 0;
 75:     }
 76:     if (mat->olist) {
 77:       PetscOListDestroy(&mat->olist);
 78:       mat->olist = 0;
 79:     }
 80:     /* create the new data structure */
 81:     (*r)(mat);

 83:     PetscObjectChangeTypeName((PetscObject)mat,matype);
 84:   }
 85:   PetscPublishAll(mat);
 86:   return(0);
 87: }


 92: /*@C
 93:    MatRegisterDestroy - Frees the list of matrix types that were
 94:    registered by MatRegister()/MatRegisterDynamic().

 96:    Not Collective

 98:    Level: advanced

100: .keywords: Mat, register, destroy

102: .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic()
103: @*/
104: int MatRegisterDestroy(void)
105: {

109:   if (MatList) {
110:     PetscFListDestroy(&MatList);
111:     MatList = 0;
112:   }
113:   MatRegisterAllCalled = PETSC_FALSE;
114:   return(0);
115: }

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

122:    Not Collective

124:    Input Parameter:
125: .  mat - the matrix

127:    Output Parameter:
128: .  name - name of matrix type

130:    Level: intermediate

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

134: .seealso: MatSetType()
135: @*/
136: int MatGetType(Mat mat,MatType *type)
137: {
139:   *type = mat->type_name;
140:   return(0);
141: }


146: /*@C
147:   MatRegister - See MatRegisterDynamic()

149:   Level: advanced
150: @*/
151: int MatRegister(const char sname[],const char path[],const char name[],int (*function)(Mat))
152: {
153:   int  ierr;
154:   char fullname[PETSC_MAX_PATH_LEN];

157:   PetscFListConcat(path,name,fullname);
158:   PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);
159:   return(0);
160: }