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,&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: /*S
     39:   PetscBagItem - Opaque linked-list node used internally by `PetscBag` to record the metadata (name, help string, type, offset, default value) of a single registered field

     41:   Level: developer

     43: .seealso: `PetscBag`, `PetscBagCreate()`, `PetscBagRegisterInt()`, `PetscBagRegisterReal()`, `PetscBagRegisterScalar()`, `PetscBagRegisterBool()`, `PetscBagRegisterString()`, `PetscBagRegisterEnum()`
     44: S*/
     45: typedef struct _n_PetscBagItem *PetscBagItem;

     47: PETSC_EXTERN PetscErrorCode PetscBagCreate(MPI_Comm, size_t, PetscBag *);
     48: PETSC_EXTERN PetscErrorCode PetscBagDestroy(PetscBag *);
     49: PETSC_EXTERN PetscErrorCode PetscBagGetData(PetscBag, PetscCtxRt);
     50: PETSC_EXTERN PetscErrorCode PetscBagRegisterReal(PetscBag, void *, PetscReal, const char *, const char *);
     51: PETSC_EXTERN PetscErrorCode PetscBagRegisterRealArray(PetscBag, void *, PetscInt, const char *, const char *);
     52: PETSC_EXTERN PetscErrorCode PetscBagRegisterString(PetscBag, void *, PetscInt, const char *, const char *, const char *);
     53: PETSC_EXTERN PetscErrorCode PetscBagRegisterScalar(PetscBag, void *, PetscScalar, const char *, const char *);
     54: PETSC_EXTERN PetscErrorCode PetscBagRegisterInt(PetscBag, void *, PetscInt, const char *, const char *);
     55: PETSC_EXTERN PetscErrorCode PetscBagRegisterInt64(PetscBag, void *, PetscInt64, const char *, const char *);
     56: PETSC_EXTERN PetscErrorCode PetscBagRegisterIntArray(PetscBag, void *, PetscInt, const char *, const char *);
     57: PETSC_EXTERN PetscErrorCode PetscBagRegisterEnum(PetscBag, void *, const char *const *, PetscEnum, const char *, const char *);
     58: PETSC_EXTERN PetscErrorCode PetscBagRegisterBool(PetscBag, void *, PetscBool, const char *, const char *);
     59: PETSC_EXTERN PetscErrorCode PetscBagRegisterBoolArray(PetscBag, void *, PetscInt, const char *, const char *);
     60: PETSC_EXTERN PetscErrorCode PetscBagGetNames(PetscBag, const char *[]);

     62: PETSC_EXTERN PetscErrorCode PetscBagSetFromOptions(PetscBag);
     63: PETSC_EXTERN PetscErrorCode PetscBagGetName(PetscBag, const char **);
     64: PETSC_EXTERN PetscErrorCode PetscBagSetName(PetscBag, const char *, const char *);
     65: PETSC_EXTERN PetscErrorCode PetscBagSetOptionsPrefix(PetscBag, const char *);

     67: PETSC_EXTERN PetscErrorCode PetscBagView(PetscBag, PetscViewer);
     68: PETSC_EXTERN PetscErrorCode PetscBagLoad(PetscViewer, PetscBag);
     69: PETSC_EXTERN PetscErrorCode PetscBagViewFromOptions(PetscBag, PetscObject, const char[]);

     71: #define PETSC_BAG_FILE_CLASSID 1211219