xref: /petsc/include/petscbag.h (revision 8cbb96b3808af90d2cf2df6e72e0fe50d08373f0)
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 
7f588057bSBarry Smith #define PETSC_BAG_NAME_LENGTH 64
8f588057bSBarry Smith #define PETSC_BAG_HELP_LENGTH 128
9f588057bSBarry Smith #define PETSC_BAG_FILE_COOKIE 1211219
107c307921SBarry Smith 
11f588057bSBarry Smith typedef struct _p_PetscBagItem *PetscBagItem;
1268eff7e6SBarry Smith struct _p_PetscBagItem {PetscDataType dtype;PetscInt offset;size_t msize;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.
15f588057bSBarry 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");
31f588057bSBarry 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 
38f588057bSBarry Smith .seealso:  PetscBagSetName(), PetscBagGetName(), PetscBagView(), PetscBagLoad()
397c307921SBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
40f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
417c307921SBarry Smith S*/
427c307921SBarry Smith typedef struct {
43f588057bSBarry Smith   MPI_Comm     bagcomm;
447c307921SBarry Smith   size_t       bagsize;
45f588057bSBarry Smith   PetscInt     count;
46f588057bSBarry Smith   char         bagname[PETSC_BAG_NAME_LENGTH];
47f588057bSBarry Smith   char         baghelp[PETSC_BAG_HELP_LENGTH];
48f588057bSBarry Smith   PetscBagItem bagitems;
497c307921SBarry Smith } PetscBag;
507c307921SBarry Smith 
51f588057bSBarry Smith /*MC
52f588057bSBarry Smith     PetscBagCreate - Create a bag of values
53f588057bSBarry Smith 
54f588057bSBarry Smith   Collective on MPI_Comm
55f588057bSBarry Smith 
56*8cbb96b3SSatish Balay   Level: Intermediate
57*8cbb96b3SSatish Balay 
58f588057bSBarry Smith   Synopsis:
59f588057bSBarry Smith      PetscErrorCode PetscBagCreate(MPI_Comm comm,C struct name,PetscBag **bag);
60f588057bSBarry Smith 
61f588057bSBarry Smith   Input Parameters:
62f588057bSBarry Smith +  comm - communicator to share bag
63f588057bSBarry Smith -  C struct name - name of the C structure holding the values
64f588057bSBarry Smith 
65f588057bSBarry Smith   Output Parameter:
66f588057bSBarry Smith .   bag - the bag of values
67f588057bSBarry Smith 
68*8cbb96b3SSatish Balay 
69f588057bSBarry Smith .seealso: PetscBag, PetscBagGetName(), PetscBagView(), PetscBagLoad()
70f588057bSBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
71f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
72f588057bSBarry Smith M*/
73f588057bSBarry Smith #define PetscBagCreate(C,A,B)  PetscNew(A,B) || ((*(B))->bagsize = sizeof(A),(*(B))->bagcomm = C,0)
74f588057bSBarry Smith 
757c307921SBarry Smith extern PetscErrorCode PetscBagDestroy(PetscBag*);
767c307921SBarry Smith 
77f588057bSBarry Smith /*MC
78f588057bSBarry Smith     PetscBagSetName - Sets the name of a bag of values
797c307921SBarry Smith 
80f588057bSBarry Smith   Not Collective
81f588057bSBarry Smith 
82*8cbb96b3SSatish Balay   Level: Intermediate
83*8cbb96b3SSatish Balay 
84f588057bSBarry Smith   Synopsis:
85f588057bSBarry Smith      PetscErrorCode PetscBagSetName(PetscBag *bag,const char *name, const char *help);
86f588057bSBarry Smith 
87f588057bSBarry Smith   Input Parameters:
88f588057bSBarry Smith +   bag - the bag of values
89f588057bSBarry Smith .   name - the name assigned to the bag
90f588057bSBarry Smith -   help - help message for bag
91f588057bSBarry Smith 
92f588057bSBarry Smith .seealso: PetscBag, PetscBagGetName(), PetscBagView(), PetscBagLoad()
93f588057bSBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
94f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
95f588057bSBarry Smith M*/
96f588057bSBarry Smith #define PetscBagSetName(A,B,C) (PetscStrncpy((A)->bagname,B,PETSC_BAG_NAME_LENGTH-1) || PetscStrncpy((A)->baghelp,C,PETSC_BAG_HELP_LENGTH-1))
97f588057bSBarry Smith 
98f588057bSBarry Smith /*MC
99f588057bSBarry Smith     PetscBagGetName - Gets the name of a bag of values
100f588057bSBarry Smith 
101f588057bSBarry Smith   Not Collective
102f588057bSBarry Smith 
103*8cbb96b3SSatish Balay   Level: Intermediate
104*8cbb96b3SSatish Balay 
105f588057bSBarry Smith   Synopsis:
106f588057bSBarry Smith      PetscErrorCode PetscBagGetName(PetscBag *bag,char **name);
107f588057bSBarry Smith 
108f588057bSBarry Smith   Input Parameter:
109f588057bSBarry Smith .   bag - the bag of values
110f588057bSBarry Smith 
111f588057bSBarry Smith   Output Parameter:
112f588057bSBarry Smith .   name - the name assigned to the bag
113f588057bSBarry Smith 
114f588057bSBarry Smith .seealso: PetscBag, PetscBagSetName(), PetscBagView(), PetscBagLoad()
115f588057bSBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
116f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
117f588057bSBarry Smith M*/
118f588057bSBarry Smith #define PetscBagGetName(A,B) (*(B) = A->bagname,0)
119f588057bSBarry Smith 
120f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterReal(PetscBag*,void*,PetscReal, const char*, const char*);
12168eff7e6SBarry Smith extern PetscErrorCode PetscBagRegisterString(PetscBag*,void*,size_t,const char*, const char*, const char*);
122f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterScalar(PetscBag*,void*,PetscScalar,const  char*,const  char*);
123f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterInt(PetscBag*,void*,PetscInt,const  char*,const  char*);
124f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterTruth(PetscBag*,void*,PetscTruth,const  char*,const  char*);
125f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterVec(PetscBag*,void*,const char*,const  char*);
1267c307921SBarry Smith 
1277c307921SBarry Smith extern PetscErrorCode PetscBagSetFromOptions(PetscBag*);
1287c307921SBarry Smith 
1297c307921SBarry Smith extern PetscErrorCode PetscBagView(PetscBag*,PetscViewer);
1307c307921SBarry Smith extern PetscErrorCode PetscBagLoad(PetscViewer,PetscBag**);
1317c307921SBarry Smith 
1327c307921SBarry Smith extern PetscErrorCode PetscBagSetViewer(PetscBag*,PetscErrorCode (*)(PetscBag*,PetscViewer));
1337c307921SBarry Smith extern PetscErrorCode PetscBagSetLoader(PetscBag*,PetscErrorCode (*)(PetscBag*,PetscViewer));
1347c307921SBarry Smith extern PetscErrorCode PetscBagSetDestroy(PetscBag*,PetscErrorCode (*)(PetscBag*));
1357c307921SBarry Smith 
1367c307921SBarry Smith #endif
137