xref: /petsc/src/sys/objects/gcomm.c (revision 118605f4c6bc2830715602a7dfcedef20024a67f)
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,
15811af0c4SBarry Smith          `PetscObjectComm`((`PetscObjec`t)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 @*/
249371c9d4SSatish Balay MPI_Comm PetscObjectComm(PetscObject obj) {
255f80ce2aSJacob Faibussowitsch   return obj ? obj->comm : MPI_COMM_NULL;
26ce94432eSBarry Smith }
27ce94432eSBarry Smith 
28e5c89e4eSSatish Balay /*@C
29811af0c4SBarry 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:
35811af0c4SBarry Smith .  obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be
36811af0c4SBarry Smith          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 
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);
50*118605f4SJacob Faibussowitsch   *comm = obj->comm;
51e5c89e4eSSatish Balay   PetscFunctionReturn(0);
52e5c89e4eSSatish Balay }
53e5c89e4eSSatish Balay 
54cbf1b8bfSBarry Smith /*@
55811af0c4SBarry Smith    PetscObjectGetTabLevel - Gets the number of tabs that `PETSCVIEWERASCII` output for that object uses
56e5c89e4eSSatish Balay 
571cee3971SBarry Smith    Not Collective
581cee3971SBarry Smith 
591cee3971SBarry Smith    Input Parameter:
60811af0c4SBarry Smith .  obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be
61811af0c4SBarry Smith          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
721cee3971SBarry Smith       is very clear.
731cee3971SBarry Smith 
74811af0c4SBarry Smith .seealso: `PetscObjectIncrementTabLevel()`, `PETSCVIEWERASCII`
751cee3971SBarry Smith @*/
769371c9d4SSatish Balay PetscErrorCode PetscObjectGetTabLevel(PetscObject obj, PetscInt *tab) {
771cee3971SBarry Smith   PetscFunctionBegin;
781cee3971SBarry Smith   PetscValidHeader(obj, 1);
795f80ce2aSJacob Faibussowitsch   PetscValidIntPointer(tab, 2);
801cee3971SBarry Smith   *tab = obj->tablevel;
811cee3971SBarry Smith   PetscFunctionReturn(0);
821cee3971SBarry Smith }
831cee3971SBarry Smith 
84da35de2aSMatthew G Knepley /*@
85811af0c4SBarry Smith    PetscObjectSetTabLevel - Sets the number of tabs that `PETSCVIEWERASCII` output for that object uses
86da35de2aSMatthew G Knepley 
87da35de2aSMatthew G Knepley    Not Collective
88da35de2aSMatthew G Knepley 
89da35de2aSMatthew G Knepley    Input Parameters:
90811af0c4SBarry Smith +  obj - any PETSc object, for example a `Vec`, `Mat` or `KSP`. Thus must be
91811af0c4SBarry Smith          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
100da35de2aSMatthew G Knepley       is very clear.
101da35de2aSMatthew G Knepley 
102811af0c4SBarry Smith     `PetscObjectIncrementTabLevel()` is the preferred API
103811af0c4SBarry Smith 
104db781477SPatrick Sanan .seealso: `PetscObjectIncrementTabLevel()`
105da35de2aSMatthew G Knepley @*/
1069371c9d4SSatish Balay PetscErrorCode PetscObjectSetTabLevel(PetscObject obj, PetscInt tab) {
107da35de2aSMatthew G Knepley   PetscFunctionBegin;
108da35de2aSMatthew G Knepley   PetscValidHeader(obj, 1);
109da35de2aSMatthew G Knepley   obj->tablevel = tab;
110da35de2aSMatthew G Knepley   PetscFunctionReturn(0);
111da35de2aSMatthew G Knepley }
112da35de2aSMatthew G Knepley 
113cbf1b8bfSBarry Smith /*@
114811af0c4SBarry Smith    PetscObjectIncrementTabLevel - Increments the number of tabs that `PETSCVIEWERASCII` output for that object use based on
1151cee3971SBarry Smith          the tablevel of another object. This should be called immediately after the object is created.
1161cee3971SBarry Smith 
1171cee3971SBarry Smith    Not Collective
1181cee3971SBarry Smith 
119d8d19677SJose E. Roman    Input Parameters:
1201cee3971SBarry Smith +  obj - any PETSc object where we are changing the tab
1211cee3971SBarry Smith .  oldobj - the object providing the tab
1221cee3971SBarry Smith -  tab - the increment that is added to the old objects tab
1231cee3971SBarry Smith 
1241cee3971SBarry Smith    Level: developer
1251cee3971SBarry Smith 
126811af0c4SBarry Smith     Note:
1276aad120cSJose E. Roman     this is used to manage the output from options that are embedded in other objects. For example
128811af0c4SBarry Smith       the `KSP` object inside a `SNES` object. By indenting each lower level further the hierarchy of objects
1291cee3971SBarry Smith       is very clear.
1301cee3971SBarry Smith 
131811af0c4SBarry Smith .seealso: `PETSCVIEWERASCII`, `PetscObjectSetTabLevel()`, `PetscObjectGetTabLevel()`
1321cee3971SBarry Smith @*/
1339371c9d4SSatish Balay PetscErrorCode PetscObjectIncrementTabLevel(PetscObject obj, PetscObject oldobj, PetscInt tab) {
1341cee3971SBarry Smith   PetscFunctionBegin;
1351cee3971SBarry Smith   PetscValidHeader(obj, 1);
1365f80ce2aSJacob Faibussowitsch   if (oldobj) PetscValidHeader(oldobj, 2);
1375f80ce2aSJacob Faibussowitsch   obj->tablevel = (oldobj ? oldobj->tablevel : 0) + tab;
1381cee3971SBarry Smith   PetscFunctionReturn(0);
1391cee3971SBarry Smith }
140