Actual source code: vecreg.c
1: #define PETSCVEC_DLL
3: #include private/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/petscvec.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 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->map.n < 0 && vec->map.N < 0) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call VecSetSizes() first");
46: PetscFListFind(VecList, vec->comm, method,(void (**)(void)) &r);
47: if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown vector type: %s", method);
49: if (vec->ops->destroy) {
50: (*vec->ops->destroy)(vec);
51: }
52: (*r)(vec);
54: PetscObjectChangeTypeName((PetscObject) vec, method);
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, VecType *type)
77: {
83: if (!VecRegisterAllCalled) {
84: VecRegisterAll(PETSC_NULL);
85: }
86: *type = 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: }