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 vecimpl.h
7: PetscFList VecList = PETSC_NULL;
8: PetscTruth VecRegisterAllCalled = PETSC_FALSE;
12: /*@C
13: VecSetType - Builds a vector, for a particular vector implementation.
15: Collective on Vec
17: Input Parameters:
18: + vec - The vector object
19: - method - The name of the vector type
21: Options Database Key:
22: . -vec_type <type> - Sets the vector type; use -help for a list
23: of available types
25: Notes:
26: See "petsc/include/vec.h" for available vector types (for instance, VECSEQ, VECMPI, or VECSHARED).
28: Use VecDuplicate() or VecDuplicateVecs() to form additional vectors of the same type as an existing vector.
30: Level: intermediate
32: .keywords: vector, set, type
33: .seealso: VecGetType(), VecCreate()
34: @*/
35: int VecSetType(Vec vec, const VecType method)
36: {
37: int (*r)(Vec);
38: PetscTruth match;
39: int ierr;
43: PetscTypeCompare((PetscObject) vec, method, &match);
44: if (match == PETSC_TRUE) return(0);
46: /* Get the function pointers for the vector requested */
47: if (VecRegisterAllCalled == PETSC_FALSE) {
48: VecRegisterAll(PETSC_NULL);
49: }
50: PetscFListFind(vec->comm, VecList, method,(void (**)(void)) &r);
51: if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown vector type: %s", method);
53: if (vec->ops->destroy != PETSC_NULL) {
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: int VecGetType(Vec vec, VecType *type)
81: {
87: if (VecRegisterAllCalled == PETSC_FALSE) {
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: int VecRegister(const char sname[], const char path[], const char name[], int (*function)(Vec))
105: {
106: char fullname[PETSC_MAX_PATH_LEN];
107: int ierr;
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: int VecRegisterDestroy(void)
132: {
136: if (VecList != PETSC_NULL) {
137: PetscFListDestroy(&VecList);
138: VecList = PETSC_NULL;
139: }
140: VecRegisterAllCalled = PETSC_FALSE;
141: return(0);
142: }