Actual source code: petscoptions.h

petsc-master 2015-03-03
Report Typos and Errors
  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 PetscOptionsGetScalarArray(const char[],const char[],PetscScalar[],PetscInt *,PetscBool *);
 17: PETSC_EXTERN PetscErrorCode PetscOptionsGetBoolArray(const char[],const char[],PetscBool [],PetscInt *,PetscBool *);
 18: PETSC_EXTERN PetscErrorCode PetscOptionsGetString(const char[],const char[],char[],size_t,PetscBool *);
 19: PETSC_EXTERN PetscErrorCode PetscOptionsGetStringArray(const char[],const char[],char*[],PetscInt*,PetscBool *);
 20: PETSC_EXTERN PetscErrorCode PetscOptionsGetEList(const char[],const char[],const char*const*,PetscInt,PetscInt*,PetscBool *);
 21: PETSC_EXTERN PetscErrorCode PetscOptionsGetEnum(const char[],const char[],const char*const*,PetscEnum*,PetscBool *);
 22: PETSC_EXTERN PetscErrorCode PetscOptionsValidKey(const char[],PetscBool *);

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

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

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

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

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

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

 57: PETSC_EXTERN PetscBool PetscOptionsPublish;


 60: /*
 61:     See manual page for PetscOptionsBegin()
 62: */
 63: typedef enum {OPTION_INT,OPTION_BOOL,OPTION_REAL,OPTION_FLIST,OPTION_STRING,OPTION_REAL_ARRAY,OPTION_HEAD,OPTION_INT_ARRAY,OPTION_ELIST,OPTION_BOOL_ARRAY,OPTION_STRING_ARRAY} PetscOptionType;
 64: typedef struct _n_PetscOption* PetscOption;
 65: struct _n_PetscOption{
 66:   char              *option;
 67:   char              *text;
 68:   void              *data;         /* used to hold the default value and then any value it is changed to by GUI */
 69:   PetscFunctionList flist;         /* used for available values for PetscOptionsList() */
 70:   const char *const *list;        /* used for available values for PetscOptionsEList() */
 71:   char              nlist;         /* number of entries in list */
 72:   char              *man;
 73:   size_t            arraylength;   /* number of entries in data in the case that it is an array (of PetscInt etc) */
 74:   PetscBool         set;           /* the user has changed this value in the GUI */
 75:   PetscOptionType   type;
 76:   PetscOption       next;
 77:   char              *pman;
 78:   void              *edata;
 79: };

 81: typedef struct _p_PetscOptions {
 82:   PetscInt         count;
 83:   PetscOption      next;
 84:   char             *prefix,*pprefix;
 85:   char             *title;
 86:   MPI_Comm         comm;
 87:   PetscBool        printhelp,changedmethod,alreadyprinted;
 88:   PetscObject      object;
 89: } PetscOptions;

 91: /*MC
 92:     PetscOptionsBegin - Begins a set of queries on the options database that are related and should be
 93:      displayed on the same window of a GUI that allows the user to set the options interactively. Often one should 
 94:      use PetscObjectOptionsBegin() rather than this call.

 96:    Synopsis:
 97:     #include <petscoptions.h>
 98:     PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])

100:     Collective on MPI_Comm

102:   Input Parameters:
103: +   comm - communicator that shares GUI
104: .   prefix - options prefix for all options displayed on window
105: .   title - short descriptive text, for example "Krylov Solver Options"
106: -   mansec - section of manual pages for options, for example KSP

108:   Level: intermediate

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

113:   Developer notes: PetscOptionsPublish is set in PetscOptionsCheckInitial_Private() with -saws_options. When PetscOptionsPublish is set the
114: $             loop between PetscOptionsBegin() and PetscOptionsEnd() is run THREE times with PetscOptionsPublishCount of values -1,0,1 otherwise
115: $             the loop is run ONCE with a PetscOptionsPublishCount of 1.
116: $             = -1 : The PetscOptionsInt() etc just call the PetscOptionsGetInt() etc
117: $             = 0  : The GUI objects are created in PetscOptionsInt() etc and displayed in PetscOptionsEnd() and the options
118: $                    database updated updated with user changes; PetscOptionsGetInt() etc are also called
119: $             = 1 : The PetscOptionsInt() etc again call the PetscOptionsGetInt() etc (possibly getting new values), in addition the help message and
120: $                   default values are printed if -help was given.
121: $           When PetscOptionsObject.changedmethod is set this causes PetscOptionsPublishCount to be reset to -2 (so in the next loop iteration it is -1)
122: $           and the whole process is repeated. This is to handle when, for example, the KSPType is changed thus changing the list of
123: $           options available so they need to be redisplayed so the user can change the. Chaning PetscOptionsObjects.changedmethod is never
124: $           currently set.


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

135: M*/
136: #define    PetscOptionsBegin(comm,prefix,mess,sec) 0; do {\
137:              PetscOptions PetscOptionsObjectBase;\
138:              PetscOptions *PetscOptionsObject = &PetscOptionsObjectBase; \
139:              PetscMemzero(PetscOptionsObject,sizeof(PetscOptions)); \
140:              for (PetscOptionsObject->count=(PetscOptionsPublish?-1:1); PetscOptionsObject->count<2; PetscOptionsObject->count++) {\
141:              PetscErrorCode _5_PetscOptionsBegin_Private(PetscOptionsObject,comm,prefix,mess,sec);CHKERRQ(_5_ierr);

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

147:    Synopsis:
148:     #include <petscoptions.h>
149:     PetscErrorCode PetscObjectOptionsBegin(PetscObject obj)

151:     Collective on PetscObject

153:   Input Parameters:
154: .   obj - object to set options for

156:   Level: intermediate

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

161: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
162:           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
163:           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
164:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
165:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
166:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
167:           PetscOptionsFList(), PetscOptionsEList()

169: M*/
170: #define PetscObjectOptionsBegin(obj) 0; do {                            \
171:              PetscOptions PetscOptionsObjectBase;\
172:              PetscOptions *PetscOptionsObject = &PetscOptionsObjectBase; \
173:              for (PetscOptionsObject->count=(PetscOptionsPublish?-1:1); PetscOptionsObject->count<2; PetscOptionsObject->count++) {\
174:              PetscErrorCode _5_PetscObjectOptionsBegin_Private(PetscOptionsObject,obj);CHKERRQ(_5_ierr);

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

180:     Collective on the MPI_Comm used in PetscOptionsBegin()

182:    Synopsis:
183:      #include <petscoptions.h>
184:      PetscErrorCode PetscOptionsEnd(void)

186:   Level: intermediate

188:   Notes: Needs to be preceded by a call to PetscOptionsBegin() or PetscObjectOptionsBegin()

190: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
191:           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
192:           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
193:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
194:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
195:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
196:           PetscOptionsFList(), PetscOptionsEList(), PetscObjectOptionsBegin()

198: M*/
199: #define    PetscOptionsEnd() _5_PetscOptionsEnd_Private(PetscOptionsObject);CHKERRQ(_5_ierr);}} while (0)

201: PETSC_EXTERN PetscErrorCode PetscOptionsBegin_Private(PetscOptions *,MPI_Comm,const char[],const char[],const char[]);
202: PETSC_EXTERN PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptions *,PetscObject);
203: PETSC_EXTERN PetscErrorCode PetscOptionsEnd_Private(PetscOptions *);
204: PETSC_EXTERN PetscErrorCode PetscOptionsHead(PetscOptions *,const char[]);

206: /*MC
207:      PetscOptionsTail - Ends a section of options begun with PetscOptionsHead()
208:             See, for example, KSPSetFromOptions_GMRES().

210:    Collective on the communicator passed in PetscOptionsBegin()

212:    Synopsis:
213:      #include <petscoptions.h>
214:      PetscErrorCode PetscOptionsTail(void)

216:   Level: intermediate

218:    Notes: Must be between a PetscOptionsBegin()/PetscObjectOptionsBegin() and a PetscOptionsEnd()

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

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

226:           This is only for use with the PETSc options GUI

228:    Concepts: options database^subheading

230: .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
231:            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
232:           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
233:           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
234:           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
235:           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum()
236: M*/
237: #define    PetscOptionsTail() 0; {if (PetscOptionsObject->count != 1) return(0);}

239: #define PetscOptionsEnum(a,b,c,d,e,f,g) PetscOptionsEnum_Private(PetscOptionsObject,a,b,c,d,e,f,g)
240: #define PetscOptionsInt(a,b,c,d,e,f) PetscOptionsInt_Private(PetscOptionsObject,a,b,c,d,e,f)
241: #define PetscOptionsReal(a,b,c,d,e,f) PetscOptionsReal_Private(PetscOptionsObject,a,b,c,d,e,f)
242: #define PetscOptionsScalar(a,b,c,d,e,f) PetscOptionsScalar_Private(PetscOptionsObject,a,b,c,d,e,f)
243: #define PetscOptionsName(a,b,c,d) PetscOptionsName_Private(PetscOptionsObject,a,b,c,d)
244: #define PetscOptionsString(a,b,c,d,e,f,g) PetscOptionsString_Private(PetscOptionsObject,a,b,c,d,e,f,g)
245: #define PetscOptionsBool(a,b,c,d,e,f) PetscOptionsBool_Private(PetscOptionsObject,a,b,c,d,e,f)
246: #define PetscOptionsBoolGroupBegin(a,b,c,d) PetscOptionsBoolGroupBegin_Private(PetscOptionsObject,a,b,c,d)
247: #define PetscOptionsBoolGroup(a,b,c,d) PetscOptionsBoolGroup_Private(PetscOptionsObject,a,b,c,d)
248: #define PetscOptionsBoolGroupEnd(a,b,c,d) PetscOptionsBoolGroupEnd_Private(PetscOptionsObject,a,b,c,d)
249: #define PetscOptionsFList(a,b,c,d,e,f,g,h) PetscOptionsFList_Private(PetscOptionsObject,a,b,c,d,e,f,g,h)
250: #define PetscOptionsEList(a,b,c,d,e,f,g,h) PetscOptionsEList_Private(PetscOptionsObject,a,b,c,d,e,f,g,h)
251: #define PetscOptionsRealArray(a,b,c,d,e,f) PetscOptionsRealArray_Private(PetscOptionsObject,a,b,c,d,e,f)
252: #define PetscOptionsIntArray(a,b,c,d,e,f) PetscOptionsIntArray_Private(PetscOptionsObject,a,b,c,d,e,f)
253: #define PetscOptionsStringArray(a,b,c,d,e,f) PetscOptionsStringArray_Private(PetscOptionsObject,a,b,c,d,e,f)
254: #define PetscOptionsBoolArray(a,b,c,d,e,f) PetscOptionsBoolArray_Private(PetscOptionsObject,a,b,c,d,e,f)


257: PETSC_EXTERN PetscErrorCode PetscOptionsEnum_Private(PetscOptions *,const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscBool *);
258: PETSC_EXTERN PetscErrorCode PetscOptionsInt_Private(PetscOptions *,const char[],const char[],const char[],PetscInt,PetscInt*,PetscBool *);
259: PETSC_EXTERN PetscErrorCode PetscOptionsReal_Private(PetscOptions *,const char[],const char[],const char[],PetscReal,PetscReal*,PetscBool *);
260: PETSC_EXTERN PetscErrorCode PetscOptionsScalar_Private(PetscOptions *,const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscBool *);
261: PETSC_EXTERN PetscErrorCode PetscOptionsName_Private(PetscOptions *,const char[],const char[],const char[],PetscBool *);
262: PETSC_EXTERN PetscErrorCode PetscOptionsString_Private(PetscOptions *,const char[],const char[],const char[],const char[],char*,size_t,PetscBool *);
263: PETSC_EXTERN PetscErrorCode PetscOptionsBool_Private(PetscOptions *,const char[],const char[],const char[],PetscBool ,PetscBool *,PetscBool *);
264: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptions *,const char[],const char[],const char[],PetscBool *);
265: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptions *,const char[],const char[],const char[],PetscBool *);
266: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptions *,const char[],const char[],const char[],PetscBool *);
267: PETSC_EXTERN PetscErrorCode PetscOptionsFList_Private(PetscOptions *,const char[],const char[],const char[],PetscFunctionList,const char[],char[],size_t,PetscBool *);
268: PETSC_EXTERN PetscErrorCode PetscOptionsEList_Private(PetscOptions *,const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscBool *);
269: PETSC_EXTERN PetscErrorCode PetscOptionsRealArray_Private(PetscOptions *,const char[],const char[],const char[],PetscReal[],PetscInt*,PetscBool *);
270: PETSC_EXTERN PetscErrorCode PetscOptionsIntArray_Private(PetscOptions *,const char[],const char[],const char[],PetscInt[],PetscInt*,PetscBool *);
271: PETSC_EXTERN PetscErrorCode PetscOptionsStringArray_Private(PetscOptions *,const char[],const char[],const char[],char*[],PetscInt*,PetscBool *);
272: PETSC_EXTERN PetscErrorCode PetscOptionsBoolArray_Private(PetscOptions *,const char[],const char[],const char[],PetscBool [],PetscInt*,PetscBool *);


275: PETSC_EXTERN PetscErrorCode PetscOptionsSetFromOptions(void);
276: PETSC_EXTERN PetscErrorCode PetscOptionsSAWsDestroy(void);

278: #endif