xref: /petsc/src/sys/objects/gcomm.c (revision cbf1b8bfcdd24f9213bd26c65c6ca26106f2b6d7)
1e5c89e4eSSatish Balay #define PETSC_DLL
2e5c89e4eSSatish Balay /*
3e5c89e4eSSatish Balay      Provides utility routines for manulating any type of PETSc object.
4e5c89e4eSSatish Balay */
5d382aafbSBarry Smith #include "petscsys.h"  /*I   "petscsys.h"    I*/
6e5c89e4eSSatish Balay 
7e5c89e4eSSatish Balay #undef __FUNCT__
8e5c89e4eSSatish Balay #define __FUNCT__ "PetscObjectGetComm"
9e5c89e4eSSatish Balay /*@C
10e5c89e4eSSatish Balay    PetscObjectGetComm - Gets the MPI communicator for any PetscObject,
11e5c89e4eSSatish Balay    regardless of the type.
12e5c89e4eSSatish Balay 
13e5c89e4eSSatish Balay    Not Collective
14e5c89e4eSSatish Balay 
15e5c89e4eSSatish Balay    Input Parameter:
16e5c89e4eSSatish Balay .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
17e5c89e4eSSatish Balay          cast with a (PetscObject), for example,
18e5c89e4eSSatish Balay          PetscObjectGetComm((PetscObject)mat,&comm);
19e5c89e4eSSatish Balay 
20e5c89e4eSSatish Balay    Output Parameter:
21e5c89e4eSSatish Balay .  comm - the MPI communicator
22e5c89e4eSSatish Balay 
23e5c89e4eSSatish Balay    Level: advanced
24e5c89e4eSSatish Balay 
25e5c89e4eSSatish Balay    Concepts: communicator^getting from object
26e5c89e4eSSatish Balay    Concepts: MPI communicator^getting from object
27e5c89e4eSSatish Balay 
28e5c89e4eSSatish Balay @*/
29e5c89e4eSSatish Balay PetscErrorCode PETSC_DLLEXPORT PetscObjectGetComm(PetscObject obj,MPI_Comm *comm)
30e5c89e4eSSatish Balay {
31e5c89e4eSSatish Balay   PetscErrorCode ierr;
32e5c89e4eSSatish Balay 
33e5c89e4eSSatish Balay   PetscFunctionBegin;
343cfa8680SLisandro Dalcin   PetscValidHeader(obj,1);
353cfa8680SLisandro Dalcin   PetscValidPointer(comm,2);
36e5c89e4eSSatish Balay   if (obj->bops->getcomm) {
37e5c89e4eSSatish Balay     ierr = obj->bops->getcomm(obj,comm);CHKERRQ(ierr);
38e5c89e4eSSatish Balay   } else {
39e5c89e4eSSatish Balay     *comm = obj->comm;
40e5c89e4eSSatish Balay   }
41e5c89e4eSSatish Balay   PetscFunctionReturn(0);
42e5c89e4eSSatish Balay }
43e5c89e4eSSatish Balay 
441cee3971SBarry Smith #undef __FUNCT__
451cee3971SBarry Smith #define __FUNCT__ "PetscObjectGetTabLevel"
46*cbf1b8bfSBarry Smith /*@
471cee3971SBarry Smith    PetscObjectGetTabLevel - Gets the number of tabs that ASCII output for that object use
48e5c89e4eSSatish Balay 
491cee3971SBarry Smith    Not Collective
501cee3971SBarry Smith 
511cee3971SBarry Smith    Input Parameter:
521cee3971SBarry Smith .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
531cee3971SBarry Smith          cast with a (PetscObject), for example,
541cee3971SBarry Smith          PetscObjectGetComm((PetscObject)mat,&comm);
551cee3971SBarry Smith 
561cee3971SBarry Smith    Output Parameter:
571cee3971SBarry Smith .   tab - the number of tabs
581cee3971SBarry Smith 
591cee3971SBarry Smith    Level: developer
601cee3971SBarry Smith 
611cee3971SBarry Smith     Notes: this is used to manage the output from options that are imbedded in other objects. For example
621cee3971SBarry Smith       the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects
631cee3971SBarry Smith       is very clear.
641cee3971SBarry Smith 
651cee3971SBarry Smith .seealso:  PetscObjectIncrementTabLevel()
661cee3971SBarry Smith 
671cee3971SBarry Smith @*/
681cee3971SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscObjectGetTabLevel(PetscObject obj,PetscInt *tab)
691cee3971SBarry Smith {
701cee3971SBarry Smith   PetscFunctionBegin;
711cee3971SBarry Smith   PetscValidHeader(obj,1);
721cee3971SBarry Smith   *tab = obj->tablevel;
731cee3971SBarry Smith   PetscFunctionReturn(0);
741cee3971SBarry Smith }
751cee3971SBarry Smith 
76*cbf1b8bfSBarry Smith /*@
771cee3971SBarry Smith    PetscObjectIncrementTabLevel - Sets the number of tabs that ASCII output for that object use based on
781cee3971SBarry Smith          the tablevel of another object. This should be called immediately after the object is created.
791cee3971SBarry Smith 
801cee3971SBarry Smith    Not Collective
811cee3971SBarry Smith 
821cee3971SBarry Smith    Input Parameter:
831cee3971SBarry Smith +  obj - any PETSc object where we are changing the tab
841cee3971SBarry Smith .  oldobj - the object providing the tab
851cee3971SBarry Smith -  tab - the increment that is added to the old objects tab
861cee3971SBarry Smith 
871cee3971SBarry Smith 
881cee3971SBarry Smith    Level: developer
891cee3971SBarry Smith 
901cee3971SBarry Smith     Notes: this is used to manage the output from options that are imbedded in other objects. For example
911cee3971SBarry Smith       the KSP object inside a SNES object. By indenting each lower level further the heirarchy of objects
921cee3971SBarry Smith       is very clear.
931cee3971SBarry Smith 
941cee3971SBarry Smith .seealso:   PetscObjectSetLabLevel(),  PetscObjectGetTabLevel()
951cee3971SBarry Smith 
961cee3971SBarry Smith @*/
971cee3971SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab)
981cee3971SBarry Smith {
991cee3971SBarry Smith 
1001cee3971SBarry Smith   PetscFunctionBegin;
1011cee3971SBarry Smith   PetscValidHeader(obj,1);
1021cee3971SBarry Smith   if (oldobj) {
1031cee3971SBarry Smith     obj->tablevel = oldobj->tablevel + tab;
1041cee3971SBarry Smith   } else {
1051cee3971SBarry Smith     obj->tablevel = tab;
1061cee3971SBarry Smith   }
1071cee3971SBarry Smith   PetscFunctionReturn(0);
1081cee3971SBarry Smith }
109