Actual source code: petscbag.h

     4:  #include petsc.h

      7: #define PETSC_BAG_NAME_LENGTH 64
      8: #define PETSC_BAG_HELP_LENGTH 128
      9: #define PETSC_BAG_FILE_COOKIE 1211219

     11: typedef struct _p_PetscBagItem *PetscBagItem;
     12: struct _p_PetscBagItem {
     13:   PetscDataType dtype;
     14:   PetscInt      offset;
     15:   PetscInt      msize;
     16:   char          name[PETSC_BAG_NAME_LENGTH],help[PETSC_BAG_HELP_LENGTH];
     17:   const char    **list;
     18:   PetscTruth    freelist;
     19:   PetscBagItem  next;};

     21: /*S
     22:      PetscBag - PETSc object that manages a collection of user data including parameters.
     23:            A bag is essentially a C struct with serialization (you can save it and load it from files).

     25:    Level: beginner

     27:     Sample Usage:
     28: $      typedef struct {
     29: $         PetscBag     bag;
     30: $         PetscInt     height;
     31: $         PetscScalar  root;
     32: $         PetscReal    byebye;
     33: $      } MyParameters;
     34: $
     35: $      MyParameters *params;
     36: $
     37: $      PetscBagCreate(MyParameters,&params);
     38: $      PetscBagSetName(params,"MyParameters");
     39: $      PetscBagRegisterInt(params,&params.height,22,"height","Height of the water tower");
     40: $
     41: $
     42: $
     43: $
     44: $

     46: .seealso:  PetscBagSetName(), PetscBagGetName(), PetscBagView(), PetscBagLoad()
     47:            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
     48:            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy(), PetscBagRegisterEnum()
     49: S*/
     50: typedef struct {
     51:   MPI_Comm     bagcomm;
     52:   PetscInt     bagsize;
     53:   PetscInt     count;
     54:   char         bagname[PETSC_BAG_NAME_LENGTH];
     55:   char         baghelp[PETSC_BAG_HELP_LENGTH];
     56:   PetscBagItem bagitems;
     57: } PetscBag;

     59: /*MC
     60:     PetscBagCreate - Create a bag of values

     62:   Collective on MPI_Comm

     64:   Level: Intermediate

     66:   Synopsis:
     67:      PetscErrorCode PetscBagCreate(MPI_Comm comm,C struct name,PetscBag **bag);

     69:   Input Parameters:
     70: +  comm - communicator to share bag
     71: -  C struct name - name of the C structure holding the values

     73:   Output Parameter:
     74: .   bag - the bag of values

     76:    Notes:
     77:       The size of the A struct must be small enough to fit in a PetscInt; by default
     78:       PetscInt is 4 bytes. The warning about casting to a shorter length can be ignored
     79:       below unless your A struct is too large

     81: .seealso: PetscBag, PetscBagGetName(), PetscBagView(), PetscBagLoad()
     82:            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
     83:            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy(), PetscBagRegisterEnum()
     84: M*/
     85: #define PetscBagCreate(C,A,B)  PetscNew(A,B) || ((*(B))->bagsize = (PetscInt)sizeof(A),(*(B))->bagcomm = C,0)

     89: /*MC
     90:     PetscBagSetName - Sets the name of a bag of values

     92:   Not Collective

     94:   Level: Intermediate

     96:   Synopsis:
     97:      PetscErrorCode PetscBagSetName(PetscBag *bag,const char *name, const char *help);

     99:   Input Parameters:
    100: +   bag - the bag of values
    101: .   name - the name assigned to the bag
    102: -   help - help message for bag

    104: .seealso: PetscBag, PetscBagGetName(), PetscBagView(), PetscBagLoad()
    105:            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
    106:            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy(), PetscBagRegisterEnum()
    107: M*/
    108: #define PetscBagSetName(A,B,C) (PetscStrncpy((A)->bagname,B,PETSC_BAG_NAME_LENGTH-1) || PetscStrncpy((A)->baghelp,C,PETSC_BAG_HELP_LENGTH-1))

    110: /*MC
    111:     PetscBagGetName - Gets the name of a bag of values

    113:   Not Collective

    115:   Level: Intermediate

    117:   Synopsis:
    118:      PetscErrorCode PetscBagGetName(PetscBag *bag,char **name);

    120:   Input Parameter:
    121: .   bag - the bag of values

    123:   Output Parameter:
    124: .   name - the name assigned to the bag

    126: .seealso: PetscBag, PetscBagSetName(), PetscBagView(), PetscBagLoad()
    127:            PetscBagRegisterReal(), PetscBagRegisterInt(), PetscBagRegisterTruth(), PetscBagRegisterScalar()
    128:            PetscBagSetFromOptions(), PetscBagRegisterVec(), PetscBagCreate(), PetscBagDestroy(), PetscBagRegisterEnum()
    129: M*/
    130: #define PetscBagGetName(A,B) (*(B) = A->bagname,0)

    149: #endif