1e5c89e4eSSatish Balay /* 2e5c89e4eSSatish Balay Provides utility routines for manulating any type of PETSc object. 3e5c89e4eSSatish Balay */ 4af0996ceSBarry Smith #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 5e5c89e4eSSatish Balay 6ce94432eSBarry Smith /*@C 7811af0c4SBarry Smith PetscObjectComm - Gets the MPI communicator for any `PetscObject` regardless of the type. 8ce94432eSBarry Smith 9*ffeef943SBarry Smith Not Collective, No Fortran Support 10ce94432eSBarry Smith 11ce94432eSBarry Smith Input Parameter: 12dde44402SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. It must be 1310450e9eSJacob Faibussowitsch cast with a (`PetscObject`), for example, `PetscObjectComm`((`PetscObject`)mat,...); 14ce94432eSBarry Smith 15ce94432eSBarry Smith Level: advanced 16ce94432eSBarry Smith 1721532e8aSBarry Smith Note: 1810450e9eSJacob Faibussowitsch Returns the MPI communicator or `MPI_COMM_NULL` if `obj` is not valid. 1910450e9eSJacob Faibussowitsch 2021532e8aSBarry Smith This is one of the rare PETSc routines that does not return an error code. Use `PetscObjectGetComm()` 2121532e8aSBarry Smith when appropriate for error handling. 2221532e8aSBarry Smith 23811af0c4SBarry Smith .seealso: `PetscObject`, `PetscObjectGetComm()` 24ce94432eSBarry Smith @*/ 25d71ae5a4SJacob Faibussowitsch MPI_Comm PetscObjectComm(PetscObject obj) 26d71ae5a4SJacob Faibussowitsch { 275f80ce2aSJacob Faibussowitsch return obj ? obj->comm : MPI_COMM_NULL; 28ce94432eSBarry Smith } 29ce94432eSBarry Smith 30e5c89e4eSSatish Balay /*@C 31dde44402SBarry Smith PetscObjectGetComm - Gets the MPI communicator for any `PetscObject` regardless of the type. 32e5c89e4eSSatish Balay 33e5c89e4eSSatish Balay Not Collective 34e5c89e4eSSatish Balay 35e5c89e4eSSatish Balay Input Parameter: 36dde44402SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. It must be cast with a (`PetscObject`), for example, 37811af0c4SBarry 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 4421532e8aSBarry Smith .seealso: `PetscObject`, `PetscObjectComm()` 45e5c89e4eSSatish Balay @*/ 46d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectGetComm(PetscObject obj, MPI_Comm *comm) 47d71ae5a4SJacob Faibussowitsch { 48e5c89e4eSSatish Balay PetscFunctionBegin; 493cfa8680SLisandro Dalcin PetscValidHeader(obj, 1); 504f572ea9SToby Isaac PetscAssertPointer(comm, 2); 51118605f4SJacob Faibussowitsch *comm = obj->comm; 523ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 53e5c89e4eSSatish Balay } 54e5c89e4eSSatish Balay 55cbf1b8bfSBarry Smith /*@ 56811af0c4SBarry 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: 61dde44402SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. It must be cast with a (`PetscObject`), for example, 62811af0c4SBarry Smith `PetscObjectGetTabLevel`((`PetscObject`)mat,&tab); 631cee3971SBarry Smith 641cee3971SBarry Smith Output Parameter: 651cee3971SBarry Smith . tab - the number of tabs 661cee3971SBarry Smith 671cee3971SBarry Smith Level: developer 681cee3971SBarry Smith 69811af0c4SBarry Smith Note: 70811af0c4SBarry Smith This is used to manage the output from options that are embedded in other objects. For example 71811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 72dde44402SBarry Smith is clear. 731cee3971SBarry Smith 7421532e8aSBarry Smith .seealso: `PetscObjectIncrementTabLevel()`, `PetscObjectSetTabLevel()`, `PETSCVIEWERASCII`, `PetscObject` 751cee3971SBarry Smith @*/ 76d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectGetTabLevel(PetscObject obj, PetscInt *tab) 77d71ae5a4SJacob Faibussowitsch { 781cee3971SBarry Smith PetscFunctionBegin; 791cee3971SBarry Smith PetscValidHeader(obj, 1); 804f572ea9SToby Isaac PetscAssertPointer(tab, 2); 811cee3971SBarry Smith *tab = obj->tablevel; 823ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 831cee3971SBarry Smith } 841cee3971SBarry Smith 85da35de2aSMatthew G Knepley /*@ 86811af0c4SBarry 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: 91dde44402SBarry Smith + obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. It must be cast with a (`PetscObject`), for example, 92811af0c4SBarry Smith `PetscObjectSetTabLevel`((`PetscObject`)mat,tab; 93da35de2aSMatthew G Knepley - tab - the number of tabs 94da35de2aSMatthew G Knepley 95da35de2aSMatthew G Knepley Level: developer 96da35de2aSMatthew G Knepley 9795452b02SPatrick Sanan Notes: 986aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 99811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 100dde44402SBarry Smith is clear. 101da35de2aSMatthew G Knepley 102811af0c4SBarry Smith `PetscObjectIncrementTabLevel()` is the preferred API 103811af0c4SBarry Smith 10421532e8aSBarry Smith .seealso: `PetscObjectIncrementTabLevel()`, `PetscObjectGetTabLevel()` 105da35de2aSMatthew G Knepley @*/ 106d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSetTabLevel(PetscObject obj, PetscInt tab) 107d71ae5a4SJacob Faibussowitsch { 108da35de2aSMatthew G Knepley PetscFunctionBegin; 109da35de2aSMatthew G Knepley PetscValidHeader(obj, 1); 110da35de2aSMatthew G Knepley obj->tablevel = tab; 1113ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 112da35de2aSMatthew G Knepley } 113da35de2aSMatthew G Knepley 114cbf1b8bfSBarry Smith /*@ 115811af0c4SBarry 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 122aa76f320SBarry Smith . oldobj - the object providing the tab, optional pass `NULL` to use 0 as the previous tablevel for `obj` 1231cee3971SBarry Smith - tab - the increment that is added to the old objects tab 1241cee3971SBarry Smith 1251cee3971SBarry Smith Level: developer 1261cee3971SBarry Smith 127811af0c4SBarry Smith Note: 1286aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 129811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 130dde44402SBarry Smith is clear. 1311cee3971SBarry Smith 132811af0c4SBarry Smith .seealso: `PETSCVIEWERASCII`, `PetscObjectSetTabLevel()`, `PetscObjectGetTabLevel()` 1331cee3971SBarry Smith @*/ 134d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectIncrementTabLevel(PetscObject obj, PetscObject oldobj, PetscInt tab) 135d71ae5a4SJacob Faibussowitsch { 1361cee3971SBarry Smith PetscFunctionBegin; 1371cee3971SBarry Smith PetscValidHeader(obj, 1); 1385f80ce2aSJacob Faibussowitsch if (oldobj) PetscValidHeader(oldobj, 2); 1395f80ce2aSJacob Faibussowitsch obj->tablevel = (oldobj ? oldobj->tablevel : 0) + tab; 1403ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1411cee3971SBarry Smith } 142