Actual source code: petscbag.h

      1: #pragma once

      3: #include <petscsys.h>

      5: /* MANSEC = Sys */
      6: /* SUBMANSEC = Bag */

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

     12:    Level: beginner

     14:    Sample Usage:
     15: .vb
     16:       typedef struct {
     17:          PetscInt     height;
     18:          PetscScalar  root;
     19:          PetscReal    byebye;
     20:       } MyParameters;

     22:       PetscBag     bag;
     23:       MyParameters *params;

     25:       PetscCall(PetscBagCreate(PETSC_COMM_WORLD,sizeof(MyParameters),&bag));
     26:       PetscCall(PetscBagGetData(bag,(void **)&params));
     27:       PetscCall(PetscBagSetName(bag,"MyParameters"));
     28:       PetscCall(PetscBagRegisterInt(bag,&params.height,22,"height","Height of the water tower"));
     29: .ve
     30:    Note:
     31:   `PetscBag` is a C struct, it is not a `PetscObject`

     33: .seealso: `PetscBagSetName()`, `PetscBagGetName()`, `PetscBagView()`, `PetscBagLoad()`, `PetscBagGetData()`
     34:           `PetscBagRegisterReal()`, `PetscBagRegisterInt()`, `PetscBagRegisterBool()`, `PetscBagRegisterScalar()`
     35:           `PetscBagSetFromOptions()`, `PetscBagRegisterVec()`, `PetscBagCreate()`, `PetscBagDestroy()`, `PetscBagRegisterEnum()`
     36: S*/
     37: typedef struct _n_PetscBag     *PetscBag;
     38: typedef struct _n_PetscBagItem *PetscBagItem;

     40: PETSC_EXTERN PetscErrorCode PetscBagCreate(MPI_Comm, size_t, PetscBag *);
     41: PETSC_EXTERN PetscErrorCode PetscBagDestroy(PetscBag *);
     42: PETSC_EXTERN PetscErrorCode PetscBagGetData(PetscBag, void *);
     43: PETSC_EXTERN PetscErrorCode PetscBagRegisterReal(PetscBag, void *, PetscReal, const char *, const char *);
     44: PETSC_EXTERN PetscErrorCode PetscBagRegisterRealArray(PetscBag, void *, PetscInt, const char *, const char *);
     45: PETSC_EXTERN PetscErrorCode PetscBagRegisterString(PetscBag, void *, PetscInt, const char *, const char *, const char *);
     46: PETSC_EXTERN PetscErrorCode PetscBagRegisterScalar(PetscBag, void *, PetscScalar, const char *, const char *);
     47: PETSC_EXTERN PetscErrorCode PetscBagRegisterInt(PetscBag, void *, PetscInt, const char *, const char *);
     48: PETSC_EXTERN PetscErrorCode PetscBagRegisterInt64(PetscBag, void *, PetscInt64, const char *, const char *);
     49: PETSC_EXTERN PetscErrorCode PetscBagRegisterIntArray(PetscBag, void *, PetscInt, const char *, const char *);
     50: PETSC_EXTERN PetscErrorCode PetscBagRegisterEnum(PetscBag, void *, const char *const *, PetscEnum, const char *, const char *);
     51: PETSC_EXTERN PetscErrorCode PetscBagRegisterBool(PetscBag, void *, PetscBool, const char *, const char *);
     52: PETSC_EXTERN PetscErrorCode PetscBagRegisterBoolArray(PetscBag, void *, PetscInt, const char *, const char *);
     53: PETSC_EXTERN PetscErrorCode PetscBagGetNames(PetscBag, const char *[]);

     55: PETSC_EXTERN PetscErrorCode PetscBagSetFromOptions(PetscBag);
     56: PETSC_EXTERN PetscErrorCode PetscBagGetName(PetscBag, const char **);
     57: PETSC_EXTERN PetscErrorCode PetscBagSetName(PetscBag, const char *, const char *);
     58: PETSC_EXTERN PetscErrorCode PetscBagSetOptionsPrefix(PetscBag, const char *);

     60: PETSC_EXTERN PetscErrorCode PetscBagView(PetscBag, PetscViewer);
     61: PETSC_EXTERN PetscErrorCode PetscBagLoad(PetscViewer, PetscBag);
     62: PETSC_EXTERN PetscErrorCode PetscBagViewFromOptions(PetscBag, PetscObject, const char[]);

     64: #define PETSC_BAG_FILE_CLASSID 1211219