Actual source code: vecreg.c

  1: #ifdef PETSC_RCS_HEADER
  2: static char vcid[] = "$Id: vecreg.c,v 1.5 2000/01/10 03:18:14 knepley Exp $";
  3: #endif

 5:  #include src/vec/vecimpl.h

  7: PetscFList VecList                       = PETSC_NULL;
  8: PetscTruth VecRegisterAllCalled          = PETSC_FALSE;
  9: PetscFList VecSerializeList              = PETSC_NULL;
 10: PetscTruth VecSerializeRegisterAllCalled = PETSC_FALSE;

 14: /*@C
 15:   VecSetType - Builds a vector, for a particular vector implementation.

 17:   Collective on Vec

 19:   Input Parameters:
 20: + vec    - The vector object
 21: - method - The name of the vector type

 23:   Options Database Key:
 24: . -vec_type <type> - Sets the vector type; use -help for a list 
 25:                      of available types

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

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

 32:   Level: intermediate

 34: .keywords: vector, set, type
 35: .seealso: VecGetType(), VecCreate()
 36: @*/
 37: int VecSetType(Vec vec, VecType method)
 38: {
 39:   int      (*r)(Vec);
 40:   PetscTruth match;
 41:   int        ierr;

 45:   PetscTypeCompare((PetscObject) vec, method, &match);
 46:   if (match == PETSC_TRUE) return(0);

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

 55:   if (vec->ops->destroy != PETSC_NULL) {
 56:     (*vec->ops->destroy)(vec);
 57:   }
 58:   (*r)(vec);

 60:   PetscObjectChangeTypeName((PetscObject) vec, method);
 61:   return(0);
 62: }

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

 69:   Not Collective

 71:   Input Parameter:
 72: . vec  - The vector

 74:   Output Parameter:
 75: . type - The vector type name

 77:   Level: intermediate

 79: .keywords: vector, get, type, name
 80: .seealso: VecSetType(), VecCreate()
 81: @*/
 82: int VecGetType(Vec vec, VecType *type)
 83: {

 89:   if (VecRegisterAllCalled == PETSC_FALSE) {
 90:     VecRegisterAll(PETSC_NULL);
 91:   }
 92:   *type = vec->type_name;
 93:   return(0);
 94: }

 98: /*@C
 99:   VecSetSerializeType - Sets the serialization method for the vector.

101:   Collective on Vec

103:   Input Parameters:
104: + vec    - The Vec object
105: - method - The vector serialization type name

107:   Options Database Command:
108: . -vec_serialize_type <method> - Sets the method; use -help for a list
109:                                  of available methods (for instance, seq_binary)

111:    Notes:
112:    See "petsc/include/petscvec.h" for available methods (for instance)
113: +  VEC_SER_SEQ_BINARY - Sequential vector to binary file
114: -  VEC_SER_MPI_BINARY - MPI vector to binary file

116:    Level: intermediate

118: .keywords: Vec, set, type, serialization
119: @*/
120: int VecSetSerializeType(Vec vec, VecSerializeType method)
121: {
122:   int      (*r)(MPI_Comm, Vec *, PetscViewer, PetscTruth);
123:   PetscTruth match;
124:   int        ierr;

128:   PetscSerializeCompare((PetscObject) vec, method, &match);
129:   if (match == PETSC_TRUE) return(0);

131:   /* Get the function pointers for the method requested but do not call */
132:   if (VecSerializeRegisterAllCalled == PETSC_FALSE) {
133:     VecSerializeRegisterAll(PETSC_NULL);
134:   }
135:   PetscFListFind(vec->comm, VecSerializeList, method, (void (**)(void)) &r);
136:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown vector serialization type: %s", method);

138:   PetscObjectChangeSerializeName((PetscObject) vec, method);
139:   return(0);
140: }

144: /*@C
145:   VecGetSerializeType - Gets the map serialization type name (as a string) from the Vec.

147:   Not collective

149:   Input Parameter:
150: . map  - The map

152:   Output Parameter:
153: . type - The map type name

155:   Level: intermediate

157: .keywords: map, get, type, name
158: .seealso VecSetSerializeType(), VecCreate()
159: @*/
160: int VecGetSerializeType(Vec map, VecSerializeType *type)
161: {

167:   if (VecSerializeRegisterAllCalled == PETSC_FALSE) {
168:     VecSerializeRegisterAll(PETSC_NULL);
169:   }
170:   *type = map->serialize_name;
171:   return(0);
172: }

174: /*--------------------------------------------------------------------------------------------------------------------*/

178: /*@C
179:   VecRegister - See VecRegisterDynamic()

181:   Level: advanced
182: @*/
183: int VecRegister(const char sname[], const char path[], const char name[], int (*function)(Vec))
184: {
185:   char fullname[PETSC_MAX_PATH_LEN];
186:   int  ierr;

189:   PetscStrcpy(fullname, path);
190:   PetscStrcat(fullname, ":");
191:   PetscStrcat(fullname, name);
192:   PetscFListAdd(&VecList, sname, fullname, (void (*)(void)) function);
193:   return(0);
194: }

198: int VecSerializeRegister(const char sname[], const char path[], const char name[],
199:                           int (*function)(MPI_Comm, Vec *, PetscViewer, PetscTruth))
200: {
201:   char fullname[PETSC_MAX_PATH_LEN];
202:   int  ierr;

205:   PetscStrcpy(fullname, path);
206:   PetscStrcat(fullname, ":");
207:   PetscStrcat(fullname, name);
208:   PetscFListAdd(&VecSerializeList, sname, fullname, (void (*)(void)) function);
209:   return(0);
210: }

212: /*--------------------------------------------------------------------------------------------------------------------*/
215: /*@C
216:    VecRegisterDestroy - Frees the list of Vec methods that were registered by VecRegister()/VecRegisterDynamic().

218:    Not Collective

220:    Level: advanced

222: .keywords: Vec, register, destroy
223: .seealso: VecRegister(), VecRegisterAll(), VecSerializeRegisterDestroy(), VecRegisterDynamic()
224: @*/
225: int VecRegisterDestroy(void)
226: {

230:   if (VecList != PETSC_NULL) {
231:     PetscFListDestroy(&VecList);
232:     VecList = PETSC_NULL;
233:   }
234:   VecRegisterAllCalled = PETSC_FALSE;
235:   return(0);
236: }

240: /*@C
241:   VecSerializeRegisterDestroy - Frees the list of serialization routines for
242:   vectors that were registered by VecSerializeRegister().

244:   Not collective

246:   Level: advanced

248: .keywords: Vec, vector, register, destroy
249: .seealso: VecSerializeRegisterAll()
250: @*/
251: int VecSerializeRegisterDestroy()
252: {

256:   if (VecSerializeList != PETSC_NULL) {
257:     PetscFListDestroy(&VecSerializeList);
258:     VecSerializeList = PETSC_NULL;
259:   }
260:   VecSerializeRegisterAllCalled = PETSC_FALSE;
261:   return(0);
262: }