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: 18811af0c4SBarry Smith . comm - the MPI communicator or `MPI_COMM_NULL` if object is not valid 19ce94432eSBarry Smith 20ce94432eSBarry Smith Level: advanced 21ce94432eSBarry Smith 22811af0c4SBarry Smith .seealso: `PetscObject`, `PetscObjectGetComm()` 23ce94432eSBarry Smith @*/ 24d71ae5a4SJacob Faibussowitsch MPI_Comm PetscObjectComm(PetscObject obj) 25d71ae5a4SJacob Faibussowitsch { 265f80ce2aSJacob Faibussowitsch return obj ? obj->comm : MPI_COMM_NULL; 27ce94432eSBarry Smith } 28ce94432eSBarry Smith 29e5c89e4eSSatish Balay /*@C 30811af0c4SBarry Smith PetscObjectGetComm - Gets the MPI communicator for any `PetscObject`, 31e5c89e4eSSatish Balay regardless of the type. 32e5c89e4eSSatish Balay 33e5c89e4eSSatish Balay Not Collective 34e5c89e4eSSatish Balay 35e5c89e4eSSatish Balay Input Parameter: 36811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 37811af0c4SBarry Smith cast with a (`PetscObject`), for example, 38811af0c4SBarry Smith `PetscObjectGetComm`((`PetscObject`)mat,&comm); 39e5c89e4eSSatish Balay 40e5c89e4eSSatish Balay Output Parameter: 41e5c89e4eSSatish Balay . comm - the MPI communicator 42e5c89e4eSSatish Balay 43e5c89e4eSSatish Balay Level: advanced 44e5c89e4eSSatish Balay 45db781477SPatrick Sanan .seealso: `PetscObjectComm()` 46e5c89e4eSSatish Balay @*/ 47d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectGetComm(PetscObject obj, MPI_Comm *comm) 48d71ae5a4SJacob Faibussowitsch { 49e5c89e4eSSatish Balay PetscFunctionBegin; 503cfa8680SLisandro Dalcin PetscValidHeader(obj, 1); 513cfa8680SLisandro Dalcin PetscValidPointer(comm, 2); 52118605f4SJacob Faibussowitsch *comm = obj->comm; 533ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 54e5c89e4eSSatish Balay } 55e5c89e4eSSatish Balay 56cbf1b8bfSBarry Smith /*@ 57811af0c4SBarry Smith PetscObjectGetTabLevel - Gets the number of tabs that `PETSCVIEWERASCII` output for that object uses 58e5c89e4eSSatish Balay 591cee3971SBarry Smith Not Collective 601cee3971SBarry Smith 611cee3971SBarry Smith Input Parameter: 62811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 63811af0c4SBarry Smith cast with a (`PetscObject`), for example, 64811af0c4SBarry Smith `PetscObjectGetTabLevel`((`PetscObject`)mat,&tab); 651cee3971SBarry Smith 661cee3971SBarry Smith Output Parameter: 671cee3971SBarry Smith . tab - the number of tabs 681cee3971SBarry Smith 691cee3971SBarry Smith Level: developer 701cee3971SBarry Smith 71811af0c4SBarry Smith Note: 72811af0c4SBarry Smith This is used to manage the output from options that are embedded in other objects. For example 73811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 741cee3971SBarry Smith is very clear. 751cee3971SBarry Smith 76811af0c4SBarry Smith .seealso: `PetscObjectIncrementTabLevel()`, `PETSCVIEWERASCII` 771cee3971SBarry Smith @*/ 78d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectGetTabLevel(PetscObject obj, PetscInt *tab) 79d71ae5a4SJacob Faibussowitsch { 801cee3971SBarry Smith PetscFunctionBegin; 811cee3971SBarry Smith PetscValidHeader(obj, 1); 825f80ce2aSJacob Faibussowitsch PetscValidIntPointer(tab, 2); 831cee3971SBarry Smith *tab = obj->tablevel; 843ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 851cee3971SBarry Smith } 861cee3971SBarry Smith 87da35de2aSMatthew G Knepley /*@ 88811af0c4SBarry Smith PetscObjectSetTabLevel - Sets the number of tabs that `PETSCVIEWERASCII` output for that object uses 89da35de2aSMatthew G Knepley 90da35de2aSMatthew G Knepley Not Collective 91da35de2aSMatthew G Knepley 92da35de2aSMatthew G Knepley Input Parameters: 93811af0c4SBarry Smith + obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 94811af0c4SBarry Smith cast with a (`PetscObject`), for example, 95811af0c4SBarry Smith `PetscObjectSetTabLevel`((`PetscObject`)mat,tab; 96da35de2aSMatthew G Knepley - tab - the number of tabs 97da35de2aSMatthew G Knepley 98da35de2aSMatthew G Knepley Level: developer 99da35de2aSMatthew G Knepley 10095452b02SPatrick Sanan Notes: 1016aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 102811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 103da35de2aSMatthew G Knepley is very clear. 104da35de2aSMatthew G Knepley 105811af0c4SBarry Smith `PetscObjectIncrementTabLevel()` is the preferred API 106811af0c4SBarry Smith 107db781477SPatrick Sanan .seealso: `PetscObjectIncrementTabLevel()` 108da35de2aSMatthew G Knepley @*/ 109d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSetTabLevel(PetscObject obj, PetscInt tab) 110d71ae5a4SJacob Faibussowitsch { 111da35de2aSMatthew G Knepley PetscFunctionBegin; 112da35de2aSMatthew G Knepley PetscValidHeader(obj, 1); 113da35de2aSMatthew G Knepley obj->tablevel = tab; 1143ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 115da35de2aSMatthew G Knepley } 116da35de2aSMatthew G Knepley 117cbf1b8bfSBarry Smith /*@ 118811af0c4SBarry Smith PetscObjectIncrementTabLevel - Increments the number of tabs that `PETSCVIEWERASCII` output for that object use based on 1191cee3971SBarry Smith the tablevel of another object. This should be called immediately after the object is created. 1201cee3971SBarry Smith 1211cee3971SBarry Smith Not Collective 1221cee3971SBarry Smith 123d8d19677SJose E. Roman Input Parameters: 1241cee3971SBarry Smith + obj - any PETSc object where we are changing the tab 125*aa76f320SBarry Smith . oldobj - the object providing the tab, optional pass `NULL` to use 0 as the previous tablevel for `obj` 1261cee3971SBarry Smith - tab - the increment that is added to the old objects tab 1271cee3971SBarry Smith 1281cee3971SBarry Smith Level: developer 1291cee3971SBarry Smith 130811af0c4SBarry Smith Note: 1316aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 132811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 1331cee3971SBarry Smith is very clear. 1341cee3971SBarry Smith 135811af0c4SBarry Smith .seealso: `PETSCVIEWERASCII`, `PetscObjectSetTabLevel()`, `PetscObjectGetTabLevel()` 1361cee3971SBarry Smith @*/ 137d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectIncrementTabLevel(PetscObject obj, PetscObject oldobj, PetscInt tab) 138d71ae5a4SJacob Faibussowitsch { 1391cee3971SBarry Smith PetscFunctionBegin; 1401cee3971SBarry Smith PetscValidHeader(obj, 1); 1415f80ce2aSJacob Faibussowitsch if (oldobj) PetscValidHeader(oldobj, 2); 1425f80ce2aSJacob Faibussowitsch obj->tablevel = (oldobj ? oldobj->tablevel : 0) + tab; 1433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1441cee3971SBarry Smith } 145