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