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