Actual source code: petscbag.h

      1: #pragma once

      3: #include <petscsys.h>

      5: /* SUBMANSEC = Sys */

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

     11:    Level: beginner

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

     21:       PetscBag     bag;
     22:       MyParameters *params;

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

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

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

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

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

     63: #define PETSC_BAG_FILE_CLASSID 1211219