xref: /petsc/include/petscbag.h (revision f588057b4e26d9feb8696312515b7a30eda4868c)
17c307921SBarry Smith 
27c307921SBarry Smith #if !defined(__PETSCBAG_H)
37c307921SBarry Smith #define __PETSCBAG_H
47c307921SBarry Smith #include "petsc.h"
57c307921SBarry Smith PETSC_EXTERN_CXX_BEGIN
67c307921SBarry Smith 
7*f588057bSBarry Smith #define PETSC_BAG_NAME_LENGTH 64
8*f588057bSBarry Smith #define PETSC_BAG_HELP_LENGTH 128
9*f588057bSBarry Smith #define PETSC_BAG_FILE_COOKIE 1211219
107c307921SBarry Smith 
11*f588057bSBarry Smith typedef struct _p_PetscBagItem *PetscBagItem;
12*f588057bSBarry Smith struct _p_PetscBagItem {PetscDataType dtype;PetscInt offset;char name[PETSC_BAG_NAME_LENGTH],help[PETSC_BAG_HELP_LENGTH];PetscBagItem next;};
137c307921SBarry Smith /*S
147c307921SBarry Smith      PetscBag - PETSc object that manages a collection of user data including parameters.
15*f588057bSBarry Smith            A bag is essentially a C struct with serialization (you can save it and load it from files).
167c307921SBarry Smith 
177c307921SBarry Smith    Level: beginner
187c307921SBarry Smith 
197c307921SBarry Smith     Sample Usage:
207c307921SBarry Smith $      typedef struct {
217c307921SBarry Smith $         PetscBag     bag;
227c307921SBarry Smith $         PetscInt     height;
237c307921SBarry Smith $         PetscScalar  root;
247c307921SBarry Smith $         PetscReal    byebye;
257c307921SBarry Smith $      } MyParameters;
267c307921SBarry Smith $
277c307921SBarry Smith $      MyParameters *params;
287c307921SBarry Smith $
297c307921SBarry Smith $      ierr = PetscBagCreate(MyParameters,&params);
307c307921SBarry Smith $      ierr = PetscBagSetName(params,"MyParameters");
31*f588057bSBarry Smith $      ierr = PetscBagRegisterInt(params,&params.height,22,"height","Height of the water tower");
327c307921SBarry Smith $
337c307921SBarry Smith $
347c307921SBarry Smith $
357c307921SBarry Smith $
367c307921SBarry Smith $
377c307921SBarry Smith 
38*f588057bSBarry Smith .seealso:  PetscBagSetName(), PetscBagGetName(), PetscBagView(), PetscBagLoad()
397c307921SBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
40*f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
417c307921SBarry Smith S*/
427c307921SBarry Smith typedef struct {
43*f588057bSBarry Smith   MPI_Comm     bagcomm;
447c307921SBarry Smith   size_t       bagsize;
45*f588057bSBarry Smith   PetscInt     count;
46*f588057bSBarry Smith   char         bagname[PETSC_BAG_NAME_LENGTH];
47*f588057bSBarry Smith   char         baghelp[PETSC_BAG_HELP_LENGTH];
48*f588057bSBarry Smith   PetscBagItem bagitems;
497c307921SBarry Smith } PetscBag;
507c307921SBarry Smith 
51*f588057bSBarry Smith /*MC
52*f588057bSBarry Smith     PetscBagCreate - Create a bag of values
53*f588057bSBarry Smith 
54*f588057bSBarry Smith   Collective on MPI_Comm
55*f588057bSBarry Smith 
56*f588057bSBarry Smith   Synopsis:
57*f588057bSBarry Smith      PetscErrorCode PetscBagCreate(MPI_Comm comm,C struct name,PetscBag **bag);
58*f588057bSBarry Smith 
59*f588057bSBarry Smith   Input Parameters:
60*f588057bSBarry Smith +  comm - communicator to share bag
61*f588057bSBarry Smith -  C struct name - name of the C structure holding the values
62*f588057bSBarry Smith 
63*f588057bSBarry Smith   Output Parameter:
64*f588057bSBarry Smith .   bag - the bag of values
65*f588057bSBarry Smith 
66*f588057bSBarry Smith .seealso: PetscBag, PetscBagGetName(), PetscBagView(), PetscBagLoad()
67*f588057bSBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
68*f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
69*f588057bSBarry Smith M*/
70*f588057bSBarry Smith #define PetscBagCreate(C,A,B)  PetscNew(A,B) || ((*(B))->bagsize = sizeof(A),(*(B))->bagcomm = C,0)
71*f588057bSBarry Smith 
727c307921SBarry Smith extern PetscErrorCode PetscBagDestroy(PetscBag*);
737c307921SBarry Smith 
74*f588057bSBarry Smith /*MC
75*f588057bSBarry Smith     PetscBagSetName - Sets the name of a bag of values
767c307921SBarry Smith 
77*f588057bSBarry Smith   Not Collective
78*f588057bSBarry Smith 
79*f588057bSBarry Smith   Synopsis:
80*f588057bSBarry Smith      PetscErrorCode PetscBagSetName(PetscBag *bag,const char *name, const char *help);
81*f588057bSBarry Smith 
82*f588057bSBarry Smith   Input Parameters:
83*f588057bSBarry Smith +   bag - the bag of values
84*f588057bSBarry Smith .   name - the name assigned to the bag
85*f588057bSBarry Smith -   help - help message for bag
86*f588057bSBarry Smith 
87*f588057bSBarry Smith .seealso: PetscBag, PetscBagGetName(), PetscBagView(), PetscBagLoad()
88*f588057bSBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
89*f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
90*f588057bSBarry Smith M*/
91*f588057bSBarry Smith #define PetscBagSetName(A,B,C) (PetscStrncpy((A)->bagname,B,PETSC_BAG_NAME_LENGTH-1) || PetscStrncpy((A)->baghelp,C,PETSC_BAG_HELP_LENGTH-1))
92*f588057bSBarry Smith 
93*f588057bSBarry Smith /*MC
94*f588057bSBarry Smith     PetscBagGetName - Gets the name of a bag of values
95*f588057bSBarry Smith 
96*f588057bSBarry Smith   Not Collective
97*f588057bSBarry Smith 
98*f588057bSBarry Smith   Synopsis:
99*f588057bSBarry Smith      PetscErrorCode PetscBagGetName(PetscBag *bag,char **name);
100*f588057bSBarry Smith 
101*f588057bSBarry Smith   Input Parameter:
102*f588057bSBarry Smith .   bag - the bag of values
103*f588057bSBarry Smith 
104*f588057bSBarry Smith   Output Parameter:
105*f588057bSBarry Smith .   name - the name assigned to the bag
106*f588057bSBarry Smith 
107*f588057bSBarry Smith .seealso: PetscBag, PetscBagSetName(), PetscBagView(), PetscBagLoad()
108*f588057bSBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
109*f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
110*f588057bSBarry Smith M*/
111*f588057bSBarry Smith #define PetscBagGetName(A,B) (*(B) = A->bagname,0)
112*f588057bSBarry Smith 
113*f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterReal(PetscBag*,void*,PetscReal, const char*, const char*);
114*f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterScalar(PetscBag*,void*,PetscScalar,const  char*,const  char*);
115*f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterInt(PetscBag*,void*,PetscInt,const  char*,const  char*);
116*f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterTruth(PetscBag*,void*,PetscTruth,const  char*,const  char*);
117*f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterVec(PetscBag*,void*,const char*,const  char*);
1187c307921SBarry Smith 
1197c307921SBarry Smith extern PetscErrorCode PetscBagSetFromOptions(PetscBag*);
1207c307921SBarry Smith 
1217c307921SBarry Smith extern PetscErrorCode PetscBagView(PetscBag*,PetscViewer);
1227c307921SBarry Smith extern PetscErrorCode PetscBagLoad(PetscViewer,PetscBag**);
1237c307921SBarry Smith 
1247c307921SBarry Smith extern PetscErrorCode PetscBagSetViewer(PetscBag*,PetscErrorCode (*)(PetscBag*,PetscViewer));
1257c307921SBarry Smith extern PetscErrorCode PetscBagSetLoader(PetscBag*,PetscErrorCode (*)(PetscBag*,PetscViewer));
1267c307921SBarry Smith extern PetscErrorCode PetscBagSetDestroy(PetscBag*,PetscErrorCode (*)(PetscBag*));
1277c307921SBarry Smith 
1287c307921SBarry Smith #endif
129