Actual source code: vecreg.c

  1: #define PETSCVEC_DLL

 3:  #include vecimpl.h

  5: PetscFList VecList                       = PETSC_NULL;
  6: PetscTruth VecRegisterAllCalled          = PETSC_FALSE;

 10: /*@C
 11:   VecSetType - Builds a vector, for a particular vector implementation.

 13:   Collective on Vec

 15:   Input Parameters:
 16: + vec    - The vector object
 17: - method - The name of the vector type

 19:   Options Database Key:
 20: . -vec_type <type> - Sets the vector type; use -help for a list 
 21:                      of available types

 23:   Notes:
 24:   See "petsc/include/vec.h" for available vector types (for instance, VECSEQ, VECMPI, or VECSHARED).

 26:   Use VecDuplicate() or VecDuplicateVecs() to form additional vectors of the same type as an existing vector.

 28:   Level: intermediate

 30: .keywords: vector, set, type
 31: .seealso: VecGetType(), VecCreate()
 32: @*/
 33: PetscErrorCode PETSCVEC_DLLEXPORT VecSetType(Vec vec, VecType method)
 34: {
 35:   PetscErrorCode (*r)(Vec);
 36:   PetscTruth match;

 41:   PetscTypeCompare((PetscObject) vec, method, &match);
 42:   if (match) return(0);

 44:   if (vec->n < 0 && vec->N < 0) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call VecSetSizes() first");

 46:   /* Get the function pointers for the vector requested */
 47:   if (!VecRegisterAllCalled) {
 48:     VecRegisterAll(PETSC_NULL);
 49:   }
 50:   PetscFListFind(vec->comm, VecList, method,(void (**)(void)) &r);
 51:   if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown vector type: %s", method);

 53:   if (vec->ops->destroy) {
 54:     (*vec->ops->destroy)(vec);
 55:   }
 56:   (*r)(vec);

 58:   PetscObjectChangeTypeName((PetscObject) vec, method);
 59:   return(0);
 60: }

 64: /*@C
 65:   VecGetType - Gets the vector type name (as a string) from the Vec.

 67:   Not Collective

 69:   Input Parameter:
 70: . vec  - The vector

 72:   Output Parameter:
 73: . type - The vector type name

 75:   Level: intermediate

 77: .keywords: vector, get, type, name
 78: .seealso: VecSetType(), VecCreate()
 79: @*/
 80: PetscErrorCode PETSCVEC_DLLEXPORT VecGetType(Vec vec, VecType *type)
 81: {

 87:   if (!VecRegisterAllCalled) {
 88:     VecRegisterAll(PETSC_NULL);
 89:   }
 90:   *type = vec->type_name;
 91:   return(0);
 92: }


 95: /*--------------------------------------------------------------------------------------------------------------------*/

 99: /*@C
100:   VecRegister - See VecRegisterDynamic()

102:   Level: advanced
103: @*/
104: PetscErrorCode PETSCVEC_DLLEXPORT VecRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(Vec))
105: {
106:   char fullname[PETSC_MAX_PATH_LEN];

110:   PetscStrcpy(fullname, path);
111:   PetscStrcat(fullname, ":");
112:   PetscStrcat(fullname, name);
113:   PetscFListAdd(&VecList, sname, fullname, (void (*)(void)) function);
114:   return(0);
115: }


118: /*--------------------------------------------------------------------------------------------------------------------*/
121: /*@C
122:    VecRegisterDestroy - Frees the list of Vec methods that were registered by VecRegister()/VecRegisterDynamic().

124:    Not Collective

126:    Level: advanced

128: .keywords: Vec, register, destroy
129: .seealso: VecRegister(), VecRegisterAll(), VecRegisterDynamic()
130: @*/
131: PetscErrorCode PETSCVEC_DLLEXPORT VecRegisterDestroy(void)
132: {

136:   if (VecList) {
137:     PetscFListDestroy(&VecList);
138:     VecList = PETSC_NULL;
139:   }
140:   VecRegisterAllCalled = PETSC_FALSE;
141:   return(0);
142: }