17d0a6c19SBarry Smith 2e5c89e4eSSatish Balay /* 3e5c89e4eSSatish Balay Provides utility routines for manulating any type of PETSc object. 4e5c89e4eSSatish Balay */ 5af0996ceSBarry Smith #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 6e5c89e4eSSatish Balay 7ce94432eSBarry Smith /*@C 8*811af0c4SBarry Smith PetscObjectComm - Gets the MPI communicator for any `PetscObject` regardless of the type. 9ce94432eSBarry Smith 10ce94432eSBarry Smith Not Collective 11ce94432eSBarry Smith 12ce94432eSBarry Smith Input Parameter: 13*811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 14*811af0c4SBarry Smith cast with a (`PetscObject`), for example, 15*811af0c4SBarry Smith `PetscObjectComm`((`PetscObjec`t)mat,...); 16ce94432eSBarry Smith 17ce94432eSBarry Smith Output Parameter: 18*811af0c4SBarry Smith . comm - the MPI communicator or `MPI_COMM_NULL` if object is not valid 19ce94432eSBarry Smith 20ce94432eSBarry Smith Level: advanced 21ce94432eSBarry Smith 22*811af0c4SBarry Smith .seealso: `PetscObject`, `PetscObjectGetComm()` 23ce94432eSBarry Smith @*/ 249371c9d4SSatish Balay MPI_Comm PetscObjectComm(PetscObject obj) { 255f80ce2aSJacob Faibussowitsch return obj ? obj->comm : MPI_COMM_NULL; 26ce94432eSBarry Smith } 27ce94432eSBarry Smith 28e5c89e4eSSatish Balay /*@C 29*811af0c4SBarry Smith PetscObjectGetComm - Gets the MPI communicator for any `PetscObject`, 30e5c89e4eSSatish Balay regardless of the type. 31e5c89e4eSSatish Balay 32e5c89e4eSSatish Balay Not Collective 33e5c89e4eSSatish Balay 34e5c89e4eSSatish Balay Input Parameter: 35*811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 36*811af0c4SBarry Smith cast with a (`PetscObject`), for example, 37*811af0c4SBarry Smith `PetscObjectGetComm`((`PetscObject`)mat,&comm); 38e5c89e4eSSatish Balay 39e5c89e4eSSatish Balay Output Parameter: 40e5c89e4eSSatish Balay . comm - the MPI communicator 41e5c89e4eSSatish Balay 42e5c89e4eSSatish Balay Level: advanced 43e5c89e4eSSatish Balay 44db781477SPatrick Sanan .seealso: `PetscObjectComm()` 45e5c89e4eSSatish Balay @*/ 469371c9d4SSatish Balay PetscErrorCode PetscObjectGetComm(PetscObject obj, MPI_Comm *comm) { 47e5c89e4eSSatish Balay PetscFunctionBegin; 483cfa8680SLisandro Dalcin PetscValidHeader(obj, 1); 493cfa8680SLisandro Dalcin PetscValidPointer(comm, 2); 509566063dSJacob Faibussowitsch if (obj->bops->getcomm) PetscCall(obj->bops->getcomm(obj, comm)); 515f80ce2aSJacob Faibussowitsch else *comm = obj->comm; 52e5c89e4eSSatish Balay PetscFunctionReturn(0); 53e5c89e4eSSatish Balay } 54e5c89e4eSSatish Balay 55cbf1b8bfSBarry Smith /*@ 56*811af0c4SBarry Smith PetscObjectGetTabLevel - Gets the number of tabs that `PETSCVIEWERASCII` output for that object uses 57e5c89e4eSSatish Balay 581cee3971SBarry Smith Not Collective 591cee3971SBarry Smith 601cee3971SBarry Smith Input Parameter: 61*811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 62*811af0c4SBarry Smith cast with a (`PetscObject`), for example, 63*811af0c4SBarry Smith `PetscObjectGetTabLevel`((`PetscObject`)mat,&tab); 641cee3971SBarry Smith 651cee3971SBarry Smith Output Parameter: 661cee3971SBarry Smith . tab - the number of tabs 671cee3971SBarry Smith 681cee3971SBarry Smith Level: developer 691cee3971SBarry Smith 70*811af0c4SBarry Smith Note: 71*811af0c4SBarry Smith This is used to manage the output from options that are embedded in other objects. For example 72*811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 731cee3971SBarry Smith is very clear. 741cee3971SBarry Smith 75*811af0c4SBarry Smith .seealso: `PetscObjectIncrementTabLevel()`, `PETSCVIEWERASCII` 761cee3971SBarry Smith @*/ 779371c9d4SSatish Balay PetscErrorCode PetscObjectGetTabLevel(PetscObject obj, PetscInt *tab) { 781cee3971SBarry Smith PetscFunctionBegin; 791cee3971SBarry Smith PetscValidHeader(obj, 1); 805f80ce2aSJacob Faibussowitsch PetscValidIntPointer(tab, 2); 811cee3971SBarry Smith *tab = obj->tablevel; 821cee3971SBarry Smith PetscFunctionReturn(0); 831cee3971SBarry Smith } 841cee3971SBarry Smith 85da35de2aSMatthew G Knepley /*@ 86*811af0c4SBarry Smith PetscObjectSetTabLevel - Sets the number of tabs that `PETSCVIEWERASCII` output for that object uses 87da35de2aSMatthew G Knepley 88da35de2aSMatthew G Knepley Not Collective 89da35de2aSMatthew G Knepley 90da35de2aSMatthew G Knepley Input Parameters: 91*811af0c4SBarry Smith + obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 92*811af0c4SBarry Smith cast with a (`PetscObject`), for example, 93*811af0c4SBarry Smith `PetscObjectSetTabLevel`((`PetscObject`)mat,tab; 94da35de2aSMatthew G Knepley - tab - the number of tabs 95da35de2aSMatthew G Knepley 96da35de2aSMatthew G Knepley Level: developer 97da35de2aSMatthew G Knepley 9895452b02SPatrick Sanan Notes: 996aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 100*811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 101da35de2aSMatthew G Knepley is very clear. 102da35de2aSMatthew G Knepley 103*811af0c4SBarry Smith `PetscObjectIncrementTabLevel()` is the preferred API 104*811af0c4SBarry Smith 105db781477SPatrick Sanan .seealso: `PetscObjectIncrementTabLevel()` 106da35de2aSMatthew G Knepley @*/ 1079371c9d4SSatish Balay PetscErrorCode PetscObjectSetTabLevel(PetscObject obj, PetscInt tab) { 108da35de2aSMatthew G Knepley PetscFunctionBegin; 109da35de2aSMatthew G Knepley PetscValidHeader(obj, 1); 110da35de2aSMatthew G Knepley obj->tablevel = tab; 111da35de2aSMatthew G Knepley PetscFunctionReturn(0); 112da35de2aSMatthew G Knepley } 113da35de2aSMatthew G Knepley 114cbf1b8bfSBarry Smith /*@ 115*811af0c4SBarry Smith PetscObjectIncrementTabLevel - Increments the number of tabs that `PETSCVIEWERASCII` output for that object use based on 1161cee3971SBarry Smith the tablevel of another object. This should be called immediately after the object is created. 1171cee3971SBarry Smith 1181cee3971SBarry Smith Not Collective 1191cee3971SBarry Smith 120d8d19677SJose E. Roman Input Parameters: 1211cee3971SBarry Smith + obj - any PETSc object where we are changing the tab 1221cee3971SBarry Smith . oldobj - the object providing the tab 1231cee3971SBarry Smith - tab - the increment that is added to the old objects tab 1241cee3971SBarry Smith 1251cee3971SBarry Smith Level: developer 1261cee3971SBarry Smith 127*811af0c4SBarry Smith Note: 1286aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 129*811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 1301cee3971SBarry Smith is very clear. 1311cee3971SBarry Smith 132*811af0c4SBarry Smith .seealso: `PETSCVIEWERASCII`, `PetscObjectSetTabLevel()`, `PetscObjectGetTabLevel()` 1331cee3971SBarry Smith @*/ 1349371c9d4SSatish Balay PetscErrorCode PetscObjectIncrementTabLevel(PetscObject obj, PetscObject oldobj, PetscInt tab) { 1351cee3971SBarry Smith PetscFunctionBegin; 1361cee3971SBarry Smith PetscValidHeader(obj, 1); 1375f80ce2aSJacob Faibussowitsch if (oldobj) PetscValidHeader(oldobj, 2); 1385f80ce2aSJacob Faibussowitsch obj->tablevel = (oldobj ? oldobj->tablevel : 0) + tab; 1391cee3971SBarry Smith PetscFunctionReturn(0); 1401cee3971SBarry Smith } 141