Actual source code: vecreg.c

 2:  #include vecimpl.h

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

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

 12:   Collective on Vec

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

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

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

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

 27:   Level: intermediate

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

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

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

 50:   if (vec->ops->destroy) {
 51:     (*vec->ops->destroy)(vec);
 52:   }
 53:   (*r)(vec);

 55:   PetscObjectChangeTypeName((PetscObject) vec, method);
 56:   return(0);
 57: }

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

 64:   Not Collective

 66:   Input Parameter:
 67: . vec  - The vector

 69:   Output Parameter:
 70: . type - The vector type name

 72:   Level: intermediate

 74: .keywords: vector, get, type, name
 75: .seealso: VecSetType(), VecCreate()
 76: @*/
 77: PetscErrorCode VecGetType(Vec vec, VecType *type)
 78: {

 84:   if (VecRegisterAllCalled == PETSC_FALSE) {
 85:     VecRegisterAll(PETSC_NULL);
 86:   }
 87:   *type = vec->type_name;
 88:   return(0);
 89: }


 92: /*--------------------------------------------------------------------------------------------------------------------*/

 96: /*@C
 97:   VecRegister - See VecRegisterDynamic()

 99:   Level: advanced
100: @*/
101: PetscErrorCode VecRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(Vec))
102: {
103:   char fullname[PETSC_MAX_PATH_LEN];

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


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

121:    Not Collective

123:    Level: advanced

125: .keywords: Vec, register, destroy
126: .seealso: VecRegister(), VecRegisterAll(), VecRegisterDynamic()
127: @*/
128: PetscErrorCode VecRegisterDestroy(void)
129: {

133:   if (VecList != PETSC_NULL) {
134:     PetscFListDestroy(&VecList);
135:     VecList = PETSC_NULL;
136:   }
137:   VecRegisterAllCalled = PETSC_FALSE;
138:   return(0);
139: }