Actual source code: petscoptions.h
petsc-3.4.2 2013-07-02

      1: /*
      2:    Routines to determine options set in the options database.
      3: */
      6: #include <petscsys.h>
      7: #include <petscviewertypes.h>

      9: PETSC_EXTERN PetscErrorCode PetscOptionsHasName(const char[],const char[],PetscBool *);
     10: PETSC_EXTERN PetscErrorCode PetscOptionsGetInt(const char[],const char [],PetscInt *,PetscBool *);
     11: PETSC_EXTERN PetscErrorCode PetscOptionsGetBool(const char[],const char [],PetscBool  *,PetscBool *);
     12: PETSC_EXTERN PetscErrorCode PetscOptionsGetReal(const char[],const char[],PetscReal *,PetscBool *);
     13: PETSC_EXTERN PetscErrorCode PetscOptionsGetScalar(const char[],const char[],PetscScalar *,PetscBool *);
     14: PETSC_EXTERN PetscErrorCode PetscOptionsGetIntArray(const char[],const char[],PetscInt[],PetscInt *,PetscBool *);
     15: PETSC_EXTERN PetscErrorCode PetscOptionsGetRealArray(const char[],const char[],PetscReal[],PetscInt *,PetscBool *);
     16: PETSC_EXTERN PetscErrorCode PetscOptionsGetBoolArray(const char[],const char[],PetscBool [],PetscInt *,PetscBool *);
     17: PETSC_EXTERN PetscErrorCode PetscOptionsGetString(const char[],const char[],char[],size_t,PetscBool *);
     18: PETSC_EXTERN PetscErrorCode PetscOptionsGetStringArray(const char[],const char[],char*[],PetscInt*,PetscBool *);
     19: PETSC_EXTERN PetscErrorCode PetscOptionsGetEList(const char[],const char[],const char*const*,PetscInt,PetscInt*,PetscBool *);
     20: PETSC_EXTERN PetscErrorCode PetscOptionsGetEnum(const char[],const char[],const char*const*,PetscEnum*,PetscBool *);
     21: PETSC_EXTERN PetscErrorCode PetscOptionsValidKey(const char[],PetscBool *);

     23: PETSC_EXTERN PetscErrorCode PetscOptionsSetAlias(const char[],const char[]);
     24: PETSC_EXTERN PetscErrorCode PetscOptionsSetValue(const char[],const char[]);
     25: PETSC_EXTERN PetscErrorCode PetscOptionsClearValue(const char[]);

     27: PETSC_EXTERN PetscErrorCode PetscOptionsAllUsed(PetscInt*);
     28: PETSC_EXTERN PetscErrorCode PetscOptionsUsed(const char *,PetscBool*);
     29: PETSC_EXTERN PetscErrorCode PetscOptionsLeft(void);
     30: PETSC_EXTERN PetscErrorCode PetscOptionsView(PetscViewer);

     32: PETSC_EXTERN PetscErrorCode PetscOptionsCreate(void);
     33: PETSC_EXTERN PetscErrorCode PetscOptionsInsert(int*,char ***,const char[]);
     34: PETSC_EXTERN PetscErrorCode PetscOptionsInsertFile(MPI_Comm,const char[],PetscBool );
     35: #if defined(PETSC_HAVE_YAML)
     36: PETSC_EXTERN PetscErrorCode PetscOptionsInsertFileYAML(MPI_Comm,const char[],PetscBool);
     37: #endif
     38: PETSC_EXTERN PetscErrorCode PetscOptionsInsertString(const char[]);
     39: PETSC_EXTERN PetscErrorCode PetscOptionsDestroy(void);
     40: PETSC_EXTERN PetscErrorCode PetscOptionsClear(void);
     41: PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPush(const char[]);
     42: PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPop(void);

     44: PETSC_EXTERN PetscErrorCode PetscOptionsReject(const char[],const char[]);
     45: PETSC_EXTERN PetscErrorCode PetscOptionsGetAll(char*[]);

     47: PETSC_EXTERN PetscErrorCode PetscOptionsGetenv(MPI_Comm,const char[],char[],size_t,PetscBool  *);
     48: PETSC_EXTERN PetscErrorCode PetscOptionsStringToInt(const char[],PetscInt*);
     49: PETSC_EXTERN PetscErrorCode PetscOptionsStringToReal(const char[],PetscReal*);
     50: PETSC_EXTERN PetscErrorCode PetscOptionsStringToBool(const char[],PetscBool*);

     52: PETSC_EXTERN PetscErrorCode PetscOptionsMonitorSet(PetscErrorCode (*)(const char[], const char[], void*), void *, PetscErrorCode (*)(void**));
     53: PETSC_EXTERN PetscErrorCode PetscOptionsMonitorCancel(void);
     54: PETSC_EXTERN PetscErrorCode PetscOptionsMonitorDefault(const char[], const char[], void *);

     56: PETSC_EXTERN PetscBool PetscOptionsPublish;
     57: PETSC_EXTERN PetscInt PetscOptionsPublishCount;

     59: /*MC
     60:     PetscOptionsBegin - Begins a set of queries on the options database that are related and should be
     61:      displayed on the same window of a GUI that allows the user to set the options interactively.

     63:    Synopsis:
     64:     #include "petscoptions.h"
     65:     PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])

     67:     Collective on MPI_Comm

     69:   Input Parameters:
     70: +   comm - communicator that shares GUI
     71: .   prefix - options prefix for all options displayed on window
     72: .   title - short descriptive text, for example "Krylov Solver Options"
     73: -   mansec - section of manual pages for options, for example KSP

     75:   Level: intermediate

     77:   Notes: Needs to be ended by a call the PetscOptionsEnd()
     78:          Can add subheadings with PetscOptionsHead()

     80:   Developer notes: PetscOptionsPublish is set in PetscOptionsCheckInitial_Private() with -options_gui. When PetscOptionsPublish is set the
     81: $             loop between PetscOptionsBegin() and PetscOptionsEnd() is run THREE times with PetscOptionsPublishCount of values -1,0,1 otherwise
     82: $             the loop is run ONCE with a PetscOptionsPublishCount of 1.
     83: $             = -1 : The PetscOptionsInt() etc just call the PetscOptionsGetInt() etc
     84: $             = 0  : The GUI objects are created in PetscOptionsInt() etc and displayed in PetscOptionsEnd() and the options
     85: $                    database updated updated with user changes; PetscOptionsGetInt() etc are also called
     86: $             = 1 : The PetscOptionsInt() etc again call the PetscOptionsGetInt() etc (possibly getting new values), in addition the help message and
     87: $                   default values are printed if -help was given.
     88: $           When PetscOptionsObject.changedmethod is set this causes PetscOptionsPublishCount to be reset to -2 (so in the next loop iteration it is -1)
     89: $           and the whole process is repeated. This is to handle when, for example, the KSPType is changed thus changing the list of
     90: $           options available so they need to be redisplayed so the user can change the. Chaning PetscOptionsObjects.changedmethod is never
     91: $           currently set.

     94: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
     95:           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
     96:           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
     97:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
     98:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
     99:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
    100:           PetscOptionsList(), PetscOptionsEList(), PetscObjectOptionsBegin()

    102: M*/
    103: #define    PetscOptionsBegin(comm,prefix,mess,sec) 0; do {\
    104:              for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) {\
    105:              PetscErrorCode _5_PetscOptionsBegin_Private(comm,prefix,mess,sec);CHKERRQ(_5_ierr);

    107: /*MC
    108:     PetscObjectOptionsBegin - Begins a set of queries on the options database that are related and should be
    109:      displayed on the same window of a GUI that allows the user to set the options interactively.

    111:    Synopsis:
    112:     #include "petscoptions.h"
    113:     PetscErrorCode PetscObjectOptionsBegin(PetscObject obj)

    115:     Collective on PetscObject

    117:   Input Parameters:
    118: .   obj - object to set options for

    120:   Level: intermediate

    122:   Notes: Needs to be ended by a call the PetscOptionsEnd()
    123:          Can add subheadings with PetscOptionsHead()

    125: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
    126:           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
    127:           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
    128:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
    129:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
    130:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
    131:           PetscOptionsList(), PetscOptionsEList()

    133: M*/
    134: #define PetscObjectOptionsBegin(obj) 0; do {                            \
    135:   for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) { \
    136:   PetscErrorCode _5_PetscObjectOptionsBegin_Private(obj);CHKERRQ(_5_ierr);

    138: /*MC
    139:     PetscOptionsEnd - Ends a set of queries on the options database that are related and should be
    140:      displayed on the same window of a GUI that allows the user to set the options interactively.

    142:     Collective on the MPI_Comm used in PetscOptionsBegin()

    144:    Synopsis:
    145:      #include "petscoptions.h"
    146:      PetscErrorCode PetscOptionsEnd(void)

    148:   Level: intermediate

    150:   Notes: Needs to be preceded by a call to PetscOptionsBegin()

    152: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
    153:           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
    154:           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
    155:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
    156:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
    157:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
    158:           PetscOptionsList(), PetscOptionsEList(), PetscObjectOptionsBegin()

    160: M*/
    161: #define    PetscOptionsEnd() _5_PetscOptionsEnd_Private();CHKERRQ(_5_ierr);}} while (0)

    163: PETSC_EXTERN PetscErrorCode PetscOptionsBegin_Private(MPI_Comm,const char[],const char[],const char[]);
    164: PETSC_EXTERN PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject);
    165: PETSC_EXTERN PetscErrorCode PetscOptionsEnd_Private(void);
    166: PETSC_EXTERN PetscErrorCode PetscOptionsHead(const char[]);

    168: /*MC
    169:      PetscOptionsTail - Ends a section of options begun with PetscOptionsHead()
    170:             See, for example, KSPSetFromOptions_GMRES().

    172:    Collective on the communicator passed in PetscOptionsBegin()

    174:    Synopsis:
    175:      #include "petscoptions.h"
    176:      PetscErrorCode PetscOptionsTail(void)

    178:   Level: intermediate

    180:    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()

    182:           Must be preceded by a call to PetscOptionsHead() in the same function.

    184:           This needs to be used only if the code below PetscOptionsTail() can be run ONLY once.
    185:       See, for example, PCSetFromOptions_Composite(). This is a return(0) in it for early exit
    186:       from the function.

    188:           This is only for use with the PETSc options GUI; which does not currently exist.

    190:    Concepts: options database^subheading

    192: .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
    193:            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
    194:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
    195:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
    196:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
    197:           PetscOptionsList(), PetscOptionsEList(), PetscOptionsEnum()
    198: M*/
    199: #define    PetscOptionsTail() 0; {if (PetscOptionsPublishCount != 1) return(0);}

    201: PETSC_EXTERN PetscErrorCode PetscOptionsEnum(const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscBool *);
    202: PETSC_EXTERN PetscErrorCode PetscOptionsInt(const char[],const char[],const char[],PetscInt,PetscInt*,PetscBool *);
    203: PETSC_EXTERN PetscErrorCode PetscOptionsReal(const char[],const char[],const char[],PetscReal,PetscReal*,PetscBool *);
    204: PETSC_EXTERN PetscErrorCode PetscOptionsScalar(const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscBool *);
    205: PETSC_EXTERN PetscErrorCode PetscOptionsName(const char[],const char[],const char[],PetscBool *);
    206: PETSC_EXTERN PetscErrorCode PetscOptionsString(const char[],const char[],const char[],const char[],char*,size_t,PetscBool *);
    207: PETSC_EXTERN PetscErrorCode PetscOptionsBool(const char[],const char[],const char[],PetscBool ,PetscBool *,PetscBool *);
    208: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupBegin(const char[],const char[],const char[],PetscBool *);
    209: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroup(const char[],const char[],const char[],PetscBool *);
    210: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupEnd(const char[],const char[],const char[],PetscBool *);
    211: PETSC_EXTERN PetscErrorCode PetscOptionsList(const char[],const char[],const char[],PetscFunctionList,const char[],char[],size_t,PetscBool *);
    212: PETSC_EXTERN PetscErrorCode PetscOptionsEList(const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscBool *);
    213: PETSC_EXTERN PetscErrorCode PetscOptionsRealArray(const char[],const char[],const char[],PetscReal[],PetscInt*,PetscBool *);
    214: PETSC_EXTERN PetscErrorCode PetscOptionsIntArray(const char[],const char[],const char[],PetscInt[],PetscInt*,PetscBool *);
    215: PETSC_EXTERN PetscErrorCode PetscOptionsStringArray(const char[],const char[],const char[],char*[],PetscInt*,PetscBool *);
    216: PETSC_EXTERN PetscErrorCode PetscOptionsBoolArray(const char[],const char[],const char[],PetscBool [],PetscInt*,PetscBool *);

    219: PETSC_EXTERN PetscErrorCode PetscOptionsSetFromOptions(void);
    220: PETSC_EXTERN PetscErrorCode PetscOptionsAMSDestroy(void);

    222: /*
    223:     See manual page for PetscOptionsBegin()
    224: */
    225: typedef enum {OPTION_INT,OPTION_LOGICAL,OPTION_REAL,OPTION_LIST,OPTION_STRING,OPTION_REAL_ARRAY,OPTION_HEAD,OPTION_INT_ARRAY,OPTION_ELIST,OPTION_LOGICAL_ARRAY,OPTION_STRING_ARRAY} PetscOptionType;
    226: typedef struct _n_PetscOptions* PetscOptions;
    227: struct _n_PetscOptions {
    228:   char              *option;
    229:   char              *text;
    230:   void              *data;         /* used to hold the default value and then any value it is changed to by GUI */
    231:   PetscFunctionList flist;         /* used for available values for PetscOptionsList() */
    232:   const char *const *list;        /* used for available values for PetscOptionsEList() */
    233:   char              nlist;         /* number of entries in list */
    234:   char              *man;
    235:   size_t            arraylength;   /* number of entries in data in the case that it is an array (of PetscInt etc) */
    236:   PetscBool         set;           /* the user has changed this value in the GUI */
    237:   PetscOptionType   type;
    238:   PetscOptions      next;
    239:   char              *pman;
    240:   void              *edata;
    241: };

    243: typedef struct {
    244:   PetscOptions     next;
    245:   char             *prefix,*pprefix;
    246:   char             *title;
    247:   MPI_Comm         comm;
    248:   PetscBool        printhelp,changedmethod,alreadyprinted;
    249:   PetscObject      object;
    250: } PetscOptionsObjectType;
    251: #endif