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