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