Actual source code: petscoptions.h

petsc-3.5.4 2015-05-23
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;
 58: PETSC_EXTERN PetscInt PetscOptionsPublishCount;

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

 65:    Synopsis:
 66:     #include <petscoptions.h>
 67:     PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])

 69:     Collective on MPI_Comm

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

 77:   Level: intermediate

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

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


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

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

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

113:    Synopsis:
114:     #include <petscoptions.h>
115:     PetscErrorCode PetscObjectOptionsBegin(PetscObject obj)

117:     Collective on PetscObject

119:   Input Parameters:
120: .   obj - object to set options for

122:   Level: intermediate

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

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()

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

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

144:     Collective on the MPI_Comm used in PetscOptionsBegin()

146:    Synopsis:
147:      #include <petscoptions.h>
148:      PetscErrorCode PetscOptionsEnd(void)

150:   Level: intermediate

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

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

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

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

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

174:    Collective on the communicator passed in PetscOptionsBegin()

176:    Synopsis:
177:      #include <petscoptions.h>
178:      PetscErrorCode PetscOptionsTail(void)

180:   Level: intermediate

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

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

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

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

192:    Concepts: options database^subheading

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

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


221: PETSC_EXTERN PetscErrorCode PetscOptionsSetFromOptions(void);
222: PETSC_EXTERN PetscErrorCode PetscOptionsSAWsDestroy(void);

224: /*
225:     See manual page for PetscOptionsBegin()
226: */
227: 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;
228: typedef struct _n_PetscOptions* PetscOptions;
229: struct _n_PetscOptions {
230:   char              *option;
231:   char              *text;
232:   void              *data;         /* used to hold the default value and then any value it is changed to by GUI */
233:   PetscFunctionList flist;         /* used for available values for PetscOptionsFList() */
234:   const char *const *list;        /* used for available values for PetscOptionsEList() */
235:   char              nlist;         /* number of entries in list */
236:   char              *man;
237:   size_t            arraylength;   /* number of entries in data in the case that it is an array (of PetscInt etc) */
238:   int               set;           /* the user has changed this value in the GUI */
239:   PetscOptionType   type;
240:   PetscOptions      next;
241:   char              *pman;
242:   void              *edata;
243: };

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