xref: /petsc/include/petscbag.h (revision 68eff7e6281a82d5a797a3bae16b5001f74c09cb)
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;
12*68eff7e6SBarry 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 
56f588057bSBarry Smith   Synopsis:
57f588057bSBarry Smith      PetscErrorCode PetscBagCreate(MPI_Comm comm,C struct name,PetscBag **bag);
58f588057bSBarry Smith 
59f588057bSBarry Smith   Input Parameters:
60f588057bSBarry Smith +  comm - communicator to share bag
61f588057bSBarry Smith -  C struct name - name of the C structure holding the values
62f588057bSBarry Smith 
63f588057bSBarry Smith   Output Parameter:
64f588057bSBarry Smith .   bag - the bag of values
65f588057bSBarry Smith 
66f588057bSBarry Smith .seealso: PetscBag, PetscBagGetName(), PetscBagView(), PetscBagLoad()
67f588057bSBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
68f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
69f588057bSBarry Smith M*/
70f588057bSBarry Smith #define PetscBagCreate(C,A,B)  PetscNew(A,B) || ((*(B))->bagsize = sizeof(A),(*(B))->bagcomm = C,0)
71f588057bSBarry Smith 
727c307921SBarry Smith extern PetscErrorCode PetscBagDestroy(PetscBag*);
737c307921SBarry Smith 
74f588057bSBarry Smith /*MC
75f588057bSBarry Smith     PetscBagSetName - Sets the name of a bag of values
767c307921SBarry Smith 
77f588057bSBarry Smith   Not Collective
78f588057bSBarry Smith 
79f588057bSBarry Smith   Synopsis:
80f588057bSBarry Smith      PetscErrorCode PetscBagSetName(PetscBag *bag,const char *name, const char *help);
81f588057bSBarry Smith 
82f588057bSBarry Smith   Input Parameters:
83f588057bSBarry Smith +   bag - the bag of values
84f588057bSBarry Smith .   name - the name assigned to the bag
85f588057bSBarry Smith -   help - help message for bag
86f588057bSBarry Smith 
87f588057bSBarry Smith .seealso: PetscBag, PetscBagGetName(), PetscBagView(), PetscBagLoad()
88f588057bSBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
89f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
90f588057bSBarry Smith M*/
91f588057bSBarry Smith #define PetscBagSetName(A,B,C) (PetscStrncpy((A)->bagname,B,PETSC_BAG_NAME_LENGTH-1) || PetscStrncpy((A)->baghelp,C,PETSC_BAG_HELP_LENGTH-1))
92f588057bSBarry Smith 
93f588057bSBarry Smith /*MC
94f588057bSBarry Smith     PetscBagGetName - Gets the name of a bag of values
95f588057bSBarry Smith 
96f588057bSBarry Smith   Not Collective
97f588057bSBarry Smith 
98f588057bSBarry Smith   Synopsis:
99f588057bSBarry Smith      PetscErrorCode PetscBagGetName(PetscBag *bag,char **name);
100f588057bSBarry Smith 
101f588057bSBarry Smith   Input Parameter:
102f588057bSBarry Smith .   bag - the bag of values
103f588057bSBarry Smith 
104f588057bSBarry Smith   Output Parameter:
105f588057bSBarry Smith .   name - the name assigned to the bag
106f588057bSBarry Smith 
107f588057bSBarry Smith .seealso: PetscBag, PetscBagSetName(), PetscBagView(), PetscBagLoad()
108f588057bSBarry Smith            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
109f588057bSBarry Smith            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy()
110f588057bSBarry Smith M*/
111f588057bSBarry Smith #define PetscBagGetName(A,B) (*(B) = A->bagname,0)
112f588057bSBarry Smith 
113f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterReal(PetscBag*,void*,PetscReal, const char*, const char*);
114*68eff7e6SBarry Smith extern PetscErrorCode PetscBagRegisterString(PetscBag*,void*,size_t,const char*, const char*, const char*);
115f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterScalar(PetscBag*,void*,PetscScalar,const  char*,const  char*);
116f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterInt(PetscBag*,void*,PetscInt,const  char*,const  char*);
117f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterTruth(PetscBag*,void*,PetscTruth,const  char*,const  char*);
118f588057bSBarry Smith extern PetscErrorCode PetscBagRegisterVec(PetscBag*,void*,const char*,const  char*);
1197c307921SBarry Smith 
1207c307921SBarry Smith extern PetscErrorCode PetscBagSetFromOptions(PetscBag*);
1217c307921SBarry Smith 
1227c307921SBarry Smith extern PetscErrorCode PetscBagView(PetscBag*,PetscViewer);
1237c307921SBarry Smith extern PetscErrorCode PetscBagLoad(PetscViewer,PetscBag**);
1247c307921SBarry Smith 
1257c307921SBarry Smith extern PetscErrorCode PetscBagSetViewer(PetscBag*,PetscErrorCode (*)(PetscBag*,PetscViewer));
1267c307921SBarry Smith extern PetscErrorCode PetscBagSetLoader(PetscBag*,PetscErrorCode (*)(PetscBag*,PetscViewer));
1277c307921SBarry Smith extern PetscErrorCode PetscBagSetDestroy(PetscBag*,PetscErrorCode (*)(PetscBag*));
1287c307921SBarry Smith 
1297c307921SBarry Smith #endif
130