xref: /petsc/src/sys/objects/gcomm.c (revision 245f004be2b2fca55a62739415aedaade1b4b42e)
1 
2 /*
3      Provides utility routines for manulating any type of PETSc object.
4 */
5 #include <petsc-private/petscimpl.h>  /*I   "petscsys.h"    I*/
6 
7 #undef __FUNCT__
8 #define __FUNCT__ "PetscObjectGetComm"
9 /*@C
10    PetscObjectGetComm - Gets the MPI communicator for any PetscObject,
11    regardless of the type.
12 
13    Not Collective
14 
15    Input Parameter:
16 .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
17          cast with a (PetscObject), for example,
18          PetscObjectGetComm((PetscObject)mat,&comm);
19 
20    Output Parameter:
21 .  comm - the MPI communicator
22 
23    Level: advanced
24 
25    Concepts: communicator^getting from object
26    Concepts: MPI communicator^getting from object
27 
28 @*/
29 PetscErrorCode  PetscObjectGetComm(PetscObject obj,MPI_Comm *comm)
30 {
31   PetscErrorCode ierr;
32 
33   PetscFunctionBegin;
34   PetscValidHeader(obj,1);
35   PetscValidPointer(comm,2);
36   if (obj->bops->getcomm) {
37     ierr = obj->bops->getcomm(obj,comm);CHKERRQ(ierr);
38   } else *comm = obj->comm;
39   PetscFunctionReturn(0);
40 }
41 
42 #undef __FUNCT__
43 #define __FUNCT__ "PetscObjectGetTabLevel"
44 /*@
45    PetscObjectGetTabLevel - Gets the number of tabs that ASCII output for that object use
46 
47    Not Collective
48 
49    Input Parameter:
50 .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
51          cast with a (PetscObject), for example,
52          PetscObjectGetComm((PetscObject)mat,&comm);
53 
54    Output Parameter:
55 .   tab - the number of tabs
56 
57    Level: developer
58 
59     Notes: this is used to manage the output from options that are imbedded in other objects. For example
60       the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects
61       is very clear.
62 
63 .seealso:  PetscObjectIncrementTabLevel()
64 
65 @*/
66 PetscErrorCode  PetscObjectGetTabLevel(PetscObject obj,PetscInt *tab)
67 {
68   PetscFunctionBegin;
69   PetscValidHeader(obj,1);
70   *tab = obj->tablevel;
71   PetscFunctionReturn(0);
72 }
73 
74 #undef __FUNCT__
75 #define __FUNCT__ "PetscObjectSetTabLevel"
76 /*@
77    PetscObjectSetTabLevel - Sets the number of tabs that ASCII output for that object use
78 
79    Not Collective
80 
81    Input Parameters:
82 +  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
83          cast with a (PetscObject), for example,
84          PetscObjectGetComm((PetscObject)mat,&comm);
85 -   tab - the number of tabs
86 
87    Level: developer
88 
89     Notes: this is used to manage the output from options that are imbedded in other objects. For example
90       the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects
91       is very clear.
92 
93 .seealso:  PetscObjectIncrementTabLevel()
94 @*/
95 PetscErrorCode  PetscObjectSetTabLevel(PetscObject obj,PetscInt tab)
96 {
97   PetscFunctionBegin;
98   PetscValidHeader(obj,1);
99   obj->tablevel = tab;
100   PetscFunctionReturn(0);
101 }
102 
103 #undef __FUNCT__
104 #define __FUNCT__ "PetscObjectIncrementTabLevel"
105 /*@
106    PetscObjectIncrementTabLevel - Sets the number of tabs that ASCII output for that object use based on
107          the tablevel of another object. This should be called immediately after the object is created.
108 
109    Not Collective
110 
111    Input Parameter:
112 +  obj - any PETSc object where we are changing the tab
113 .  oldobj - the object providing the tab
114 -  tab - the increment that is added to the old objects tab
115 
116 
117    Level: developer
118 
119     Notes: this is used to manage the output from options that are imbedded in other objects. For example
120       the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects
121       is very clear.
122 
123 .seealso:   PetscObjectSetLabLevel(),  PetscObjectGetTabLevel()
124 
125 @*/
126 PetscErrorCode  PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab)
127 {
128 
129   PetscFunctionBegin;
130   PetscValidHeader(obj,1);
131   if (oldobj) obj->tablevel = oldobj->tablevel + tab;
132   else obj->tablevel = tab;
133   PetscFunctionReturn(0);
134 }
135