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