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, const VecType method)
34: {
35: PetscErrorCode (*r)(Vec);
36: PetscTruth match;
41: PetscTypeCompare((PetscObject) vec, method, &match);
42: if (match) return(0);
44: if (!VecRegisterAllCalled) {VecRegisterAll(PETSC_NULL);}
45: PetscFListFind(VecList, ((PetscObject)vec)->comm, method,(void (**)(void)) &r);
46: if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown vector type: %s", method);
48: if (vec->ops->destroy) {
49: (*vec->ops->destroy)(vec);
50: }
51: if (vec->map->n < 0 && vec->map->N < 0) {
52: vec->ops->create = r;
53: } else {
54: (*r)(vec);
55: }
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, const VecType *type)
78: {
84: if (!VecRegisterAllCalled) {
85: VecRegisterAll(PETSC_NULL);
86: }
87: *type = ((PetscObject)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: PetscFListDestroy(&VecList);
134: VecRegisterAllCalled = PETSC_FALSE;
135: return(0);
136: }