Actual source code: petscoptions.h
petsc-3.11.4 2019-09-28
1: /*
2: Routines to determine options set in the options database.
3: */
4: #if !defined(PETSCOPTIONS_H)
5: #define PETSCOPTIONS_H
6: #include <petscsys.h>
7: #include <petscviewertypes.h>
9: typedef struct _n_PetscOptions* PetscOptions;
10: PETSC_EXTERN PetscErrorCode PetscOptionsCreate(PetscOptions*);
11: PETSC_EXTERN PetscErrorCode PetscOptionsDestroy(PetscOptions*);
12: PETSC_EXTERN PetscErrorCode PetscOptionsCreateDefault(void);
13: PETSC_EXTERN PetscErrorCode PetscOptionsDestroyDefault(void);
15: PETSC_EXTERN PetscErrorCode PetscOptionsHasHelp(PetscOptions,PetscBool*);
16: PETSC_EXTERN PetscErrorCode PetscOptionsHasName(PetscOptions,const char[],const char[],PetscBool*);
17: PETSC_EXTERN PetscErrorCode PetscOptionsGetBool(PetscOptions,const char[],const char [],PetscBool*,PetscBool*);
18: PETSC_EXTERN PetscErrorCode PetscOptionsGetInt(PetscOptions,const char[],const char [],PetscInt*,PetscBool*);
19: PETSC_EXTERN PetscErrorCode PetscOptionsGetEnum(PetscOptions,const char[],const char[],const char*const*,PetscEnum*,PetscBool*);
20: PETSC_EXTERN PetscErrorCode PetscOptionsGetEList(PetscOptions,const char[],const char[],const char*const*,PetscInt,PetscInt*,PetscBool*);
21: PETSC_EXTERN PetscErrorCode PetscOptionsGetReal(PetscOptions,const char[],const char[],PetscReal*,PetscBool*);
22: PETSC_EXTERN PetscErrorCode PetscOptionsGetScalar(PetscOptions,const char[],const char[],PetscScalar*,PetscBool*);
23: PETSC_EXTERN PetscErrorCode PetscOptionsGetString(PetscOptions,const char[],const char[],char[],size_t,PetscBool*);
25: PETSC_EXTERN PetscErrorCode PetscOptionsGetBoolArray(PetscOptions,const char[],const char[],PetscBool [],PetscInt*,PetscBool*);
26: PETSC_EXTERN PetscErrorCode PetscOptionsGetEnumArray(PetscOptions,const char[],const char[],const char*const*,PetscEnum*,PetscInt*,PetscBool*);
27: PETSC_EXTERN PetscErrorCode PetscOptionsGetIntArray(PetscOptions,const char[],const char[],PetscInt[],PetscInt*,PetscBool*);
28: PETSC_EXTERN PetscErrorCode PetscOptionsGetRealArray(PetscOptions,const char[],const char[],PetscReal[],PetscInt*,PetscBool*);
29: PETSC_EXTERN PetscErrorCode PetscOptionsGetScalarArray(PetscOptions,const char[],const char[],PetscScalar[],PetscInt*,PetscBool*);
30: PETSC_EXTERN PetscErrorCode PetscOptionsGetStringArray(PetscOptions,const char[],const char[],char*[],PetscInt*,PetscBool*);
32: PETSC_EXTERN PetscErrorCode PetscOptionsValidKey(const char[],PetscBool*);
33: PETSC_EXTERN PetscErrorCode PetscOptionsSetAlias(PetscOptions,const char[],const char[]);
34: PETSC_EXTERN PetscErrorCode PetscOptionsSetValue(PetscOptions,const char[],const char[]);
35: PETSC_EXTERN PetscErrorCode PetscOptionsClearValue(PetscOptions,const char[]);
36: PETSC_EXTERN PetscErrorCode PetscOptionsFindPair(PetscOptions,const char[],const char[],const char*[],PetscBool*);
38: PETSC_EXTERN PetscErrorCode PetscOptionsGetAll(PetscOptions,char*[]);
39: PETSC_EXTERN PetscErrorCode PetscOptionsAllUsed(PetscOptions,PetscInt*);
40: PETSC_EXTERN PetscErrorCode PetscOptionsUsed(PetscOptions,const char[],PetscBool*);
41: PETSC_EXTERN PetscErrorCode PetscOptionsLeft(PetscOptions);
42: PETSC_EXTERN PetscErrorCode PetscOptionsLeftGet(PetscOptions,PetscInt*,char***,char***);
43: PETSC_EXTERN PetscErrorCode PetscOptionsLeftRestore(PetscOptions,PetscInt*,char***,char***);
44: PETSC_EXTERN PetscErrorCode PetscOptionsView(PetscOptions,PetscViewer);
46: PETSC_EXTERN PetscErrorCode PetscOptionsReject(PetscOptions,const char[],const char[],const char[]);
47: PETSC_EXTERN PetscErrorCode PetscOptionsInsert(PetscOptions,int*,char***,const char[]);
48: PETSC_EXTERN PetscErrorCode PetscOptionsInsertFile(MPI_Comm,PetscOptions,const char[],PetscBool );
49: #if defined(PETSC_HAVE_YAML)
50: PETSC_EXTERN PetscErrorCode PetscOptionsInsertFileYAML(MPI_Comm,const char[],PetscBool);
51: #endif
52: PETSC_EXTERN PetscErrorCode PetscOptionsInsertString(PetscOptions,const char[]);
53: PETSC_EXTERN PetscErrorCode PetscOptionsClear(PetscOptions);
54: PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPush(PetscOptions,const char[]);
55: PETSC_EXTERN PetscErrorCode PetscOptionsPrefixPop(PetscOptions);
57: PETSC_EXTERN PetscErrorCode PetscOptionsGetenv(MPI_Comm,const char[],char[],size_t,PetscBool*);
58: PETSC_EXTERN PetscErrorCode PetscOptionsStringToBool(const char[],PetscBool*);
59: PETSC_EXTERN PetscErrorCode PetscOptionsStringToInt(const char[],PetscInt*);
60: PETSC_EXTERN PetscErrorCode PetscOptionsStringToReal(const char[],PetscReal*);
61: PETSC_EXTERN PetscErrorCode PetscOptionsStringToScalar(const char[],PetscScalar*);
63: PETSC_EXTERN PetscErrorCode PetscOptionsMonitorSet(PetscErrorCode (*)(const char[], const char[], void*), void*, PetscErrorCode (*)(void**));
64: PETSC_EXTERN PetscErrorCode PetscOptionsMonitorCancel(void);
65: PETSC_EXTERN PetscErrorCode PetscOptionsMonitorDefault(const char[], const char[], void*);
67: PETSC_EXTERN PetscErrorCode PetscObjectSetOptions(PetscObject,PetscOptions);
68: PETSC_EXTERN PetscErrorCode PetscObjectGetOptions(PetscObject,PetscOptions*);
70: PETSC_EXTERN PetscBool PetscOptionsPublish;
73: /*
74: See manual page for PetscOptionsBegin()
76: PetscOptionsItem and PetscOptionsItems are a single option (such as ksp_type) and a collection of such single
77: options being handled with a PetscOptionsBegin/End()
79: */
80: typedef enum {OPTION_INT,OPTION_BOOL,OPTION_REAL,OPTION_FLIST,OPTION_STRING,OPTION_REAL_ARRAY,OPTION_SCALAR_ARRAY,OPTION_HEAD,OPTION_INT_ARRAY,OPTION_ELIST,OPTION_BOOL_ARRAY,OPTION_STRING_ARRAY} PetscOptionType;
81: typedef struct _n_PetscOptionItem* PetscOptionItem;
82: struct _n_PetscOptionItem{
83: char *option;
84: char *text;
85: void *data; /* used to hold the default value and then any value it is changed to by GUI */
86: PetscFunctionList flist; /* used for available values for PetscOptionsList() */
87: const char *const *list; /* used for available values for PetscOptionsEList() */
88: char nlist; /* number of entries in list */
89: char *man;
90: size_t arraylength; /* number of entries in data in the case that it is an array (of PetscInt etc) */
91: PetscBool set; /* the user has changed this value in the GUI */
92: PetscOptionType type;
93: PetscOptionItem next;
94: char *pman;
95: void *edata;
96: };
98: typedef struct _p_PetscOptionItems {
99: PetscInt count;
100: PetscOptionItem next;
101: char *prefix,*pprefix;
102: char *title;
103: MPI_Comm comm;
104: PetscBool printhelp,changedmethod,alreadyprinted;
105: PetscObject object;
106: PetscOptions options;
107: } PetscOptionItems;
110: /*MC
111: PetscOptionsBegin - Begins a set of queries on the options database that are related and should be
112: displayed on the same window of a GUI that allows the user to set the options interactively. Often one should
113: use PetscObjectOptionsBegin() rather than this call.
115: Synopsis:
116: #include <petscoptions.h>
117: PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
119: Collective on MPI_Comm
121: Input Parameters:
122: + comm - communicator that shares GUI
123: . prefix - options prefix for all options displayed on window
124: . title - short descriptive text, for example "Krylov Solver Options"
125: - mansec - section of manual pages for options, for example KSP
127: Level: intermediate
129: Notes:
130: Needs to be ended by a call the PetscOptionsEnd()
131: Can add subheadings with PetscOptionsHead()
133: Developer Notes:
134: PetscOptionsPublish is set in PetscOptionsCheckInitial_Private() with -saws_options. When PetscOptionsPublish is set the
135: $ loop between PetscOptionsBegin() and PetscOptionsEnd() is run THREE times with PetscOptionsPublishCount of values -1,0,1 otherwise
136: $ the loop is run ONCE with a PetscOptionsPublishCount of 1.
137: $ = -1 : The PetscOptionsInt() etc just call the PetscOptionsGetInt() etc
138: $ = 0 : The GUI objects are created in PetscOptionsInt() etc and displayed in PetscOptionsEnd() and the options
139: $ database updated updated with user changes; PetscOptionsGetInt() etc are also called
140: $ = 1 : The PetscOptionsInt() etc again call the PetscOptionsGetInt() etc (possibly getting new values), in addition the help message and
141: $ default values are printed if -help was given.
142: $ When PetscOptionsObject.changedmethod is set this causes PetscOptionsPublishCount to be reset to -2 (so in the next loop iteration it is -1)
143: $ and the whole process is repeated. This is to handle when, for example, the KSPType is changed thus changing the list of
144: $ options available so they need to be redisplayed so the user can change the. Chaning PetscOptionsObjects.changedmethod is never
145: $ currently set.
148: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
149: PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
150: PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
151: PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
152: PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
153: PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
154: PetscOptionsFList(), PetscOptionsEList(), PetscObjectOptionsBegin()
156: M*/
157: #define PetscOptionsBegin(comm,prefix,mess,sec) 0; do {\
158: PetscOptionItems PetscOptionsObjectBase;\
159: PetscOptionItems *PetscOptionsObject = &PetscOptionsObjectBase; \
160: PetscMemzero(PetscOptionsObject,sizeof(PetscOptionItems)); \
161: for (PetscOptionsObject->count=(PetscOptionsPublish?-1:1); PetscOptionsObject->count<2; PetscOptionsObject->count++) {\
162: PetscErrorCode _5_PetscOptionsBegin_Private(PetscOptionsObject,comm,prefix,mess,sec);CHKERRQ(_5_ierr);
164: /*MC
165: PetscObjectOptionsBegin - Begins a set of queries on the options database that are related and should be
166: displayed on the same window of a GUI that allows the user to set the options interactively.
168: Synopsis:
169: #include <petscoptions.h>
170: PetscErrorCode PetscObjectOptionsBegin(PetscObject obj)
172: Collective on PetscObject
174: Input Parameters:
175: . obj - object to set options for
177: Level: intermediate
179: Notes:
180: Needs to be ended by a call the PetscOptionsEnd()
181: Can add subheadings with PetscOptionsHead()
183: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
184: PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
185: PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
186: PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
187: PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
188: PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
189: PetscOptionsFList(), PetscOptionsEList()
191: M*/
192: #define PetscObjectOptionsBegin(obj) 0; do { \
193: PetscOptionItems PetscOptionsObjectBase;\
194: PetscOptionItems *PetscOptionsObject = &PetscOptionsObjectBase; \
195: PetscOptionsObject->options = ((PetscObject)obj)->options; \
196: for (PetscOptionsObject->count=(PetscOptionsPublish?-1:1); PetscOptionsObject->count<2; PetscOptionsObject->count++) {\
197: PetscErrorCode _5_PetscObjectOptionsBegin_Private(PetscOptionsObject,obj);CHKERRQ(_5_ierr);
199: /*MC
200: PetscOptionsEnd - Ends a set of queries on the options database that are related and should be
201: displayed on the same window of a GUI that allows the user to set the options interactively.
203: Collective on the MPI_Comm used in PetscOptionsBegin()
205: Synopsis:
206: #include <petscoptions.h>
207: PetscErrorCode PetscOptionsEnd(void)
209: Level: intermediate
211: Notes:
212: Needs to be preceded by a call to PetscOptionsBegin() or PetscObjectOptionsBegin()
214: .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
215: PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
216: PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
217: PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
218: PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
219: PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
220: PetscOptionsFList(), PetscOptionsEList(), PetscObjectOptionsBegin()
222: M*/
223: #define PetscOptionsEnd() _5_PetscOptionsEnd_Private(PetscOptionsObject);CHKERRQ(_5_ierr);}} while (0)
225: PETSC_EXTERN PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *,MPI_Comm,const char[],const char[],const char[]);
226: PETSC_EXTERN PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptionItems *,PetscObject);
227: PETSC_EXTERN PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *);
228: PETSC_EXTERN PetscErrorCode PetscOptionsHead(PetscOptionItems *,const char[]);
230: /*MC
231: PetscOptionsTail - Ends a section of options begun with PetscOptionsHead()
232: See, for example, KSPSetFromOptions_GMRES().
234: Collective on the communicator passed in PetscOptionsBegin()
236: Synopsis:
237: #include <petscoptions.h>
238: PetscErrorCode PetscOptionsTail(void)
240: Level: intermediate
242: Notes:
243: Must be between a PetscOptionsBegin()/PetscObjectOptionsBegin() and a PetscOptionsEnd()
245: Must be preceded by a call to PetscOptionsHead() in the same function.
247: This needs to be used only if the code below PetscOptionsTail() can be run ONLY once.
248: See, for example, PCSetFromOptions_Composite(). This is a return(0) in it for early exit
249: from the function.
251: This is only for use with the PETSc options GUI
253: Concepts: options database^subheading
255: .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
256: PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
257: PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
258: PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
259: PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
260: PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum()
261: M*/
262: #define PetscOptionsTail() 0; {if (PetscOptionsObject->count != 1) return(0);}
264: #define PetscOptionsEnum(a,b,c,d,e,f,g) PetscOptionsEnum_Private(PetscOptionsObject,a,b,c,d,e,f,g)
265: #define PetscOptionsInt(a,b,c,d,e,f) PetscOptionsInt_Private(PetscOptionsObject,a,b,c,d,e,f)
266: #define PetscOptionsReal(a,b,c,d,e,f) PetscOptionsReal_Private(PetscOptionsObject,a,b,c,d,e,f)
267: #define PetscOptionsScalar(a,b,c,d,e,f) PetscOptionsScalar_Private(PetscOptionsObject,a,b,c,d,e,f)
268: #define PetscOptionsName(a,b,c,d) PetscOptionsName_Private(PetscOptionsObject,a,b,c,d)
269: #define PetscOptionsString(a,b,c,d,e,f,g) PetscOptionsString_Private(PetscOptionsObject,a,b,c,d,e,f,g)
270: #define PetscOptionsBool(a,b,c,d,e,f) PetscOptionsBool_Private(PetscOptionsObject,a,b,c,d,e,f)
271: #define PetscOptionsBoolGroupBegin(a,b,c,d) PetscOptionsBoolGroupBegin_Private(PetscOptionsObject,a,b,c,d)
272: #define PetscOptionsBoolGroup(a,b,c,d) PetscOptionsBoolGroup_Private(PetscOptionsObject,a,b,c,d)
273: #define PetscOptionsBoolGroupEnd(a,b,c,d) PetscOptionsBoolGroupEnd_Private(PetscOptionsObject,a,b,c,d)
274: #define PetscOptionsFList(a,b,c,d,e,f,g,h) PetscOptionsFList_Private(PetscOptionsObject,a,b,c,d,e,f,g,h)
275: #define PetscOptionsEList(a,b,c,d,e,f,g,h) PetscOptionsEList_Private(PetscOptionsObject,a,b,c,d,e,f,g,h)
276: #define PetscOptionsRealArray(a,b,c,d,e,f) PetscOptionsRealArray_Private(PetscOptionsObject,a,b,c,d,e,f)
277: #define PetscOptionsScalarArray(a,b,c,d,e,f) PetscOptionsScalarArray_Private(PetscOptionsObject,a,b,c,d,e,f)
278: #define PetscOptionsIntArray(a,b,c,d,e,f) PetscOptionsIntArray_Private(PetscOptionsObject,a,b,c,d,e,f)
279: #define PetscOptionsStringArray(a,b,c,d,e,f) PetscOptionsStringArray_Private(PetscOptionsObject,a,b,c,d,e,f)
280: #define PetscOptionsBoolArray(a,b,c,d,e,f) PetscOptionsBoolArray_Private(PetscOptionsObject,a,b,c,d,e,f)
281: #define PetscOptionsEnumArray(a,b,c,d,e,f,g) PetscOptionsEnumArray_Private(PetscOptionsObject,a,b,c,d,e,f,g)
282: #define PetscOptionsDeprecated(a,b,c,d) PetscOptionsDeprecated_Private(PetscOptionsObject,a,b,c,d)
285: PETSC_EXTERN PetscErrorCode PetscOptionsEnum_Private(PetscOptionItems*,const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscBool*);
286: PETSC_EXTERN PetscErrorCode PetscOptionsInt_Private(PetscOptionItems*,const char[],const char[],const char[],PetscInt,PetscInt*,PetscBool*);
287: PETSC_EXTERN PetscErrorCode PetscOptionsReal_Private(PetscOptionItems*,const char[],const char[],const char[],PetscReal,PetscReal*,PetscBool*);
288: PETSC_EXTERN PetscErrorCode PetscOptionsScalar_Private(PetscOptionItems*,const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscBool*);
289: PETSC_EXTERN PetscErrorCode PetscOptionsName_Private(PetscOptionItems*,const char[],const char[],const char[],PetscBool*);
290: PETSC_EXTERN PetscErrorCode PetscOptionsString_Private(PetscOptionItems*,const char[],const char[],const char[],const char[],char*,size_t,PetscBool*);
291: PETSC_EXTERN PetscErrorCode PetscOptionsBool_Private(PetscOptionItems*,const char[],const char[],const char[],PetscBool ,PetscBool*,PetscBool*);
292: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupBegin_Private(PetscOptionItems*,const char[],const char[],const char[],PetscBool*);
293: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroup_Private(PetscOptionItems*,const char[],const char[],const char[],PetscBool*);
294: PETSC_EXTERN PetscErrorCode PetscOptionsBoolGroupEnd_Private(PetscOptionItems*,const char[],const char[],const char[],PetscBool*);
295: PETSC_EXTERN PetscErrorCode PetscOptionsFList_Private(PetscOptionItems*,const char[],const char[],const char[],PetscFunctionList,const char[],char[],size_t,PetscBool*);
296: PETSC_EXTERN PetscErrorCode PetscOptionsEList_Private(PetscOptionItems*,const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscBool*);
297: PETSC_EXTERN PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems*,const char[],const char[],const char[],PetscReal[],PetscInt*,PetscBool*);
298: PETSC_EXTERN PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems*,const char[],const char[],const char[],PetscScalar[],PetscInt*,PetscBool*);
299: PETSC_EXTERN PetscErrorCode PetscOptionsIntArray_Private(PetscOptionItems*,const char[],const char[],const char[],PetscInt[],PetscInt*,PetscBool*);
300: PETSC_EXTERN PetscErrorCode PetscOptionsStringArray_Private(PetscOptionItems*,const char[],const char[],const char[],char*[],PetscInt*,PetscBool*);
301: PETSC_EXTERN PetscErrorCode PetscOptionsBoolArray_Private(PetscOptionItems*,const char[],const char[],const char[],PetscBool [],PetscInt*,PetscBool*);
302: PETSC_EXTERN PetscErrorCode PetscOptionsEnumArray_Private(PetscOptionItems*,const char[],const char[],const char[],const char *const*,PetscEnum[],PetscInt*,PetscBool*);
303: PETSC_EXTERN PetscErrorCode PetscOptionsDeprecated_Private(PetscOptionItems*,const char[],const char[],const char[],const char[]);
306: PETSC_EXTERN PetscErrorCode PetscOptionsSetFromOptions(PetscOptions);
307: PETSC_EXTERN PetscErrorCode PetscOptionsSAWsDestroy(void);
309: PETSC_EXTERN PetscErrorCode PetscObjectAddOptionsHandler(PetscObject,PetscErrorCode (*)(PetscOptionItems*,PetscObject,void*),PetscErrorCode (*)(PetscObject,void*),void*);
310: PETSC_EXTERN PetscErrorCode PetscObjectProcessOptionsHandlers(PetscOptionItems*,PetscObject);
311: PETSC_EXTERN PetscErrorCode PetscObjectDestroyOptionsHandlers(PetscObject);
313: #endif