Actual source code: petscoptions.h

petsc-3.3-p7 2013-05-11
  1: /*
  2:    Routines to determine options set in the options database.
  3: */
 6:  #include petscsys.h

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

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

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

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

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

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

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

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

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

 62:    Synopsis: PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])

 64:     Collective on MPI_Comm

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

 72:   Level: intermediate

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

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


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

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

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

108:    Synopsis: PetscErrorCode PetscObjectOptionsBegin(PetscObject obj)

110:     Collective on PetscObject

112:   Input Parameters:
113: .   obj - object to set options for

115:   Level: intermediate

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

120: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
121:           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
122:           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
123:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
124:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
125:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
126:           PetscOptionsList(), PetscOptionsEList()

128: M*/
129: #define PetscObjectOptionsBegin(obj) 0; do {                            \
130:   for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) { \
131:   PetscErrorCode _5_PetscObjectOptionsBegin_Private(obj);CHKERRQ(_5_ierr);

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

137:     Collective on the MPI_Comm used in PetscOptionsBegin()

139:    Synopsis: PetscErrorCode PetscOptionsEnd(void)

141:   Level: intermediate

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

145: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
146:           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
147:           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
148:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
149:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
150:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
151:           PetscOptionsList(), PetscOptionsEList(), PetscObjectOptionsBegin()

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

156: PETSC_EXTERN PetscErrorCode PetscOptionsBegin_Private(MPI_Comm,const char[],const char[],const char[]);
157: PETSC_EXTERN PetscErrorCode PetscObjectOptionsBegin_Private(PetscObject);
158: PETSC_EXTERN PetscErrorCode PetscOptionsEnd_Private(void);
159: PETSC_EXTERN PetscErrorCode PetscOptionsHead(const char[]);

161: /*MC
162:      PetscOptionsTail - Ends a section of options begun with PetscOptionsHead()
163:             See, for example, KSPSetFromOptions_GMRES().

165:    Collective on the communicator passed in PetscOptionsBegin()

167:    Synopsis: PetscErrorCode PetscOptionsTail(void)

169:   Level: intermediate

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

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

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

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

181:    Concepts: options database^subheading

183: .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),  
184:            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
185:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
186:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
187:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
188:           PetscOptionsList(), PetscOptionsEList(), PetscOptionsEnum()
189: M*/
190: #define    PetscOptionsTail() 0; {if (PetscOptionsPublishCount != 1) return(0);}

192: PETSC_EXTERN PetscErrorCode PetscOptionsEnum(const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscBool *);
193: PETSC_EXTERN PetscErrorCode PetscOptionsInt(const char[],const char[],const char[],PetscInt,PetscInt*,PetscBool *);
194: PETSC_EXTERN PetscErrorCode PetscOptionsReal(const char[],const char[],const char[],PetscReal,PetscReal*,PetscBool *);
195: PETSC_EXTERN PetscErrorCode PetscOptionsScalar(const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscBool *);
196: PETSC_EXTERN PetscErrorCode PetscOptionsName(const char[],const char[],const char[],PetscBool *);
197: PETSC_EXTERN PetscErrorCode PetscOptionsString(const char[],const char[],const char[],const char[],char*,size_t,PetscBool *);
198: PETSC_EXTERN PetscErrorCode PetscOptionsBool(const char[],const char[],const char[],PetscBool ,PetscBool *,PetscBool *);
199: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupBegin(const char[],const char[],const char[],PetscBool *);
200: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroup(const char[],const char[],const char[],PetscBool *);
201: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupEnd(const char[],const char[],const char[],PetscBool *);
202: PETSC_EXTERN PetscErrorCode PetscOptionsList(const char[],const char[],const char[],PetscFList,const char[],char[],size_t,PetscBool *);
203: PETSC_EXTERN PetscErrorCode PetscOptionsEList(const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscBool *);
204: PETSC_EXTERN PetscErrorCode PetscOptionsRealArray(const char[],const char[],const char[],PetscReal[],PetscInt*,PetscBool *);
205: PETSC_EXTERN PetscErrorCode PetscOptionsIntArray(const char[],const char[],const char[],PetscInt[],PetscInt*,PetscBool *);
206: PETSC_EXTERN PetscErrorCode PetscOptionsStringArray(const char[],const char[],const char[],char*[],PetscInt*,PetscBool *);
207: PETSC_EXTERN PetscErrorCode PetscOptionsBoolArray(const char[],const char[],const char[],PetscBool [],PetscInt*,PetscBool *);

209: PETSC_EXTERN PetscErrorCode PetscOptionsSetFromOptions(void);
210: PETSC_EXTERN PetscErrorCode PetscOptionsAMSDestroy(void);

212: /* 
213:     See manual page for PetscOptionsBegin() 
214: */
215: 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;
216: typedef struct _n_PetscOptions* PetscOptions;
217: struct _n_PetscOptions {
218:   char              *option;
219:   char              *text;
220:   void              *data;         /* used to hold the default value and then any value it is changed to by GUI */
221:   PetscFList        flist;         /* used for available values for PetscOptionsList() */
222:   const char *const *list;        /* used for available values for PetscOptionsEList() */
223:   char              nlist;         /* number of entries in list */
224:   char              *man;
225:   size_t            arraylength;   /* number of entries in data in the case that it is an array (of PetscInt etc) */
226:   PetscBool         set;           /* the user has changed this value in the GUI */
227:   PetscOptionType   type;
228:   PetscOptions      next;
229:   char              *pman;
230:   void              *edata;
231: };

233: typedef struct {
234:   PetscOptions     next;
235:   char             *prefix,*pprefix;
236:   char             *title;
237:   MPI_Comm         comm;
238:   PetscBool        printhelp,changedmethod,alreadyprinted;
239:   PetscObject      object;
240: } PetscOptionsObjectType;
241: #endif