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 8811af0c4SBarry 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: 13811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 14811af0c4SBarry Smith cast with a (`PetscObject`), for example, 151a9a975bSPierre Jolivet `PetscObjectComm`((`PetscObject`)mat,...); 16ce94432eSBarry Smith 17ce94432eSBarry Smith Output Parameter: 18*21532e8aSBarry Smith . comm - the MPI communicator or `MPI_COMM_NULL` if `obj` is not valid 19ce94432eSBarry Smith 20ce94432eSBarry Smith Level: advanced 21ce94432eSBarry Smith 22*21532e8aSBarry Smith Note: 23*21532e8aSBarry Smith This is one of the rare PETSc routines that does not return an error code. Use `PetscObjectGetComm()` 24*21532e8aSBarry Smith when appropriate for error handling. 25*21532e8aSBarry Smith 26811af0c4SBarry Smith .seealso: `PetscObject`, `PetscObjectGetComm()` 27ce94432eSBarry Smith @*/ 28d71ae5a4SJacob Faibussowitsch MPI_Comm PetscObjectComm(PetscObject obj) 29d71ae5a4SJacob Faibussowitsch { 305f80ce2aSJacob Faibussowitsch return obj ? obj->comm : MPI_COMM_NULL; 31ce94432eSBarry Smith } 32ce94432eSBarry Smith 33e5c89e4eSSatish Balay /*@C 34811af0c4SBarry Smith PetscObjectGetComm - Gets the MPI communicator for any `PetscObject`, 35e5c89e4eSSatish Balay regardless of the type. 36e5c89e4eSSatish Balay 37e5c89e4eSSatish Balay Not Collective 38e5c89e4eSSatish Balay 39e5c89e4eSSatish Balay Input Parameter: 40811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 41811af0c4SBarry Smith cast with a (`PetscObject`), for example, 42811af0c4SBarry Smith `PetscObjectGetComm`((`PetscObject`)mat,&comm); 43e5c89e4eSSatish Balay 44e5c89e4eSSatish Balay Output Parameter: 45e5c89e4eSSatish Balay . comm - the MPI communicator 46e5c89e4eSSatish Balay 47e5c89e4eSSatish Balay Level: advanced 48e5c89e4eSSatish Balay 49*21532e8aSBarry Smith .seealso: `PetscObject`, `PetscObjectComm()` 50e5c89e4eSSatish Balay @*/ 51d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectGetComm(PetscObject obj, MPI_Comm *comm) 52d71ae5a4SJacob Faibussowitsch { 53e5c89e4eSSatish Balay PetscFunctionBegin; 543cfa8680SLisandro Dalcin PetscValidHeader(obj, 1); 553cfa8680SLisandro Dalcin PetscValidPointer(comm, 2); 56118605f4SJacob Faibussowitsch *comm = obj->comm; 573ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 58e5c89e4eSSatish Balay } 59e5c89e4eSSatish Balay 60cbf1b8bfSBarry Smith /*@ 61811af0c4SBarry Smith PetscObjectGetTabLevel - Gets the number of tabs that `PETSCVIEWERASCII` output for that object uses 62e5c89e4eSSatish Balay 631cee3971SBarry Smith Not Collective 641cee3971SBarry Smith 651cee3971SBarry Smith Input Parameter: 66811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 67811af0c4SBarry Smith cast with a (`PetscObject`), for example, 68811af0c4SBarry Smith `PetscObjectGetTabLevel`((`PetscObject`)mat,&tab); 691cee3971SBarry Smith 701cee3971SBarry Smith Output Parameter: 711cee3971SBarry Smith . tab - the number of tabs 721cee3971SBarry Smith 731cee3971SBarry Smith Level: developer 741cee3971SBarry Smith 75811af0c4SBarry Smith Note: 76811af0c4SBarry Smith This is used to manage the output from options that are embedded in other objects. For example 77811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 781cee3971SBarry Smith is very clear. 791cee3971SBarry Smith 80*21532e8aSBarry Smith .seealso: `PetscObjectIncrementTabLevel()`, `PetscObjectSetTabLevel()`, `PETSCVIEWERASCII`, `PetscObject` 811cee3971SBarry Smith @*/ 82d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectGetTabLevel(PetscObject obj, PetscInt *tab) 83d71ae5a4SJacob Faibussowitsch { 841cee3971SBarry Smith PetscFunctionBegin; 851cee3971SBarry Smith PetscValidHeader(obj, 1); 865f80ce2aSJacob Faibussowitsch PetscValidIntPointer(tab, 2); 871cee3971SBarry Smith *tab = obj->tablevel; 883ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 891cee3971SBarry Smith } 901cee3971SBarry Smith 91da35de2aSMatthew G Knepley /*@ 92811af0c4SBarry Smith PetscObjectSetTabLevel - Sets the number of tabs that `PETSCVIEWERASCII` output for that object uses 93da35de2aSMatthew G Knepley 94da35de2aSMatthew G Knepley Not Collective 95da35de2aSMatthew G Knepley 96da35de2aSMatthew G Knepley Input Parameters: 97811af0c4SBarry Smith + obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 98811af0c4SBarry Smith cast with a (`PetscObject`), for example, 99811af0c4SBarry Smith `PetscObjectSetTabLevel`((`PetscObject`)mat,tab; 100da35de2aSMatthew G Knepley - tab - the number of tabs 101da35de2aSMatthew G Knepley 102da35de2aSMatthew G Knepley Level: developer 103da35de2aSMatthew G Knepley 10495452b02SPatrick Sanan Notes: 1056aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 106811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 107da35de2aSMatthew G Knepley is very clear. 108da35de2aSMatthew G Knepley 109811af0c4SBarry Smith `PetscObjectIncrementTabLevel()` is the preferred API 110811af0c4SBarry Smith 111*21532e8aSBarry Smith .seealso: `PetscObjectIncrementTabLevel()`, `PetscObjectGetTabLevel()` 112da35de2aSMatthew G Knepley @*/ 113d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSetTabLevel(PetscObject obj, PetscInt tab) 114d71ae5a4SJacob Faibussowitsch { 115da35de2aSMatthew G Knepley PetscFunctionBegin; 116da35de2aSMatthew G Knepley PetscValidHeader(obj, 1); 117da35de2aSMatthew G Knepley obj->tablevel = tab; 1183ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 119da35de2aSMatthew G Knepley } 120da35de2aSMatthew G Knepley 121cbf1b8bfSBarry Smith /*@ 122811af0c4SBarry Smith PetscObjectIncrementTabLevel - Increments the number of tabs that `PETSCVIEWERASCII` output for that object use based on 1231cee3971SBarry Smith the tablevel of another object. This should be called immediately after the object is created. 1241cee3971SBarry Smith 1251cee3971SBarry Smith Not Collective 1261cee3971SBarry Smith 127d8d19677SJose E. Roman Input Parameters: 1281cee3971SBarry Smith + obj - any PETSc object where we are changing the tab 129aa76f320SBarry Smith . oldobj - the object providing the tab, optional pass `NULL` to use 0 as the previous tablevel for `obj` 1301cee3971SBarry Smith - tab - the increment that is added to the old objects tab 1311cee3971SBarry Smith 1321cee3971SBarry Smith Level: developer 1331cee3971SBarry Smith 134811af0c4SBarry Smith Note: 1356aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 136811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 1371cee3971SBarry Smith is very clear. 1381cee3971SBarry Smith 139811af0c4SBarry Smith .seealso: `PETSCVIEWERASCII`, `PetscObjectSetTabLevel()`, `PetscObjectGetTabLevel()` 1401cee3971SBarry Smith @*/ 141d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectIncrementTabLevel(PetscObject obj, PetscObject oldobj, PetscInt tab) 142d71ae5a4SJacob Faibussowitsch { 1431cee3971SBarry Smith PetscFunctionBegin; 1441cee3971SBarry Smith PetscValidHeader(obj, 1); 1455f80ce2aSJacob Faibussowitsch if (oldobj) PetscValidHeader(oldobj, 2); 1465f80ce2aSJacob Faibussowitsch obj->tablevel = (oldobj ? oldobj->tablevel : 0) + tab; 1473ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1481cee3971SBarry Smith } 149