1 2 /* 3 Provides utility routines for manulating any type of PETSc object. 4 */ 5 #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 6 7 /*@C 8 PetscObjectComm - Gets the MPI communicator for any PetscObject regardless of the type. 9 10 Not Collective 11 12 Input Parameter: 13 . obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be 14 cast with a (PetscObject), for example, 15 SETERRQ(PetscObjectComm((PetscObject)mat,...); 16 17 Output Parameter: 18 . comm - the MPI communicator or MPI_COMM_NULL if object is not valid 19 20 Level: advanced 21 22 Notes: 23 Never use this in the form 24 $ comm = PetscObjectComm((PetscObject)obj); 25 instead use PetscObjectGetComm() 26 27 28 .seealso: PetscObjectGetComm() 29 @*/ 30 MPI_Comm PetscObjectComm(PetscObject obj) 31 { 32 if (!obj) return MPI_COMM_NULL; 33 return obj->comm; 34 } 35 36 /*@C 37 PetscObjectGetComm - Gets the MPI communicator for any PetscObject, 38 regardless of the type. 39 40 Not Collective 41 42 Input Parameter: 43 . obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be 44 cast with a (PetscObject), for example, 45 PetscObjectGetComm((PetscObject)mat,&comm); 46 47 Output Parameter: 48 . comm - the MPI communicator 49 50 Level: advanced 51 52 53 .seealso: PetscObjectComm() 54 @*/ 55 PetscErrorCode PetscObjectGetComm(PetscObject obj,MPI_Comm *comm) 56 { 57 PetscErrorCode ierr; 58 59 PetscFunctionBegin; 60 PetscValidHeader(obj,1); 61 PetscValidPointer(comm,2); 62 if (obj->bops->getcomm) { 63 ierr = obj->bops->getcomm(obj,comm);CHKERRQ(ierr); 64 } else *comm = obj->comm; 65 PetscFunctionReturn(0); 66 } 67 68 /*@ 69 PetscObjectGetTabLevel - Gets the number of tabs that ASCII output for that object use 70 71 Not Collective 72 73 Input Parameter: 74 . obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be 75 cast with a (PetscObject), for example, 76 PetscObjectGetComm((PetscObject)mat,&comm); 77 78 Output Parameter: 79 . tab - the number of tabs 80 81 Level: developer 82 83 Notes: 84 this is used to manage the output from options that are imbedded in other objects. For example 85 the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects 86 is very clear. 87 88 .seealso: PetscObjectIncrementTabLevel() 89 90 @*/ 91 PetscErrorCode PetscObjectGetTabLevel(PetscObject obj,PetscInt *tab) 92 { 93 PetscFunctionBegin; 94 PetscValidHeader(obj,1); 95 *tab = obj->tablevel; 96 PetscFunctionReturn(0); 97 } 98 99 /*@ 100 PetscObjectSetTabLevel - Sets the number of tabs that ASCII output for that object use 101 102 Not Collective 103 104 Input Parameters: 105 + obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be 106 cast with a (PetscObject), for example, 107 PetscObjectGetComm((PetscObject)mat,&comm); 108 - tab - the number of tabs 109 110 Level: developer 111 112 Notes: 113 this is used to manage the output from options that are imbedded in other objects. For example 114 the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects 115 is very clear. 116 117 .seealso: PetscObjectIncrementTabLevel() 118 @*/ 119 PetscErrorCode PetscObjectSetTabLevel(PetscObject obj,PetscInt tab) 120 { 121 PetscFunctionBegin; 122 PetscValidHeader(obj,1); 123 obj->tablevel = tab; 124 PetscFunctionReturn(0); 125 } 126 127 /*@ 128 PetscObjectIncrementTabLevel - Sets the number of tabs that ASCII output for that object use based on 129 the tablevel of another object. This should be called immediately after the object is created. 130 131 Not Collective 132 133 Input Parameter: 134 + obj - any PETSc object where we are changing the tab 135 . oldobj - the object providing the tab 136 - tab - the increment that is added to the old objects tab 137 138 139 Level: developer 140 141 Notes: 142 this is used to manage the output from options that are imbedded in other objects. For example 143 the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects 144 is very clear. 145 146 .seealso: PetscObjectSetTabLevel(), PetscObjectGetTabLevel() 147 148 @*/ 149 PetscErrorCode PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab) 150 { 151 152 PetscFunctionBegin; 153 PetscValidHeader(obj,1); 154 if (oldobj) obj->tablevel = oldobj->tablevel + tab; 155 else obj->tablevel = tab; 156 PetscFunctionReturn(0); 157 } 158