1be1d678aSKris Buschelman #define PETSCMAT_DLL 2be1d678aSKris Buschelman 37e14e8a7SBarry Smith /* 499cd5145SBarry Smith Mechanism for register PETSc matrix types 57e14e8a7SBarry Smith */ 6*b9147fbbSdalcinl #include "include/private/matimpl.h" /*I "petscmat.h" I*/ 799cd5145SBarry Smith #include "petscsys.h" 87e14e8a7SBarry Smith 991af72abSBarry Smith PetscTruth MatRegisterAllCalled = PETSC_FALSE; 107e14e8a7SBarry Smith 117e14e8a7SBarry Smith /* 1299cd5145SBarry Smith Contains the list of registered Mat routines 137e14e8a7SBarry Smith */ 14b0a32e0cSBarry Smith PetscFList MatList = 0; 157e14e8a7SBarry Smith 164a2ae208SSatish Balay #undef __FUNCT__ 174a2ae208SSatish Balay #define __FUNCT__ "MatSetType" 187e14e8a7SBarry Smith /*@C 1999cd5145SBarry Smith MatSetType - Builds matrix object for a particular matrix type 207e14e8a7SBarry Smith 2199cd5145SBarry Smith Collective on Mat 227e14e8a7SBarry Smith 237e14e8a7SBarry Smith Input Parameters: 2499cd5145SBarry Smith + mat - the matrix object 2599cd5145SBarry Smith - matype - matrix type 267e14e8a7SBarry Smith 277e14e8a7SBarry Smith Options Database Key: 2899cd5145SBarry Smith . -mat_type <method> - Sets the type; use -help for a list 2999cd5145SBarry Smith of available methods (for instance, seqaij) 307e14e8a7SBarry Smith 317e14e8a7SBarry Smith Notes: 3299cd5145SBarry Smith See "${PETSC_DIR}/include/petscmat.h" for available methods 337e14e8a7SBarry Smith 347e14e8a7SBarry Smith Level: intermediate 357e14e8a7SBarry Smith 36c2bf8781Svictorle .keywords: Mat, MatType, set, method 377e14e8a7SBarry Smith 386e0d5acbSBarry Smith .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat 397e14e8a7SBarry Smith @*/ 40f69a0ea3SMatthew Knepley PetscErrorCode PETSCMAT_DLLEXPORT MatSetType(Mat mat, MatType matype) 417e14e8a7SBarry Smith { 42dfbe8321SBarry Smith PetscErrorCode ierr,(*r)(Mat); 4399cd5145SBarry Smith PetscTruth sametype; 447e14e8a7SBarry Smith 457e14e8a7SBarry Smith PetscFunctionBegin; 464482741eSBarry Smith PetscValidHeaderSpecific(mat,MAT_COOKIE,1); 47899cda47SBarry Smith if (mat->rmap.n < 0 && mat->rmap.N < 0 && mat->cmap.n < 0 && mat->cmap.N < 0) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call MatSetSizes() first"); 4899cd5145SBarry Smith ierr = PetscTypeCompare((PetscObject)mat,matype,&sametype);CHKERRQ(ierr); 4935d8aa7fSBarry Smith if (!sametype) { 5099cd5145SBarry Smith /* Get the function pointers for the matrix requested */ 5199cd5145SBarry Smith if (!MatRegisterAllCalled) {ierr = MatRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 52c134de8dSSatish Balay ierr = PetscFListFind(mat->comm,MatList,matype,(void(**)(void))&r);CHKERRQ(ierr); 53958c9bccSBarry Smith if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown Mat type given: %s",matype); 547e14e8a7SBarry Smith 5535d8aa7fSBarry Smith /* free the old data structure if it existed */ 5635d8aa7fSBarry Smith if (mat->ops->destroy) { 57b50b34bdSBarry Smith ierr = MatPreallocated(mat);CHKERRQ(ierr); 5835d8aa7fSBarry Smith ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr); 590dd8e64fSKris Buschelman mat->ops->destroy = PETSC_NULL; 60a2ec6df8SKris Buschelman mat->preallocated = PETSC_FALSE; 6135d8aa7fSBarry Smith } 62a2ec6df8SKris Buschelman 6335d8aa7fSBarry Smith /* create the new data structure */ 6499cd5145SBarry Smith ierr = (*r)(mat);CHKERRQ(ierr); 6535d8aa7fSBarry Smith } 6635d8aa7fSBarry Smith ierr = PetscPublishAll(mat);CHKERRQ(ierr); 677e14e8a7SBarry Smith PetscFunctionReturn(0); 687e14e8a7SBarry Smith } 697e14e8a7SBarry Smith 7035d8aa7fSBarry Smith 714a2ae208SSatish Balay #undef __FUNCT__ 724a2ae208SSatish Balay #define __FUNCT__ "MatRegisterDestroy" 737e14e8a7SBarry Smith /*@C 7499cd5145SBarry Smith MatRegisterDestroy - Frees the list of matrix types that were 753cea93caSBarry Smith registered by MatRegister()/MatRegisterDynamic(). 767e14e8a7SBarry Smith 777e14e8a7SBarry Smith Not Collective 787e14e8a7SBarry Smith 797e14e8a7SBarry Smith Level: advanced 807e14e8a7SBarry Smith 8199cd5145SBarry Smith .keywords: Mat, register, destroy 827e14e8a7SBarry Smith 833cea93caSBarry Smith .seealso: MatRegister(), MatRegisterAll(), MatRegisterDynamic() 847e14e8a7SBarry Smith @*/ 85be1d678aSKris Buschelman PetscErrorCode PETSCMAT_DLLEXPORT MatRegisterDestroy(void) 867e14e8a7SBarry Smith { 87dfbe8321SBarry Smith PetscErrorCode ierr; 887e14e8a7SBarry Smith 897e14e8a7SBarry Smith PetscFunctionBegin; 9099cd5145SBarry Smith if (MatList) { 91b0a32e0cSBarry Smith ierr = PetscFListDestroy(&MatList);CHKERRQ(ierr); 9299cd5145SBarry Smith MatList = 0; 937e14e8a7SBarry Smith } 940e9836bfSBarry Smith MatRegisterAllCalled = PETSC_FALSE; 957e14e8a7SBarry Smith PetscFunctionReturn(0); 967e14e8a7SBarry Smith } 977e14e8a7SBarry Smith 984a2ae208SSatish Balay #undef __FUNCT__ 994a2ae208SSatish Balay #define __FUNCT__ "MatGetType" 1007e14e8a7SBarry Smith /*@C 101f87b78b8SBarry Smith MatGetType - Gets the matrix type as a string from the matrix object. 1027e14e8a7SBarry Smith 1037e14e8a7SBarry Smith Not Collective 1047e14e8a7SBarry Smith 1057e14e8a7SBarry Smith Input Parameter: 10699cd5145SBarry Smith . mat - the matrix 1077e14e8a7SBarry Smith 1087e14e8a7SBarry Smith Output Parameter: 10999cd5145SBarry Smith . name - name of matrix type 1107e14e8a7SBarry Smith 1117e14e8a7SBarry Smith Level: intermediate 1127e14e8a7SBarry Smith 113c2bf8781Svictorle .keywords: Mat, MatType, get, method, name 1147e14e8a7SBarry Smith 11599cd5145SBarry Smith .seealso: MatSetType() 1167e14e8a7SBarry Smith @*/ 117be1d678aSKris Buschelman PetscErrorCode PETSCMAT_DLLEXPORT MatGetType(Mat mat,MatType *type) 1187e14e8a7SBarry Smith { 1197e14e8a7SBarry Smith PetscFunctionBegin; 12099cd5145SBarry Smith *type = mat->type_name; 1217e14e8a7SBarry Smith PetscFunctionReturn(0); 1227e14e8a7SBarry Smith } 1237e14e8a7SBarry Smith 1247e14e8a7SBarry Smith 1254a2ae208SSatish Balay #undef __FUNCT__ 1264a2ae208SSatish Balay #define __FUNCT__ "MatRegister" 1273cea93caSBarry Smith /*@C 1283cea93caSBarry Smith MatRegister - See MatRegisterDynamic() 1293cea93caSBarry Smith 1307f6c08e0SMatthew Knepley Level: advanced 1313cea93caSBarry Smith @*/ 132be1d678aSKris Buschelman PetscErrorCode PETSCMAT_DLLEXPORT MatRegister(const char sname[],const char path[],const char name[],PetscErrorCode (*function)(Mat)) 1337e14e8a7SBarry Smith { 134dfbe8321SBarry Smith PetscErrorCode ierr; 135e10c49a3SBarry Smith char fullname[PETSC_MAX_PATH_LEN]; 1367e14e8a7SBarry Smith 1377e14e8a7SBarry Smith PetscFunctionBegin; 138b0a32e0cSBarry Smith ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr); 139c134de8dSSatish Balay ierr = PetscFListAdd(&MatList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr); 14099cd5145SBarry Smith PetscFunctionReturn(0); 14199cd5145SBarry Smith } 14299cd5145SBarry Smith 14399cd5145SBarry Smith 14499cd5145SBarry Smith 14599cd5145SBarry Smith 146273d9f13SBarry Smith 147273d9f13SBarry Smith 148273d9f13SBarry Smith 149273d9f13SBarry Smith 150273d9f13SBarry Smith 151273d9f13SBarry Smith 152