Actual source code: vecreg.c
2: #include <private/vecimpl.h> /*I "petscvec.h" I*/
4: PetscFList VecList = PETSC_NULL;
5: PetscBool 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/petscvec.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: PetscBool match;
40: PetscTypeCompare((PetscObject) vec, method, &match);
41: if (match) return(0);
43: if (!VecRegisterAllCalled) {VecRegisterAll(PETSC_NULL);}
44: PetscFListFind(VecList, ((PetscObject)vec)->comm, method,PETSC_TRUE,(void (**)(void)) &r);
45: if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown vector type: %s", method);
46: if (vec->ops->destroy) {
47: (*vec->ops->destroy)(vec);
48: }
49: if (vec->map->n < 0 && vec->map->N < 0) {
50: vec->ops->create = r;
51: vec->ops->load = VecLoad_Default;
52: } else {
53: (*r)(vec);
54: }
55: return(0);
56: }
60: /*@C
61: VecGetType - Gets the vector type name (as a string) from the Vec.
63: Not Collective
65: Input Parameter:
66: . vec - The vector
68: Output Parameter:
69: . type - The vector type name
71: Level: intermediate
73: .keywords: vector, get, type, name
74: .seealso: VecSetType(), VecCreate()
75: @*/
76: PetscErrorCode VecGetType(Vec vec, const VecType *type)
77: {
83: if (!VecRegisterAllCalled) {
84: VecRegisterAll(PETSC_NULL);
85: }
86: *type = ((PetscObject)vec)->type_name;
87: return(0);
88: }
91: /*--------------------------------------------------------------------------------------------------------------------*/
95: /*@C
96: VecRegister - See VecRegisterDynamic()
98: Level: advanced
99: @*/
100: PetscErrorCode VecRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(Vec))
101: {
102: char fullname[PETSC_MAX_PATH_LEN];
106: PetscStrcpy(fullname, path);
107: PetscStrcat(fullname, ":");
108: PetscStrcat(fullname, name);
109: PetscFListAdd(&VecList, sname, fullname, (void (*)(void)) function);
110: return(0);
111: }
114: /*--------------------------------------------------------------------------------------------------------------------*/
117: /*@C
118: VecRegisterDestroy - Frees the list of Vec methods that were registered by VecRegister()/VecRegisterDynamic().
120: Not Collective
122: Level: advanced
124: .keywords: Vec, register, destroy
125: .seealso: VecRegister(), VecRegisterAll(), VecRegisterDynamic()
126: @*/
127: PetscErrorCode VecRegisterDestroy(void)
128: {
132: PetscFListDestroy(&VecList);
133: VecRegisterAllCalled = PETSC_FALSE;
134: return(0);
135: }