xref: /petsc/include/petscoptions.h (revision 74b542b28bb42f38c4ca5f4352f971c4aacef7be)
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 PETSC_EXTERN_CXX_BEGIN
8 
9 extern PetscErrorCode   PetscOptionsHasName(const char[],const char[],PetscBool *);
10 extern PetscErrorCode   PetscOptionsGetInt(const char[],const char [],PetscInt *,PetscBool *);
11 extern PetscErrorCode   PetscOptionsGetBool(const char[],const char [],PetscBool  *,PetscBool *);
12 extern PetscErrorCode   PetscOptionsGetReal(const char[],const char[],PetscReal *,PetscBool *);
13 extern PetscErrorCode   PetscOptionsGetScalar(const char[],const char[],PetscScalar *,PetscBool *);
14 extern PetscErrorCode   PetscOptionsGetIntArray(const char[],const char[],PetscInt[],PetscInt *,PetscBool *);
15 extern PetscErrorCode   PetscOptionsGetRealArray(const char[],const char[],PetscReal[],PetscInt *,PetscBool *);
16 extern PetscErrorCode   PetscOptionsGetBoolArray(const char[],const char[],PetscBool [],PetscInt *,PetscBool *);
17 extern PetscErrorCode   PetscOptionsGetString(const char[],const char[],char[],size_t,PetscBool *);
18 extern PetscErrorCode   PetscOptionsGetStringArray(const char[],const char[],char*[],PetscInt*,PetscBool *);
19 extern PetscErrorCode  PetscOptionsGetEList(const char[],const char[],const char*const*,PetscInt,PetscInt*,PetscBool *);
20 extern PetscErrorCode  PetscOptionsGetEnum(const char[],const char[],const char*const*,PetscEnum*,PetscBool *);
21 extern PetscErrorCode  PetscOptionsValidKey(const char[],PetscBool *);
22 
23 extern PetscErrorCode   PetscOptionsSetAlias(const char[],const char[]);
24 extern PetscErrorCode   PetscOptionsSetValue(const char[],const char[]);
25 extern PetscErrorCode   PetscOptionsClearValue(const char[]);
26 
27 extern PetscErrorCode   PetscOptionsAllUsed(PetscInt*);
28 extern PetscErrorCode   PetscOptionsUsed(const char *,PetscBool*);
29 extern PetscErrorCode   PetscOptionsLeft(void);
30 extern PetscErrorCode   PetscOptionsView(PetscViewer);
31 
32 extern PetscErrorCode   PetscOptionsCreate(void);
33 extern PetscErrorCode   PetscOptionsInsert(int*,char ***,const char[]);
34 extern PetscErrorCode   PetscOptionsInsertFile(MPI_Comm,const char[],PetscBool );
35 #if defined(PETSC_HAVE_YAML)
36 extern PetscErrorCode   PetscOptionsInsertFile_YAML(MPI_Comm,const char[],PetscBool);
37 #endif
38 extern PetscErrorCode   PetscOptionsInsertString(const char[]);
39 extern PetscErrorCode   PetscOptionsDestroy(void);
40 extern PetscErrorCode   PetscOptionsClear(void);
41 extern PetscErrorCode   PetscOptionsPrefixPush(const char[]);
42 extern PetscErrorCode   PetscOptionsPrefixPop(void);
43 
44 extern PetscErrorCode   PetscOptionsReject(const char[],const char[]);
45 extern PetscErrorCode   PetscOptionsGetAll(char*[]);
46 
47 extern PetscErrorCode   PetscOptionsGetenv(MPI_Comm,const char[],char[],size_t,PetscBool  *);
48 extern PetscErrorCode   PetscOptionsStringToInt(const char[],PetscInt*);
49 extern PetscErrorCode   PetscOptionsStringToReal(const char[],PetscReal*);
50 extern PetscErrorCode   PetscOptionsStringToBool(const char[],PetscBool*);
51 
52 extern PetscErrorCode  PetscOptionsMonitorSet(PetscErrorCode (*)(const char[], const char[], void*), void *, PetscErrorCode (*)(void**));
53 extern PetscErrorCode  PetscOptionsMonitorCancel(void);
54 extern PetscErrorCode  PetscOptionsMonitorDefault(const char[], const char[], void *);
55 
56 extern  PetscBool  PetscOptionsPublish;
57 extern  PetscInt   PetscOptionsPublishCount;
58 
59 /*MC
60     PetscOptionsBegin - Begins a set of queries on the options database that are related and should be
61      displayed on the same window of a GUI that allows the user to set the options interactively.
62 
63    Synopsis: PetscErrorCode PetscOptionsBegin(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
64 
65     Collective on MPI_Comm
66 
67   Input Parameters:
68 +   comm - communicator that shares GUI
69 .   prefix - options prefix for all options displayed on window
70 .   title - short descriptive text, for example "Krylov Solver Options"
71 -   mansec - section of manual pages for options, for example KSP
72 
73   Level: intermediate
74 
75   Notes: Needs to be ended by a call the PetscOptionsEnd()
76          Can add subheadings with PetscOptionsHead()
77 
78   Developer notes: PetscOptionsPublish is set in PetscOptionsCheckInitial_Private() with -options_gui. When PetscOptionsPublish is set the
79 $             loop between PetscOptionsBegin() and PetscOptionsEnd() is run THREE times with PetscOptionsPublishCount of values -1,0,1 otherwise
80 $             the loop is run ONCE with a PetscOptionsPublishCount of 1.
81 $             = -1 : The PetscOptionsInt() etc just call the PetscOptionsGetInt() etc
82 $             = 0  : The GUI objects are created in PetscOptionsInt() etc and displayed in PetscOptionsEnd() and the options
83 $                    database updated updated with user changes; PetscOptionsGetInt() etc are also called
84 $             = 1 : The PetscOptionsInt() etc again call the PetscOptionsGetInt() etc (possibly getting new values), in addition the help message and
85 $                   default values are printed if -help was given.
86 $           When PetscOptionsObject.changedmethod is set this causes PetscOptionsPublishCount to be reset to -2 (so in the next loop iteration it is -1)
87 $           and the whole process is repeated. This is to handle when, for example, the KSPType is changed thus changing the list of
88 $           options available so they need to be redisplayed so the user can change the. Chaning PetscOptionsObjects.changedmethod is never
89 $           currently set.
90 
91 
92 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
93           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
94           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
95           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
96           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
97           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
98           PetscOptionsList(), PetscOptionsEList(), PetscObjectOptionsBegin()
99 
100 M*/
101 #define    PetscOptionsBegin(comm,prefix,mess,sec) 0; do {\
102              for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) {\
103              PetscErrorCode _5_ierr = PetscOptionsBegin_Private(comm,prefix,mess,sec);CHKERRQ(_5_ierr);
104 
105 /*MC
106     PetscObjectOptionsBegin - Begins a set of queries on the options database that are related and should be
107      displayed on the same window of a GUI that allows the user to set the options interactively.
108 
109    Synopsis: PetscErrorCode PetscObjectOptionsBegin(PetscObject obj)
110 
111     Collective on PetscObject
112 
113   Input Parameters:
114 .   obj - object to set options for
115 
116   Level: intermediate
117 
118   Notes: Needs to be ended by a call the PetscOptionsEnd()
119          Can add subheadings with PetscOptionsHead()
120 
121 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
122           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
123           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
124           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
125           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
126           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
127           PetscOptionsList(), PetscOptionsEList()
128 
129 M*/
130 #define PetscObjectOptionsBegin(obj) 0; do {                            \
131   for (PetscOptionsPublishCount=(PetscOptionsPublish?-1:1); PetscOptionsPublishCount<2; PetscOptionsPublishCount++) { \
132   PetscErrorCode _5_ierr = PetscObjectOptionsBegin_Private(obj);CHKERRQ(_5_ierr);
133 
134 /*MC
135     PetscOptionsEnd - Ends a set of queries on the options database that are related and should be
136      displayed on the same window of a GUI that allows the user to set the options interactively.
137 
138     Collective on the MPI_Comm used in PetscOptionsBegin()
139 
140    Synopsis: PetscErrorCode PetscOptionsEnd(void)
141 
142   Level: intermediate
143 
144   Notes: Needs to be preceded by a call to PetscOptionsBegin()
145 
146 .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
147           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
148           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
149           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
150           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
151           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
152           PetscOptionsList(), PetscOptionsEList(), PetscObjectOptionsBegin()
153 
154 M*/
155 #define    PetscOptionsEnd() _5_ierr = PetscOptionsEnd_Private();CHKERRQ(_5_ierr);}} while (0)
156 
157 extern PetscErrorCode  PetscOptionsBegin_Private(MPI_Comm,const char[],const char[],const char[]);
158 extern PetscErrorCode  PetscObjectOptionsBegin_Private(PetscObject);
159 extern PetscErrorCode  PetscOptionsEnd_Private(void);
160 extern PetscErrorCode  PetscOptionsHead(const char[]);
161 
162 /*MC
163      PetscOptionsTail - Ends a section of options begun with PetscOptionsHead()
164             See, for example, KSPSetFromOptions_GMRES().
165 
166    Collective on the communicator passed in PetscOptionsBegin()
167 
168    Synopsis: PetscErrorCode PetscOptionsTail(void)
169 
170   Level: intermediate
171 
172    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
173 
174           Must be preceded by a call to PetscOptionsHead() in the same function.
175 
176           This needs to be used only if the code below PetscOptionsTail() can be run ONLY once.
177       See, for example, PCSetFromOptions_Composite(). This is a return(0) in it for early exit
178       from the function.
179 
180           This is only for use with the PETSc options GUI; which does not currently exist.
181 
182    Concepts: options database^subheading
183 
184 .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
185            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
186           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
187           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
188           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
189           PetscOptionsList(), PetscOptionsEList(), PetscOptionsEnum()
190 M*/
191 #define    PetscOptionsTail() 0; {if (PetscOptionsPublishCount != 1) PetscFunctionReturn(0);}
192 
193 extern PetscErrorCode  PetscOptionsEnum(const char[],const char[],const char[],const char *const*,PetscEnum,PetscEnum*,PetscBool *);
194 extern PetscErrorCode  PetscOptionsInt(const char[],const char[],const char[],PetscInt,PetscInt*,PetscBool *);
195 extern PetscErrorCode  PetscOptionsReal(const char[],const char[],const char[],PetscReal,PetscReal*,PetscBool *);
196 extern PetscErrorCode  PetscOptionsScalar(const char[],const char[],const char[],PetscScalar,PetscScalar*,PetscBool *);
197 extern PetscErrorCode  PetscOptionsName(const char[],const char[],const char[],PetscBool *);
198 extern PetscErrorCode  PetscOptionsString(const char[],const char[],const char[],const char[],char*,size_t,PetscBool *);
199 extern PetscErrorCode  PetscOptionsBool(const char[],const char[],const char[],PetscBool ,PetscBool *,PetscBool *);
200 extern PetscErrorCode  PetscOptionsBoolGroupBegin(const char[],const char[],const char[],PetscBool *);
201 extern PetscErrorCode  PetscOptionsBoolGroup(const char[],const char[],const char[],PetscBool *);
202 extern PetscErrorCode  PetscOptionsBoolGroupEnd(const char[],const char[],const char[],PetscBool *);
203 extern PetscErrorCode  PetscOptionsList(const char[],const char[],const char[],PetscFList,const char[],char[],size_t,PetscBool *);
204 extern PetscErrorCode  PetscOptionsEList(const char[],const char[],const char[],const char*const*,PetscInt,const char[],PetscInt*,PetscBool *);
205 extern PetscErrorCode  PetscOptionsRealArray(const char[],const char[],const char[],PetscReal[],PetscInt*,PetscBool *);
206 extern PetscErrorCode  PetscOptionsIntArray(const char[],const char[],const char[],PetscInt[],PetscInt*,PetscBool *);
207 extern PetscErrorCode  PetscOptionsStringArray(const char[],const char[],const char[],char*[],PetscInt*,PetscBool *);
208 extern PetscErrorCode  PetscOptionsBoolArray(const char[],const char[],const char[],PetscBool [],PetscInt*,PetscBool *);
209 
210 extern PetscErrorCode  PetscOptionsSetFromOptions(void);
211 extern PetscErrorCode  PetscOptionsAMSDestroy(void);
212 PETSC_EXTERN_CXX_END
213 
214 /*
215     See manual page for PetscOptionsBegin()
216 */
217 typedef enum {OPTION_INT,OPTION_LOGICAL,OPTION_REAL,OPTION_LIST,OPTION_STRING,OPTION_REAL_ARRAY,OPTION_HEAD,OPTION_INT_ARRAY,OPTION_ELIST,OPTION_LOGICAL_ARRAY,OPTION_STRING_ARRAY} PetscOptionType;
218 typedef struct _n_PetscOptions* PetscOptions;
219 struct _n_PetscOptions {
220   char              *option;
221   char              *text;
222   void              *data;         /* used to hold the default value and then any value it is changed to by GUI */
223   PetscFList        flist;         /* used for available values for PetscOptionsList() */
224   const char *const *list;        /* used for available values for PetscOptionsEList() */
225   char              nlist;         /* number of entries in list */
226   char              *man;
227   size_t            arraylength;   /* number of entries in data in the case that it is an array (of PetscInt etc) */
228   PetscBool         set;           /* the user has changed this value in the GUI */
229   PetscOptionType   type;
230   PetscOptions      next;
231   char              *pman;
232   void              *edata;
233 };
234 
235 typedef struct {
236   PetscOptions     next;
237   char             *prefix,*pprefix;
238   char             *title;
239   MPI_Comm         comm;
240   PetscBool        printhelp,changedmethod,alreadyprinted;
241   PetscObject      object;
242 } PetscOptionsObjectType;
243 #endif
244