Actual source code: destroy.c
1: /*$Id: destroy.c,v 1.59 2001/03/23 23:20:38 balay Exp $*/
2: /*
3: Provides utility routines for manulating any type of PETSc object.
4: */
5: #include petsc.h
7: #undef __FUNCT__
9: /*@C
10: PetscObjectDestroy - Destroys any PetscObject, regardless of the type.
12: Collective on PetscObject
14: Input Parameter:
15: . obj - any PETSc object, for example a Vec, Mat or KSP.
16: This must be cast with a (PetscObject), for example,
17: PetscObjectDestroy((PetscObject)mat);
19: Level: intermediate
21: Concepts: destroying object
22: Concepts: freeing object
23: Concepts: deleting object
25: @*/
26: int PetscObjectDestroy(PetscObject obj)
27: {
33: if (obj->bops->destroy) {
34: (*obj->bops->destroy)(obj);
35: } else {
36: SETERRQ(PETSC_ERR_SUP,"This PETSc object does not have a generic destroy routine");
37: }
38: return(0);
39: }
41: #undef __FUNCT__
43: /*@C
44: PetscObjectView - Views any PetscObject, regardless of the type.
46: Collective on PetscObject
48: Input Parameters:
49: + obj - any PETSc object, for example a Vec, Mat or KSP.
50: This must be cast with a (PetscObject), for example,
51: PetscObjectView((PetscObject)mat,viewer);
52: - viewer - any PETSc viewer
54: Level: intermediate
56: @*/
57: int PetscObjectView(PetscObject obj,PetscViewer viewer)
58: {
63: if (!viewer) viewer = PETSC_VIEWER_STDOUT_(obj->comm);
66: if (obj->bops->view) {
67: (*obj->bops->view)(obj,viewer);
68: } else {
69: SETERRQ(PETSC_ERR_SUP,"This PETSc object does not have a generic viewer routine");
70: }
71: return(0);
72: }
74: #undef __FUNCT__
76: /*@C
77: PetscTypeCompare - Determines whether a PETSc object is of a particular type.
79: Not Collective
81: Input Parameters:
82: + obj - any PETSc object, for example a Vec, Mat or KSP.
83: This must be cast with a (PetscObject), for example,
84: PetscObjectDestroy((PetscObject)mat);
85: - type_name - string containing a type name
87: Output Parameter:
88: . same - PETSC_TRUE if they are the same, else PETSC_FALSE
89:
90: Level: intermediate
92: .seealso: VecGetType(), KSPGetType(), PCGetType(), SNESGetType()
94: Concepts: comparing^object types
95: Concepts: types^comparing
96: Concepts: object type^comparing
98: @*/
99: int PetscTypeCompare(PetscObject obj,char *type_name,PetscTruth *same)
100: {
104: if (!obj) {
105: *same = PETSC_FALSE;
106: } else if (type_name == PETSC_NULL && obj->type_name == PETSC_NULL) {
107: *same = PETSC_TRUE;
108: } else if (type_name == PETSC_NULL || obj->type_name == PETSC_NULL) {
109: *same = PETSC_FALSE;
110: } else {
113: PetscStrcmp((char*)(obj->type_name),type_name,same);
114: }
115: return(0);
116: }
118: #undef __FUNCT__
120: /*@C
121: PetscSerializeCompare - Determines if a PETSc object has a particular serializer.
123: Not Collective
125: Input Parameters:
126: + obj - The PETSc object, for example a Vec, Mat or KSP.
127: - serialize_name - string containing a serializer name
129: Output Parameter:
130: . same - PETSC_TRUE if they are the same, else PETSC_FALSE
132: Note:
133: This works for any PETSc object, and thus must be cast with a (PetscObject).
135: Level: intermediate
137: .keywords: comparing serializers
138: .seealso: VecGetType(), KSPGetType(), PCGetType(), SNESGetType()
140: Concepts: comparing^object serializers
141: Concepts: serialize^comparing
142: Concepts: object serialize^comparing
143: @*/
144: int PetscSerializeCompare(PetscObject obj, char *serialize_name, PetscTruth *same)
145: {
149: if (!obj) {
150: *same = PETSC_FALSE;
151: } else if ((serialize_name == PETSC_NULL) && (obj->serialize_name == PETSC_NULL)) {
152: *same = PETSC_TRUE;
153: } else if ((serialize_name == PETSC_NULL) || (obj->serialize_name == PETSC_NULL)) {
154: *same = PETSC_FALSE;
155: } else {
158: PetscStrcmp((char *) (obj->serialize_name), serialize_name, same);
159: }
160: return(0);
161: }
163: static int PetscObjectRegisterDestroy_Count = 0;
164: static PetscObject PetscObjectRegisterDestroy_Objects[128];
166: #undef __FUNCT__
168: /*@C
169: PetscObjectRegisterDestroy - Registers a PETSc object to be destroyed when
170: PetscFinalize() is called.
172: Collective on PetscObject
174: Input Parameter:
175: . obj - any PETSc object, for example a Vec, Mat or KSP.
176: This must be cast with a (PetscObject), for example,
177: PetscObjectRegisterDestroy((PetscObject)mat);
179: Level: developer
181: Notes:
182: This is used by, for example, PETSC_VIEWER_XXX_() routines to free the viewer
183: when PETSc ends.
185: .seealso: PetscObjectRegisterDestroyAll()
186: @*/
187: int PetscObjectRegisterDestroy(PetscObject obj)
188: {
191: PetscObjectRegisterDestroy_Objects[PetscObjectRegisterDestroy_Count++] = obj;
192: return(0);
193: }
195: #undef __FUNCT__
197: /*@C
198: PetscObjectRegisterDestroyAll - Frees all the PETSc objects that have been registered
199: with PetscObjectRegisterDestroy(). Called by PetscFinalize()
200: PetscFinalize() is called.
202: Collective on individual PetscObjects
204: Level: developer
206: .seealso: PetscObjectRegisterDestroy()
207: @*/
208: int PetscObjectRegisterDestroyAll(void)
209: {
210: int ierr,i;
213: for (i=0; i<PetscObjectRegisterDestroy_Count; i++) {
214: PetscObjectDestroy(PetscObjectRegisterDestroy_Objects[i]);
215: }
216: return(0);
217: }