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