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 14*10450e9eSJacob Faibussowitsch cast with a (`PetscObject`), for example, `PetscObjectComm`((`PetscObject`)mat,...); 15ce94432eSBarry Smith 16ce94432eSBarry Smith Level: advanced 17ce94432eSBarry Smith 1821532e8aSBarry Smith Note: 19*10450e9eSJacob Faibussowitsch Returns the MPI communicator or `MPI_COMM_NULL` if `obj` is not valid. 20*10450e9eSJacob Faibussowitsch 2121532e8aSBarry Smith This is one of the rare PETSc routines that does not return an error code. Use `PetscObjectGetComm()` 2221532e8aSBarry Smith when appropriate for error handling. 2321532e8aSBarry Smith 24811af0c4SBarry Smith .seealso: `PetscObject`, `PetscObjectGetComm()` 25ce94432eSBarry Smith @*/ 26d71ae5a4SJacob Faibussowitsch MPI_Comm PetscObjectComm(PetscObject obj) 27d71ae5a4SJacob Faibussowitsch { 285f80ce2aSJacob Faibussowitsch return obj ? obj->comm : MPI_COMM_NULL; 29ce94432eSBarry Smith } 30ce94432eSBarry Smith 31e5c89e4eSSatish Balay /*@C 32811af0c4SBarry Smith PetscObjectGetComm - Gets the MPI communicator for any `PetscObject`, 33e5c89e4eSSatish Balay regardless of the type. 34e5c89e4eSSatish Balay 35e5c89e4eSSatish Balay Not Collective 36e5c89e4eSSatish Balay 37e5c89e4eSSatish Balay Input Parameter: 38811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 39811af0c4SBarry Smith cast with a (`PetscObject`), for example, 40811af0c4SBarry Smith `PetscObjectGetComm`((`PetscObject`)mat,&comm); 41e5c89e4eSSatish Balay 42e5c89e4eSSatish Balay Output Parameter: 43e5c89e4eSSatish Balay . comm - the MPI communicator 44e5c89e4eSSatish Balay 45e5c89e4eSSatish Balay Level: advanced 46e5c89e4eSSatish Balay 4721532e8aSBarry Smith .seealso: `PetscObject`, `PetscObjectComm()` 48e5c89e4eSSatish Balay @*/ 49d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectGetComm(PetscObject obj, MPI_Comm *comm) 50d71ae5a4SJacob Faibussowitsch { 51e5c89e4eSSatish Balay PetscFunctionBegin; 523cfa8680SLisandro Dalcin PetscValidHeader(obj, 1); 533cfa8680SLisandro Dalcin PetscValidPointer(comm, 2); 54118605f4SJacob Faibussowitsch *comm = obj->comm; 553ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 56e5c89e4eSSatish Balay } 57e5c89e4eSSatish Balay 58cbf1b8bfSBarry Smith /*@ 59811af0c4SBarry Smith PetscObjectGetTabLevel - Gets the number of tabs that `PETSCVIEWERASCII` output for that object uses 60e5c89e4eSSatish Balay 611cee3971SBarry Smith Not Collective 621cee3971SBarry Smith 631cee3971SBarry Smith Input Parameter: 64811af0c4SBarry Smith . obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 65811af0c4SBarry Smith cast with a (`PetscObject`), for example, 66811af0c4SBarry Smith `PetscObjectGetTabLevel`((`PetscObject`)mat,&tab); 671cee3971SBarry Smith 681cee3971SBarry Smith Output Parameter: 691cee3971SBarry Smith . tab - the number of tabs 701cee3971SBarry Smith 711cee3971SBarry Smith Level: developer 721cee3971SBarry Smith 73811af0c4SBarry Smith Note: 74811af0c4SBarry Smith This is used to manage the output from options that are embedded in other objects. For example 75811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 761cee3971SBarry Smith is very clear. 771cee3971SBarry Smith 7821532e8aSBarry Smith .seealso: `PetscObjectIncrementTabLevel()`, `PetscObjectSetTabLevel()`, `PETSCVIEWERASCII`, `PetscObject` 791cee3971SBarry Smith @*/ 80d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectGetTabLevel(PetscObject obj, PetscInt *tab) 81d71ae5a4SJacob Faibussowitsch { 821cee3971SBarry Smith PetscFunctionBegin; 831cee3971SBarry Smith PetscValidHeader(obj, 1); 845f80ce2aSJacob Faibussowitsch PetscValidIntPointer(tab, 2); 851cee3971SBarry Smith *tab = obj->tablevel; 863ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 871cee3971SBarry Smith } 881cee3971SBarry Smith 89da35de2aSMatthew G Knepley /*@ 90811af0c4SBarry Smith PetscObjectSetTabLevel - Sets the number of tabs that `PETSCVIEWERASCII` output for that object uses 91da35de2aSMatthew G Knepley 92da35de2aSMatthew G Knepley Not Collective 93da35de2aSMatthew G Knepley 94da35de2aSMatthew G Knepley Input Parameters: 95811af0c4SBarry Smith + obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be 96811af0c4SBarry Smith cast with a (`PetscObject`), for example, 97811af0c4SBarry Smith `PetscObjectSetTabLevel`((`PetscObject`)mat,tab; 98da35de2aSMatthew G Knepley - tab - the number of tabs 99da35de2aSMatthew G Knepley 100da35de2aSMatthew G Knepley Level: developer 101da35de2aSMatthew G Knepley 10295452b02SPatrick Sanan Notes: 1036aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 104811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 105da35de2aSMatthew G Knepley is very clear. 106da35de2aSMatthew G Knepley 107811af0c4SBarry Smith `PetscObjectIncrementTabLevel()` is the preferred API 108811af0c4SBarry Smith 10921532e8aSBarry Smith .seealso: `PetscObjectIncrementTabLevel()`, `PetscObjectGetTabLevel()` 110da35de2aSMatthew G Knepley @*/ 111d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectSetTabLevel(PetscObject obj, PetscInt tab) 112d71ae5a4SJacob Faibussowitsch { 113da35de2aSMatthew G Knepley PetscFunctionBegin; 114da35de2aSMatthew G Knepley PetscValidHeader(obj, 1); 115da35de2aSMatthew G Knepley obj->tablevel = tab; 1163ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 117da35de2aSMatthew G Knepley } 118da35de2aSMatthew G Knepley 119cbf1b8bfSBarry Smith /*@ 120811af0c4SBarry Smith PetscObjectIncrementTabLevel - Increments the number of tabs that `PETSCVIEWERASCII` output for that object use based on 1211cee3971SBarry Smith the tablevel of another object. This should be called immediately after the object is created. 1221cee3971SBarry Smith 1231cee3971SBarry Smith Not Collective 1241cee3971SBarry Smith 125d8d19677SJose E. Roman Input Parameters: 1261cee3971SBarry Smith + obj - any PETSc object where we are changing the tab 127aa76f320SBarry Smith . oldobj - the object providing the tab, optional pass `NULL` to use 0 as the previous tablevel for `obj` 1281cee3971SBarry Smith - tab - the increment that is added to the old objects tab 1291cee3971SBarry Smith 1301cee3971SBarry Smith Level: developer 1311cee3971SBarry Smith 132811af0c4SBarry Smith Note: 1336aad120cSJose E. Roman this is used to manage the output from options that are embedded in other objects. For example 134811af0c4SBarry Smith the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects 1351cee3971SBarry Smith is very clear. 1361cee3971SBarry Smith 137811af0c4SBarry Smith .seealso: `PETSCVIEWERASCII`, `PetscObjectSetTabLevel()`, `PetscObjectGetTabLevel()` 1381cee3971SBarry Smith @*/ 139d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscObjectIncrementTabLevel(PetscObject obj, PetscObject oldobj, PetscInt tab) 140d71ae5a4SJacob Faibussowitsch { 1411cee3971SBarry Smith PetscFunctionBegin; 1421cee3971SBarry Smith PetscValidHeader(obj, 1); 1435f80ce2aSJacob Faibussowitsch if (oldobj) PetscValidHeader(oldobj, 2); 1445f80ce2aSJacob Faibussowitsch obj->tablevel = (oldobj ? oldobj->tablevel : 0) + tab; 1453ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1461cee3971SBarry Smith } 147